From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751664AbZJWM6g (ORCPT ); Fri, 23 Oct 2009 08:58:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751487AbZJWM6f (ORCPT ); Fri, 23 Oct 2009 08:58:35 -0400 Received: from mtagate6.uk.ibm.com ([195.212.29.139]:61564 "EHLO mtagate6.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751385AbZJWM6f (ORCPT ); Fri, 23 Oct 2009 08:58:35 -0400 From: Christian Borntraeger Organization: IBM To: Ingo Molnar Subject: Re: [RFC/PATCH] ratelimit: make output more useful Date: Fri, 23 Oct 2009 14:58:11 +0200 User-Agent: KMail/1.12.1 (Linux/2.6.32-rc5-prerelease; KDE/4.3.1; i686; ; ) Cc: Linux Kernel Mailing List , Andrew Morton , Dave Young , Linus Torvalds References: <200910191706.42223.borntraeger@de.ibm.com> <20091023113348.GD5886@elte.hu> In-Reply-To: <20091023113348.GD5886@elte.hu> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200910231458.11832.borntraeger@de.ibm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 CC: Andrew Morton CC: Ingo Molnar CC: Dave Young --- 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 #include #include +#include #include #include @@ -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);