As suggested in D12425 it would be better for the readcyclecounter function on ARM architecture to use the CNTVCT_EL0 register (Counter-timer Virtual Count register) instead of the PMCCNTR_EL0 (Performance Monitors Cycle Count Register) because the PMCCNTR_EL0 is a PMU register which, depending on the configuration, it might always return zeroes and it doesn't guaranteed to always be increased.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Hi Salvatore,
the patch looks good to me.
As you suggested to me, we should also remove this part let Predicates = [HasPerfMon] in.
A little bit more context on what this patch fixes: MariaDB compiled with clang crashes on arm64-freebsd https://jira.mariadb.org/browse/MDEV-23249
Hi Sebastian,
have update the diff removing the predicate for the READCYCLECOUNTER function
The change looks good to me.
Could one of the arm64 maintainers also approve this patch? Thanks!
Thank @sebpop for approving it.
Since I do not have commit access and if there is no other objections, Can you please commit the change on my behalf? Thanks
Ping patch.
Could one of the arm64 maintainers approve this patch and commit?
Thank you.
Ping patch.
In the Linux kernel rdtsc for Arm64 is implemented with CNTVCT_EL0:
https://lore.kernel.org/patchwork/patch/1305380/
The system register CNTVCT_EL0 can be used to retrieve the counter from
user space. Add rdtsc() for Arm64.
Hello. I gave the two registers a look and CNTVCT_EL0 seemed to work better than PMCCNTR_EL0 on the systems I tried. The existing PMCCNTR_EL0 would run into illegal instruction exceptions.
This was added by @ab though and I only tried linux/android. It would be good to hear from them about whether changing this is OK for their platform.
For context, MySQL had also to overwrite this function and it is using the CNTVCT_EL0 register for over 3 years now
This makes sense, thanks for checking! I'll have a closer look on my side and follow-up if needed
OK great, thanks.
If you provide a way to attribute this patch ("name <em@ail>"), I am happy to commit it.