Skip to contentSkip to conversation

xen/lib: Introduce printk_once() and replace some opencoded examples

PATCH In review Andrew Cooper 3 participants 5 messages May 17, 2019 – May 31, 2019 Arm/Zynq architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xen/lib: Introduce printk_once() and replace some opencoded examples

Reflow the ZynqMP message for grepability, and fix the omission of a newline.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/arm/cpuerrata.c               | 18 ++----------------
 xen/arch/arm/platforms/xilinx-zynqmp.c |  9 ++-------
 xen/include/xen/lib.h                  | 11 +++++++++++
 3 files changed, 15 insertions(+), 23 deletions(-)
xen/arch/arm/cpuerrata.c +2 -16
index 4431b24..8904939 100644
@@ -336,18 +336,11 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)
     switch ( ssbd_state )
     {
     case ARM_SSBD_FORCE_DISABLE:
-    {
-        static bool once = true;
-
-        if ( once )
-            printk("%s disabled from command-line\n", entry->desc);
-        once = false;
+        printk_once("%s disabled from command-line\n", entry->desc);
 
         arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 0, NULL);
         required = false;
-
         break;
-    }
 
     case ARM_SSBD_RUNTIME:
         if ( required )
@@ -359,18 +352,11 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)
         break;
 
     case ARM_SSBD_FORCE_ENABLE:
-    {
-        static bool once = true;
-
-        if ( once )
-            printk("%s forced from command-line\n", entry->desc);
-        once = false;
+        printk_once("%s forced from command-line\n", entry->desc);
 
         arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 1, NULL);
         required = true;
-
         break;
-    }
 
     default:
         ASSERT_UNREACHABLE();
xen/arch/arm/platforms/xilinx-zynqmp.c +2 -7
index 08e3e11..3060d79 100644
@@ -35,14 +35,9 @@ static bool zynqmp_smc(struct cpu_user_regs *regs)
      */
     if ( !cpus_have_const_cap(ARM_SMCCC_1_1) )
     {
-        static bool once = true;
+        printk_once(XENLOG_WARNING
+                    "ZynqMP firmware Error: no SMCCC 1.1 support. Disabling firmware calls\n");
 
-        if ( once )
-        {
-            printk(XENLOG_WARNING "ZynqMP firmware Error: no SMCCC 1.1 "
-                   "support. Disabling firmware calls.");
-            once = false;
-        }
         return false;
     }
     return zynqmp_eemi(regs);
xen/include/xen/lib.h +11 -0
index 91ed56c..ce231c5 100644
@@ -105,6 +105,17 @@ debugtrace_printk(const char *fmt, ...) {}
 #define _p(_x) ((void *)(unsigned long)(_x))
 extern void printk(const char *format, ...)
     __attribute__ ((format (printf, 1, 2)));
