Re: [CFR] Replacing while loops with proper division and multiplication

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Fri, 5 Jun 2015 14:38:16 +0300
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.
Received on Fri Jun 05 2015 - 09:38:22 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:58 UTC