* [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG
@ 2015-08-04 3:26 Jason A. Donenfeld
2015-08-04 3:57 ` Joe Perches
0 siblings, 1 reply; 9+ messages in thread
From: Jason A. Donenfeld @ 2015-08-04 3:26 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, netdev, linux-kernel; +Cc: Jason A. Donenfeld
The pr_debug family of functions turns into a no-op when -DDEBUG is not
specified, opting instead to call "no_printk", which gets compiled to a
no-op (but retains gcc's nice warnings about printf-style arguments).
The problem with net_dbg_ratelimited is that it is defined to be a
variant of net_ratelimited_function, which expands to essentially:
if (net_ratelimit())
pr_debug(fmt, ...);
When DEBUG is not defined, then this becomes,
if (net_ratelimit())
;
This seems benign, except it isn't. Firstly, there's the obvious
overhead of calling net_ratelimit needlessly, which does quite some book
keeping for the rate limiting. Given that the pr_debug and
net_dbg_ratelimited family of functions are sprinkled liberally through
performance critical code, with developers assuming they'll be compiled
out to a no-op most of the time, we certainly do not want this needless
book keeping. Secondly, and most visibly, even though no debug message
is printed when DEBUG is not defined, if there is a flood of
invocations, dmesg winds up peppered with messages such as
"net_ratelimit: 320 callbacks suppressed". This is because our
aforementioned net_ratelimit() function actually prints this text in
some circumstances. It's especially odd to see this when there isn't any
other accompanying debug message.
So, in sum, it doesn't make sense to have this function's current
behavior, and instead it should match what every other debug family of
functions in the kernel does with !DEBUG -- nothing.
This patch replaces calls to net_dbg_ratelimited when !DEBUG with
no_printk, keeping with the idiom of all the other debug print helpers.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
include/linux/net.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/net.h b/include/linux/net.h
index 04aa068..500fdfe 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -239,8 +239,13 @@ do { \
net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
#define net_info_ratelimited(fmt, ...) \
net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
+#if defined(DEBUG)
#define net_dbg_ratelimited(fmt, ...) \
net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
+#else
+#define net_dbg_ratelimited(fmt, ...) \
+ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#endif
bool __net_get_random_once(void *buf, int nbytes, bool *done,
struct static_key *done_key);
--
2.4.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 3:26 [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG Jason A. Donenfeld
@ 2015-08-04 3:57 ` Joe Perches
2015-08-04 4:02 ` Joe Perches
0 siblings, 1 reply; 9+ messages in thread
From: Joe Perches @ 2015-08-04 3:57 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Andrew Morton, David S. Miller, netdev, linux-kernel
On Tue, 2015-08-04 at 05:26 +0200, Jason A. Donenfeld wrote:
> The pr_debug family of functions turns into a no-op when -DDEBUG is not
> specified, opting instead to call "no_printk", which gets compiled to a
> no-op (but retains gcc's nice warnings about printf-style arguments).
>
> The problem with net_dbg_ratelimited is that it is defined to be a
> variant of net_ratelimited_function, which expands to essentially:
>
> if (net_ratelimit())
> pr_debug(fmt, ...);
>
> When DEBUG is not defined, then this becomes,
>
> if (net_ratelimit())
> ;
>
> This seems benign, except it isn't. Firstly, there's the obvious
> overhead of calling net_ratelimit needlessly, which does quite some book
> keeping for the rate limiting. Given that the pr_debug and
> net_dbg_ratelimited family of functions are sprinkled liberally through
> performance critical code, with developers assuming they'll be compiled
> out to a no-op most of the time, we certainly do not want this needless
> book keeping. Secondly, and most visibly, even though no debug message
> is printed when DEBUG is not defined, if there is a flood of
> invocations, dmesg winds up peppered with messages such as
> "net_ratelimit: 320 callbacks suppressed". This is because our
> aforementioned net_ratelimit() function actually prints this text in
> some circumstances. It's especially odd to see this when there isn't any
> other accompanying debug message.
>
> So, in sum, it doesn't make sense to have this function's current
> behavior, and instead it should match what every other debug family of
> functions in the kernel does with !DEBUG -- nothing.
>
> This patch replaces calls to net_dbg_ratelimited when !DEBUG with
> no_printk, keeping with the idiom of all the other debug print helpers.
Makes sense, thanks Jason.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 3:57 ` Joe Perches
@ 2015-08-04 4:02 ` Joe Perches
2015-08-04 4:59 ` David Miller
0 siblings, 1 reply; 9+ messages in thread
From: Joe Perches @ 2015-08-04 4:02 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Andrew Morton, David S. Miller, netdev, linux-kernel
On Mon, 2015-08-03 at 20:57 -0700, Joe Perches wrote:
> On Tue, 2015-08-04 at 05:26 +0200, Jason A. Donenfeld wrote:
> > This patch replaces calls to net_dbg_ratelimited when !DEBUG with
> > no_printk, keeping with the idiom of all the other debug print helpers.
>
> Makes sense, thanks Jason.
Perhaps better still would be to use if (0) no_printk so that
the call and whatever argument calls the net_dbg_ratelimited
makes are completely eliminated.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 4:02 ` Joe Perches
@ 2015-08-04 4:59 ` David Miller
2015-08-04 15:07 ` Jason A. Donenfeld
0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2015-08-04 4:59 UTC (permalink / raw)
To: joe; +Cc: Jason, akpm, netdev, linux-kernel
From: Joe Perches <joe@perches.com>
Date: Mon, 03 Aug 2015 21:02:21 -0700
> On Mon, 2015-08-03 at 20:57 -0700, Joe Perches wrote:
>> On Tue, 2015-08-04 at 05:26 +0200, Jason A. Donenfeld wrote:
>> > This patch replaces calls to net_dbg_ratelimited when !DEBUG with
>> > no_printk, keeping with the idiom of all the other debug print helpers.
>>
>> Makes sense, thanks Jason.
>
> Perhaps better still would be to use if (0) no_printk so that
> the call and whatever argument calls the net_dbg_ratelimited
> makes are completely eliminated.
Agreed. Jason please respin your patch to work this way.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 4:59 ` David Miller
@ 2015-08-04 15:07 ` Jason A. Donenfeld
2015-08-04 15:08 ` Jason A. Donenfeld
2015-08-04 15:51 ` Joe Perches
0 siblings, 2 replies; 9+ messages in thread
From: Jason A. Donenfeld @ 2015-08-04 15:07 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, netdev, linux-kernel, Joe Perches
Cc: Jason A. Donenfeld
The pr_debug family of functions turns into a no-op when -DDEBUG is not
specified, opting instead to call "no_printk", which gets compiled to a
no-op (but retains gcc's nice warnings about printf-style arguments).
The problem with net_dbg_ratelimited is that it is defined to be a
variant of net_ratelimited_function, which expands to essentially:
if (net_ratelimit())
pr_debug(fmt, ...);
When DEBUG is not defined, then this becomes,
if (net_ratelimit())
;
This seems benign, except it isn't. Firstly, there's the obvious
overhead of calling net_ratelimit needlessly, which does quite some book
keeping for the rate limiting. Given that the pr_debug and
net_dbg_ratelimited family of functions are sprinkled liberally through
performance critical code, with developers assuming they'll be compiled
out to a no-op most of the time, we certainly do not want this needless
book keeping. Secondly, and most visibly, even though no debug message
is printed when DEBUG is not defined, if there is a flood of
invocations, dmesg winds up peppered with messages such as
"net_ratelimit: 320 callbacks suppressed". This is because our
aforementioned net_ratelimit() function actually prints this text in
some circumstances. It's especially odd to see this when there isn't any
other accompanying debug message.
So, in sum, it doesn't make sense to have this function's current
behavior, and instead it should match what every other debug family of
functions in the kernel does with !DEBUG -- nothing.
This patch replaces calls to net_dbg_ratelimited when !DEBUG with
no_printk, keeping with the idiom of all the other debug print helpers.
Also, though not strictly neccessary, it guards the call with an if (0)
so that all evaluation of any arguments are sure to be compiled out.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
include/linux/net.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/net.h b/include/linux/net.h
index 04aa068..b3a06ef 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -239,8 +239,14 @@ do { \
net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
#define net_info_ratelimited(fmt, ...) \
net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
+#if defined(DEBUG)
#define net_dbg_ratelimited(fmt, ...) \
net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
+#else
+#define net_dbg_ratelimited(fmt, ...) \
+ if (0) \
+ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#endif
bool __net_get_random_once(void *buf, int nbytes, bool *done,
struct static_key *done_key);
--
2.4.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 15:07 ` Jason A. Donenfeld
@ 2015-08-04 15:08 ` Jason A. Donenfeld
2015-08-04 15:51 ` Joe Perches
1 sibling, 0 replies; 9+ messages in thread
From: Jason A. Donenfeld @ 2015-08-04 15:08 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, netdev, linux-kernel, Joe Perches
Cc: Jason A. Donenfeld
Sorry, I forgot to 'v2' the subject, but here's the respin suggested
by Joe and asked for by David.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 15:07 ` Jason A. Donenfeld
2015-08-04 15:08 ` Jason A. Donenfeld
@ 2015-08-04 15:51 ` Joe Perches
2015-08-04 16:26 ` [PATCH v3] " Jason A. Donenfeld
1 sibling, 1 reply; 9+ messages in thread
From: Joe Perches @ 2015-08-04 15:51 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Andrew Morton, David S. Miller, netdev, linux-kernel
On Tue, 2015-08-04 at 17:07 +0200, Jason A. Donenfeld wrote:
> The pr_debug family of functions turns into a no-op when -DDEBUG is not
> specified, opting instead to call "no_printk", which gets compiled to a
> no-op (but retains gcc's nice warnings about printf-style arguments).
[]
> diff --git a/include/linux/net.h b/include/linux/net.h
[]
> @@ -239,8 +239,14 @@ do { \
> net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
> #define net_info_ratelimited(fmt, ...) \
> net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
> +#if defined(DEBUG)
> #define net_dbg_ratelimited(fmt, ...) \
> net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
> +#else
> +#define net_dbg_ratelimited(fmt, ...) \
> + if (0) \
> + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
> +#endif
This should be:
#define net_dbg_ratelimited(fmt, ...) \
do { \
if (0) \
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
} while (0)
to be safe in if/else uses
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 15:51 ` Joe Perches
@ 2015-08-04 16:26 ` Jason A. Donenfeld
2015-08-07 6:51 ` David Miller
0 siblings, 1 reply; 9+ messages in thread
From: Jason A. Donenfeld @ 2015-08-04 16:26 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, netdev, linux-kernel, Joe Perches
Cc: Jason A. Donenfeld
The pr_debug family of functions turns into a no-op when -DDEBUG is not
specified, opting instead to call "no_printk", which gets compiled to a
no-op (but retains gcc's nice warnings about printf-style arguments).
The problem with net_dbg_ratelimited is that it is defined to be a
variant of net_ratelimited_function, which expands to essentially:
if (net_ratelimit())
pr_debug(fmt, ...);
When DEBUG is not defined, then this becomes,
if (net_ratelimit())
;
This seems benign, except it isn't. Firstly, there's the obvious
overhead of calling net_ratelimit needlessly, which does quite some book
keeping for the rate limiting. Given that the pr_debug and
net_dbg_ratelimited family of functions are sprinkled liberally through
performance critical code, with developers assuming they'll be compiled
out to a no-op most of the time, we certainly do not want this needless
book keeping. Secondly, and most visibly, even though no debug message
is printed when DEBUG is not defined, if there is a flood of
invocations, dmesg winds up peppered with messages such as
"net_ratelimit: 320 callbacks suppressed". This is because our
aforementioned net_ratelimit() function actually prints this text in
some circumstances. It's especially odd to see this when there isn't any
other accompanying debug message.
So, in sum, it doesn't make sense to have this function's current
behavior, and instead it should match what every other debug family of
functions in the kernel does with !DEBUG -- nothing.
This patch replaces calls to net_dbg_ratelimited when !DEBUG with
no_printk, keeping with the idiom of all the other debug print helpers.
Also, though not strictly neccessary, it guards the call with an if (0)
so that all evaluation of any arguments are sure to be compiled out.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
include/linux/net.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/net.h b/include/linux/net.h
index 04aa068..049d4b0 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -239,8 +239,16 @@ do { \
net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)
#define net_info_ratelimited(fmt, ...) \
net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
+#if defined(DEBUG)
#define net_dbg_ratelimited(fmt, ...) \
net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
+#else
+#define net_dbg_ratelimited(fmt, ...) \
+ do { \
+ if (0) \
+ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
+ } while (0)
+#endif
bool __net_get_random_once(void *buf, int nbytes, bool *done,
struct static_key *done_key);
--
2.5.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3] net_dbg_ratelimited: turn into no-op when !DEBUG
2015-08-04 16:26 ` [PATCH v3] " Jason A. Donenfeld
@ 2015-08-07 6:51 ` David Miller
0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2015-08-07 6:51 UTC (permalink / raw)
To: Jason; +Cc: akpm, netdev, linux-kernel, joe
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
Date: Tue, 4 Aug 2015 18:26:19 +0200
> The pr_debug family of functions turns into a no-op when -DDEBUG is not
> specified, opting instead to call "no_printk", which gets compiled to a
> no-op (but retains gcc's nice warnings about printf-style arguments).
>
> The problem with net_dbg_ratelimited is that it is defined to be a
> variant of net_ratelimited_function, which expands to essentially:
>
> if (net_ratelimit())
> pr_debug(fmt, ...);
>
> When DEBUG is not defined, then this becomes,
>
> if (net_ratelimit())
> ;
>
> This seems benign, except it isn't. Firstly, there's the obvious
> overhead of calling net_ratelimit needlessly, which does quite some book
> keeping for the rate limiting. Given that the pr_debug and
> net_dbg_ratelimited family of functions are sprinkled liberally through
> performance critical code, with developers assuming they'll be compiled
> out to a no-op most of the time, we certainly do not want this needless
> book keeping. Secondly, and most visibly, even though no debug message
> is printed when DEBUG is not defined, if there is a flood of
> invocations, dmesg winds up peppered with messages such as
> "net_ratelimit: 320 callbacks suppressed". This is because our
> aforementioned net_ratelimit() function actually prints this text in
> some circumstances. It's especially odd to see this when there isn't any
> other accompanying debug message.
>
> So, in sum, it doesn't make sense to have this function's current
> behavior, and instead it should match what every other debug family of
> functions in the kernel does with !DEBUG -- nothing.
>
> This patch replaces calls to net_dbg_ratelimited when !DEBUG with
> no_printk, keeping with the idiom of all the other debug print helpers.
>
> Also, though not strictly neccessary, it guards the call with an if (0)
> so that all evaluation of any arguments are sure to be compiled out.
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Applied to net-next, thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-08-07 6:51 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-04 3:26 [PATCH] net_dbg_ratelimited: turn into no-op when !DEBUG Jason A. Donenfeld
2015-08-04 3:57 ` Joe Perches
2015-08-04 4:02 ` Joe Perches
2015-08-04 4:59 ` David Miller
2015-08-04 15:07 ` Jason A. Donenfeld
2015-08-04 15:08 ` Jason A. Donenfeld
2015-08-04 15:51 ` Joe Perches
2015-08-04 16:26 ` [PATCH v3] " Jason A. Donenfeld
2015-08-07 6:51 ` David Miller
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).