From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Pavel Machek <pavel@ucw.cz>
Cc: Dave Jones <davej@redhat.com>,
Mitchell Blank Jr <mitch@sfgoth.com>,
Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] oops_in_progress is unlikely()
Date: Wed, 10 Sep 2003 12:07:02 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.53.0309101147040.14762@chaos> (raw)
In-Reply-To: <20030910152902.GA2764@elf.ucw.cz>
On Wed, 10 Sep 2003, Pavel Machek wrote:
> Hi!
>
> > > > none of this patch seems to touch particularly performance critical code.
> > > > Is it really worth adding these macros to every if statement in the kernel?
> > > > There comes a point where readability is lost, for no measurable gain.
> > >
> > > Perhaps we should have macros ifu() and ifl(), that would be used as a
> > > plain if, just with likelyness-indication? That way we could have it
> > > in *every* statement and readability would not suffer that much...
> >
> > You've got to be kidding.
>
> I'm pretty serious.
>
> ifu (a==b) {
> something();
> }
>
> looks better than
>
> if (unlikely(a==b)) {
> something();
> }
>
> sched.c alone probably would get more readable as a result of such
> conversion...
>
> [Okay, having it at every statement is prbably bad idea.]
> Pavel
> --
> When do you have a heart between your knees?
> [Johanka's followup: and *two* hearts?]
Dumb question? Has anybody actually tested "__builtin_expect", and
friends to see if any of this "coloration" actually enhances performance?
"unlikely()" is the negative of the new built-in. I would guess that
any conversion operations are going to negate any advantage possibly
gained by reordering instructions.
For instance:
Given:
if(a == b)
foo();
else
bar();
... and ...
if(unlikely(a == b))
foo();
else
bar();
I would guess that the compiler output might be:
movl a(%esp), %eax # Get 'a' off the stack
cmpl b(%esp), %eax # Compare against 'b' on the stack
jnz 1f # Not the same
call foo # Are the same, call foo()
jmp 2f # Need to jump around stuff
1: call bar # Execute bar()
2: # Do more stuff.
Note that no matter what you do, comparing equal or not equal,
when you get down to the actual code, it's apples and apples.
You are always going to take an extra jump in one execution
path after the function, and you will take a conditional jump
before the function call in the other execution path. So, you
always have the "extra" jumps, no matter.
I would guess that most all of the conditional code will turn
out this way and, won't even be as efficient as what I have
written above.
Before a lot of readable code is modified (trashed???), maybe
somebody should benchmark the differences? The tests I have
made here, seem to show that any measurment differences are
in the noise and... favor leaving __builtin_expect() out of
the code.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (794.73 BogoMips).
Note 96.31% of all statistics are fiction.
next prev parent reply other threads:[~2003-09-10 16:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-07 6:42 Mitchell Blank Jr
2003-09-07 22:13 ` Dave Jones
2003-09-10 14:20 ` Pavel Machek
2003-09-10 14:23 ` Dave Jones
2003-09-10 15:29 ` Pavel Machek
2003-09-10 16:07 ` Richard B. Johnson [this message]
2003-09-10 18:31 ` Jamie Lokier
2003-09-10 18:58 ` Richard B. Johnson
2003-09-10 19:02 ` Pavel Machek
2003-09-10 20:12 ` Jamie Lokier
2003-09-10 20:32 ` Richard B. Johnson
2003-09-10 21:27 ` Pavel Machek
2003-09-10 21:52 ` Jamie Lokier
2003-09-10 21:46 ` Jamie Lokier
2003-09-12 5:12 ` Mitchell Blank Jr
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=Pine.LNX.4.53.0309101147040.14762@chaos \
--to=root@chaos.analogic.com \
--cc=akpm@osdl.org \
--cc=davej@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mitch@sfgoth.com \
--cc=pavel@ucw.cz \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®