Skip to contentSkip to conversation

Prevent printk ratelimiting from spamming kernel log while DEBUG not defined

PATCH New Sander Eikelenboom 2 participants 4 messages May 2, 2014 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Prevent printk ratelimiting from spamming kernel log while DEBUG not defined

Hi All,

This patch is for USB sound, but the construction is widely used in the kernel, so this could pop up in more places.

Greg, Julia,

Would it be worthwhile to sweep this tree wide ?
And would this be something for Coccinelle ?
This probably also goes for the other loglevels and the "net" variant.

Sander Eikelenboom (1):
Sound USB: Prevent printk ratelimiting from spamming kernel log while
DEBUG not defined

 sound/usb/pcm.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 Sound USB: Prevent printk ratelimiting from spamming kernel log while DEBUG not defined

This (widely used) construction:

if(printk_ratelimit())

	dev_dbg()

Causes the ratelimiting to spam the kernel log with the "callbacks suppressed" message below, even while the dev_dbg it is supposed to rate limit wouldn't print anything because DEBUG is not defined for this device.

[  533.803964] retire_playback_urb: 852 callbacks suppressed
[  538.807930] retire_playback_urb: 852 callbacks suppressed
[  543.811897] retire_playback_urb: 852 callbacks suppressed
[  548.815745] retire_playback_urb: 852 callbacks suppressed
[  553.819826] retire_playback_urb: 852 callbacks suppressed

So use dev_dbg_ratelimited() instead of this construction.

---
 sound/usb/pcm.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
sound/usb/pcm.c +2 -3
index 131336d..c62a165 100644
@@ -1501,9 +1501,8 @@ static void retire_playback_urb(struct snd_usb_substream *subs,
 	 * The error should be lower than 2ms since the estimate relies
 	 * on two reads of a counter updated every ms.
 	 */
-	if (printk_ratelimit() &&
-	    abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
-		dev_dbg(&subs->dev->dev,
+	if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
+		dev_dbg_ratelimited(&subs->dev->dev,
 			"delay: estimated %d, actual %d\n",
 			est_delay, subs->last_delay);
 
Signature · 1 line
1.7.10.4
Applied
#2 lore raw

Re: [PATCH] Sound USB: Prevent printk ratelimiting from spamming kernel log while DEBUG not defined

At Fri, 2 May 2014 15:09:27 +0200,

Quoted 16 lines · Sander Eikelenboom

This (widely used) construction:

if(printk_ratelimit())

	dev_dbg()

Causes the ratelimiting to spam the kernel log with the "callbacks suppressed" message below, even while the dev_dbg it is supposed to rate limit wouldn't print anything because DEBUG is not defined for this device.

[  533.803964] retire_playback_urb: 852 callbacks suppressed
[  538.807930] retire_playback_urb: 852 callbacks suppressed
[  543.811897] retire_playback_urb: 852 callbacks suppressed
[  548.815745] retire_playback_urb: 852 callbacks suppressed
[  553.819826] retire_playback_urb: 852 callbacks suppressed
Quoted 3 lines

So use dev_dbg_ratelimited() instead of this construction.

Thanks, applied. This is a result of the recent rewrite to dev_dbg() from plain printk(), I suppose.

Takashi

Quoted 23 lines
---
 sound/usb/pcm.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
sound/usb/pcm.c +2 -3
index 131336d..c62a165 100644
@@ -1501,9 +1501,8 @@ static void retire_playback_urb(struct snd_usb_substream *subs,
 	 * The error should be lower than 2ms since the estimate relies
 	 * on two reads of a counter updated every ms.
 	 */
-	if (printk_ratelimit() &&
-	    abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
-		dev_dbg(&subs->dev->dev,
+	if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
+		dev_dbg_ratelimited(&subs->dev->dev,
 			"delay: estimated %d, actual %d\n",
 			est_delay, subs->last_delay);
 
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH] Sound USB: Prevent printk ratelimiting from spamming kernel log while DEBUG not defined

Quoted 18 lines · you

At Fri, 2 May 2014 15:09:27 +0200,

Quoted 16 lines · Sander Eikelenboom

This (widely used) construction:

if(printk_ratelimit())

      dev_dbg()

Causes the ratelimiting to spam the kernel log with the "callbacks suppressed" message below, even while the dev_dbg it is supposed to rate limit wouldn't print anything because DEBUG is not defined for this device.

[  533.803964] retire_playback_urb: 852 callbacks suppressed
[  538.807930] retire_playback_urb: 852 callbacks suppressed
[  543.811897] retire_playback_urb: 852 callbacks suppressed
[  548.815745] retire_playback_urb: 852 callbacks suppressed
[  553.819826] retire_playback_urb: 852 callbacks suppressed
Quoted 6 lines
Quoted 3 lines

So use dev_dbg_ratelimited() instead of this construction.

Thanks, applied. This is a result of the recent rewrite to dev_dbg() from plain printk(), I suppose.

Yes that patch (https://lkml.org/lkml/2014/4/9/457) prevented spamming the kernel log when debugging was enabled .. but now the rate limiting code starts spamming the kernel log instead :-)

I must say i wasn't very aware of that effect either and also used this construction on debug patches.

Quoted 25 lines

Takashi

Quoted 23 lines
---
 sound/usb/pcm.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
sound/usb/pcm.c +2 -3
index 131336d..c62a165 100644
@@ -1501,9 +1501,8 @@ static void retire_playback_urb(struct snd_usb_substream *subs,
       * The error should be lower than 2ms since the estimate relies
       * on two reads of a counter updated every ms.
       */
-     if (printk_ratelimit() &&
-         abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
-             dev_dbg(&subs->dev->dev,
+     if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
+             dev_dbg_ratelimited(&subs->dev->dev,
                      "delay: estimated %d, actual %d\n",
                      est_delay, subs->last_delay);
 
Signature · 1 line
1.7.10.4