net_dbg_ratelimited: turn into no-op when !DEBUG
Subsystems (2)
PATCH 1/1 net_dbg_ratelimited: turn into no-op when !DEBUG
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.
--- include/linux/net.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/net.h +5 -0
@@ -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);
Signature · 1 line
2.4.5
Quoted 29 lines · Jason A. Donenfeld
The
pr_debugfamily 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_ratelimitedis that it is defined to be a variant ofnet_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_ratelimitneedlessly, which does quite some book keeping for the rate limiting. Given that thepr_debugandnet_dbg_ratelimitedfamily 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 aforementionednet_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.
Quoted 6 lines
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_ratelimitedwhen !DEBUG withno_printk, keeping with the idiom of all the other debug print helpers.
Makes sense, thanks Jason.
Quoted 5 lines · Joe Perches
Quoted 2 lines · Jason A. Donenfeld
This patch replaces calls to
net_dbg_ratelimitedwhen !DEBUG withno_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.
David Miller
maintainerFrom: Joe Perches <[email protected]>
Date: Mon, 03 Aug 2015 21:02:21 -0700
Quoted 10 lines · Joe Perches
Quoted 5 lines · Jason A. Donenfeld
Quoted 2 lines
This patch replaces calls to
net_dbg_ratelimitedwhen !DEBUG withno_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_printkso that the call and whatever argument calls thenet_dbg_ratelimitedmakes are completely eliminated.
Agreed. Jason please respin your patch to work this way.
PATCH 1/1 net_dbg_ratelimited: turn into no-op when !DEBUG
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.
--- include/linux/net.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/net.h +6 -0
@@ -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);
Signature · 1 line
2.4.5
Sorry, I forgot to 'v2' the subject, but here's the respin suggested by Joe and asked for by David.
Quoted 3 lines · Jason A. Donenfeld
The
pr_debugfamily 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).
[]
include/linux/net.h
Quoted 1 line
include/linux/net.h +0
-0
[]
include/linux/net.h do { \ · line 249
Quoted 12 lines
include/linux/net.h +6
-0@@ -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
PATCH v3 1/1 net_dbg_ratelimited: turn into no-op when !DEBUG
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.
--- include/linux/net.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/linux/net.h +8 -0
@@ -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);
Signature · 1 line
2.5.0
From: "Jason A. Donenfeld" <[email protected]>
Date: Tue, 4 Aug 2015 18:26:19 +0200
Quoted 33 lines
The
pr_debugfamily 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_ratelimitedis that it is defined to be a variant ofnet_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_ratelimitneedlessly, which does quite some book keeping for the rate limiting. Given that thepr_debugandnet_dbg_ratelimitedfamily 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 aforementionednet_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.
Quoted 7 lines
This patch replaces calls to
net_dbg_ratelimitedwhen !DEBUG withno_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 <[email protected]>
Applied to net-next, thanks.