Skip to content

Use architected timers for delay loop

Russell King - ARM Linux linux-arm-kernel 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest0 of 2 patches 0 repliesNew

Patches in v1 No applies recorded yet

None of the 2 patches the cover letter announces are in this archive.

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] Use architected timers for delay loop
Quoted 11 lines · Will Deacon

Hello,

This patch series reworks our delay loop implementation to allow the busy-loop to be replaced with the physical counter included as part of the architected timer on recent CPUs. The polling implementation is still maintained to support cores without the timers and we use the same maths and upper delay bound of 2ms.

Russell - I think my maths is correct, but why can't we increase the
precision by using a magic constant of 4398046U and a right shift of 31?

It's been soo long since I looked at that code that I've forgotten the maths behind it.

What I can say is that the maths in the assembly code version is carefully chosen to avoid overflows during the various stages of computation without loosing too much precision along the way.

The assembly is also designed to round up any lost precision, so we try to produce a longer delay by way of the lost precision in the maths.

I forget what kind of precision we do get, but precision is not really a major concern here. We are only after a "rough" estimate of the delay (hell, we don't even guarantee according to Linus that you will get a minimum of the delay you asked for - you might get a shorter delay!) You _will_ get shorter delays because of the way the loop is calibrated (think: the jiffy code tries to find how many loops fit in a single jiffy, but a jiffy _also_ includes the overhead of running the timer interrupt, which artificially reduces loops_per_jiffy.)

Provided we get a delay "in the ballpark" of what was requested, that's good enough.