Thread (8 messages) 8 messages, 5 authors, 2011-08-03

Usage of unlikely in RCU code

From: Julie Sullivan <hidden>
Date: 2011-08-03 20:13:57

On Wed, Aug 3, 2011 at 7:37 AM, Mulyadi Santosa
[off-list ref] wrote:
Dear Julie....

On Tue, Aug 2, 2011 at 04:28, Julie Sullivan [off-list ref] wrote:
quoted
Specifically, the conditional

?if (t->rcu_read_lock_nesting == 0 &&
? ? ? ? ? ?unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
? ? ? ? ? ? ? ?rcu_read_unlock_special(t);

I've googled for 'likely/unlikely' and i've seen

?if (unlikely(...

before in kernel code, and I might understand if the logical operator
here were || not &&, but why is the 'unlikely' attribute only applied
to the second operand here?
i guess that's because first condition "t->rcu_read_lock_nesting == 0"
has about 50%-50% chance.... so putting likely() or unlikely() has no
use here...

i read somewhere (or maybe someone's opinion) that you only use
likely() or unlikely() if you are about above 90% (or maybe...if
possible 99%) sure that condition will be true or false....otherwise,
avoid likely()/unlikely() and let the compiler+processor do the usual
ordering/branch prediction.

just my 2 cents...

--
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

Thanks Mulyadi, maybe someday when I get round to performance testing
I'll try this out for myself...


Cheers
Julie
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help