From: "H. Peter Anvin" <hpa@zytor.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Jason Baron <jbaron@redhat.com>,
a.p.zijlstra@chello.nl, rostedt@goodmis.org,
mathieu.desnoyers@efficios.com, davem@davemloft.net,
ddaney.cavm@gmail.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 00/10] jump label: introduce very_[un]likely + cleanups + docs
Date: Tue, 21 Feb 2012 23:55:00 -0800 [thread overview]
Message-ID: <efc1cd8f-7114-460b-a704-a3e533d48d02@email.android.com> (raw)
In-Reply-To: <20120222074839.GA24890@elte.hu>
Not arguing that, but the static aspect is still key... or people will read it as another version of likely/unlikely. I'd be fine with static_likely/unlikely for example; I wish "static" wasn't such an overloaded word in C but I can't.personally think of a better term.
Ingo Molnar <mingo@elte.hu> wrote:
>
>* H. Peter Anvin <hpa@zytor.com> wrote:
>
>> On 02/21/2012 11:25 PM, Ingo Molnar wrote:
>> >
>> > There is a fundamental assymetry, and intentionally so. You
>> > *really* have to think what the common case is, and make
>> > sure the build defaults to that. It's not the end of the
>> > world to have it flipped over, but there's costs and those
>> > costs are higher even in the branch path than a regular
>> > likely()/unlikely().
>>
>> No, not really -- it's still an unconditional branch, which
>> means you will not tax the branch predictor in any way and
>> which can be followed by the front end without taking a
>> speculation hit. [...]
>
>You are talking about CPU level costs, I am also talking about
>costs introduced at build time.
>
>Fact is, jump-label unlikely branches are moved *out of line*:
>they are often in unlikely portions of the function (near other
>unlikely branches), with instruction cache granularity costs and
>potentially higher instruction-cache miss costs attached, etc.
>
>You are missing three important aspects:
>
>Firstly, instead of:
>
> ins1
> ins2
> ins3
> ins4
> ins5
> ins-compare
> ins-branch
> ins6
> ins7
> ins8
> ins9
> ins10
>
>We have:
>
> ins1
> ins2
> ins3
> ins4
> ins5
> ins-jump
>
> [ hole ]
>
> ins6
> ins7
> ins8
> ins9
> ins10
> ins-jump back
>
>Where the 'hole' fragments the instruction cache layout. Given
>that most of kernel execution is instruction-cache-cold, the
>'straightness' of kernel code matters quite a bit.
>
>Secondly, there's build time instruction scheduling costs as
>well: GCC will prefer the likely branch over the unlikely one,
>so we might see extra instructions in the out-of-line code:
>
>
> ins1
> ins2
> ins3
> ins4
> ins5
> ins-jump
>
> [ hole ]
>
> ins-extra-1
> ins-extra-2
> ins6
> ins7
> ins8
> ins9
> ins10
> ins-jump back
>
>In that sense jump labels are unlikely() branches combined with
>a patching mechanism.
>
>Thus *both* aspects are important: if a branch is *truly* 50/50
>then it's quite possibly *NOT* a correct optimization to use
>jump-labels as the 'uncommon' code goes through extra hoops and
>fragments out of the fastpath, which in quite many real life
>cases can outstrip the advantage of the avoidance of a single
>branch ...
>
>Thirdly,
>
>even if it's a correct optimization and both branches happen to
>outperform the pre-jump-label version, regardless of the
>direction of the jump label flag, it's *STILL* fundamentally
>assymetric: due to the hole and due to the possible extra
>instructions the out of line code will be slower by a few
>instruction and the NOP fall-through will be faster.
>
>This is fundamentally so, and any naming that tries to *hide*
>that assymetry and the associated micro-costs is confused.
>
>Thanks,
>
> Ingo
--
Sent from my mobile phone. Please excuse my brevity and lack of formatting.
next prev parent reply other threads:[~2012-02-22 7:55 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-21 20:02 [PATCH 00/10] jump label: introduce very_[un]likely + cleanups + docs Jason Baron
2012-02-21 20:02 ` [PATCH 01/10] jump label: Add a WARN() if jump label key count goes negative Jason Baron
2012-02-29 10:13 ` [tip:perf/core] " tip-bot for Jason Baron
2012-02-21 20:02 ` [PATCH 02/10] jump label: fix compiler warning Jason Baron
2012-02-29 10:14 ` [tip:perf/core] jump label: Fix " tip-bot for Jason Baron
2012-02-21 20:03 ` [PATCH 03/10] jump label: introduce very_unlikely() Jason Baron
2012-02-21 20:03 ` [PATCH 04/10] jump label: introduce very_likely() Jason Baron
2012-02-21 20:03 ` [PATCH 05/10] perf: update to use 'very_unlikely()' Jason Baron
2012-02-21 20:03 ` [PATCH 06/10] tracepoints: update to use very_unlikely() Jason Baron
2012-02-21 20:03 ` [PATCH 07/10] sched: update to use very_[un]likely() Jason Baron
2012-02-21 20:03 ` [PATCH 08/10] kvm: update to use very_unlikely() Jason Baron
2012-02-21 20:03 ` [PATCH 09/10] net: " Jason Baron
2012-02-21 20:03 ` [PATCH 10/10] jump label: Add docs better explaining the whole jump label mechanism Jason Baron
2012-02-29 10:15 ` [tip:perf/core] static keys: Add docs better explaining the whole 'struct static_key' mechanism tip-bot for Jason Baron
2012-02-21 20:09 ` [PATCH 00/10] jump label: introduce very_[un]likely + cleanups + docs H. Peter Anvin
2012-02-21 20:20 ` Jason Baron
2012-02-21 20:39 ` Steven Rostedt
2012-02-21 21:10 ` H. Peter Anvin
2012-02-21 21:16 ` Mathieu Desnoyers
2012-02-21 21:11 ` Mathieu Desnoyers
2012-02-22 7:32 ` Ingo Molnar
2012-02-22 7:53 ` Ingo Molnar
2012-02-22 8:01 ` H. Peter Anvin
2012-02-22 8:18 ` Ingo Molnar
2012-02-22 8:58 ` [PATCH] static keys: Introduce 'struct static_key', very_[un]likely(), static_key_slow_[inc|dec]() Ingo Molnar
2012-02-29 10:16 ` [tip:perf/core] static keys: Introduce 'struct static_key', static_key_true()/false() and static_key_slow_[inc|dec]() tip-bot for Ingo Molnar
2012-02-22 9:03 ` [PATCH] jump labels: Explain the .config option better Ingo Molnar
2012-02-22 15:08 ` [PATCH 00/10] jump label: introduce very_[un]likely + cleanups + docs H. Peter Anvin
2012-02-22 15:51 ` Ingo Molnar
2012-02-22 21:33 ` Paul Mackerras
2012-02-23 10:02 ` Ingo Molnar
2012-02-23 16:21 ` Jason Baron
2012-02-23 17:10 ` H. Peter Anvin
2012-02-24 9:11 ` Ingo Molnar
2012-02-23 17:18 ` Linus Torvalds
2012-02-23 22:33 ` Ingo Molnar
2012-02-23 22:39 ` Ingo Molnar
2012-02-23 22:44 ` Steven Rostedt
2012-02-23 23:18 ` Mathieu Desnoyers
2012-02-24 2:25 ` Jason Baron
2012-02-24 9:08 ` Ingo Molnar
2012-02-24 15:35 ` Jason Baron
2012-02-27 7:40 ` Ingo Molnar
2012-02-24 15:51 ` Mathieu Desnoyers
2012-02-24 16:06 ` Steven Rostedt
2012-02-24 7:52 ` static keys: Introduce 'struct static_key', static_key_true()/false() and static_key_slow_[inc|dec]() Ingo Molnar
2012-02-24 7:59 ` [PATCH] " Ingo Molnar
2012-02-24 7:54 ` [PATCH] static keys: Add docs better explaining the whole 'struct static_key' mechanism Ingo Molnar
2012-02-23 22:45 ` [PATCH 00/10] jump label: introduce very_[un]likely + cleanups + docs Linus Torvalds
2012-02-24 8:04 ` Ingo Molnar
2012-02-24 2:42 ` Jason Baron
2012-02-21 20:21 ` Steven Rostedt
2012-02-21 21:11 ` H. Peter Anvin
2012-02-22 6:50 ` Ingo Molnar
2012-02-22 7:03 ` H. Peter Anvin
2012-02-22 7:25 ` Ingo Molnar
2012-02-22 7:35 ` H. Peter Anvin
2012-02-22 7:48 ` Ingo Molnar
2012-02-22 7:55 ` H. Peter Anvin [this message]
2012-02-22 8:06 ` Ingo Molnar
2012-02-22 13:22 ` Steven Rostedt
2012-02-22 13:34 ` Ingo Molnar
2012-02-22 13:54 ` Steven Rostedt
2012-02-22 14:20 ` Mathieu Desnoyers
2012-02-22 14:36 ` Steven Rostedt
2012-02-22 14:56 ` Ingo Molnar
2012-02-22 15:11 ` H. Peter Anvin
2012-02-22 15:11 ` Peter Zijlstra
2012-02-22 15:47 ` Ingo Molnar
2012-02-22 15:12 ` Steven Rostedt
2012-02-22 15:15 ` H. Peter Anvin
2012-02-22 15:19 ` H. Peter Anvin
2012-02-22 15:42 ` Jason Baron
2012-02-22 15:54 ` Steven Rostedt
2012-02-22 15:56 ` Jason Baron
2012-02-22 16:08 ` Steven Rostedt
2012-02-22 15:19 ` Jason Baron
2012-02-22 15:40 ` H. Peter Anvin
2012-02-22 15:13 ` Peter Zijlstra
2012-02-22 15:32 ` Peter Zijlstra
2012-02-22 17:14 ` Richard Henderson
2012-02-22 18:28 ` H. Peter Anvin
2012-02-22 18:58 ` Jason Baron
2012-02-22 19:10 ` H. Peter Anvin
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=efc1cd8f-7114-460b-a704-a3e533d48d02@email.android.com \
--to=hpa@zytor.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=ddaney.cavm@gmail.com \
--cc=jbaron@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).