Re: [PATCH] driver core: Add branch prediction hints in really_probe()

From: Greg KH
Date: Tue Nov 06 2018 - 15:27:03 EST


On Tue, Nov 06, 2018 at 09:46:30PM +0800, Muchun Song wrote:
> If condition is false in most cases. So, add an unlikely() to the if
> condition, so that the optimizer assumes that the condition is false.
>
> Signed-off-by: Muchun Song <smuchun@xxxxxxxxx>

As Rafael said, don't do stuff like this unless you can actually measure
the difference. Last time we tested the kernel for this a few years
ago, about 75% of the unlikely/likely additions were incorrect, removing
them made the kernel faster. Turns out the compiler and cpu know better
than developers do :)

Also, the probe() path is never a hot-path to worry about stuff like
this.

thanks,

greg k-h