Skip to contentSkip to conversation

kernel.h: Add a never optimized away pr_dbg for printk(KERN_DEBUG pr_fmt(fmt)...)

PATCH In review Joe Perches 2 participants 5 messages Oct 14, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel.h: Add a never optimized away pr_dbg for printk(KERN_DEBUG pr_fmt(fmt)...)

Many developers use a logging message that is printed at KERN_DEBUG level that is always printed regardless of #define DEBUG levels.

pr_debug can be optimized away to a null statement.

Add a pr_dbg message that prints at KERN_DEBUG level that uses pr_fmt() that can not be optimized to nothing.

 include/linux/kernel.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/kernel.h +0 -0
index f4e3184..2ad0396 100644
@@ -380,6 +380,8 @@ static inline char *pack_hex_byte(char *buf, u8

byte)

         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_info(fmt, ...) \
         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)

+#define pr_dbg(fmt, ...) \
+ printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#define pr_cont(fmt, ...) \
printk(KERN_CONT fmt, ##__VA_ARGS__)

#1 lore raw
Quoted 10 lines · Joe Perches

Many developers use a logging message that is printed at KERN_DEBUG level that is always printed regardless of #define DEBUG levels.

pr_debug can be optimized away to a null statement.

Add a pr_dbg message that prints at KERN_DEBUG level that uses pr_fmt() that can not be optimized to nothing.

pr_dbg() is horribly misnamed, it doesn't indicate why it exists vs. pr_debug() at all. Future users will undoubtedly use it by mistake when they only really mean for the message to be emitted on DEBUG because they've seen it in other places and haven't checked the implementation.

I'd suggest pr_debug_force(), even though it's much longer (although still shorter than printk(KERN_DEBUG)).

#2 lore raw
Quoted 10 lines · David Rientjes
Quoted 7 lines · Joe Perches

Many developers use a logging message that is printed at KERN_DEBUG level that is always printed regardless of #define DEBUG levels. pr_debug can be optimized away to a null statement. Add a pr_dbg message that prints at KERN_DEBUG level that uses pr_fmt() that can not be optimized to nothing.

pr_dbg() is horribly misnamed, it doesn't indicate why it exists vs. pr_debug() at all.

Partially true, it's reasonably named because it's very short.

Quoted 3 lines

Future users will undoubtedly use it by mistake when
they only really mean for the message to be emitted on DEBUG because they've seen it in other places and haven't checked the implementation.

The cost of using pr_dbg instead of pr_debug isn't high.

The primary benefit is getting an automatic pr_fmt and shorter code.

Quoted 2 lines

I'd suggest pr_debug_force(), even though it's much longer (although still shorter than printk(KERN_DEBUG)).

pr_dbg allows longer format strings without exceeding 80 chars.

printk(KERN_DEBUG
pr_debug_force
pr_dbg_always
pr_dbg_noopt

Other suggestions?

#3 lore raw
Quoted 5 lines · Joe Perches
Quoted 2 lines

pr_dbg() is horribly misnamed, it doesn't indicate why it exists vs. pr_debug() at all.

Partially true, it's reasonably named because it's very short.

It doesn't really matter how long it is if it doesn't accurately describe what it does.

Quoted 12 lines
Quoted 2 lines

I'd suggest pr_debug_force(), even though it's much longer (although still shorter than printk(KERN_DEBUG)).

pr_dbg allows longer format strings without exceeding 80 chars.

printk(KERN_DEBUG
pr_debug_force
pr_dbg_always
pr_dbg_noopt

Other suggestions?

The pr_dbg_* variations seem reasonable if the current pr_debug() were changed to pr_dbg().

I suggest converting some mainline code to use whatever you end up calling the !DEBUG variant, though, because this discussion is irrelevant if there are no current use cases (in which case the patch is pointless).

#4 lore raw
Quoted 2 lines · David Rientjes

The pr_dbg_* variations seem reasonable if the current pr_debug() were changed to pr_dbg().

I think that's unlikely to happen.

Quoted 2 lines

this discussion is irrelevant if there
are no current use cases (in which case the patch is pointless).

Yeah, right. It's alway irrelevant to add new
facilities when where are no current use cases.

I sent a 21 deep patchset over a week ago.
http://lkml.org/lkml/2009/10/4/198