+
+#define printk_once(fmt, args...)               \
+({                                              \
+    static bool __read_mostly once_;            \
+    if ( unlikely(!once_) )                     \
+    {                                           \
+        once_ = true;                           \
+        printk(fmt, ## args);                   \
+    }                                           \
+})
+
 extern void guest_printk(const struct domain *d, const char *format, ...)
     __attribute__ ((format (printf, 2, 3)));
 extern void noreturn panic(const char *format, ...)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 2/2 x86/mpparse: Don't print "limit reached" for every subsequent processor

When you boot Xen with the default 256 NR_CPUS, on a box with rather more processors, the resulting spew is unnecesserily verbose. Instead, print the message once, e.g:

(XEN) ACPI: X2APIC (apic_id[0x115] uid[0x115] enabled)
(XEN) WARNING: NR_CPUS limit of 256 reached - ignoring further processors (XEN) ACPI: X2APIC (apic_id[0x119] uid[0x119] enabled)
(XEN) ACPI: X2APIC (apic_id[0x11d] uid[0x11d] enabled)
(XEN) ACPI: X2APIC (apic_id[0x121] uid[0x121] enabled)

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/mpparse.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/mpparse.c +5 -4
index 16c93a9..f057d91 100644
@@ -157,15 +157,16 @@ static int MP_processor_info_x(struct mpc_config_processor *m,
 	set_apicid(apicid, &phys_cpu_present_map);
 
 	if (num_processors >= nr_cpu_ids) {
-		printk(KERN_WARNING "WARNING: NR_CPUS limit of %u reached."
-			"  Processor ignored.\n", nr_cpu_ids);
+		printk_once(XENLOG_WARNING
+			    "WARNING: NR_CPUS limit of %u reached - ignoring further processors\n",
+			    nr_cpu_ids);
 		return -ENOSPC;
 	}
 
 	if (num_processors >= 8 && hotplug
 	    && genapic.name == apic_default.name) {
-		printk(KERN_WARNING "WARNING: CPUs limit of 8 reached."
-			" Processor ignored.\n");
+		printk_once(XENLOG_WARNING
+			    "WARNING: CPUs limit of 8 reached - ignoring futher processors\n");
 		return -ENOSPC;
 	}
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] x86/mpparse: Don't print "limit reached" for every subsequent processor

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 17.05.19 at 20:58, <[email protected]> wrote:

When you boot Xen with the default 256 NR_CPUS, on a box with rather more processors, the resulting spew is unnecesserily verbose. Instead, print the message once, e.g:

Quoted 7 lines

(XEN) ACPI: X2APIC (apic_id[0x115] uid[0x115] enabled)
(XEN) WARNING: NR_CPUS limit of 256 reached - ignoring further processors (XEN) ACPI: X2APIC (apic_id[0x119] uid[0x119] enabled)
(XEN) ACPI: X2APIC (apic_id[0x11d] uid[0x11d] enabled)
(XEN) ACPI: X2APIC (apic_id[0x121] uid[0x121] enabled)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/2
#3 lore raw
In reply to Andrew Cooper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 17.05.19 at 20:58, <[email protected]> wrote:

Reflow the ZynqMP message for grepability, and fix the omission of a newline.

with two remarks:

Quoted 6 lines
xen/include/xen/lib.h +0 -0
@@ -105,6 +105,17 @@ debugtrace_printk(const char *fmt, ...) {}
 #define _p(_x) ((void *)(unsigned long)(_x))
 extern void printk(const char *format, ...)
     __attribute__ ((format (printf, 1, 2)));

xen/include/xen/lib.h debugtrace_printk(const char *fmt, ...) {} · line 117

Quoted 10 lines
xen/include/xen/lib.h +10 -0
+
+#define printk_once(fmt, args...)               \
+({                                              \
+    static bool __read_mostly once_;            \
+    if ( unlikely(!once_) )                     \
+    {                                           \
+        once_ = true;                           \
+        printk(fmt, ## args);                   \
+    }                                           \
+})

Just like Linux we accept this having a small race window, i.e. it not truly being "once" in unlikely cases. I think it would be worthwhile to make this intention explicit in the commit message.

Unlike Linux'es the macro doesn't have a "return value". Is this intentional? I view this as particularly useful for the WARN_ONCE() sort-of counterpart, but I have to admit I can't immediately see a good use here, so I'm largely curious. (The 2 uses I could find in x86-specific code in Linux look to me like they'd better be WARN_ONCE().)

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/2
#4 lore raw
In reply to Andrew Cooper

Hi Andrew,

Quoted 3 lines · Andrew Cooper

Reflow the ZynqMP message for grepability, and fix the omission of a newline.

Regardless Jan's comment:

I will let Jan/You to commit the patch.

Cheers,

Quoted 100 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
  xen/arch/arm/cpuerrata.c               | 18 ++----------------
  xen/arch/arm/platforms/xilinx-zynqmp.c |  9 ++-------
  xen/include/xen/lib.h                  | 11 +++++++++++
  3 files changed, 15 insertions(+), 23 deletions(-)
xen/arch/arm/cpuerrata.c +2 -16
index 4431b24..8904939 100644
@@ -336,18 +336,11 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)
      switch ( ssbd_state )
      {
      case ARM_SSBD_FORCE_DISABLE:
-    {
-        static bool once = true;
-
-        if ( once )
-            printk("%s disabled from command-line\n", entry->desc);
-        once = false;
+        printk_once("%s disabled from command-line\n", entry->desc);
 
          arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 0, NULL);
          required = false;
-
          break;
-    }
 
      case ARM_SSBD_RUNTIME:
          if ( required )
@@ -359,18 +352,11 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)
          break;
 
      case ARM_SSBD_FORCE_ENABLE:
-    {
-        static bool once = true;
-
-        if ( once )
-            printk("%s forced from command-line\n", entry->desc);
-        once = false;
+        printk_once("%s forced from command-line\n", entry->desc);
 
          arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 1, NULL);
          required = true;
-
          break;
-    }
 
      default:
          ASSERT_UNREACHABLE();
xen/arch/arm/platforms/xilinx-zynqmp.c +2 -7
index 08e3e11..3060d79 100644
@@ -35,14 +35,9 @@ static bool zynqmp_smc(struct cpu_user_regs *regs)
       */
      if ( !cpus_have_const_cap(ARM_SMCCC_1_1) )
      {
-        static bool once = true;
+        printk_once(XENLOG_WARNING
+                    "ZynqMP firmware Error: no SMCCC 1.1 support. Disabling firmware calls\n");
 
-        if ( once )
-        {
-            printk(XENLOG_WARNING "ZynqMP firmware Error: no SMCCC 1.1 "
-                   "support. Disabling firmware calls.");
-            once = false;
-        }
          return false;
      }
      return zynqmp_eemi(regs);
xen/include/xen/lib.h +11 -0
index 91ed56c..ce231c5 100644
@@ -105,6 +105,17 @@ debugtrace_printk(const char *fmt, ...) {}
  #define _p(_x) ((void *)(unsigned long)(_x))
  extern void printk(const char *format, ...)
      __attribute__ ((format (printf, 1, 2)));
+
+#define printk_once(fmt, args...)               \
+({                                              \
+    static bool __read_mostly once_;            \
+    if ( unlikely(!once_) )                     \
+    {                                           \
+        once_ = true;                           \
+        printk(fmt, ## args);                   \
+    }                                           \
+})
+
  extern void guest_printk(const struct domain *d, const char *format, ...)
      __attribute__ ((format (printf, 2, 3)));
  extern void noreturn panic(const char *format, ...)
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel