From: Thomas Gleixner <tglx@linutronix.de>
To: richard clark <richard.xnu.clark@gmail.com>
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: hrtimer precision issue/question??
Date: Sat, 22 Mar 2025 22:04:01 +0100 [thread overview]
Message-ID: <875xk022wu.ffs@tglx> (raw)
In-Reply-To: <CAJNi4rPaPeVWzBve6Toi8hhrxP6GROAGRug7+c3zg1crDeOt7Q@mail.gmail.com>
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
next prev parent reply other threads:[~2025-03-22 21:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-22 3:20 hrtimer precision issue/question?? richard clark
2025-03-22 21:04 ` Thomas Gleixner [this message]
2025-03-25 9:54 ` richard clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875xk022wu.ffs@tglx \
--to=tglx@linutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=richard.xnu.clark@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox