All of lore.kernel.org
 help / color / mirror / Atom feed
From: joe@perches.com (Joe Perches)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Side-effect free printk?
Date: Wed, 03 Dec 2014 10:05:58 -0800	[thread overview]
Message-ID: <1417629958.2902.18.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1412031855180.2373@hadrien>

On Wed, 2014-12-03 at 19:02 +0100, Julia Lawall wrote:
> 
> On Wed, 3 Dec 2014, Joe Perches wrote:
> 
> > Most all printks uses do not have any side-effects.
> >
> > Some however modify local or global state or perform
> > IO on various ports.
> >
> > Things like:
> >
> > drivers/video/fbdev/sa1100fb.c:	dev_dbg(fbi->dev, "DBAR1: 0x%08x\n", readl_relaxed(fbi->base + DBAR1));
> > drivers/remoteproc/remoteproc_core.c:	dev_err(dev, "handling crash #%u in %s\n", ++rproc->crash_cnt,
> >
> > CONFIG_PRINTK can be set to 'n', but all direct printk
> > calls still evaluate their arguments.
> >
> > These calls can unnecessarily increase code size.
> >
> > Some printk using macros are defined like:
> >
> > #define foo_dbg(fmt, ...)	\
> > do {				\
> > 	if (0)			\
> > 		printk(...);	\
> > } while (0)
> >
> > The compiler can optimize any use away so this can
> > eliminate any side-effect.
> >
> > For the general case, printk arguments that call
> > functions that perform simple calculations should not
> > qualify unless there is some global state change or
> > additional IO.
> >
> > So, with the goal of elimination of side-effects from
> > as many of the printks as possible (and the eventual
> > removal of all of the side-effects), is it possible to
> > use coccinelle to list all printk calls that have
> > side-effects in their arguments?
> >
> > It seems coccinelle would need the entire source tree
> > to do this, so I'm not sure it's possible, but it
> > doesn't hurt to ask...
[]
> When you say "have the entire source tree", do you mean things like:
> 
> printk(..., foo(x));
> 
> where it is not clear whether foo performs a side effect or not?  That
> could indeed be harder to detect.

Yes, exactly.

The ++/-- stuff is trivial.
grep can find those easily enough.

WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: cocci <cocci@systeme.lip6.fr>,
	Sebastien.Hinderer@inria.fr, LKML <linux-kernel@vger.kernel.org>
Subject: Re: Side-effect free printk?
Date: Wed, 03 Dec 2014 10:05:58 -0800	[thread overview]
Message-ID: <1417629958.2902.18.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1412031855180.2373@hadrien>

On Wed, 2014-12-03 at 19:02 +0100, Julia Lawall wrote:
> 
> On Wed, 3 Dec 2014, Joe Perches wrote:
> 
> > Most all printks uses do not have any side-effects.
> >
> > Some however modify local or global state or perform
> > IO on various ports.
> >
> > Things like:
> >
> > drivers/video/fbdev/sa1100fb.c:	dev_dbg(fbi->dev, "DBAR1: 0x%08x\n", readl_relaxed(fbi->base + DBAR1));
> > drivers/remoteproc/remoteproc_core.c:	dev_err(dev, "handling crash #%u in %s\n", ++rproc->crash_cnt,
> >
> > CONFIG_PRINTK can be set to 'n', but all direct printk
> > calls still evaluate their arguments.
> >
> > These calls can unnecessarily increase code size.
> >
> > Some printk using macros are defined like:
> >
> > #define foo_dbg(fmt, ...)	\
> > do {				\
> > 	if (0)			\
> > 		printk(...);	\
> > } while (0)
> >
> > The compiler can optimize any use away so this can
> > eliminate any side-effect.
> >
> > For the general case, printk arguments that call
> > functions that perform simple calculations should not
> > qualify unless there is some global state change or
> > additional IO.
> >
> > So, with the goal of elimination of side-effects from
> > as many of the printks as possible (and the eventual
> > removal of all of the side-effects), is it possible to
> > use coccinelle to list all printk calls that have
> > side-effects in their arguments?
> >
> > It seems coccinelle would need the entire source tree
> > to do this, so I'm not sure it's possible, but it
> > doesn't hurt to ask...
[]
> When you say "have the entire source tree", do you mean things like:
> 
> printk(..., foo(x));
> 
> where it is not clear whether foo performs a side effect or not?  That
> could indeed be harder to detect.

Yes, exactly.

The ++/-- stuff is trivial.
grep can find those easily enough.



  reply	other threads:[~2014-12-03 18:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-03 17:50 [Cocci] Side-effect free printk? Joe Perches
2014-12-03 17:50 ` Joe Perches
2014-12-03 18:02 ` [Cocci] " Julia Lawall
2014-12-03 18:02   ` Julia Lawall
2014-12-03 18:05   ` Joe Perches [this message]
2014-12-03 18:05     ` Joe Perches
2014-12-05 10:32 ` [Cocci] printf vs. printk (was Re: Side-effect free printk?) Pavel Machek
2014-12-05 10:32   ` Pavel Machek
2014-12-05 15:24   ` [Cocci] " Joe Perches
2014-12-05 15:24     ` Joe Perches
2014-12-05 15:26     ` [Cocci] " Joe Perches
2014-12-05 15:26       ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417629958.2902.18.camel@perches.com \
    --to=joe@perches.com \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.