Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1436552 > unrolled thread
| Started by | Borislav Petkov <bp@alien8.de> |
|---|---|
| First post | 2016-07-04 16:30 +0200 |
| Last post | 2016-07-06 17:00 +0200 |
| Articles | 17 — 5 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Borislav Petkov <bp@alien8.de> - 2016-07-04 16:30 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Steven Rostedt <rostedt@goodmis.org> - 2016-07-05 20:30 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Borislav Petkov <bp@alien8.de> - 2016-07-05 20:50 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Steven Rostedt <rostedt@goodmis.org> - 2016-07-05 21:00 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Borislav Petkov <bp@alien8.de> - 2016-07-05 21:50 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Steven Rostedt <rostedt@goodmis.org> - 2016-07-05 22:00 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Joe Perches <joe@perches.com> - 2016-07-05 22:10 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Christian Borntraeger <borntraeger@de.ibm.com> - 2016-07-05 23:00 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Paolo Bonzini <pbonzini@redhat.com> - 2016-07-05 23:20 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Christian Borntraeger <borntraeger@de.ibm.com> - 2016-07-05 23:30 +0200
Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release Borislav Petkov <bp@alien8.de> - 2016-07-05 23:40 +0200
[PATCH -v3.1 1/2] ratelimit: Extend to print suppressed messages on release Borislav Petkov <bp@alien8.de> - 2016-07-06 15:30 +0200
Re: [PATCH -v3.1 1/2] ratelimit: Extend to print suppressed messages on release Steven Rostedt <rostedt@goodmis.org> - 2016-07-06 15:50 +0200
[PATCH -v3.2 1/2] ratelimit: Extend to print suppressed messages on release Borislav Petkov <bp@alien8.de> - 2016-07-06 17:00 +0200
Re: [PATCH -v3.2 1/2] ratelimit: Extend to print suppressed messages on release Steven Rostedt <rostedt@goodmis.org> - 2016-07-07 03:20 +0200
Re: [PATCH -v3.2 1/2] ratelimit: Extend to print suppressed messages on release Borislav Petkov <bp@alien8.de> - 2016-07-07 07:40 +0200
Re: [PATCH -v3.1 1/2] ratelimit: Extend to print suppressed messages on release Joe Perches <joe@perches.com> - 2016-07-06 17:00 +0200
| From | Borislav Petkov <bp@alien8.de> |
|---|---|
| Date | 2016-07-04 16:30 +0200 |
| Subject | [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRd2N-6Kd-11@gated-at.bofh.it> |
From: Borislav Petkov <bp@suse.de>
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 <bp@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Franck Bui <fbui@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
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 <linux/param.h>
+#include <linux/sched.h>
#include <linux/spinlock.h>
#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);
+}
+
+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++;
--
2.7.3
[toc] | [next] | [standalone]
| From | Steven Rostedt <rostedt@goodmis.org> |
|---|---|
| Date | 2016-07-05 20:30 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRDgC-6pN-15@gated-at.bofh.it> |
| In reply to | #1436552 |
On Mon, 4 Jul 2016 16:24:51 +0200
Borislav Petkov <bp@alien8.de> wrote:
> From: Borislav Petkov <bp@suse.de>
>
> 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 <bp@suse.de>
> Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Franck Bui <fbui@suse.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> 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 <linux/param.h>
> +#include <linux/sched.h>
> #include <linux/spinlock.h>
>
> #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++;
[toc] | [prev] | [next] | [standalone]
| From | Borislav Petkov <bp@alien8.de> |
|---|---|
| Date | 2016-07-05 20:50 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRDzX-6xV-9@gated-at.bofh.it> |
| In reply to | #1437225 |
On Tue, Jul 05, 2016 at 02:26:48PM -0400, Steven Rostedt wrote:
> > + if (rs->missed)
> > + printk(KERN_WARNING "%s: %d output lines suppressed due to ratelimiting\n",
> > + current->comm, rs->missed);
>
> Is the comm important?
Yes, we wanna dump the task name which called devkmsg_release().
> 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?
That would inadvertently be devkmsg_release() in this use case. But
we want to dump the task name which opened and spat so much crap into
/dev/kmsg so as to cause the ratelimiting to hit.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
[toc] | [prev] | [next] | [standalone]
| From | Steven Rostedt <rostedt@goodmis.org> |
|---|---|
| Date | 2016-07-05 21:00 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRDJD-6BU-21@gated-at.bofh.it> |
| In reply to | #1437230 |
On Tue, 5 Jul 2016 20:45:17 +0200 Borislav Petkov <bp@alien8.de> wrote: > On Tue, Jul 05, 2016 at 02:26:48PM -0400, Steven Rostedt wrote: > > > + if (rs->missed) > > > + printk(KERN_WARNING "%s: %d output lines suppressed due to ratelimiting\n", > > > + current->comm, rs->missed); > > > > Is the comm important? > > Yes, we wanna dump the task name which called devkmsg_release(). > > > 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? > > That would inadvertently be devkmsg_release() in this use case. But > we want to dump the task name which opened and spat so much crap into > /dev/kmsg so as to cause the ratelimiting to hit. > Perhaps we should show both, unless you don't think this will ever be used by anything other than devkmsg? -- Steve
[toc] | [prev] | [next] | [standalone]
| From | Borislav Petkov <bp@alien8.de> |
|---|---|
| Date | 2016-07-05 21:50 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rREw1-7cF-7@gated-at.bofh.it> |
| In reply to | #1437233 |
On Tue, Jul 05, 2016 at 02:57:32PM -0400, Steven Rostedt wrote:
> Perhaps we should show both, unless you don't think this will ever be
> used by anything other than devkmsg?
I'd say let's do it only when we go down that road and start using it
for something else.
Because, for example, the ratelimiting thing is, in fact, generic but it
is used primarily to ratelimit printks. Even though it could be used for
something else, theoretically...
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
[toc] | [prev] | [next] | [standalone]
| From | Steven Rostedt <rostedt@goodmis.org> |
|---|---|
| Date | 2016-07-05 22:00 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rREFI-7gf-31@gated-at.bofh.it> |
| In reply to | #1437243 |
On Tue, 5 Jul 2016 21:42:45 +0200 Borislav Petkov <bp@alien8.de> wrote: > On Tue, Jul 05, 2016 at 02:57:32PM -0400, Steven Rostedt wrote: > > Perhaps we should show both, unless you don't think this will ever be > > used by anything other than devkmsg? > > I'd say let's do it only when we go down that road and start using it > for something else. > > Because, for example, the ratelimiting thing is, in fact, generic but it > is used primarily to ratelimit printks. Even though it could be used for > something else, theoretically... > But you know... Build it and they will come. OK, I'm fine then. -- Steve
[toc] | [prev] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2016-07-05 22:10 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rREPn-7zl-1@gated-at.bofh.it> |
| In reply to | #1437249 |
On Tue, 2016-07-05 at 15:49 -0400, Steven Rostedt wrote:
> On Tue, 5 Jul 2016 21:42:45 +0200 Borislav Petkov <bp@alien8.de> wrote:
> > On Tue, Jul 05, 2016 at 02:57:32PM -0400, Steven Rostedt wrote:
> > > Perhaps we should show both, unless you don't think this will ever be
> > > used by anything other than devkmsg?
> > I'd say let's do it only when we go down that road and start using it
> > for something else.
> >
> > Because, for example, the ratelimiting thing is, in fact, generic but it
> > is used primarily to ratelimit printks. Even though it could be used for
> > something else, theoretically...
> >
> But you know... Build it and they will come.
arch/s390/kvm/kvm-s390.c: ratelimit_state_init(&kvm->arch.sthyi_limit, 5 * HZ, 500);
As far as I know, _ratelimit is used for non-printk purposes in
arch/s390/kvm/sthyi.c
int handle_sthyi(struct kvm_vcpu *vcpu)
{
int reg1, reg2, r = 0;
u64 code, addr, cc = 0;
struct sthyi_sctns *sctns = NULL;
/*
* STHYI requires extensive locking in the higher hypervisors
* and is very computational/memory expensive. Therefore we
* ratelimit the executions per VM.
*/
if (!__ratelimit(&vcpu->kvm->arch.sthyi_limit)) {
kvm_s390_retry_instr(vcpu);
return 0;
}
[toc] | [prev] | [next] | [standalone]
| From | Christian Borntraeger <borntraeger@de.ibm.com> |
|---|---|
| Date | 2016-07-05 23:00 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRFBM-7Sm-9@gated-at.bofh.it> |
| In reply to | #1437251 |
On 07/05/2016 10:08 PM, Joe Perches wrote:
> On Tue, 2016-07-05 at 15:49 -0400, Steven Rostedt wrote:
>> On Tue, 5 Jul 2016 21:42:45 +0200 Borislav Petkov <bp@alien8.de> wrote:
>>> On Tue, Jul 05, 2016 at 02:57:32PM -0400, Steven Rostedt wrote:
>>>> Perhaps we should show both, unless you don't think this will ever be
>>>> used by anything other than devkmsg?
>>> I'd say let's do it only when we go down that road and start using it
>>> for something else.
>>>
>>> Because, for example, the ratelimiting thing is, in fact, generic but it
>>> is used primarily to ratelimit printks. Even though it could be used for
>>> something else, theoretically...
>>>
>> But you know... Build it and they will come.
>
> arch/s390/kvm/kvm-s390.c: ratelimit_state_init(&kvm->arch.sthyi_limit, 5 * HZ, 500);
>
> As far as I know, _ratelimit is used for non-printk purposes in
> arch/s390/kvm/sthyi.c
>
> int handle_sthyi(struct kvm_vcpu *vcpu)
> {
> int reg1, reg2, r = 0;
> u64 code, addr, cc = 0;
> struct sthyi_sctns *sctns = NULL;
>
> /*
> * STHYI requires extensive locking in the higher hypervisors
> * and is very computational/memory expensive. Therefore we
> * ratelimit the executions per VM.
> */
> if (!__ratelimit(&vcpu->kvm->arch.sthyi_limit)) {
> kvm_s390_retry_instr(vcpu);
> return 0;
> }
Yes, this is new in next. As far as I can see, the new message would only
appear if we would call ratelimit_state_exit. Correct? We do not call this -
I assume this is ok?
We really only want to reuse the rate limit base code (to avoid writing the same
code twice) and being in lib indicated that this can indeed be used outside
printk.
Now: your patch 1 would allow me to get rid of the messages completely
by setting the flag and by not calling ratelimit_state_exit. Which is probably
what we should do in our code.
Christian
[toc] | [prev] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2016-07-05 23:20 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRFV7-8fV-1@gated-at.bofh.it> |
| In reply to | #1437278 |
On 05/07/2016 22:53, Christian Borntraeger wrote: > Yes, this is new in next. As far as I can see, the new message would only > appear if we would call ratelimit_state_exit. Correct? We do not call this - > I assume this is ok? > > We really only want to reuse the rate limit base code (to avoid writing the same > code twice) and being in lib indicated that this can indeed be used outside > printk. > Now: your patch 1 would allow me to get rid of the messages completely > by setting the flag and by not calling ratelimit_state_exit. Which is probably > what we should do in our code. Can we delay fixing this after the code is merged in Linus's tree? Paolo
[toc] | [prev] | [next] | [standalone]
| From | Christian Borntraeger <borntraeger@de.ibm.com> |
|---|---|
| Date | 2016-07-05 23:30 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRG4N-8lJ-3@gated-at.bofh.it> |
| In reply to | #1437289 |
On 07/05/2016 11:14 PM, Paolo Bonzini wrote: > > > On 05/07/2016 22:53, Christian Borntraeger wrote: >> Yes, this is new in next. As far as I can see, the new message would only >> appear if we would call ratelimit_state_exit. Correct? We do not call this - >> I assume this is ok? >> >> We really only want to reuse the rate limit base code (to avoid writing the same >> code twice) and being in lib indicated that this can indeed be used outside >> printk. >> Now: your patch 1 would allow me to get rid of the messages completely >> by setting the flag and by not calling ratelimit_state_exit. Which is probably >> what we should do in our code. > > Can we delay fixing this after the code is merged in Linus's tree? Absolutely. We already have 2 smaller conflicts in next and I certainly do not want to add another one. The current ratelimit print does not hurt - it is just not necessary for us. so my statement was just a "statement of direction" to write some IBM speak ;-)
[toc] | [prev] | [next] | [standalone]
| From | Borislav Petkov <bp@alien8.de> |
|---|---|
| Date | 2016-07-05 23:40 +0200 |
| Subject | Re: [PATCH -v3 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRGet-8pR-15@gated-at.bofh.it> |
| In reply to | #1437278 |
On Tue, Jul 05, 2016 at 10:53:55PM +0200, Christian Borntraeger wrote:
> Yes, this is new in next. As far as I can see, the new message would only
> appear if we would call ratelimit_state_exit. Correct? We do not call this -
> I assume this is ok?
Right, the idea for the /dev/kmsg use case was to issue the suppressed
count only when we release the ratelimit state.
> We really only want to reuse the rate limit base code (to avoid writing the same
> code twice) and being in lib indicated that this can indeed be used outside
> printk.
> Now: your patch 1 would allow me to get rid of the messages completely
> by setting the flag and by not calling ratelimit_state_exit. Which is probably
> what we should do in our code.
Yeah, that should work for your usecase.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
[toc] | [prev] | [next] | [standalone]
| From | Borislav Petkov <bp@alien8.de> |
|---|---|
| Date | 2016-07-06 15:30 +0200 |
| Subject | [PATCH -v3.1 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRV3Q-1jb-21@gated-at.bofh.it> |
| In reply to | #1436552 |
From: Borislav Petkov <bp@suse.de>
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 <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Franck Bui <fbui@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
v3.1: Simplify testing of !RATELIMIT_MSG_ON_RELEASE in ___ratelimit()
include/linux/ratelimit.h | 36 +++++++++++++++++++++++++++++++-----
lib/ratelimit.c | 15 +++++++++------
2 files changed, 40 insertions(+), 11 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 <linux/param.h>
+#include <linux/sched.h>
#include <linux/spinlock.h>
#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);
+}
+
+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..734cba5c8842 100644
--- a/lib/ratelimit.c
+++ b/lib/ratelimit.c
@@ -46,12 +46,15 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
rs->begin = jiffies;
if (time_is_before_jiffies(rs->begin + rs->interval)) {
- if (rs->missed)
- printk(KERN_WARNING "%s: %d callbacks suppressed\n",
- func, rs->missed);
- rs->begin = jiffies;
- rs->printed = 0;
- rs->missed = 0;
+ if (rs->missed) {
+ if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) {
+ pr_warn("%s: %d callbacks suppressed\n", func, rs->missed);
+ rs->missed = 0;
+ }
+
+ rs->begin = jiffies;
+ rs->printed = 0;
+ }
}
if (rs->burst && rs->burst > rs->printed) {
rs->printed++;
--
2.7.3
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
[toc] | [prev] | [next] | [standalone]
| From | Steven Rostedt <rostedt@goodmis.org> |
|---|---|
| Date | 2016-07-06 15:50 +0200 |
| Subject | Re: [PATCH -v3.1 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRVnc-1pJ-7@gated-at.bofh.it> |
| In reply to | #1437721 |
On Wed, 6 Jul 2016 15:28:00 +0200
Borislav Petkov <bp@alien8.de> wrote:
> extern struct ratelimit_state printk_ratelimit_state;
> diff --git a/lib/ratelimit.c b/lib/ratelimit.c
> index 2c5de86460c5..734cba5c8842 100644
> --- a/lib/ratelimit.c
> +++ b/lib/ratelimit.c
> @@ -46,12 +46,15 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
> rs->begin = jiffies;
>
> if (time_is_before_jiffies(rs->begin + rs->interval)) {
> - if (rs->missed)
> - printk(KERN_WARNING "%s: %d callbacks suppressed\n",
> - func, rs->missed);
> - rs->begin = jiffies;
> - rs->printed = 0;
> - rs->missed = 0;
> + if (rs->missed) {
> + if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) {
> + pr_warn("%s: %d callbacks suppressed\n", func, rs->missed);
> + rs->missed = 0;
> + }
> +
> + rs->begin = jiffies;
> + rs->printed = 0;
> + }
Hmm, the above changes the previous logic. That seems wrong.
Before:
if (rs->missed)
[...]
rs->begin = jiffies;
rs->printed = 0;
after:
if (rs->missed) {
rs->begin = jiffies;
rs->printed = 0;
}
I think you wanted:
if (rs->missed) {
if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) {
[..]
rs->missed = 0;
}
}
rs->begin = jiffies;
rs->printed = 0;
-- Steve
> }
> if (rs->burst && rs->burst > rs->printed) {
> rs->printed++;
[toc] | [prev] | [next] | [standalone]
| From | Borislav Petkov <bp@alien8.de> |
|---|---|
| Date | 2016-07-06 17:00 +0200 |
| Subject | [PATCH -v3.2 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRWsV-22V-5@gated-at.bofh.it> |
| In reply to | #1437734 |
On Wed, Jul 06, 2016 at 09:40:34AM -0400, Steven Rostedt wrote:
> if (rs->missed) {
> rs->begin = jiffies;
> rs->printed = 0;
> }
This is what I get when I'm trying to juggle 10 things at the same time
:-\
Ok, here's v3.2. Thanks dude!
---
From: Borislav Petkov <bp@suse.de>
Date: Tue, 14 Jun 2016 11:51:04 +0200
Subject: [PATCH -v3.2 1/2] ratelimit: Extend to print suppressed messages on release
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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 <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Franck Bui <fbui@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
v3.2: Simplify testing of !RATELIMIT_MSG_ON_RELEASE in ___ratelimit() correctly!
include/linux/ratelimit.h | 36 +++++++++++++++++++++++++++++++-----
lib/ratelimit.c | 10 ++++++----
2 files changed, 37 insertions(+), 9 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 <linux/param.h>
+#include <linux/sched.h>
#include <linux/spinlock.h>
#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);
+}
+
+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..08f8043cac61 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)
- printk(KERN_WARNING "%s: %d callbacks suppressed\n",
- func, rs->missed);
+ if (rs->missed) {
+ if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) {
+ pr_warn("%s: %d callbacks suppressed\n", func, rs->missed);
+ rs->missed = 0;
+ }
+ }
rs->begin = jiffies;
rs->printed = 0;
- rs->missed = 0;
}
if (rs->burst && rs->burst > rs->printed) {
rs->printed++;
--
2.7.3
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
[toc] | [prev] | [next] | [standalone]
| From | Steven Rostedt <rostedt@goodmis.org> |
|---|---|
| Date | 2016-07-07 03:20 +0200 |
| Subject | Re: [PATCH -v3.2 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rS68W-8q2-13@gated-at.bofh.it> |
| In reply to | #1437779 |
On Wed, 6 Jul 2016 16:59:29 +0200
Borislav Petkov <bp@alien8.de> wrote:
> +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);
Hmm, should this clear the missed flag? Especially since it isn't
cleared below.
-- 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..08f8043cac61 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)
> - printk(KERN_WARNING "%s: %d callbacks suppressed\n",
> - func, rs->missed);
> + if (rs->missed) {
> + if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) {
> + pr_warn("%s: %d callbacks suppressed\n", func, rs->missed);
> + rs->missed = 0;
> + }
> + }
> rs->begin = jiffies;
> rs->printed = 0;
> - rs->missed = 0;
> }
> if (rs->burst && rs->burst > rs->printed) {
> rs->printed++;
[toc] | [prev] | [next] | [standalone]
| From | Borislav Petkov <bp@alien8.de> |
|---|---|
| Date | 2016-07-07 07:40 +0200 |
| Subject | Re: [PATCH -v3.2 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rSacy-2D8-19@gated-at.bofh.it> |
| In reply to | #1438053 |
On Wed, Jul 06, 2016 at 09:17:52PM -0400, Steven Rostedt wrote:
> Hmm, should this clear the missed flag? Especially since it isn't
> cleared below.
The expectation is that after you call exit on something, you don't need
it anymore. But I know exactly why you're asking for this so I'll do the
change. :-)
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
[toc] | [prev] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2016-07-06 17:00 +0200 |
| Subject | Re: [PATCH -v3.1 1/2] ratelimit: Extend to print suppressed messages on release |
| Message-ID | <rRWsV-22V-13@gated-at.bofh.it> |
| In reply to | #1437721 |
On Wed, 2016-07-06 at 15:28 +0200, Borislav Petkov wrote:
> Extend the ratelimiting facility to print the amount of suppressed lines
> when it is being released.
[]
> diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
[]
> +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);
Please use pr_warn as it will use whatever
pr_fmt prefix is specified by the subsystem.
Maybe:
if (rs->missed)
pr_warn("ratelimit: %s: %d output lines suppressed\n",
current->comm, rs->missed);
to be more similar to the callback suppressed message in
lib/ratelimit.c
pr_warn("%s: %d callbacks suppressed\n", func, rs->missed);
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web