lkml.org 
[lkml]   [2010]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[RFC PATCH] printk_ratelimited: Move definitions to ratelimit.h, use DEFINE_RATELIMIT_STATE
From
Date
On Thu, 2010-02-18 at 15:49 -0800, john stultz wrote:
> On Thu, 2010-02-18 at 15:33 -0800, john stultz wrote:
> > On Thu, 2010-02-18 at 15:23 -0800, Joe Perches wrote:
> > > On Thu, 2010-02-18 at 14:36 -0800, john stultz wrote:
> > > > > Am I missing something obvious, or did something get broken after this went in?
> > > > Ok. Solved it. I needed to #include <linux/ratelimit.h> in the file I
> > > > was adding the printk_ratelimited usage in, rather then where
> > > > printk_ratelimited is defined.
> > > >
> > > > Maybe would it be better to move the printk_ratelimited definitions into
> > > > ratelimit.h so this would be more obvious?
> > >
> > > That's one option.
> > >
> > > Probably the only places I tried it had an
> > > #include <linux/net.h> somewhere which does an
> > > #include <linux/ratelimit.h>
> > >
> > > Personally, I think it'd be better to put
> > > #include <linux/ratelimit.h> back in kernel.h
> > > Commit 3fff4c42bd0a89869a0eb1e7874cc06ffa4aa0f5 removed it.
> >
> > Right, that's what I tried first, but it doesn't build. :)
> >
> > If ratelimit.h has to be included for it to work (which is fine by me),
> > it seems ratelimit.h would be the ideal place to define it.
> >
> > CC'ing Peter to see what his thoughts are.
>
> Sorry, that should have been Ingo I cc'ed. Peter didn't make that
> change.

One possible problem with this is kernel.h needs to be
#included before ratelimit.h.

Maybe ratelimit.h needs to #include <linux/kernel.h>

------

Move the printk_ratelimited and pr_<level>_ratelimited
macro helpers to ratelimit.h

Use DEFINE_RATELIMIT_STATE

Signed-off-by: Joe Perches <joe@perches.com>
---
include/linux/kernel.h | 44 --------------------------------------------
include/linux/ratelimit.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 328bca6..db8e089 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -405,50 +405,6 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
#endif

/*
- * ratelimited messages with local ratelimit_state,
- * no local ratelimit_state used in the !PRINTK case
- */
-#ifdef CONFIG_PRINTK
-#define printk_ratelimited(fmt, ...) ({ \
- static struct ratelimit_state _rs = { \
- .interval = DEFAULT_RATELIMIT_INTERVAL, \
- .burst = DEFAULT_RATELIMIT_BURST, \
- }; \
- \
- if (!__ratelimit(&_rs)) \
- printk(fmt, ##__VA_ARGS__); \
-})
-#else
-/* No effect, but we still get type checking even in the !PRINTK case: */
-#define printk_ratelimited printk
-#endif
-
-#define pr_emerg_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_alert_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_crit_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_err_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_warning_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_notice_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_info_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
-/* no pr_cont_ratelimited, don't do that... */
-/* If you are writing a driver, please use dev_dbg instead */
-#if defined(DEBUG)
-#define pr_debug_ratelimited(fmt, ...) \
- printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
-#else
-#define pr_debug_ratelimited(fmt, ...) \
- ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
- ##__VA_ARGS__); 0; })
-#endif
-
-/*
* General tracing related utility functions - trace_printk(),
* tracing_on/tracing_off and tracing_start()/tracing_stop
*
diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
index 668cf1b..c892373 100644
--- a/include/linux/ratelimit.h
+++ b/include/linux/ratelimit.h
@@ -28,4 +28,48 @@ struct ratelimit_state {
extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
#define __ratelimit(state) ___ratelimit(state, __func__)

+/*
+ * ratelimited messages with local ratelimit_state,
+ * no local ratelimit_state used in the !PRINTK case
+ */
+#ifdef CONFIG_PRINTK
+#define printk_ratelimited(fmt, ...) \
+({ \
+ DEFINE_RATELIMIT_STATE(_rs, \
+ DEFAULT_RATELIMIT_INTERVAL, \
+ DEFAULT_RATELIMIT_BURST); \
+ \
+ if (!__ratelimit(&_rs)) \
+ printk(fmt, ##__VA_ARGS__); \
+})
+#else
+/* No effect, but we still get type checking even in the !PRINTK case: */
+#define printk_ratelimited printk
+#endif
+
+#define pr_emerg_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_alert_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_crit_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_err_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_notice_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+/* no pr_cont_ratelimited, don't do that... */
+/* If you are writing a driver, please use dev_dbg instead */
+#if defined(DEBUG)
+#define pr_debug_ratelimited(fmt, ...) \
+ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#else
+#define pr_debug_ratelimited(fmt, ...) \
+ ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
+ ##__VA_ARGS__); 0; })
+#endif
+
#endif /* _LINUX_RATELIMIT_H */



\
 
 \ /
  Last update: 2010-02-19 01:17    [W:0.046 / U:0.832 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site