bug.h: Add WARN_RATELIMIT
authorJoe Perches <joe@perches.com>
Sat, 21 May 2011 07:48:39 +0000 (07:48 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 23 May 2011 21:37:43 +0000 (17:37 -0400)
Add a generic mechanism to ratelimit WARN(foo, fmt, ...) messages
using a hidden per call site static struct ratelimit_state.

Also add an __WARN_RATELIMIT variant to be able to use a specific
struct ratelimit_state.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/asm-generic/bug.h

index e5a3f58..12b250c 100644 (file)
@@ -165,6 +165,22 @@ extern void warn_slowpath_null(const char *file, const int line);
 #define WARN_ON_RATELIMIT(condition, state)                    \
                WARN_ON((condition) && __ratelimit(state))
 
+#define __WARN_RATELIMIT(condition, state, format...)          \
+({                                                             \
+       int rtn = 0;                                            \
+       if (unlikely(__ratelimit(state)))                       \
+               rtn = WARN(condition, format);                  \
+       rtn;                                                    \
+})
+
+#define WARN_RATELIMIT(condition, format...)                   \
+({                                                             \
+       static DEFINE_RATELIMIT_STATE(_rs,                      \
+                                     DEFAULT_RATELIMIT_INTERVAL,       \
+                                     DEFAULT_RATELIMIT_BURST); \
+       __WARN_RATELIMIT(condition, &_rs, format);              \
+})
+
 /*
  * WARN_ON_SMP() is for cases that the warning is either
  * meaningless for !SMP or may even cause failures.