aarch64 lacks HP_TIMING support in glibc

Rafael Eduardo Ruviaro Christ rafaeleduardoruviaro.christ@asml.com
Wed Jun 30 13:27:38 GMT 2021


Hi Wilco,

The function clock_getres returns hardcoded 1ns if platform has high-resolution timers, instead of the actual resolution based on clock frequency. According to linux/include/linux/hrtimer.h:
/*
* The resolution of the clocks. The resolution value is returned in
* the clock_getres() system call to give application programmers an
* idea of the (in)accuracy of timers. Timer values are rounded up to
* this resolution values.
*/
# define HIGH_RES_NSEC          1
We consider this a bad design, but the Linux kernel community has decided that it meets their needs and have therefore not pursued any new implementation to return the real resolution.  For instance, if system clock is 25MHz, correct resolution should be 40ns.

I cannot patch the kernel because it is considered internally to risky. I was hoping to fix this in user space.
For AArch64, it is possible to retrieve the system clock frequency:
asm volatile("mrs %0, cntfrq_el0" : "=r" (freq));
The ideal would be to implement the solution in glibc.
What do you think Wilco?

Kind regards,
Rafael



From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Sent: Monday, June 28, 2021 9:25 PM
To: Rafael Eduardo Ruviaro Christ <rafaeleduardoruviaro.christ@asml.com>; 'GNU C Library' <libc-alpha@sourceware.org>
Subject: Re: aarch64 lacks HP_TIMING support in glibc

CAUTION: This message is from an external sender
Hi Rafael,

> Thank you for your message. Currently, we're using glibc 2.28. As soon as I am able to
> update to the latest glibc I will repeat the tests in our platform to evaluate the
> clock_getres() behavior.

I don't believe there has been any change in behaviour since 2.28 - clock_getres does not
use hp-timing in any way (and never did on AArch64). So is there something specific that
you have an issue with?

Cheers,
Wilco
-- The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. Unless explicitly stated otherwise in the body of this communication or the attachment thereto (if any), the information is provided on an AS-IS basis without any express or implied warranties or liabilities. To the extent you are relying on this information, you are doing so at your own risk. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. Neither the sender nor the company/group of companies he or she represents shall be liable for the proper and complete transmission of the information contained in this communication, or for any delay in its receipt.


More information about the Libc-alpha mailing list