linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5%
@ 2016-06-22 18:23 Joe Perches
  2016-06-22 20:40 ` Jason Gunthorpe
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Joe Perches @ 2016-06-22 18:23 UTC (permalink / raw)
  To: Matan Barak, Leon Romanovsky; +Cc: netdev, linux-rdma, linux-kernel

The logging macros create a bit of duplicated code/text.

Use specialized functions to reduce the duplication.

(defconfig/x86-64)
$ size drivers/net/ethernet/mellanox/mlx5/core/built-in.o*
   text	   data	    bss	    dec	    hex	filename
 178634	   2059	     16	 180709	  2c1e5	drivers/net/ethernet/mellanox/mlx5/core/built-in.o.new
 188679	   2059	     16	 190754	  2e922	drivers/net/ethernet/mellanox/mlx5/core/built-in.o.old

The output changes now do not include line #,
but do include the function offset.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/main.c     | 34 ++++++++++++++++++++++
 .../net/ethernet/mellanox/mlx5/core/mlx5_core.h    | 13 +++------
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index a19b593..34cbaf0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -1557,3 +1557,37 @@ static void __exit cleanup(void)
 
 module_init(init);
 module_exit(cleanup);
+
+void mlx5_core_err(struct mlx5_core_dev *dev, const char *fmt, ...)
+{
+	struct va_format vaf;
+	va_list args;
+
+	va_start(args, fmt);
+
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	dev_err(&dev->pdev->dev, "%s:%pS:(pid %d): %pV",
+		dev->priv.name, __builtin_return_address(0), current->pid,
+		&vaf);
+
+	va_end(args);
+}
+
+void mlx5_core_warn(struct mlx5_core_dev *dev, const char *fmt, ...)
+{
+	struct va_format vaf;
+	va_list args;
+
+	va_start(args, fmt);
+
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	dev_warn(&dev->pdev->dev, "%s:%pS:(pid %d): %pV",
+		 dev->priv.name, __builtin_return_address(0), current->pid,
+		 &vaf);
+
+	va_end(args);
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
index 2f86ec6..31430a7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
@@ -57,15 +57,10 @@ do {									\
 		mlx5_core_dbg(__dev, format, ##__VA_ARGS__);		\
 } while (0)
 
-#define mlx5_core_err(__dev, format, ...)				\
-	dev_err(&(__dev)->pdev->dev, "%s:%s:%d:(pid %d): " format,	\
-	       (__dev)->priv.name, __func__, __LINE__, current->pid,	\
-	       ##__VA_ARGS__)
-
-#define mlx5_core_warn(__dev, format, ...)				\
-	dev_warn(&(__dev)->pdev->dev, "%s:%s:%d:(pid %d): " format,	\
-		(__dev)->priv.name, __func__, __LINE__, current->pid,	\
-		##__VA_ARGS__)
+__printf(2, 3)
+void mlx5_core_err(struct mlx5_core_dev *dev, const char *fmt, ...);
+__printf(2, 3)
+void mlx5_core_warn(struct mlx5_core_dev *dev, const char *fmt, ...);
 
 #define mlx5_core_info(__dev, format, ...)				\
 	dev_info(&(__dev)->pdev->dev, format, ##__VA_ARGS__)

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5%
  2016-06-22 18:23 [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5% Joe Perches
@ 2016-06-22 20:40 ` Jason Gunthorpe
  2016-06-22 22:20   ` Joe Perches
  2016-06-23  5:27 ` Leon Romanovsky
  2016-06-23  8:09 ` Saeed Mahameed
  2 siblings, 1 reply; 7+ messages in thread
From: Jason Gunthorpe @ 2016-06-22 20:40 UTC (permalink / raw)
  To: Joe Perches
  Cc: Matan Barak, Leon Romanovsky, netdev, linux-rdma, linux-kernel

On Wed, Jun 22, 2016 at 11:23:59AM -0700, Joe Perches wrote:

> The output changes now do not include line #, but do include the
> function offset.

I've been using a technique like this in some code with good results:

struct source_location
{
   const char *file;
   const char *func;
   const char *format;
   uint16_t line;
};
#define _LOCATION(format) ({static const source_location __location__ = {\
             __FILE__,__PRETTY_FUNCTION__,format,__LINE__};\
	     &__location__;})

void _mlx5_core_err(const struct source_location *loc,struct mlx5_core_dev *dev, ...);
#define mlx5_core_err(dev,format,...) _mlx_core_err(_LOCATION(format),dev,__VA_ARGS__)

The call site .text overhead is the about same as what you have, but
this still retains the function and line number information in
.rodata.

Jason

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5%
  2016-06-22 20:40 ` Jason Gunthorpe
@ 2016-06-22 22:20   ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2016-06-22 22:20 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Matan Barak, Leon Romanovsky, netdev, linux-rdma, linux-kernel

On Wed, 2016-06-22 at 14:40 -0600, Jason Gunthorpe wrote:
> On Wed, Jun 22, 2016 at 11:23:59AM -0700, Joe Perches wrote:
> > The output changes now do not include line #, but do include the
> > function offset.
> I've been using a technique like this in some code with good results:
> 
> struct source_location
> {
>    const char *file;
>    const char *func;
>    const char *format;
>    uint16_t line;
> };
> #define _LOCATION(format) ({static const source_location __location__
> = {\
>              __FILE__,__PRETTY_FUNCTION__,format,__LINE__};\
> 	     &__location__;})
> 
> void _mlx5_core_err(const struct source_location *loc,struct
> mlx5_core_dev *dev, ...);
> #define mlx5_core_err(dev,format,...)
> _mlx_core_err(_LOCATION(format),dev,__VA_ARGS__)
> 
> The call site .text overhead is the about same as what you have, but
> this still retains the function and line number information in
> .rodata.

Hello Jason.

As far as I know, no kernel code currently uses a _LOCATION
like macro.

I think your proposal is nearly identical code size to the
existing call.  Also, compiler format/argument checking is
eliminated and I think that is a significant negative.

Using the kernel vsprintf %pS or %ps extension is pretty common.

Using printk("%pS", __builtin_return_address(0)); in the called
function is no overhead at all and returns almost exactly
the same information.

Using more expressive messages is generally better than using
printk("%d", __LINE__);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5%
  2016-06-22 18:23 [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5% Joe Perches
  2016-06-22 20:40 ` Jason Gunthorpe
@ 2016-06-23  5:27 ` Leon Romanovsky
  2016-06-23  7:12   ` Leon Romanovsky
  2016-06-23  8:12   ` Saeed Mahameed
  2016-06-23  8:09 ` Saeed Mahameed
  2 siblings, 2 replies; 7+ messages in thread
From: Leon Romanovsky @ 2016-06-23  5:27 UTC (permalink / raw)
  To: Saeed Mahameed, Joe Perches; +Cc: Matan Barak, netdev, linux-rdma, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 896 bytes --]

On Wed, Jun 22, 2016 at 11:23:59AM -0700, Joe Perches wrote:
> The logging macros create a bit of duplicated code/text.
> 
> Use specialized functions to reduce the duplication.
> 
> (defconfig/x86-64)
> $ size drivers/net/ethernet/mellanox/mlx5/core/built-in.o*
>    text	   data	    bss	    dec	    hex	filename
>  178634	   2059	     16	 180709	  2c1e5	drivers/net/ethernet/mellanox/mlx5/core/built-in.o.new
>  188679	   2059	     16	 190754	  2e922	drivers/net/ethernet/mellanox/mlx5/core/built-in.o.old
> 
> The output changes now do not include line #,
> but do include the function offset.
> 
> Signed-off-by: Joe Perches <joe@perches.com>

As far as I see all these functions are used in error paths, so no
implication on performance is expected.

And I'm fine with function offsets.

Saeed,
What do you think?

Reviewed-by: Leon Romanovsky <leonro@mellanox.com>

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5%
  2016-06-23  5:27 ` Leon Romanovsky
@ 2016-06-23  7:12   ` Leon Romanovsky
  2016-06-23  8:12   ` Saeed Mahameed
  1 sibling, 0 replies; 7+ messages in thread
From: Leon Romanovsky @ 2016-06-23  7:12 UTC (permalink / raw)
  To: Saeed Mahameed, Joe Perches; +Cc: Matan Barak, netdev, linux-rdma, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2079 bytes --]

On Thu, Jun 23, 2016 at 08:27:01AM +0300, Leon Romanovsky wrote:
> On Wed, Jun 22, 2016 at 11:23:59AM -0700, Joe Perches wrote:
> > The logging macros create a bit of duplicated code/text.
> > 
> > Use specialized functions to reduce the duplication.
> > 
> > (defconfig/x86-64)
> > $ size drivers/net/ethernet/mellanox/mlx5/core/built-in.o*
> >    text	   data	    bss	    dec	    hex	filename
> >  178634	   2059	     16	 180709	  2c1e5	drivers/net/ethernet/mellanox/mlx5/core/built-in.o.new
> >  188679	   2059	     16	 190754	  2e922	drivers/net/ethernet/mellanox/mlx5/core/built-in.o.old
> > 
> > The output changes now do not include line #,
> > but do include the function offset.
> > 
> > Signed-off-by: Joe Perches <joe@perches.com>
> 
> As far as I see all these functions are used in error paths, so no
> implication on performance is expected.
> 
> And I'm fine with function offsets.
> 
> Saeed,
> What do you think?
> 
> Reviewed-by: Leon Romanovsky <leonro@mellanox.com>

I continued to play with this patch and it doesn't pass checkpatch.
It looks like corrupted file.

➜  linux-rdma git:(master) ./scripts/checkpatch.pl
~/Downloads/mellanox-mlx5-Use-logging-functions-to-reduce-text-10k-5.patch
WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#21: 
 178634    2059      16  180709   2c1e5
drivers/net/ethernet/mellanox/mlx5/core/built-in.o.new

ERROR: patch seems to be corrupt (line wrapped?)
#46: FILE: drivers/net/ethernet/mellanox/mlx5/core/main.c:1556:

CHECK: Alignment should match open parenthesis
#78: FILE: drivers/net/ethernet/mellanox/mlx5/core/main.c:1586:
+       dev_warn(&dev->pdev->dev, "%s:%pS:(pid %d): %pV",
+                dev->priv.name, __builtin_return_address(0), current->pid,

ERROR: space required before that '&' (ctx:VxV)
#79: FILE: drivers/net/ethernet/mellanox/mlx5/core/main.c:1587:
+                &vaf);
                  ^
total: 2 errors, 1 warnings, 1 checks, 58 lines  checked

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5%
  2016-06-22 18:23 [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5% Joe Perches
  2016-06-22 20:40 ` Jason Gunthorpe
  2016-06-23  5:27 ` Leon Romanovsky
@ 2016-06-23  8:09 ` Saeed Mahameed
  2 siblings, 0 replies; 7+ messages in thread
From: Saeed Mahameed @ 2016-06-23  8:09 UTC (permalink / raw)
  To: Joe Perches
  Cc: Matan Barak, Leon Romanovsky, Linux Netdev List, linux-rdma,
	linux-kernel

On Wed, Jun 22, 2016 at 9:23 PM, Joe Perches <joe@perches.com> wrote:
[...]
> --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
> @@ -1557,3 +1557,37 @@ static void __exit cleanup(void)
>
>  module_init(init);
>  module_exit(cleanup);
> +
> +void mlx5_core_err(struct mlx5_core_dev *dev, const char *fmt, ...)
> +{
> +       struct va_format vaf;
> +       va_list args;
> +
> +       va_start(args, fmt);
> +
> +       vaf.fmt = fmt;
> +       vaf.va = &args;
> +
> +       dev_err(&dev->pdev->dev, "%s:%pS:(pid %d): %pV",
> +               dev->priv.name, __builtin_return_address(0), current->pid,
> +               &vaf);
> +
> +       va_end(args);
> +}
> +
> +void mlx5_core_warn(struct mlx5_core_dev *dev, const char *fmt, ...)
> +{
> +       struct va_format vaf;
> +       va_list args;
> +
> +       va_start(args, fmt);
> +
> +       vaf.fmt = fmt;
> +       vaf.va = &args;
> +
> +       dev_warn(&dev->pdev->dev, "%s:%pS:(pid %d): %pV",
> +                dev->priv.name, __builtin_return_address(0), current->pid,
> +                &vaf);
> +
> +       va_end(args);
> +}

Hi Joe,

I like to keep the file organized in a bottom-up fashion.  Those
functions need to appear as early as possible in the file, just move
them up to appear after the MACROs defines and static fields
declarations.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5%
  2016-06-23  5:27 ` Leon Romanovsky
  2016-06-23  7:12   ` Leon Romanovsky
@ 2016-06-23  8:12   ` Saeed Mahameed
  1 sibling, 0 replies; 7+ messages in thread
From: Saeed Mahameed @ 2016-06-23  8:12 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Saeed Mahameed, Joe Perches, Matan Barak, Linux Netdev List,
	linux-rdma, linux-kernel

On Thu, Jun 23, 2016 at 8:27 AM, Leon Romanovsky <leonro@mellanox.com> wrote:
> On Wed, Jun 22, 2016 at 11:23:59AM -0700, Joe Perches wrote:
>> The logging macros create a bit of duplicated code/text.
>>
>> Use specialized functions to reduce the duplication.
>>
>> (defconfig/x86-64)
>> $ size drivers/net/ethernet/mellanox/mlx5/core/built-in.o*
>>    text          data     bss     dec     hex filename
>>  178634          2059      16  180709   2c1e5 drivers/net/ethernet/mellanox/mlx5/core/built-in.o.new
>>  188679          2059      16  190754   2e922 drivers/net/ethernet/mellanox/mlx5/core/built-in.o.old
>>
>> The output changes now do not include line #,
>> but do include the function offset.
>>
>> Signed-off-by: Joe Perches <joe@perches.com>
>
> As far as I see all these functions are used in error paths, so no
> implication on performance is expected.
>
> And I'm fine with function offsets.
>
> Saeed,
> What do you think?

Fine with me, need to fix my comment on functions placement, an your
comment on checkpatch.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-06-23  8:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-22 18:23 [PATCH] mellanox: mlx5: Use logging functions to reduce text ~10k/5% Joe Perches
2016-06-22 20:40 ` Jason Gunthorpe
2016-06-22 22:20   ` Joe Perches
2016-06-23  5:27 ` Leon Romanovsky
2016-06-23  7:12   ` Leon Romanovsky
2016-06-23  8:12   ` Saeed Mahameed
2016-06-23  8:09 ` Saeed Mahameed

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).