[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] x86: replace a few do_div() uses
- To: Andrew Cooper <amc96@xxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Wed, 12 Jan 2022 10:28:59 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hK7jxMd8QWBPM4jkHaeNyWepghdlEvfCz7HrNcxjCcY=; b=PJZZbZmA1FDbS4Jrsd6Ashi8buFFC8+pzRmQrADoYcOXW/1MHoJg1tPrlYGHq2THfvTxA36zSrMk7dEo1O3D763U4nbyKLEJFdboPq+QQV2teBilSzG71OnudbbpaECtmgCD96ga5ZKZmBC0hsY7xYzCWl5cpkA2LTQ5T6sKwZTtFn0vFk54i4W0Rc29g1DtYYIhh7CaQ4SarQUHOTMFAr944hB/kAyRKcCxsywdsh7CwlaucBHY0L9OT+yPok3nBC5UGOPYmT3L7LN6DKlqrPJBD6J2Mpm2XvT+qrnNAToFIt6vFruuzCFL6nDzZTs0p7NYNPJa+CcUmAmM0G4rKQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lmRLLYv7ZakwgeuXT3mxcc6j8PMXs812Wa6MnoQCa5Fe/a5dWaLrBNz+asd4LYiHrt1W7pPct1ZG7hZO7kbjZtd+KiCoF5fGRkZ7YITzGNCp3OitbVPBboGqv2XHkEtak87fuL8YVDchCTFoZOXiW64u3Qlqn2cDQ4xj/k7uyMuWvs7zLFkOyZjziV/Z8ejs1nlL+iPg5ZIb89KQZ3CgCmbIkSc3ATyfQR2d2Be4pvODd02ptjK987sbTyJEk12KppBmxjLMvSx/iqMC1Ew9Zq5fnqT4Gw3lZxtHM3d8PhFacFZy2BzE6BT9KykRNoJgs9st3Kb6yTgMrpluk54H+w==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Wed, 12 Jan 2022 09:45:30 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 12.01.2022 10:22, Andrew Cooper wrote:
> 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.
That ought to be a 2nd step, requiring agreement with Arm folks (and
adjustments to their code).
>> --- 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.
If by "output" you mean its "return value", then it clearly isn't
consumed. And I continue to think that I did express correctly the
effect do_div() did have on "freq".
Jan
|