Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1213183 > unrolled thread

[PATCH] cred: Remove unnecessary kdebug atomic reads

Started byJoe Perches <joe@perches.com>
First post2015-08-25 19:00 +0200
Last post2015-08-26 01:40 +0200
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] cred: Remove unnecessary kdebug atomic reads Joe Perches <joe@perches.com> - 2015-08-25 19:00 +0200
    Re: [PATCH] cred: Remove unnecessary kdebug atomic reads Andrew Morton <akpm@linux-foundation.org> - 2015-08-25 22:40 +0200
      Re: [PATCH] cred: Remove unnecessary kdebug atomic reads Andrew Morton <akpm@linux-foundation.org> - 2015-08-25 23:00 +0200
        Re: [PATCH] cred: Remove unnecessary kdebug atomic reads Joe Perches <joe@perches.com> - 2015-08-25 23:20 +0200
      Re: [PATCH] cred: Remove unnecessary kdebug atomic reads Joe Perches <joe@perches.com> - 2015-08-25 23:00 +0200
      Re: [PATCH] cred: Remove unnecessary kdebug atomic reads David Howells <dhowells@redhat.com> - 2015-08-26 01:40 +0200

#1213183 — [PATCH] cred: Remove unnecessary kdebug atomic reads

FromJoe Perches <joe@perches.com>
Date2015-08-25 19:00 +0200
Subject[PATCH] cred: Remove unnecessary kdebug atomic reads
Message-ID<q1pJL-3ZR-7@gated-at.bofh.it>
commit e0e817392b9a ("CRED: Add some configurable debugging [try #6]")
added the kdebug mechanism to this file back in 2009.

The kdebug macro calls no_printk which always evaluates arguments.

Most of the kdebug uses have an unnecessary call of
	atomic_read(&cred->usage)

Make the kdebug macro do nothing by defining it with
	do { if (0) no_printk(...); } while (0)
when not enabled.

$ size kernel/cred.o* (defconfig x86-64)
   text	   data	    bss	    dec	    hex	filename
   2748	    336	      8	   3092	    c14	kernel/cred.o.new
   2788	    336	      8	   3132	    c3c	kernel/cred.o.old

Miscellanea:
o Neaten the #define kdebug macros while there

Signed-off-by: Joe Perches <joe@perches.com>
---
 kernel/cred.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/kernel/cred.c b/kernel/cred.c
index ec1c076..71179a0 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -20,11 +20,16 @@
 #include <linux/cn_proc.h>
 
 #if 0
-#define kdebug(FMT, ...) \
-	printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__)
+#define kdebug(FMT, ...)						\
+	printk("[%-5.5s%5u] " FMT "\n",					\
+	       current->comm, current->pid, ##__VA_ARGS__)
 #else
-#define kdebug(FMT, ...) \
-	no_printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__)
+#define kdebug(FMT, ...)						\
+do {									\
+	if (0)								\
+		no_printk("[%-5.5s%5u] " FMT "\n",			\
+			  current->comm, current->pid, ##__VA_ARGS__);	\
+} while (0)
 #endif
 
 static struct kmem_cache *cred_jar;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1213322

FromAndrew Morton <akpm@linux-foundation.org>
Date2015-08-25 22:40 +0200
Message-ID<q1taF-He-7@gated-at.bofh.it>
In reply to#1213183
On Tue, 25 Aug 2015 09:53:51 -0700 Joe Perches <joe@perches.com> wrote:

> commit e0e817392b9a ("CRED: Add some configurable debugging [try #6]")
> added the kdebug mechanism to this file back in 2009.
> 
> The kdebug macro calls no_printk which always evaluates arguments.
> 
> Most of the kdebug uses have an unnecessary call of
> 	atomic_read(&cred->usage)
> 
> Make the kdebug macro do nothing by defining it with
> 	do { if (0) no_printk(...); } while (0)
> when not enabled.
> 
> $ size kernel/cred.o* (defconfig x86-64)
>    text	   data	    bss	    dec	    hex	filename
>    2748	    336	      8	   3092	    c14	kernel/cred.o.new
>    2788	    336	      8	   3132	    c3c	kernel/cred.o.old
> 
> Miscellanea:
> o Neaten the #define kdebug macros while there
> 
> ...
>
> --- a/kernel/cred.c
> +++ b/kernel/cred.c
> @@ -20,11 +20,16 @@
>  #include <linux/cn_proc.h>
>  
>  #if 0
> -#define kdebug(FMT, ...) \
> -	printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__)
> +#define kdebug(FMT, ...)						\
> +	printk("[%-5.5s%5u] " FMT "\n",					\
> +	       current->comm, current->pid, ##__VA_ARGS__)
>  #else
> -#define kdebug(FMT, ...) \
> -	no_printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__)
> +#define kdebug(FMT, ...)						\
> +do {									\
> +	if (0)								\
> +		no_printk("[%-5.5s%5u] " FMT "\n",			\
> +			  current->comm, current->pid, ##__VA_ARGS__);	\
> +} while (0)
>  #endif
>  
>  static struct kmem_cache *cred_jar;

Did you consider doing this within no_printk()?  That would break code
which is relying on side-effects in the evaluation of a printk arg but
that's pretty weird and I bet there isn't (and won't be) such code.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1213340

FromAndrew Morton <akpm@linux-foundation.org>
Date2015-08-25 23:00 +0200
Message-ID<q1tu2-142-23@gated-at.bofh.it>
In reply to#1213322
On Tue, 25 Aug 2015 13:51:06 -0700 Joe Perches <joe@perches.com> wrote:

> On Tue, 2015-08-25 at 13:39 -0700, Andrew Morton wrote:
> > On Tue, 25 Aug 2015 09:53:51 -0700 Joe Perches <joe@perches.com> wrote:
> > > commit e0e817392b9a ("CRED: Add some configurable debugging [try #6]")
> > > added the kdebug mechanism to this file back in 2009.
> > > 
> > > The kdebug macro calls no_printk which always evaluates arguments.
> > > 
> > > Most of the kdebug uses have an unnecessary call of
> > > 	atomic_read(&cred->usage)
> > > 
> > > Make the kdebug macro do nothing by defining it with
> > > 	do { if (0) no_printk(...); } while (0)
> > > when not enabled.
> []
> > Did you consider doing this within no_printk()?
> 
> Yes.
> 
> > That would break code
> > which is relying on side-effects in the evaluation of a printk arg but
> > that's pretty weird and I bet there isn't (and won't be) such code.
> 
> I'll bet you there is more than a little and I don't want to
> experiment with it unconditionally.
> 
> All printks would need to be evaluated for that side-effect.
> 
> Safer would be to create a new no_eval_printk macro and convert
> the no_printk uses over to that as appropriate and possibly create
> a CONFIG_ option to use no_eval_printk instead of no_printk/printk
> and let the adventurous find the side-effects.
> 
> Maybe a coccinelle script can be written to find all the locations
> with evaluated non-constant expression arguments with side-effects.

wimp.


That duplicated printk in cred.c is nasty.  We could do this?

#if 0
#define __kdebug printk
#else
#define __kdebug if (0) no_printk
#endif

#define kdebug(FMT, ...) \
	__kdebug(...)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1213364

FromJoe Perches <joe@perches.com>
Date2015-08-25 23:20 +0200
Message-ID<q1tNo-1Gf-19@gated-at.bofh.it>
In reply to#1213340
On Tue, 2015-08-25 at 13:56 -0700, Andrew Morton wrote:
> On Tue, 25 Aug 2015 13:51:06 -0700 Joe Perches <joe@perches.com> wrote:
> 
> > On Tue, 2015-08-25 at 13:39 -0700, Andrew Morton wrote:
> > > On Tue, 25 Aug 2015 09:53:51 -0700 Joe Perches <joe@perches.com> wrote:
> > > > commit e0e817392b9a ("CRED: Add some configurable debugging [try #6]")
> > > > added the kdebug mechanism to this file back in 2009.
> > > > 
> > > > The kdebug macro calls no_printk which always evaluates arguments.
> > > > 
> > > > Most of the kdebug uses have an unnecessary call of
> > > > 	atomic_read(&cred->usage)
> > > > 
> > > > Make the kdebug macro do nothing by defining it with
> > > > 	do { if (0) no_printk(...); } while (0)
> > > > when not enabled.
> > []
> > > Did you consider doing this within no_printk()?
> > 
> > Yes.
> > 
> > > That would break code
> > > which is relying on side-effects in the evaluation of a printk arg but
> > > that's pretty weird and I bet there isn't (and won't be) such code.
> > 
> > I'll bet you there is more than a little and I don't want to
> > experiment with it unconditionally.
> > 
> > All printks would need to be evaluated for that side-effect.
> > 
> > Safer would be to create a new no_eval_printk macro and convert
> > the no_printk uses over to that as appropriate and possibly create
> > a CONFIG_ option to use no_eval_printk instead of no_printk/printk
> > and let the adventurous find the side-effects.
> > 
> > Maybe a coccinelle script can be written to find all the locations
> > with evaluated non-constant expression arguments with side-effects.
> 
> wimp.

twice shy...

Coccinelle isn't very good at calling tree analysis, so it'd
be a difficult thing for it to do well anyway.

btw; I seems to recall suggestions around the same thing when
no_printk was moved from subsystems to kernel.h by David Howells
in 2010.

> That duplicated printk in cred.c is nasty.  We could do this?
> 
> #if 0
> #define __kdebug printk
> #else
> #define __kdebug if (0) no_printk
> #endif

You could, but what's there is a very common idiom and what
you suggest is unsafe for if/else


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1213344

FromJoe Perches <joe@perches.com>
Date2015-08-25 23:00 +0200
Message-ID<q1tu2-142-25@gated-at.bofh.it>
In reply to#1213322
On Tue, 2015-08-25 at 13:39 -0700, Andrew Morton wrote:
> On Tue, 25 Aug 2015 09:53:51 -0700 Joe Perches <joe@perches.com> wrote:
> > commit e0e817392b9a ("CRED: Add some configurable debugging [try #6]")
> > added the kdebug mechanism to this file back in 2009.
> > 
> > The kdebug macro calls no_printk which always evaluates arguments.
> > 
> > Most of the kdebug uses have an unnecessary call of
> > 	atomic_read(&cred->usage)
> > 
> > Make the kdebug macro do nothing by defining it with
> > 	do { if (0) no_printk(...); } while (0)
> > when not enabled.
[]
> Did you consider doing this within no_printk()?

Yes.

> That would break code
> which is relying on side-effects in the evaluation of a printk arg but
> that's pretty weird and I bet there isn't (and won't be) such code.

I'll bet you there is more than a little and I don't want to
experiment with it unconditionally.

All printks would need to be evaluated for that side-effect.

Safer would be to create a new no_eval_printk macro and convert
the no_printk uses over to that as appropriate and possibly create
a CONFIG_ option to use no_eval_printk instead of no_printk/printk
and let the adventurous find the side-effects.

Maybe a coccinelle script can be written to find all the locations
with evaluated non-constant expression arguments with side-effects.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1213438

FromDavid Howells <dhowells@redhat.com>
Date2015-08-26 01:40 +0200
Message-ID<q1vYR-50b-11@gated-at.bofh.it>
In reply to#1213322
Andrew Morton <akpm@linux-foundation.org> wrote:

> Did you consider doing this within no_printk()?  That would break code
> which is relying on side-effects in the evaluation of a printk arg but
> that's pretty weird and I bet there isn't (and won't be) such code.

The reasons that no_printk() is like it is are (1) so that the side-effects
stay intact and (2) you still get format warnings.  If someone prints a device
register, for example, it *must* work the same whether or not you use printk()
or no_printk().  Of course, printing a device register like this is probably
not a good idea...

David
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web