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

Re: [PATCH] x86: replace a few do_div() uses



On 12/01/2022 09:00, Jan Beulich wrote:
> When the macro's "return value" is not used, the macro use can be
> replaced by a simply division, avoiding some obfuscation.
>
> According to my observations, no change to generated code.
>
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

I like this change in principle, but see below.

do_div() needs to be deleted, because it's far too easy screw up.  At a
bare minimum, it should be replaced with a static inline that takes it's
first parameter by pointer, because then at least every callsite reads
correctly in terms of the C language.

> --- a/xen/arch/x86/time.c
> +++ b/xen/arch/x86/time.c
> @@ -610,8 +610,7 @@ static uint64_t xen_timer_cpu_frequency(
>      struct vcpu_time_info *info = &this_cpu(vcpu_info)->time;
>      uint64_t freq;
>  
> -    freq = 1000000000ULL << 32;
> -    do_div(freq, info->tsc_to_system_mul);
> +    freq = (1000000000ULL << 32) / info->tsc_to_system_mul;
>      if ( info->tsc_shift < 0 )
>          freq <<= -info->tsc_shift;

do_div()'s output is consumed here.  I don't think this hunk is safe to
convert.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.