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

[PATCH] x86: Use printk_once() instead of opencoding it


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 10 May 2023 20:33:57 +0100
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>
  • Delivery-date: Wed, 10 May 2023 19:34:26 +0000
  • Ironport-data: A9a23:wWybV6+Nq8Zpenw8ko37DrUDvn6TJUtcMsCJ2f8bNWPcYEJGY0x3m mZKXT2OMq6PamGjf9p0PIu+oUgO7cTQm9I3TAdkrio8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKicYXoZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kI+1BjOkGlA5AdmOKkT5AW2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDklI7 t8gbwocYirTlr3t3paHSLh+ic0aeZyD0IM34hmMzBncBPciB5vCX7/L9ZlT2zJYasJmRKiEI ZBDMHw2MUqGOkcUUrsUIMtWcOOAr3/zaTBH7nmSorI6+TP7xw1tyrn9dtHSf7RmQO0MxhbJ+ T2XpzSR7hcyDN2l8TfCqG2Q3qzyux28cpMIGf6m6as/6LGU7jNKU0BHPbehmtGph0j7V99BJ kg8/is1sbN05EGtVsP6XRCzvDiDpBF0c/h6HvA+6QqN4rHJ+AvfDW8BJhZebPQ2uclwQiYlv neLgtWvAzVsub+UTHu197GIoDf0Mi8QRUcBaDEFS00Z4tDliIA1kh/LCN1kFcaIYsbdQG+qh WrQ9W5n2utV1JRQv0mmwbzZqzS3haCOdB853FXGATm7yj97NZyqbrX9vDA38s18BIqeS1CAu l0NlM6f8P0CAPmxqcCdfAkeNOr3vqjYaVUwlXYqRsB8rGr1pxZPaKgKuFlDyFFV3tHokNMDS Gvaoktv6ZBaJxNGhocnMtvqW6zGIUUNfOkJt8w4jPIUOvCdlyfdpkmCgHJ8OEiy+HXAaYllZ f+mnT+EVB7285hPwjusXPs62rQ23C04zm67bcmln0/4jeHOOiXJE+tt3L6yggcRs8u5TPj9q Y4DZ6NmNT0FOAEBXsUn2dFKdg1bRZTKLZv3t9ZWZoa+H+aSI0l4U6W56ep4K+RYc1F9yr+gE oeVBhUJlzISRBTvdW23V5yUQOqzDM4n9S5hZXBE0JTB8yFLXLtDJZw3L/MfFYTLPsQ6pRKoZ 5Hpo/m9P8k=
  • Ironport-hdrordr: A9a23:XiJNPq9MaMZP3eR45DBuk+DnI+orL9Y04lQ7vn2ZhyYlC/Bw9v re5MjzsCWftN9/YgBEpTntAtjjfZqYz+8X3WBzB9aftWvdyQ+VxehZhOOI/9SjIU3DH4VmpM BdmsZFebvN5JtB4foSIjPULz/t+ra6GWmT69vj8w==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Technically our helper post-dates all of these examples, but it's good cleanup
