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

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


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 12 Jan 2022 10:00:06 +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=99aq0vw8NRqNyBe+YhHkXBIjNUpFYn+VJxKaX72+69Y=; b=NuVIv/FGXKOjUdRh3WqWrjCeK9uM7BqukvQ1K/4hKYzPic5U+OJK7qbEhEH8HqqOlXDHLr8asQXno7AlZoDtjS1LXe7uCDqpKoRjOUmKe94X0J0CngEefsVBCoh715CtpOsdxF9DJbEBbIpE/vdISWhBNSluTkTpvmi4+xgMipIXd6znvKhWKd6VtYiQVKNFHOK4OozBw8QaodaxQPD7bBU0/sPmK5I91EWhW+NiGg0og+xd9yOEulWOHz7yJQdVXMbzDv+h+EuSzblCJAhvMXjZpzAGmy26/8vLF28KhbOebXtqw2B3WsDQqZDxda29fXTOp45g/0EXWxeI95OGXA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hq3Qjt5xNlO0Hu1MOkHgWSeruHkgT0NNR/NQvOzLGUDCrZadtpnYhKL0z756aFcZaj6FeJ8HG/nImGMD0otneNyBRBugxryWWV2ysH7qektcDxdyBUmRgsHM74WVgWDq4yK2mF6N1qvOWLyfq7yXFGT23nx5xfEXqtcT9cJmpqhHCtrU/bjrDrZ2dha8QViqoyfbAnLm19NARXzlOdQRBeR/YmEE5eogFyULfdY2m1R9mU1oqcte6lLb7+1zrLrzFXQQmpqbOB2ahKv/bCjDmEBBySOzM9PKW4OkrpnzQUxdN0A3mTUwIB/ZibJH7Ikkh4wr1PDwvj32mIENp9dtHw==
  • 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>
  • Delivery-date: Wed, 12 Jan 2022 09:00:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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>
---
Arguably the ULL suffix (in write_watchdog_counter()) or the cast to
uint64_t (in div_sc()) aren't really needed in code which gets built for
64-bit only.

--- a/xen/arch/x86/cpu/intel.c
+++ b/xen/arch/x86/cpu/intel.c
@@ -392,9 +392,8 @@ static void intel_log_freq(const struct
             unsigned long long val = ecx;
 
             val *= ebx;
-            do_div(val, eax);
             printk("CPU%u: TSC: %u Hz * %u / %u = %Lu Hz\n",
-                   smp_processor_id(), ecx, ebx, eax, val);
+                   smp_processor_id(), ecx, ebx, eax, val / eax);
         }
         else if ( ecx | eax | ebx )
         {
--- a/xen/arch/x86/hpet.c
+++ b/xen/arch/x86/hpet.c
@@ -105,10 +105,7 @@ custom_param("hpet", parse_hpet_param);
 static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
                                    int shift)
 {
-    uint64_t tmp = ((uint64_t)ticks) << shift;
-
-    do_div(tmp, nsec);
-    return (unsigned long) tmp;
+    return ((uint64_t)ticks << shift) / nsec;
 }
 
 /*
--- a/xen/arch/x86/nmi.c
+++ b/xen/arch/x86/nmi.c
@@ -292,10 +292,9 @@ static void clear_msr_range(unsigned int
 
 static inline void write_watchdog_counter(const char *descr)
 {
-    u64 count = (u64)cpu_khz * 1000;
+    uint64_t count = cpu_khz * 1000ULL / nmi_hz;
 
-    do_div(count, nmi_hz);
-    if(descr)
+    if ( descr )
         Dprintk("setting %s to -%#"PRIx64"\n", descr, count);
     wrmsrl(nmi_perfctr_msr, 0 - count);
 }
--- 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;
     else
@@ -2173,8 +2172,7 @@ void __init early_time_init(void)
     set_time_scale(&t->tsc_scale, tmp);
     t->stamp.local_tsc = boot_tsc_stamp;
 
-    do_div(tmp, 1000);
-    cpu_khz = (unsigned long)tmp;
+    cpu_khz = tmp / 1000;
     printk("Detected %lu.%03lu MHz processor.\n", 
            cpu_khz / 1000, cpu_khz % 1000);
 




 


Rackspace

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