Re: [PATCH v1 2/6] x86/tsc: Convert Time Stamp Counter (TSC) value to Always Running Timer (ART)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 17 2023 at 10:54, lakshmi.sowjanya.d@xxxxxxxxx wrote:
>  
> +/*
> + * Converts input TSC to the corresponding ART value using conversion
> + * factors discovered by detect_art().
> + *
> + * Return: 0 on success, -errno on failure.

bool indicating success / fail ?

> + */
> +int convert_tsc_to_art(const struct system_counterval_t *system_counter,
> +		       u64 *art)
> +{
> +	u64 tmp, res, rem;
> +	/* ART = TSC * tsc_to_art_denominator / tsc_to_art_numerator */
> +	struct u32_fract tsc_to_art = {
> +		.numerator = art_to_tsc_denominator,
> +		.denominator = art_to_tsc_numerator,
> +	};

The purpose of this struct is to obfuscate the code, right?

The struct would make sense if a pointer would be handed to some other
function.

> +	if (system_counter->cs != art_related_clocksource)
> +		return -EINVAL;
> +
> +	res = system_counter->cycles - art_to_tsc_offset;
> +	rem = do_div(res, tsc_to_art.denominator);
> +
> +	tmp = rem * tsc_to_art.numerator;
> +	do_div(tmp, tsc_to_art.denominator);
> +	*art = res * tsc_to_art.numerator + tmp;

Yet another copy of the math in convert_art_to_tsc() and in
convert_art_ns_to_tsc(). Seriously?

Can we please have _one_ helper function which takes value, nominator,
denominator as arguments and clean up the copy&pasta instead of adding
more?

Thanks,

        tglx














[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux