linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH] ratelimit: make output more useful
@ 2009-10-19 15:06 Christian Borntraeger
  2009-10-23 11:33 ` Ingo Molnar
  0 siblings, 1 reply; 9+ messages in thread
From: Christian Borntraeger @ 2009-10-19 15:06 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Andrew Morton, Ingo Molnar, Dave Young

Today I got 


[39648.224782] Registered led device: iwl-phy0::TX
[40676.545099] __ratelimit: 246 callbacks suppressed
[40676.545103] abcdef[23675]: segfault at 0 ...

as you can see the ratelimit message contains a function prefix. Since this is 
always __ratelimit, this wont help much. This patch changes __ratelimit and 
printk_ratelimit to print the function name  that calls ratelimit.

Opinions?

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

CC: Andrew Morton <akpm@linux-foundation.org>
CC: Ingo Molnar <mingo@elte.hu>
CC: Dave Young <hidave.darkstar@gmail.com>

 include/linux/kernel.h    |    6 +++++-
 include/linux/ratelimit.h |    3 ++-
 kernel/printk.c           |    9 +--------
 lib/ratelimit.c           |    6 +++---
 4 files changed, 11 insertions(+), 13 deletions(-)

Index: linux-2.6/include/linux/kernel.h
===================================================================
--- linux-2.6.orig/include/linux/kernel.h
+++ linux-2.6/include/linux/kernel.h
@@ -241,8 +241,12 @@ asmlinkage int vprintk(const char *fmt, 
 asmlinkage int printk(const char * fmt, ...)
 	__attribute__ ((format (printf, 1, 2))) __cold;
 
+/*
+ * printk rate limiting, lifted from the networking subsystem.
+ */
 extern struct ratelimit_state printk_ratelimit_state;
-extern int printk_ratelimit(void);
+#define printk_ratelimit() ___ratelimit(&printk_ratelimit_state, __func__)
+
 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
 				   unsigned int interval_msec);
 
Index: linux-2.6/include/linux/ratelimit.h
===================================================================
--- linux-2.6.orig/include/linux/ratelimit.h
+++ linux-2.6/include/linux/ratelimit.h
@@ -16,5 +16,6 @@ struct ratelimit_state {
 #define DEFINE_RATELIMIT_STATE(name, interval, burst)		\
 		struct ratelimit_state name = {interval, burst,}
 
-extern int __ratelimit(struct ratelimit_state *rs);
+extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
+#define __ratelimit(state) ___ratelimit(state, __func__)
 #endif
Index: linux-2.6/kernel/printk.c
===================================================================
--- linux-2.6.orig/kernel/printk.c
+++ linux-2.6/kernel/printk.c
@@ -1369,18 +1369,11 @@ late_initcall(disable_boot_consoles);
 #if defined CONFIG_PRINTK
 
 /*
- * printk rate limiting, lifted from the networking subsystem.
- *
  * This enforces a rate limit: not more than 10 kernel messages
  * every 5s to make a denial-of-service attack impossible.
  */
 DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
-
-int printk_ratelimit(void)
-{
-	return __ratelimit(&printk_ratelimit_state);
-}
-EXPORT_SYMBOL(printk_ratelimit);
+EXPORT_SYMBOL(printk_ratelimit_state);
 
 /**
  * printk_timed_ratelimit - caller-controlled printk ratelimiting
Index: linux-2.6/lib/ratelimit.c
===================================================================
--- linux-2.6.orig/lib/ratelimit.c
+++ linux-2.6/lib/ratelimit.c
@@ -23,7 +23,7 @@ static DEFINE_SPINLOCK(ratelimit_lock);
  * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
  * in every @rs->ratelimit_jiffies
  */
-int __ratelimit(struct ratelimit_state *rs)
+int ___ratelimit(struct ratelimit_state *rs, const char *func)
 {
 	unsigned long flags;
 
@@ -37,7 +37,7 @@ int __ratelimit(struct ratelimit_state *
 	if (time_is_before_jiffies(rs->begin + rs->interval)) {
 		if (rs->missed)
 			printk(KERN_WARNING "%s: %d callbacks suppressed\n",
-				__func__, rs->missed);
+				func, rs->missed);
 		rs->begin = 0;
 		rs->printed = 0;
 		rs->missed = 0;
@@ -54,4 +54,4 @@ print:
 	spin_unlock_irqrestore(&ratelimit_lock, flags);
 	return 1;
 }
-EXPORT_SYMBOL(__ratelimit);
+EXPORT_SYMBOL(___ratelimit);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC/PATCH] ratelimit: make output more useful
  2009-10-19 15:06 [RFC/PATCH] ratelimit: make output more useful Christian Borntraeger
@ 2009-10-23 11:33 ` Ingo Molnar
  2009-10-23 12:58   ` Christian Borntraeger
  0 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2009-10-23 11:33 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Linux Kernel Mailing List, Andrew Morton, Dave Young, Linus Torvalds


* Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> Today I got 
> 
> 
> [39648.224782] Registered led device: iwl-phy0::TX
> [40676.545099] __ratelimit: 246 callbacks suppressed
> [40676.545103] abcdef[23675]: segfault at 0 ...
> 
> as you can see the ratelimit message contains a function prefix. Since this is 
> always __ratelimit, this wont help much. This patch changes __ratelimit and 
> printk_ratelimit to print the function name  that calls ratelimit.
> 
> Opinions?
> 
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> 
> CC: Andrew Morton <akpm@linux-foundation.org>
> CC: Ingo Molnar <mingo@elte.hu>
> CC: Dave Young <hidave.darkstar@gmail.com>
> 
>  include/linux/kernel.h    |    6 +++++-
>  include/linux/ratelimit.h |    3 ++-
>  kernel/printk.c           |    9 +--------
>  lib/ratelimit.c           |    6 +++---
>  4 files changed, 11 insertions(+), 13 deletions(-)
> 
> Index: linux-2.6/include/linux/kernel.h
> ===================================================================
> --- linux-2.6.orig/include/linux/kernel.h
> +++ linux-2.6/include/linux/kernel.h
> @@ -241,8 +241,12 @@ asmlinkage int vprintk(const char *fmt, 
>  asmlinkage int printk(const char * fmt, ...)
>  	__attribute__ ((format (printf, 1, 2))) __cold;
>  
> +/*
> + * printk rate limiting, lifted from the networking subsystem.
> + */
>  extern struct ratelimit_state printk_ratelimit_state;
> -extern int printk_ratelimit(void);
> +#define printk_ratelimit() ___ratelimit(&printk_ratelimit_state, __func__)
> +
>  extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
>  				   unsigned int interval_msec);
>  
> Index: linux-2.6/include/linux/ratelimit.h
> ===================================================================
> --- linux-2.6.orig/include/linux/ratelimit.h
> +++ linux-2.6/include/linux/ratelimit.h
> @@ -16,5 +16,6 @@ struct ratelimit_state {
>  #define DEFINE_RATELIMIT_STATE(name, interval, burst)		\
>  		struct ratelimit_state name = {interval, burst,}
>  
> -extern int __ratelimit(struct ratelimit_state *rs);
> +extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
> +#define __ratelimit(state) ___ratelimit(state, __func__)
>  #endif
> Index: linux-2.6/kernel/printk.c
> ===================================================================
> --- linux-2.6.orig/kernel/printk.c
> +++ linux-2.6/kernel/printk.c
> @@ -1369,18 +1369,11 @@ late_initcall(disable_boot_consoles);
>  #if defined CONFIG_PRINTK
>  
>  /*
> - * printk rate limiting, lifted from the networking subsystem.
> - *
>   * This enforces a rate limit: not more than 10 kernel messages
>   * every 5s to make a denial-of-service attack impossible.
>   */
>  DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
> -
> -int printk_ratelimit(void)
> -{
> -	return __ratelimit(&printk_ratelimit_state);
> -}
> -EXPORT_SYMBOL(printk_ratelimit);
> +EXPORT_SYMBOL(printk_ratelimit_state);
>  
>  /**
>   * printk_timed_ratelimit - caller-controlled printk ratelimiting
> Index: linux-2.6/lib/ratelimit.c
> ===================================================================
> --- linux-2.6.orig/lib/ratelimit.c
> +++ linux-2.6/lib/ratelimit.c
> @@ -23,7 +23,7 @@ static DEFINE_SPINLOCK(ratelimit_lock);
>   * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
>   * in every @rs->ratelimit_jiffies
>   */
> -int __ratelimit(struct ratelimit_state *rs)
> +int ___ratelimit(struct ratelimit_state *rs, const char *func)
>  {
>  	unsigned long flags;
>  
> @@ -37,7 +37,7 @@ int __ratelimit(struct ratelimit_state *
>  	if (time_is_before_jiffies(rs->begin + rs->interval)) {
>  		if (rs->missed)
>  			printk(KERN_WARNING "%s: %d callbacks suppressed\n",
> -				__func__, rs->missed);
> +				func, rs->missed);
>  		rs->begin = 0;
>  		rs->printed = 0;
>  		rs->missed = 0;
> @@ -54,4 +54,4 @@ print:
>  	spin_unlock_irqrestore(&ratelimit_lock, flags);
>  	return 1;
>  }
> -EXPORT_SYMBOL(__ratelimit);
> +EXPORT_SYMBOL(___ratelimit);

Makes quite a bit of sense.

Mind sending it against latest tip:master (or tip:core/printk):

  http://people.redhat.com/mingo/tip.git/README

Which has a couple of ratelimit changes queued up already that collide 
with your patch:

Hunk #1 FAILED at 241.
1 out of 1 hunk FAILED -- rejects in file include/linux/kernel.h
patching file include/linux/ratelimit.h
Hunk #1 FAILED at 16.
1 out of 1 hunk FAILED -- rejects in file include/linux/ratelimit.h
patching file kernel/printk.c
Hunk #1 succeeded at 1357 (offset -12 lines).
patching file lib/ratelimit.c
Hunk #1 succeeded at 20 with fuzz 1 (offset -3 lines).
Hunk #2 FAILED at 34.
Hunk #3 succeeded at 62 with fuzz 2 (offset 8 lines).
1 out of 3 hunks FAILED -- rejects in file lib/ratelimit.c

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC/PATCH] ratelimit: make output more useful
  2009-10-23 11:33 ` Ingo Molnar
@ 2009-10-23 12:58   ` Christian Borntraeger
  2009-10-23 13:11     ` Ingo Molnar
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Christian Borntraeger @ 2009-10-23 12:58 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Linux Kernel Mailing List, Andrew Morton, Dave Young, Linus Torvalds

Am Freitag 23 Oktober 2009 13:33:48 schrieb Ingo Molnar:
> Mind sending it against latest tip:master (or tip:core/printk):
[...]
> Which has a couple of ratelimit changes queued up already that collide
> with your patch:

Sure, something like the following?

[PATCH] ratelimit: make output more useful

Today I got 

[39648.224782] Registered led device: iwl-phy0::TX
[40676.545099] __ratelimit: 246 callbacks suppressed
[40676.545103] abcdef[23675]: segfault at 0 ...

as you can see the ratelimit message contains a function prefix. Since this
is  always __ratelimit, this wont help much. This patch changes __ratelimit
and printk_ratelimit to print the function name  that calls ratelimit.
This will pinpoint the responsible function, as long as not several different 
places call ratelimit with the same ratelimit state at the same time. In that
case we catch only one random function that calls ratelimit after the wait
period.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Ingo Molnar <mingo@elte.hu>
CC: Dave Young <hidave.darkstar@gmail.com>
---
 include/linux/kernel.h    |    7 ++++++-
 include/linux/ratelimit.h |    3 ++-
 kernel/printk.c           |    9 +--------
 lib/ratelimit.c           |    6 +++---
 4 files changed, 12 insertions(+), 13 deletions(-)

Index: tip/include/linux/kernel.h
===================================================================
--- tip.orig/include/linux/kernel.h
+++ tip/include/linux/kernel.h
@@ -16,6 +16,7 @@
 #include <linux/log2.h>
 #include <linux/typecheck.h>
 #include <linux/dynamic_debug.h>
+#include <linux/ratelimit.h>
 #include <asm/byteorder.h>
 #include <asm/bug.h>
 
@@ -332,7 +333,11 @@ asmlinkage int vprintk(const char *fmt, 
 asmlinkage int printk(const char * fmt, ...)
 	__attribute__ ((format (printf, 1, 2))) __cold;
 
-extern int printk_ratelimit(void);
+/*
+ * printk rate limiting, lifted from the networking subsystem.
+ */
+extern struct ratelimit_state printk_ratelimit_state;
+#define printk_ratelimit() ___ratelimit(&printk_ratelimit_state, __func__)
 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
 				   unsigned int interval_msec);
 
Index: tip/include/linux/ratelimit.h
===================================================================
--- tip.orig/include/linux/ratelimit.h
+++ tip/include/linux/ratelimit.h
@@ -25,6 +25,7 @@ struct ratelimit_state {
 		.burst		= burst_init,				\
 	}
 
-extern int __ratelimit(struct ratelimit_state *rs);
+extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
+#define __ratelimit(state) ___ratelimit(state, __func__)
 
 #endif /* _LINUX_RATELIMIT_H */
Index: tip/kernel/printk.c
===================================================================
--- tip.orig/kernel/printk.c
+++ tip/kernel/printk.c
@@ -1370,18 +1370,11 @@ late_initcall(disable_boot_consoles);
 #if defined CONFIG_PRINTK
 
 /*
- * printk rate limiting, lifted from the networking subsystem.
- *
  * This enforces a rate limit: not more than 10 kernel messages
  * every 5s to make a denial-of-service attack impossible.
  */
 DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
-
-int printk_ratelimit(void)
-{
-	return __ratelimit(&printk_ratelimit_state);
-}
-EXPORT_SYMBOL(printk_ratelimit);
+EXPORT_SYMBOL(printk_ratelimit_state);
 
 /**
  * printk_timed_ratelimit - caller-controlled printk ratelimiting
Index: tip/lib/ratelimit.c
===================================================================
--- tip.orig/lib/ratelimit.c
+++ tip/lib/ratelimit.c
@@ -20,7 +20,7 @@
  * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
  * in every @rs->ratelimit_jiffies
  */
-int __ratelimit(struct ratelimit_state *rs)
+int ___ratelimit(struct ratelimit_state *rs, const char *func)
 {
 	unsigned long flags;
 	int ret;
@@ -43,7 +43,7 @@ int __ratelimit(struct ratelimit_state *
 	if (time_is_before_jiffies(rs->begin + rs->interval)) {
 		if (rs->missed)
 			printk(KERN_WARNING "%s: %d callbacks suppressed\n",
-				__func__, rs->missed);
+				func, rs->missed);
 		rs->begin   = 0;
 		rs->printed = 0;
 		rs->missed  = 0;
@@ -59,4 +59,4 @@ int __ratelimit(struct ratelimit_state *
 
 	return ret;
 }
-EXPORT_SYMBOL(__ratelimit);
+EXPORT_SYMBOL(___ratelimit);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC/PATCH] ratelimit: make output more useful
  2009-10-23 12:58   ` Christian Borntraeger
@ 2009-10-23 13:11     ` Ingo Molnar
  2009-10-23 14:51       ` Christian Borntraeger
  2009-10-23 14:55     ` Ingo Molnar
  2009-10-24  1:04     ` [tip:branch?] ratelimit: Make suppressed output messages " tip-bot for Christian Borntraeger
  2 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2009-10-23 13:11 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Linux Kernel Mailing List, Andrew Morton, Dave Young, Linus Torvalds


* Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> Am Freitag 23 Oktober 2009 13:33:48 schrieb Ingo Molnar:
> > Mind sending it against latest tip:master (or tip:core/printk):
> [...]
> > Which has a couple of ratelimit changes queued up already that collide
> > with your patch:
> 
> Sure, something like the following?
> 
> [PATCH] ratelimit: make output more useful
> 
> Today I got 
> 
> [39648.224782] Registered led device: iwl-phy0::TX
> [40676.545099] __ratelimit: 246 callbacks suppressed
> [40676.545103] abcdef[23675]: segfault at 0 ...

btw., an effect of this will be a small amount of extra bloat at every 
callsite of printk_ratelimit(). There's 200 of them kernel-wide, so i 
guess it's OK as all these codepaths are atypical slowpaths already.

	Ingo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC/PATCH] ratelimit: make output more useful
  2009-10-23 13:11     ` Ingo Molnar
@ 2009-10-23 14:51       ` Christian Borntraeger
  0 siblings, 0 replies; 9+ messages in thread
From: Christian Borntraeger @ 2009-10-23 14:51 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Linux Kernel Mailing List, Andrew Morton, Dave Young, Linus Torvalds

Am Freitag 23 Oktober 2009 15:11:14 schrieb Ingo Molnar:
> btw., an effect of this will be a small amount of extra bloat at every
> callsite of printk_ratelimit(). There's 200 of them kernel-wide, so i
> guess it's OK as all these codepaths are atypical slowpaths already.

Well, this patch is definitely no high priority.
Maybe you could keep it in tip for a while and see if somebody complains?

Christian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC/PATCH] ratelimit: make output more useful
  2009-10-23 12:58   ` Christian Borntraeger
  2009-10-23 13:11     ` Ingo Molnar
@ 2009-10-23 14:55     ` Ingo Molnar
  2009-10-23 15:12       ` Christian Borntraeger
  2009-10-24  1:04     ` [tip:branch?] ratelimit: Make suppressed output messages " tip-bot for Christian Borntraeger
  2 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2009-10-23 14:55 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Linux Kernel Mailing List, Andrew Morton, Dave Young, Linus Torvalds


* Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> Index: tip/include/linux/kernel.h
> ===================================================================
> --- tip.orig/include/linux/kernel.h
> +++ tip/include/linux/kernel.h
> @@ -16,6 +16,7 @@
>  #include <linux/log2.h>
>  #include <linux/typecheck.h>
>  #include <linux/dynamic_debug.h>
> +#include <linux/ratelimit.h>
>  #include <asm/byteorder.h>
>  #include <asm/bug.h>
>  

hm, this will cause circular dependencies - see:

 3fff4c4: printk: Remove ratelimit.h from kernel.h

Any reason why it couldnt be pushed inside printk.c? We just need the 
func string - not the pointer pass-in. That would also address some of 
the call-site bloat.

	Ingo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC/PATCH] ratelimit: make output more useful
  2009-10-23 14:55     ` Ingo Molnar
@ 2009-10-23 15:12       ` Christian Borntraeger
  2009-10-23 21:17         ` Joe Perches
  0 siblings, 1 reply; 9+ messages in thread
From: Christian Borntraeger @ 2009-10-23 15:12 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Linux Kernel Mailing List, Andrew Morton, Dave Young, Linus Torvalds

Am Freitag 23 Oktober 2009 16:55:09 schrieb Ingo Molnar:
> Any reason why it couldnt be pushed inside printk.c? We just need the
> func string - not the pointer pass-in. That would also address some of
> the call-site bloat.

Right, I changed that and made the patch a bit simpler. So what about:

[PATCH] ratelimit: make output more useful

Today I got 

[39648.224782] Registered led device: iwl-phy0::TX
[40676.545099] __ratelimit: 246 callbacks suppressed
[40676.545103] abcdef[23675]: segfault at 0 ...

as you can see the ratelimit message contains a function prefix. Since this
is  always __ratelimit, this wont help much. This patch changes __ratelimit
and printk_ratelimit to print the function name  that calls ratelimit.
This will pinpoint the responsible function, as long as not several different 
places call ratelimit with the same ratelimit state at the same time. In that
case we catch only one random function that calls ratelimit after the wait
period.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Ingo Molnar <mingo@elte.hu>
CC: Dave Young <hidave.darkstar@gmail.com>
---
 include/linux/kernel.h    |    3 ++-
 include/linux/ratelimit.h |    3 ++-
 kernel/printk.c           |    6 +++---
 lib/ratelimit.c           |    6 +++---
 4 files changed, 10 insertions(+), 8 deletions(-)

Index: tip/include/linux/kernel.h
===================================================================
--- tip.orig/include/linux/kernel.h
+++ tip/include/linux/kernel.h
@@ -332,7 +332,8 @@ asmlinkage int vprintk(const char *fmt, 
 asmlinkage int printk(const char * fmt, ...)
 	__attribute__ ((format (printf, 1, 2))) __cold;
 
-extern int printk_ratelimit(void);
+extern int __printk_ratelimit(const char *func);
+#define printk_ratelimit() __printk_ratelimit(__func__)
 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
 				   unsigned int interval_msec);
 
Index: tip/include/linux/ratelimit.h
===================================================================
--- tip.orig/include/linux/ratelimit.h
+++ tip/include/linux/ratelimit.h
@@ -25,6 +25,7 @@ struct ratelimit_state {
 		.burst		= burst_init,				\
 	}
 
-extern int __ratelimit(struct ratelimit_state *rs);
+extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
+#define __ratelimit(state) ___ratelimit(state, __func__)
 
 #endif /* _LINUX_RATELIMIT_H */
Index: tip/kernel/printk.c
===================================================================
--- tip.orig/kernel/printk.c
+++ tip/kernel/printk.c
@@ -1377,11 +1377,11 @@ late_initcall(disable_boot_consoles);
  */
 DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
 
-int printk_ratelimit(void)
+int __printk_ratelimit(const char *func)
 {
-	return __ratelimit(&printk_ratelimit_state);
+	return ___ratelimit(&printk_ratelimit_state, func);
 }
-EXPORT_SYMBOL(printk_ratelimit);
+EXPORT_SYMBOL(__printk_ratelimit);
 
 /**
  * printk_timed_ratelimit - caller-controlled printk ratelimiting
Index: tip/lib/ratelimit.c
===================================================================
--- tip.orig/lib/ratelimit.c
+++ tip/lib/ratelimit.c
@@ -20,7 +20,7 @@
  * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
  * in every @rs->ratelimit_jiffies
  */
-int __ratelimit(struct ratelimit_state *rs)
+int ___ratelimit(struct ratelimit_state *rs, const char *func)
 {
 	unsigned long flags;
 	int ret;
@@ -43,7 +43,7 @@ int __ratelimit(struct ratelimit_state *
 	if (time_is_before_jiffies(rs->begin + rs->interval)) {
 		if (rs->missed)
 			printk(KERN_WARNING "%s: %d callbacks suppressed\n",
-				__func__, rs->missed);
+				func, rs->missed);
 		rs->begin   = 0;
 		rs->printed = 0;
 		rs->missed  = 0;
@@ -59,4 +59,4 @@ int __ratelimit(struct ratelimit_state *
 
 	return ret;
 }
-EXPORT_SYMBOL(__ratelimit);
+EXPORT_SYMBOL(___ratelimit);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC/PATCH] ratelimit: make output more useful
  2009-10-23 15:12       ` Christian Borntraeger
