|From:||Rusty Russell <rusty-AT-rustcorp.com.au>|
|To:||David Woodhouse <dwmw2-AT-infradead.org>|
|Subject:||Re: When should we use likely() / unlikely() / get_unaligned() ?|
|Date:||Sun, 8 Feb 2004 21:43:35 +1100|
|Cc:||linux-kernel-AT-vger.kernel.org, matthew-AT-wil.cx, rth-AT-twiddle.net|
On Fri, 06 Feb 2004 11:06:19 +0000 David Woodhouse <email@example.com> 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 firstname.lastname@example.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Copyright © 2004, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds