* Side-effect free printk?
@ 2014-12-03 17:50 Joe Perches
2014-12-03 18:02 ` Julia Lawall
2014-12-05 10:32 ` printf vs. printk (was Re: Side-effect free printk?) Pavel Machek
0 siblings, 2 replies; 6+ messages in thread
From: Joe Perches @ 2014-12-03 17:50 UTC (permalink / raw)
To: Julia Lawall, cocci; +Cc: LKML
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...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Side-effect free printk?
2014-12-03 17:50 Side-effect free printk? Joe Perches
@ 2014-12-03 18:02 ` Julia Lawall
2014-12-03 18:05 ` Joe Perches
2014-12-05 10:32 ` printf vs. printk (was Re: Side-effect free printk?) Pavel Machek
1 sibling, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2014-12-03 18:02 UTC (permalink / raw)
To: Joe Perches; +Cc: cocci, Sebastien.Hinderer, LKML
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...
I'm not completely sure to understand the question. The following
is certainly possible:
printk(...,\(x++\|x--\|++x\|--x\),...)
Of course one would want to have a lot more operators than the ones shown.
(As a side note, we are planning to add a metavariable for arithmetic and
side-effecting operators, which will make this sort of thing much
simpler.)
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.
Perhaps the most relevant case is when there is a definition in the same
file, typically a macro in a header file. It could still be complicated
to make a pattern that would match all of the possibilities.
julia
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Side-effect free printk?
2014-12-03 18:02 ` Julia Lawall
@ 2014-12-03 18:05 ` Joe Perches
0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2014-12-03 18:05 UTC (permalink / raw)
To: Julia Lawall; +Cc: cocci, Sebastien.Hinderer, LKML
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* printf vs. printk (was Re: Side-effect free printk?)
2014-12-03 17:50 Side-effect free printk? Joe Perches
2014-12-03 18:02 ` Julia Lawall
@ 2014-12-05 10:32 ` Pavel Machek
2014-12-05 15:24 ` Joe Perches
1 sibling, 1 reply; 6+ messages in thread
From: Pavel Machek @ 2014-12-05 10:32 UTC (permalink / raw)
To: Joe Perches; +Cc: Julia Lawall, cocci, LKML
Hi!
BTW... All the time I'm programming in kernel, I use printf(), and
when hacking userspace, I use printk().
Nasty.
Given that printf() and printk() have exactly the same behaviour,
could we allow printf() in kernel? Now... printk()s are usually
removed before merging the driver, so code will not see much change,
but it will certainly result in less 4-letter words while developing.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: printf vs. printk (was Re: Side-effect free printk?)
2014-12-05 10:32 ` printf vs. printk (was Re: Side-effect free printk?) Pavel Machek
@ 2014-12-05 15:24 ` Joe Perches
2014-12-05 15:26 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2014-12-05 15:24 UTC (permalink / raw)
To: Pavel Machek; +Cc: Julia Lawall, cocci, LKML
On Fri, 2014-12-05 at 11:32 +0100, Pavel Machek wrote:
> Hi!
>
> BTW... All the time I'm programming in kernel, I use printf(), and
> when hacking userspace, I use printk().
>
> Nasty.
>
> Given that printf() and printk() have exactly the same behaviour,
> could we allow printf() in kernel? Now... printk()s are usually
> removed before merging the driver, so code will not see much change,
> but it will certainly result in less 4-letter words while developing.
My preference would be to eventually eliminate printk
altogether but I don't see a real problem adding
#define printf printk
to include/linux/printk.h
but
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: printf vs. printk (was Re: Side-effect free printk?)
2014-12-05 15:24 ` Joe Perches
@ 2014-12-05 15:26 ` Joe Perches
0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2014-12-05 15:26 UTC (permalink / raw)
To: Pavel Machek; +Cc: Julia Lawall, cocci, LKML
On Fri, 2014-12-05 at 07:24 -0800, Joe Perches wrote:
> My preference would be to eventually eliminate printk
> altogether but I don't see a real problem adding
> #define printf printk
> to include/linux/printk.h
>
> but
(bah, bad touchpad)
but I'm not going to write or ack that patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-12-05 15:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-03 17:50 Side-effect free printk? Joe Perches
2014-12-03 18:02 ` Julia Lawall
2014-12-03 18:05 ` Joe Perches
2014-12-05 10:32 ` printf vs. printk (was Re: Side-effect free printk?) Pavel Machek
2014-12-05 15:24 ` Joe Perches
2014-12-05 15:26 ` Joe Perches
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).