@ 2009-10-23 21:17         ` Joe Perches
  0 siblings, 0 replies; 9+ messages in thread
From: Joe Perches @ 2009-10-23 21:17 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Ingo Molnar, Linux Kernel Mailing List, Andrew Morton,
	Dave Young, Linus Torvalds

On Fri, 2009-10-23 at 17:12 +0200, Christian Borntraeger wrote:
> Am Freitag 23 Oktober 2009 16:55:09 schrieb Ingo Molnar:
> > Any reason why it couldnt be pushed inside printk.c? We just need the
> > func string - not the pointer pass-in. That would also address some of
> > the call-site bloat.

[]

> +extern int __printk_ratelimit(const char *func);
> +#define printk_ratelimit() __printk_ratelimit(__func__)

Perhaps check if CONFIG_KALLSYMS is defined and use

%pS ... __builtin_return_address(0) ?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip:branch?] ratelimit: Make suppressed output messages more useful
  2009-10-23 12:58   ` Christian Borntraeger
  2009-10-23 13:11     ` Ingo Molnar
  2009-10-23 14:55     ` Ingo Molnar
@ 2009-10-24  1:04     ` tip-bot for Christian Borntraeger
  2 siblings, 0 replies; 9+ messages in thread
From: tip-bot for Christian Borntraeger @ 2009-10-24  1:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hidave.darkstar, hpa, mingo, torvalds, borntraeger,
	akpm, tglx, mingo

Commit-ID:  5c828713358cb9df8aa174371edcbbb62203a490
Gitweb:     http://git.kernel.org/tip/5c828713358cb9df8aa174371edcbbb62203a490
Author:     Christian Borntraeger <borntraeger@de.ibm.com>
AuthorDate: Fri, 23 Oct 2009 14:58:11 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 23 Oct 2009 17:26:37 +0200

ratelimit: Make suppressed output messages more useful

Today I got:

  [39648.224782] Registered led device: iwl-phy0::TX
  [40676.545099] __ratelimit: 246 callbacks suppressed
  [40676.545103] abcdef[23675]: segfault at 0 ...

as you can see the ratelimit message contains a function prefix.
Since this is always __ratelimit, this wont help much.

This patch changes __ratelimit and printk_ratelimit to print the
function name that calls ratelimit.

This will pinpoint the responsible function, as long as not several
different places call ratelimit with the same ratelimit state at
the same time. In that case we catch only one random function that
calls ratelimit after the wait period.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Dave Young <hidave.darkstar@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
CC: Andrew Morton <akpm@linux-foundation.org>
LKML-Reference: <200910231458.11832.borntraeger@de.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 include/linux/kernel.h    |    3 ++-
 include/linux/ratelimit.h |    3 ++-
 kernel/printk.c           |    6 +++---
 lib/ratelimit.c           |    6 +++---
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3305f33..21d0d82 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -240,7 +240,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 asmlinkage int printk(const char * fmt, ...)
 	__attribute__ ((format (printf, 1, 2))) __cold;
 
-extern int printk_ratelimit(void);
+extern int __printk_ratelimit(const char *func);
+#define printk_ratelimit() __printk_ratelimit(__func__)
 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
 				   unsigned int interval_msec);
 
diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
index 187bc16..668cf1b 100644
--- a/include/linux/ratelimit.h
+++ b/include/linux/ratelimit.h
@@ -25,6 +25,7 @@ struct ratelimit_state {
 		.burst		= burst_init,				\
 	}
 
-extern int __ratelimit(struct ratelimit_state *rs);
+extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
+#define __ratelimit(state) ___ratelimit(state, __func__)
 
 #endif /* _LINUX_RATELIMIT_H */
diff --git a/kernel/printk.c b/kernel/printk.c
index b997c89..8283dbe 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1364,11 +1364,11 @@ late_initcall(disable_boot_consoles);
  */
 DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
 
-int printk_ratelimit(void)
+int __printk_ratelimit(const char *func)
 {
-	return __ratelimit(&printk_ratelimit_state);
+	return ___ratelimit(&printk_ratelimit_state, func);
 }
-EXPORT_SYMBOL(printk_ratelimit);
+EXPORT_SYMBOL(__printk_ratelimit);
 
 /**
  * printk_timed_ratelimit - caller-controlled printk ratelimiting
diff --git a/lib/ratelimit.c b/lib/ratelimit.c
index 5551731..09f5ce1 100644
--- a/lib/ratelimit.c
+++ b/lib/ratelimit.c
@@ -20,7 +20,7 @@
  * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
  * in every @rs->ratelimit_jiffies
  */
-int __ratelimit(struct ratelimit_state *rs)
+int ___ratelimit(struct ratelimit_state *rs, const char *func)
 {
 	unsigned long flags;
 	int ret;
@@ -43,7 +43,7 @@ int __ratelimit(struct ratelimit_state *rs)
 	if (time_is_before_jiffies(rs->begin + rs->interval)) {
 		if (rs->missed)
 			printk(KERN_WARNING "%s: %d callbacks suppressed\n",
-				__func__, rs->missed);
+				func, rs->missed);
 		rs->begin   = 0;
 		rs->printed = 0;
 		rs->missed  = 0;
@@ -59,4 +59,4 @@ int __ratelimit(struct ratelimit_state *rs)
 
 	return ret;
 }
-EXPORT_SYMBOL(__ratelimit);
+EXPORT_SYMBOL(___ratelimit);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-10-24  1:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-19 15:06 [RFC/PATCH] ratelimit: make output more useful Christian Borntraeger
2009-10-23 11:33 ` Ingo Molnar
2009-10-23 12:58   ` Christian Borntraeger
2009-10-23 13:11     ` Ingo Molnar
2009-10-23 14:51       ` Christian Borntraeger
2009-10-23 14:55     ` Ingo Molnar
2009-10-23 15:12       ` Christian Borntraeger
2009-10-23 21:17         ` Joe Perches
2009-10-24  1:04     ` [tip:branch?] ratelimit: Make suppressed output messages " tip-bot for Christian Borntraeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).