diff mbox series

[v2,4/4] coding-style: add explanation about pr_fmt macro

Message ID 20190913220300.422869-5-andrealmeid@collabora.com (mailing list archive)
State New, archived
Headers show
Series null_blk: fixes around nr_devices and log improvements | expand

Commit Message

André Almeida Sept. 13, 2019, 10:03 p.m. UTC
The pr_fmt macro is useful to format log messages printed by pr_XXXX()
functions. Add text to explain the purpose of it, how to use and an
example.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
Cc: Jonathan Corbet <corbet@lwn.net>
---
Changes from v1:
- Add Jonathan as explict Cc
- Replace "include/printk.h" by "#include <linux/kernel.h>
- Add note about #undef
- Replace hardcore string by KBUILD_MODNAME at the example
---
 Documentation/process/coding-style.rst | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Chaitanya Kulkarni Sept. 13, 2019, 10:18 p.m. UTC | #1
I'm not super familier with the format, will let someone do the
final review.

In general looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

On 09/13/2019 03:04 PM, André Almeida wrote:
> The pr_fmt macro is useful to format log messages printed by pr_XXXX()
> functions. Add text to explain the purpose of it, how to use and an
> example.
>
> Signed-off-by: André Almeida<andrealmeid@collabora.com>
> Cc: Jonathan Corbet<corbet@lwn.net>
> ---
> Changes from v1:
> - Add Jonathan as explict Cc
> - Replace "include/printk.h" by "#include <linux/kernel.h>
> - Add note about #undef
> - Replace hardcore string by KBUILD_MODNAME at the example
> ---
Jonathan Corbet Sept. 14, 2019, 7:50 a.m. UTC | #2
On Fri, 13 Sep 2019 19:03:00 -0300
André Almeida <andrealmeid@collabora.com> wrote:

> The pr_fmt macro is useful to format log messages printed by pr_XXXX()
> functions. Add text to explain the purpose of it, how to use and an
> example.

So I've finally had a chance to take a real look at this...

> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> index f4a2198187f9..1a33a933fbd3 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -819,7 +819,15 @@ which you should use to make sure messages are matched to the right device
>  and driver, and are tagged with the right level:  dev_err(), dev_warn(),
>  dev_info(), and so forth.  For messages that aren't associated with a
>  particular device, <linux/printk.h> defines pr_notice(), pr_info(),
> -pr_warn(), pr_err(), etc.
> +pr_warn(), pr_err(), etc. It's possible to format pr_XXX() messages using the
> +macro pr_fmt() to prevent rewriting the style of messages. It should be
> +defined before ``#include <linux/kernel.h>``, to avoid compiler warning about
> +redefinitions, or just use ``#undef pr_fmt``. This is particularly useful for
> +adding the name of the module at the beginning of the message, for instance:
> +
> +.. code-block:: c
> +
> +        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

Honestly, I think that this is out of scope for a document on coding
style.  That document is already far too long for most people to read, I
don't think we should load it down with more stuff that isn't directly
style related.

That said, the information can be useful.  I wanted to say that it should
go with the documentation of the pr_* macros but ... well ... um ... we
don't seem to have a whole lot of that.  Figures.

I suspect this is more than you wanted to sign up for, but...IMO, the right
thing to do is to fill printk.h with a nice set of kerneldoc comments
describing how this stuff should be used, then to pull that information
into the core-api manual, somewhere near our extensive discussion of printk
formats.  It's amazing that we lack docs for something so basic.

Thanks,

jon
André Almeida Sept. 16, 2019, 1:38 p.m. UTC | #3
On 9/14/19 4:50 AM, Jonathan Corbet wrote:
> On Fri, 13 Sep 2019 19:03:00 -0300
> André Almeida <andrealmeid@collabora.com> wrote:
> 
>> The pr_fmt macro is useful to format log messages printed by pr_XXXX()
>> functions. Add text to explain the purpose of it, how to use and an
>> example.
> 
> So I've finally had a chance to take a real look at this...
> 
>> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
>> index f4a2198187f9..1a33a933fbd3 100644
>> --- a/Documentation/process/coding-style.rst
>> +++ b/Documentation/process/coding-style.rst
>> @@ -819,7 +819,15 @@ which you should use to make sure messages are matched to the right device
>>  and driver, and are tagged with the right level:  dev_err(), dev_warn(),
>>  dev_info(), and so forth.  For messages that aren't associated with a
>>  particular device, <linux/printk.h> defines pr_notice(), pr_info(),
>> -pr_warn(), pr_err(), etc.
>> +pr_warn(), pr_err(), etc. It's possible to format pr_XXX() messages using the
>> +macro pr_fmt() to prevent rewriting the style of messages. It should be
>> +defined before ``#include <linux/kernel.h>``, to avoid compiler warning about
>> +redefinitions, or just use ``#undef pr_fmt``. This is particularly useful for
>> +adding the name of the module at the beginning of the message, for instance:
>> +
>> +.. code-block:: c
>> +
>> +        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> 
> Honestly, I think that this is out of scope for a document on coding
> style.  That document is already far too long for most people to read, I
> don't think we should load it down with more stuff that isn't directly
> style related.
> 
> That said, the information can be useful.  I wanted to say that it should
> go with the documentation of the pr_* macros but ... well ... um ... we
> don't seem to have a whole lot of that.  Figures.
> 
> I suspect this is more than you wanted to sign up for, but...IMO, the right
> thing to do is to fill printk.h with a nice set of kerneldoc comments
> describing how this stuff should be used, then to pull that information
> into the core-api manual, somewhere near our extensive discussion of printk
> formats.  It's amazing that we lack docs for something so basic.
> 

Thanks for the feedback jon. For now, I'll drop this patch for this
series. In a future patch I'll move this text for
Documentation/core-api/printk-formats.rst and will also add kernel-doc
comments to pr_XXXX() functions.

> Thanks,
> 
> jon
>
diff mbox series

Patch

diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
index f4a2198187f9..1a33a933fbd3 100644
--- a/Documentation/process/coding-style.rst
+++ b/Documentation/process/coding-style.rst
@@ -819,7 +819,15 @@  which you should use to make sure messages are matched to the right device
 and driver, and are tagged with the right level:  dev_err(), dev_warn(),
 dev_info(), and so forth.  For messages that aren't associated with a
 particular device, <linux/printk.h> defines pr_notice(), pr_info(),
-pr_warn(), pr_err(), etc.
+pr_warn(), pr_err(), etc. It's possible to format pr_XXX() messages using the
+macro pr_fmt() to prevent rewriting the style of messages. It should be
+defined before ``#include <linux/kernel.h>``, to avoid compiler warning about
+redefinitions, or just use ``#undef pr_fmt``. This is particularly useful for
+adding the name of the module at the beginning of the message, for instance:
+
+.. code-block:: c
+
+        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 Coming up with good debugging messages can be quite a challenge; and once
 you have them, they can be a huge help for remote troubleshooting.  However