Messages in this thread | | | Date | Fri, 18 May 2007 18:37:26 -0400 | From | Jeff Garzik <> | Subject | Re: aio is unlikely |
| |
Andrew Morton wrote: > On Fri, 18 May 2007 17:54:32 -0400 > Phillip Susi <psusi@cfl.rr.com> wrote: > >> Andrew Morton wrote: >>> Yes, if you agree with Jeff's original point. >>> >>> But I don't, actually. Sure, on some machines+workloads, AIO is more >>> common than sync IO. But I expect that when we sum across all the >>> machines+workloads in the world, sync IO is more common and is hence the >>> case we should optimise for. >>> >>> That's assuming that the unlikely() actually does something. >> 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.
Jeff
- 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/
| |