[CFR] Replacing while loops with proper division and multiplication

Konstantin Belousov kostikbel at gmail.com
Fri Jun 5 11:38:22 UTC 2015


On Fri, Jun 05, 2015 at 09:09:26AM +0200, Hans Petter Selasky wrote:
> Hi,
> 
> I was going through some timer code and found some unnecessary while 
> loops in kern/kern_clocksource.c .
> 
> I added some prints and found that during boot, "runs" can exceed 2000, 
> while during regular usage runs is typically 1. Do you think it is worth 
> to convert these loops into division and multiplications? It might make 
> the CPU pipeline a tiny bit faster, having to skip some conditionals? 
> And also possibly improve readability?
For typical loop count of one, I think that setup time for the division is
much greater than single substraction and non-taken conditional jump, which
is also should be consistently predicted as not taken.

You could try to run a microbenchmark to see if the patch makes any sense.


More information about the freebsd-current mailing list