From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751859AbcGES04 (ORCPT ); Tue, 5 Jul 2016 14:26:56 -0400 Received: from smtprelay0139.hostedemail.com ([216.40.44.139]:45692 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750962AbcGES0z convert rfc822-to-8bit (ORCPT ); Tue, 5 Jul 2016 14:26:55 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::,RULES_HIT:41:152:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1513:1515:1516:1518:1521:1535:1543:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2897:3138:3139:3140:3141:3142:3167:3355:3622:3865:3866:3867:3871:3872:3874:4321:4605:5007:6261:7576:7875:7903:10004:10400:10848:10967:11026:11232:11473:11658:11914:12043:12291:12296:12438:12517:12519:12555:12683:12740:13095:13869:14181:14659:14721:21080:21212:21220:21325:21433:30005:30029:30045:30054:30056:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: lunch38_1e8da698abb48 X-Filterd-Recvd-Size: 5136 Date: Tue, 5 Jul 2016 14:26:48 -0400 From: Steven Rostedt To: Borislav Petkov Cc: LKML , Andrew Morton , Franck Bui , Greg Kroah-Hartman , Ingo Molnar , Linus Torvalds , Peter Zijlstra , Uwe =?UTF-8?B?S2xlaW5lLUvDtm5pZw==?= Subject: Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Message-ID: <20160705142648.57456ef8@gandalf.local.home> In-Reply-To: <1467642292-15671-2-git-send-email-bp@alien8.de> References: <1467642292-15671-1-git-send-email-bp@alien8.de> <1467642292-15671-2-git-send-email-bp@alien8.de> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 4 Jul 2016 16:24:51 +0200 Borislav Petkov wrote: > From: Borislav Petkov > > Extend the ratelimiting facility to print the amount of suppressed lines > when it is being released. > > Separated from a previous patch by Linus. > > Also, make the ON_RELEASE image not use "callbacks" as it is misleading. > > Signed-off-by: Borislav Petkov > Acked-by: Linus Torvalds > Cc: Andrew Morton > Cc: Franck Bui > Cc: Greg Kroah-Hartman > Cc: Ingo Molnar > Cc: Linus Torvalds > Cc: Peter Zijlstra > Cc: Steven Rostedt > Cc: Uwe Kleine-König > --- > include/linux/ratelimit.h | 36 +++++++++++++++++++++++++++++++----- > lib/ratelimit.c | 6 ++++-- > 2 files changed, 35 insertions(+), 7 deletions(-) > > diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h > index 18102529254e..1d8a17ee8395 100644 > --- a/include/linux/ratelimit.h > +++ b/include/linux/ratelimit.h > @@ -2,11 +2,15 @@ > #define _LINUX_RATELIMIT_H > > #include > +#include > #include > > #define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) > #define DEFAULT_RATELIMIT_BURST 10 > > +/* issue num suppressed message on exit */ > +#define RATELIMIT_MSG_ON_RELEASE BIT(0) > + > struct ratelimit_state { > raw_spinlock_t lock; /* protect the state */ > > @@ -15,6 +19,7 @@ struct ratelimit_state { > int printed; > int missed; > unsigned long begin; > + unsigned long flags; > }; > > #define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \ > @@ -34,12 +39,33 @@ struct ratelimit_state { > static inline void ratelimit_state_init(struct ratelimit_state *rs, > int interval, int burst) > { > + memset(rs, 0, sizeof(*rs)); > + > raw_spin_lock_init(&rs->lock); > - rs->interval = interval; > - rs->burst = burst; > - rs->printed = 0; > - rs->missed = 0; > - rs->begin = 0; > + rs->interval = interval; > + rs->burst = burst; > +} > + > +static inline void ratelimit_default_init(struct ratelimit_state *rs) > +{ > + return ratelimit_state_init(rs, DEFAULT_RATELIMIT_INTERVAL, > + DEFAULT_RATELIMIT_BURST); > +} > + > +static inline void ratelimit_state_exit(struct ratelimit_state *rs) > +{ > + if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) > + return; > + > + if (rs->missed) > + printk(KERN_WARNING "%s: %d output lines suppressed due to ratelimiting\n", > + current->comm, rs->missed); Is the comm important? Maybe add the function that called it? "%pS", _THIS_IP_ Perhaps add __always_inline, as _THIS_IP_ will point into the function that calls this? -- Steve > +} > + > +static inline void > +ratelimit_set_flags(struct ratelimit_state *rs, unsigned long flags) > +{ > + rs->flags = flags; > } > > extern struct ratelimit_state printk_ratelimit_state; > diff --git a/lib/ratelimit.c b/lib/ratelimit.c > index 2c5de86460c5..b753f0cfb00b 100644 > --- a/lib/ratelimit.c > +++ b/lib/ratelimit.c > @@ -46,12 +46,14 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func) > rs->begin = jiffies; > > if (time_is_before_jiffies(rs->begin + rs->interval)) { > - if (rs->missed) > + if (rs->missed && !(rs->flags & RATELIMIT_MSG_ON_RELEASE)) > printk(KERN_WARNING "%s: %d callbacks suppressed\n", > func, rs->missed); > rs->begin = jiffies; > rs->printed = 0; > - rs->missed = 0; > + > + if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) > + rs->missed = 0; > } > if (rs->burst && rs->burst > rs->printed) { > rs->printed++;