lkml.org 
[lkml]   [2004]   [Feb]   [8]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateSun, 8 Feb 2004 21:43:35 +1100
FromRusty Russell <>
SubjectRe: When should we use likely() / unlikely() / get_unaligned() ?
On Fri, 06 Feb 2004 11:06:19 +0000
David Woodhouse <dwmw2@infradead.org> wrote:
> There seems to be no coherent answer to the above questions. On some
> architectures likely() might bypass dynamic branch prediction, so we
> shouldn't use it unless there's at _least_ a 95% probability; on others
> it may simply affect code ordering and we gain a tiny benefit from it if
> the probabilities aren't precisely 50/50.

Yes, agreed.  But many unlikely() macros are simply there because gcc isn't
smart enough yet:

eg. fs/read_write.c:

		if (unlikely(put_user(pos, offset)))
			return -EFAULT;
It'd be better to have gcc know that this function was unlikely to return
a -ve value, and derive all the error paths itself.

It'd also be nice to be able to mark eg. printk() and BUG() as fundamentally
unlikely.

Sometimes, unlikely()/likely() help code readability.  But generally it
should be considered the register keyword of the 2000's: if the case isn't
ABSOLUTELY CRYSTAL CLEAR, or doesn't show up on benchmarks, distain is
appropriate.

Cheers,
Rusty.
-- 
   there are those who do and those who hang on and you don't see too
   many doers quoting their contemporaries.  -- Larry McVoy
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:00    [from the cache]
©2003-2008