hrtimer precision issue/question??
Thomas Gleixner
tglx at linutronix.de
Sat Mar 22 14:04:01 PDT 2025
On Sat, Mar 22 2025 at 11:20, richard clark wrote:
> With diff below under the 'cyclictest -a 0 -t 1 -m -p99' trigger from
> the arm64-based linux box, the interval is 1000us and the arch_timer
> in the system is: arch_timer: cp15 timer(s) running at 31.25MHz
> (phys). 1tick = 32ns for the arch timer, I am not sure if those
> durations less than 1000us are expected?
With your method of measurement yes. There is a german saying, which
describes this. It roughly translates to:
"Who measures a lot, might measure a lot of garbage."
But it accurately describes, what you are measuring here. You do:
t1 = ktime_get();
arm_timer(T);
schedule();
t2 = ktime_get();
and then look at t2 - t1. That only tells you how long the task actually
slept. But that's ignoring the most important information here:
arm_timer(T);
cyclictest uses:
clock_nanosleep(clockid, ABSTIME, &T);
and T is maintained in absolute time on a periodic time line.
T = starttime + N * interval;
So the only interesting information here is at which time the task
returns from schedule(), i.e. you want to look at:
t2 - T
Why? Because that gives you the latency of the wakeup. That's what
cyclictest is looking at in user space:
clock_nanosleep(... &T);
clock_gettime(..., &T2);
latency = T2 - T;
Now what you are looking at is the time at which the cyclictest task
comes back into the kernel to sleep, which is obviously
t1 = T[N] + latency[N-1] + execution_time;
But the timer is armed for T[N], so your t2 is:
t2 = T[N] + latency[N];
You surely can do the remaining math and map that to the output:
> [ 165.555795] [ 0- 0]t0=165550399226,t1=165551394303,d=995 us
> [ 165.556802] [ 0- 0]t0=165551398751,t1=165552400997,d=1002 us
Right?
Thanks,
tglx
More information about the linux-arm-kernel
mailing list