public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Jeff Garzik <jeff@garzik.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Phillip Susi <psusi@cfl.rr.com>,
	Alex Volkov <avcp-lkmail@usa.net>,
	"'Linux Kernel Mailing List'" <linux-kernel@vger.kernel.org>
Subject: Re: aio is unlikely
Date: Sat, 19 May 2007 13:43:16 +1000	[thread overview]
Message-ID: <464E7254.60406@yahoo.com.au> (raw)
In-Reply-To: <464E2AA6.3080402@garzik.org>

Jeff Garzik wrote:
> Andrew Morton wrote:
> 
>> On Fri, 18 May 2007 17:54:32 -0400
>> Phillip Susi <psusi@cfl.rr.com> wrote:

>>> But as Jeff said, that's not what unlikely is for.  It should only be 
>>> used when it is unlikely for everybody, all the time, because when it 
>>> is right, it helps rather little, but when it is wrong, it hurts a lot.
>>
>>
>> It does?  Tell us more.
> 
> 
> It is difficult to quantify either way.  The details are both 
> CPU-specific and compiler-specific.  The best information can be culled 
> from the gcc list archives, which is where I obtained my knowledge on 
> the subject (which is now ~2 years old).
> 
> Under the hood, likely() and unlikely() are implemented as percentage 
> predictions.  likely() is implemented in the kernel as a 99-100% chance 
> of success, and unlikely() is implemented as a 0-1% chance of success.
> 
> As such, for our purposes, likely() and unlikely() should only be used 
> when a situation is [likely | unlikely] across all runtime 
> configurations.  So if you mark a branch unlikely() when it is hit often 
> by 1% of your users, that is an incorrect usage.
> 
> The effects are probably most dramatic on older CPUs.  Repeatedly 
> hitting an unlikely() can cause a pipeline stall on every single access. 
>  Branch delay slots are filled improperly, with obvious implications.
> 
> But on modern hardware, I would /guess/ that the effect of repeatedly 
> hitting an unlikely() would be mitigated by smarter branch prediction.
> 
> We really need a GCC expert to answer this question in any more detail.

Aside from using branch constructs or hints that help the predictor
guess the right way... I think gcc will move unlikely paths right past
the end of the "likely" fastpath, so it can increase code size and be
somewhat suboptimal in terms of icache usage.

I don't know particularly why it would hurt a lot more when it goes
wrong than it helps when it goes right, though.

Also, I don't think I agree that it should be used where it is correct
for all users. We make rt_task unlikely in the scheduler, and I measured
that a very long time ago was IIRC good for nearly 5% pipe based context
switching peformance. Systems running a lot of rt tasks aren't going to
like it, but bugger them :)

-- 
SUSE Labs, Novell Inc.

  reply	other threads:[~2007-05-19  3:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200705092101.l49L1CF1023363@hera.kernel.org>
2007-05-09 22:06 ` aio is unlikely Jeff Garzik
2007-05-09 22:18   ` Andrew Morton
2007-05-09 22:37     ` Jeff Garzik
2007-05-18 20:49     ` Alex Volkov
2007-05-18 21:06       ` Andrew Morton
2007-05-18 21:11         ` Jeff Garzik
2007-05-18 21:54         ` Phillip Susi
2007-05-18 22:12           ` Andrew Morton
2007-05-18 22:37             ` Jeff Garzik
2007-05-19  3:43               ` Nick Piggin [this message]
2007-05-19  3:50                 ` Jeff Garzik
2007-05-18 21:30       ` Bernd Eckenfels

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=464E7254.60406@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=akpm@linux-foundation.org \
    --cc=avcp-lkmail@usa.net \
    --cc=jeff@garzik.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=psusi@cfl.rr.com \
    /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