nevertheless.  None of these examples should be using fully locked
test_and_set_bool() in the first place.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Jun Nakajima <jun.nakajima@xxxxxxxxx>
CC: Kevin Tian <kevin.tian@xxxxxxxxx>
---
 xen/arch/x86/cpu/amd.c     | 22 ++++++++--------------
 xen/arch/x86/hvm/vmx/vmx.c | 18 ++++++------------
 xen/arch/x86/srat.c        |  8 ++------
 xen/arch/x86/time.c        | 19 ++++---------------
 4 files changed, 20 insertions(+), 47 deletions(-)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index caafe4474021..630adead2fc1 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -1061,25 +1061,19 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)
 
                rdmsrl(MSR_AMD64_LS_CFG, value);
                if (!(value & (1 << 15))) {
-                       static bool_t warned;
-
-                       if (c == &boot_cpu_data || opt_cpu_info ||
-                           !test_and_set_bool(warned))
-                               printk(KERN_WARNING
-                                      "CPU%u: Applying workaround for erratum 
793\n",
-                                      smp_processor_id());
+                       if (c == &boot_cpu_data || opt_cpu_info)
+                               printk_once(XENLOG_WARNING
+                                           "CPU%u: Applying workaround for 
erratum 793\n",
+                                           smp_processor_id());
                        wrmsrl(MSR_AMD64_LS_CFG, value | (1 << 15));
                }
        } else if (c->x86 == 0x12) {
                rdmsrl(MSR_AMD64_DE_CFG, value);
                if (!(value & (1U << 31))) {
-                       static bool warned;
-
-                       if (c == &boot_cpu_data || opt_cpu_info ||
-                           !test_and_set_bool(warned))
-                               printk(KERN_WARNING
-                                      "CPU%u: Applying workaround for erratum 
665\n",
-                                      smp_processor_id());
+                       if (c == &boot_cpu_data || opt_cpu_info)
+                               printk_once(XENLOG_WARNING
+                                           "CPU%u: Applying workaround for 
erratum 665\n",
+                                           smp_processor_id());
                        wrmsrl(MSR_AMD64_DE_CFG, value | (1U << 31));
                }
        }
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 096c69251d58..0f392fc0d4fe 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1183,16 +1183,11 @@ static void cf_check vmx_get_segment_register(
      */
     if ( unlikely(!vmx_vmcs_try_enter(v)) )
     {
-        static bool_t warned;
+        printk_once(XENLOG_WARNING "Segment register inaccessible for %pv\n"
+                    "(If you see this outside of debugging activity,"
+                    " please report to xen-devel@xxxxxxxxxxxxxxxxxxxx)\n",
+                    v);
 
-        if ( !warned )
-        {
-            warned = 1;
-            printk(XENLOG_WARNING "Segment register inaccessible for %pv\n"
-                   "(If you see this outside of debugging activity,"
-                   " please report to xen-devel@xxxxxxxxxxxxxxxxxxxx)\n",
-                   v);
-        }
         memset(reg, 0, sizeof(*reg));
         return;
     }
@@ -2301,10 +2296,9 @@ static bool cf_check vmx_test_pir(const struct vcpu *v, 
uint8_t vec)
 static void cf_check vmx_handle_eoi(uint8_t vector, int isr)
 {
     uint8_t old_svi = set_svi(isr);
-    static bool warned;
 
-    if ( vector != old_svi && !test_and_set_bool(warned) )
-        printk(XENLOG_WARNING "EOI for %02x but SVI=%02x\n", vector, old_svi);
+    if ( vector != old_svi )
+        printk_once(XENLOG_WARNING "EOI for %02x but SVI=%02x\n", vector, 
old_svi);
 }
 
 static void cf_check vmx_enable_msr_interception(struct domain *d, uint32_t 
msr)
diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c
index 56749ddca526..3f70338e6e23 100644
--- a/xen/arch/x86/srat.c
+++ b/xen/arch/x86/srat.c
@@ -55,7 +55,6 @@ nodeid_t setup_node(unsigned pxm)
 {
        nodeid_t node;
        unsigned idx;
-       static bool warned;
        static unsigned nodes_found;
 
        BUILD_BUG_ON(MAX_NUMNODES >= NUMA_NO_NODE);
@@ -75,11 +74,8 @@ nodeid_t setup_node(unsigned pxm)
                if (pxm2node[idx].node == NUMA_NO_NODE)
                        goto finish;
 
-       if (!warned) {
-               printk(KERN_WARNING "SRAT: Too many proximity domains (%#x)\n",
-                      pxm);
-               warned = true;
-       }
+       printk_once(XENLOG_WARNING "SRAT: Too many proximity domains (%#x)\n",
+                   pxm);
 
        return NUMA_NO_NODE;
 
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index bc75e1ae7d42..f5e30d4e0236 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -876,13 +876,8 @@ static void cf_check plt_overflow(void *unused)
         plt_stamp64 += plt_mask + 1;
     }
     if ( i != 0 )
-    {
-        static bool warned_once;
-
-        if ( !test_and_set_bool(warned_once) )
-            printk("Platform timer appears to have unexpectedly wrapped "
-                   "%u%s times.\n", i, (i == 10) ? " or more" : "");
-    }
+        printk_once("Platform timer appears to have unexpectedly wrapped "
+                    "%u%s times.\n", i, (i == 10) ? " or more" : "");
 
     spin_unlock_irq(&platform_timer_lock);
 
@@ -2156,14 +2151,8 @@ void init_percpu_time(void)
         }
         else if ( adj != tsc_adjust[socket] )
         {
-            static bool __read_mostly warned;
-
-            if ( !warned )
-            {
-                warned = true;
-                printk(XENLOG_WARNING
-                       "Differing TSC ADJUST values within socket(s) - fixing 
all\n");
-            }
+            printk_once(XENLOG_WARNING
+                        "Differing TSC ADJUST values within socket(s) - fixing 
all\n");
             wrmsrl(MSR_IA32_TSC_ADJUST, tsc_adjust[socket]);
         }
     }

base-commit: 31c65549746179e16cf3f82b694b4b1e0b7545ca
-- 
2.30.2




 


Rackspace

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