diff mbox series

[Xen-devel,v3,1/6] Define WARN_ON_ONCE() macro to mirror Linux functionality

Message ID 20180607234732.20124-2-sameer.goel@linaro.org
State New
Headers show
Series SMMUv3 driver | expand

Commit Message

Sameer Goel June 7, 2018, 11:47 p.m. UTC
Define WARN_ON_ONCE() macro to mirror Linux functionality.

Signed-off-by: Sameer Goel <sameer.goel@linaro.org>
Acked-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/xen.lds.S |  1 +
 xen/arch/x86/xen.lds.S |  1 +
 xen/include/xen/lib.h  | 13 +++++++++++++
 3 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S
index 245a0e0e85..1ef714110a 100644
--- a/xen/arch/arm/xen.lds.S
+++ b/xen/arch/arm/xen.lds.S
@@ -94,6 +94,7 @@  SECTIONS
        __end_schedulers_array = .;
        *(.data.rel)
        *(.data.rel.*)
+       *(.data.cold)
        CONSTRUCTORS
   } :text
 
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 70afedd31d..51d9da2482 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -270,6 +270,7 @@  SECTIONS
        *(.data)
        *(.data.rel)
        *(.data.rel.*)
+       *(.data.cold)
        CONSTRUCTORS
   } :text
 
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 1d9771340c..2bdaf6d60d 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -11,6 +11,19 @@ 
 #define BUG_ON(p)  do { if (unlikely(p)) BUG();  } while (0)
 #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
 
+#define WARN_ON_ONCE(p)                               \
+({                                                    \
+    static bool __section(".data.cold") warned;   \
+    bool ret_warn_once = !!(p);                       \
+                                                      \
+    if ( unlikely(ret_warn_once && !warned) )         \
+    {                                                 \
+        warned = true;                                \
+        WARN();                                       \
+    }                                                 \
+    unlikely(ret_warn_once);                          \
+})
+
 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
 /* Force a compilation error if condition is true */
 #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })