printk or pr_<level>?
Hello guys,
1)
If I use printk(KERN_<LEVEL>...) the checkpatch warns me:
WARNING: Prefer [subsystem eg: netdev]_dbg([subsystem]dev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ...
So, pr_devel() is the correct way to print a debug level msg?
2)
if pr_<level> is the correct way, what about KERN_DEFAULT ?
If I don't put the kern_level (printk("Hello");)
WARNING: printk() should include KERN_ facility level
if I put KERN_DEFAULT:
WARNING: Prefer [subsystem eg: netdev]_default([subsystem]dev, ... then dev_default(dev, ... then pr_default(... to printk(KERN_DEFAULT ...
But for KERN_DEFAULT, there isn't a macro pr_<level> like pr_devel().
Can anyone show me the correct way?
tks
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem netdev_dbg is suitable and so on. Otherwise pr_debug will always work and is always preferred over printk.
2. Use pr_debug.
Quoted 32 lines · Raphael Silva
Hello guys,
1)
If I useprintk(KERN_<LEVEL>...)the checkpatch warns me:
WARNING: Prefer [subsystem eg: netdev]_dbg([subsystem]dev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ...So,
pr_devel()is the correct way to print a debug level msg?2)
if pr_<level> is the correct way, what aboutKERN_DEFAULT?If I don't put the
kern_level(printk("Hello");)
WARNING:printk()should includeKERN_facility levelif I put
KERN_DEFAULT:
WARNING: Prefer [subsystem eg: netdev]_default([subsystem]dev, ... then dev_default(dev, ... then pr_default(... to printk(KERN_DEFAULT ...But for
KERN_DEFAULT, there isn't a macro pr_<level> likepr_devel().Can anyone show me the correct way?
tks
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 5 lines · Kristofer Hallin
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem
netdev_dbgis suitable and so on. Otherwisepr_debugwill always work and is always preferred over printk.
By default, pr_debug is an empty macro unless you add -DDEBUG to CFLAGS. So in addition to what Kristofer said, be sure you compile your module/kernel with that flag enabled.
Cheers.
Quoted 38 lines
2. Use
pr_debug.Quoted 28 lines · Raphael Silva
Hello guys,
1)
If I useprintk(KERN_<LEVEL>...)the checkpatch warns me:
WARNING: Prefer [subsystem eg: netdev]_dbg([subsystem]dev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ...So,
pr_devel()is the correct way to print a debug level msg?2)
if pr_<level> is the correct way, what aboutKERN_DEFAULT?If I don't put the
kern_level(printk("Hello");)
WARNING:printk()should includeKERN_facility levelif I put
KERN_DEFAULT:
WARNING: Prefer [subsystem eg: netdev]_default([subsystem]dev, ... then dev_default(dev, ... then pr_default(... to printk(KERN_DEFAULT ...But for
KERN_DEFAULT, there isn't a macro pr_<level> likepr_devel().Can anyone show me the correct way?
tks
Quoted 4 lines
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 5 lines
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140723/4ca278c5/attachment.html
Yes.
https://www.kernel.org/doc/local/pr_debug.txt
Quoted 63 lines · Fernando Apestegu?a
Quoted 5 lines · Kristofer Hallin
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem
netdev_dbgis suitable and so on. Otherwisepr_debugwill always work and is always preferred over printk.By default,
pr_debugis an empty macro unless you add -DDEBUG to CFLAGS. So in addition to what Kristofer said, be sure you compile your module/kernel with that flag enabled.Cheers.
Quoted 43 lines
2. Use
pr_debug.Quoted 28 lines · Raphael Silva
Hello guys,
1)
If I useprintk(KERN_<LEVEL>...)the checkpatch warns me:
WARNING: Prefer [subsystem eg: netdev]_dbg([subsystem]dev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ...So,
pr_devel()is the correct way to print a debug level msg?2)
if pr_<level> is the correct way, what aboutKERN_DEFAULT?If I don't put the
kern_level(printk("Hello");)
WARNING:printk()should includeKERN_facility levelif I put
KERN_DEFAULT:
WARNING: Prefer [subsystem eg: netdev]_default([subsystem]dev, ... then dev_default(dev, ... then pr_default(... to printk(KERN_DEFAULT ...But for
KERN_DEFAULT, there isn't a macro pr_<level> likepr_devel().Can anyone show me the correct way?
tks
Quoted 4 lines
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 3 lines · Kristofer Hallin
Yes.
No, that isn't true if CONFIG_DYNAMIC_DEBUG is enabled, which you really should enable all the time. If that option is enabled, then you can enable the debugging messages after the code is loaded, or from the module load command line, through that interface, which is much more useful than just "enable/disable at build time".
Hope this helps,
greg k-h
Quoted 4 lines · Kristofer Hallin
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem
netdev_dbgis suitable and so on. Otherwisepr_debugwill always work and is always preferred over printk.
Why?
No snark intended here, just confused curiousity.
It would seem to me that one common method of printing would be better than a different one for each subsystem, each needing to be individually remembered, and potentially having its own bugs\b\b\b\bquirks.
The kernel is complex enough, without adding uneeded extra.
And yes, this begs the question of why you want to print messages from the kernel, whether they ought to be conditional and/or rate
limited, etc. etc. Clearly the recommendation of pr_debug() suggests
someone thinks they should be at least somewhat conditional...
Quoted 29 lines
2. Use
pr_debug.Quoted 24 lines · Raphael Silva
Hello guys,
1)
If I useprintk(KERN_<LEVEL>...)the checkpatch warns me:
WARNING: Prefer [subsystem eg: netdev]_dbg([subsystem]dev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ...So,
pr_devel()is the correct way to print a debug level msg?2)
if pr_<level> is the correct way, what aboutKERN_DEFAULT?If I don't put the
kern_level(printk("Hello");)
WARNING:printk()should includeKERN_facility levelif I put
KERN_DEFAULT:
WARNING: Prefer [subsystem eg: netdev]_default([subsystem]dev, ... then dev_default(dev, ... then pr_default(... to printk(KERN_DEFAULT ...But for
KERN_DEFAULT, there isn't a macro pr_<level> likepr_devel().Can anyone show me the correct way?
tks
Signature · 3 lines
Arlie (Arlie Stephens arlie at worldash.org)
Quoted 9 lines · Arlie Stephens
Quoted 4 lines · Kristofer Hallin
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem
netdev_dbgis suitable and so on. Otherwisepr_debugwill always work and is always preferred over printk.Why?
Quoted 8 lines
No snark intended here, just confused curiousity.
It would seem to me that one common method of printing would be better than a different one for each subsystem, each needing to be individually remembered, and potentially having its own bugs\b\b\b\bquirks.
The kernel is complex enough, without adding uneeded extra.
Yes it is, but it's "layered", in that normally you only deal with one specific layer. Very rarely are you touching code everywhere in the kernel.
Quoted 4 lines
And yes, this begs the question of why you want to print messages from the kernel, whether they ought to be conditional and/or rate
limited, etc. etc. Clearly the recommendation ofpr_debug()suggests
someone thinks they should be at least somewhat conditional...
Ok, here's the rule in one sentance:
Be as _descriptive_ as you can with the device that is emitting the message.
So what does that mean in reality?
Use the subsystem's logging macros for your messages. If you are not in a subsystem, then fall back to the "default" pr_* messages.
So, if you are a network driver, then use netdev_dbg(). Other subsystems of "class" devices have their own form of logging macros, and they should be easy to find.
If you aren't in a class driver, but are a driver, then use dev_dbg(), because you do have a device pointer accessable to you (if you don't, either you are in your module init or exit function, and you shouldn't be printing messages then anyway.)
If you are not in a driver, and you do not have _any_ 'struct device' accessable to you, reconsider if you really want to be printing anything, as the use of it to a user is going to be really low. But if you have to, then fall back to the pr_* functions, as those tie into the dynamic debugging logic of the kernel, and provide a format that is unified that userspace tools can use to hopefully search and find things properly.
So there is a method to this madness, and it is pretty simple if you think about it this way.
Does that help out?
greg k-h
Quoted 46 lines · Greg KH
Quoted 9 lines · Arlie Stephens
Quoted 4 lines · Kristofer Hallin
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem
netdev_dbgis suitable and so on. Otherwisepr_debugwill always work and is always preferred over printk.Why?
Quoted 8 lines
No snark intended here, just confused curiousity.
It would seem to me that one common method of printing would be better than a different one for each subsystem, each needing to be individually remembered, and potentially having its own bugs\b\b\b\bquirks.
The kernel is complex enough, without adding uneeded extra.
Yes it is, but it's "layered", in that normally you only deal with one specific layer. Very rarely are you touching code everywhere in the kernel.
Quoted 4 lines
And yes, this begs the question of why you want to print messages from the kernel, whether they ought to be conditional and/or rate
limited, etc. etc. Clearly the recommendation ofpr_debug()suggests
someone thinks they should be at least somewhat conditional...Ok, here's the rule in one sentance:
Be as _descriptive_ as you can with the device that is emitting the message.So what does that mean in reality?
Use the subsystem's logging macros for your messages. If you are not in a subsystem, then fall back to the "default" pr_* messages.
So, if you are a network driver, then use
netdev_dbg(). Other subsystems of "class" devices have their own form of logging macros, and they should be easy to find.If you aren't in a class driver, but are a driver, then use
dev_dbg(), because you do have a device pointer accessable to you (if you don't, either you are in your module init or exit function, and you shouldn't be printing messages then anyway.)
Quoted 7 lines
If you are not in a driver, and you do not have _any_ 'struct device' accessable to you, reconsider if you really want to be printing anything, as the use of it to a user is going to be really low. But if you have to, then fall back to the pr_* functions, as those tie into the dynamic debugging logic of the kernel, and provide a format that is unified that userspace tools can use to hopefully search and find things properly.
Oh, and never use a "raw" printk() call anymore, someone will just come along behind you and fix it up to use the "proper" macro, if you happen to get it accepted into the kernel tree.
greg k-h
Hi guys,
Thanks for the help, I learned a lot of new things.
Quoted 56 lines · Greg KH
Quoted 43 lines · Greg KH
Quoted 8 lines · Arlie Stephens
Quoted 4 lines · Kristofer Hallin
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem
netdev_dbgis suitable and so on. Otherwisepr_debugwill always work and is always preferred over printk.Why?
Quoted 8 lines
No snark intended here, just confused curiousity.
It would seem to me that one common method of printing would be better than a different one for each subsystem, each needing to be individually remembered, and potentially having its own bugs\b\b\b\bquirks.
The kernel is complex enough, without adding uneeded extra.
Yes it is, but it's "layered", in that normally you only deal with one specific layer. Very rarely are you touching code everywhere in the kernel.
Quoted 4 lines
And yes, this begs the question of why you want to print messages from the kernel, whether they ought to be conditional and/or rate
limited, etc. etc. Clearly the recommendation ofpr_debug()suggests
someone thinks they should be at least somewhat conditional...Ok, here's the rule in one sentance:
Be as _descriptive_ as you can with the device that is emitting the message.So what does that mean in reality?
Use the subsystem's logging macros for your messages. If you are not in a subsystem, then fall back to the "default" pr_* messages.
So, if you are a network driver, then use
netdev_dbg(). Other subsystems of "class" devices have their own form of logging macros, and they should be easy to find.If you aren't in a class driver, but are a driver, then use
dev_dbg(), because you do have a device pointer accessable to you (if you don't, either you are in your module init or exit function, and you shouldn't be printing messages then anyway.)Quoted 7 lines
If you are not in a driver, and you do not have _any_ 'struct device' accessable to you, reconsider if you really want to be printing anything, as the use of it to a user is going to be really low. But if you have to, then fall back to the pr_* functions, as those tie into the dynamic debugging logic of the kernel, and provide a format that is unified that userspace tools can use to hopefully search and find things properly.
Oh, and never use a "raw"
printk()call anymore, someone will just come along behind you and fix it up to use the "proper" macro, if you happen to get it accepted into the kernel tree.greg k-h
Thank-you Greg
Quoted 10 lines · Greg KH
Quoted 8 lines · Arlie Stephens
Quoted 4 lines · Kristofer Hallin
1. No. Depending on what subsystem your are printing logs from you should use different functions for logging. In the networking subsystem
netdev_dbgis suitable and so on. Otherwisepr_debugwill always work and is always preferred over printk.Why?
[snip]
Quoted 26 lines
Ok, here's the rule in one sentance:
Be as _descriptive_ as you can with the device that is emitting the message.So what does that mean in reality?
Use the subsystem's logging macros for your messages. If you are not in a subsystem, then fall back to the "default" pr_* messages.
So, if you are a network driver, then use
netdev_dbg(). Other subsystems of "class" devices have their own form of logging macros, and they should be easy to find.If you aren't in a class driver, but are a driver, then use
dev_dbg(), because you do have a device pointer accessable to you (if you don't, either you are in your module init or exit function, and you shouldn't be printing messages then anyway.)If you are not in a driver, and you do not have _any_ 'struct device' accessable to you, reconsider if you really want to be printing anything, as the use of it to a user is going to be really low. But if you have to, then fall back to the pr_* functions, as those tie into the dynamic debugging logic of the kernel, and provide a format that is unified that userspace tools can use to hopefully search and find things properly.
Quoted 4 lines
So there is a method to this madness, and it is pretty simple if you think about it this way.
Does that help out?
Yes it does. Thank you.
And I think I see why I needed help - I'm mentally a "core kernel" person, whatever I may happen to be working on at the moment ;-)
So my archetypal kernel message would be something like the ones generated by BUG_ON() ;-)
Quoted 2 lines
greg k-h
Signature · 3 lines
Arlie (Arlie Stephens arlie at worldash.org)