Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[X86] Use __builtin_readsteadycounter to access MPERF counter (and APERF equivalent) #81755

Open
RKSimon opened this issue Feb 14, 2024 · 1 comment

Comments

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 14, 2024

#81331 added support for a __builtin_readsteadycounter intrinsic which returns a fixed frequency clock counter. It returns 0 on failure.

x86 can use this as a wrapper to read the MPERF counter - on Intel (and default) I think this will need to lower to a libcall, but on AMD znver2 (or later) we can use the RDPRU instruction.

Ideally we need a companion __builtin_readvariablecounter intrinsic which returns the APERF counter to calculate the effective cpu frequency (we can't use __builtin_readcyclecounter as that returns RDTSC which is a different time scale).

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 14, 2024

@llvm/issue-subscribers-backend-x86

Author: Simon Pilgrim (RKSimon)

#81331 added support for a `__builtin_readsteadycounter` intrinsic which returns a fixed frequency clock counter. It returns 0 on failure.

x86 can use this as a wrapper to read the MPERF counter - on Intel (and default) I think this will need to lower to a libcall, but on AMD znver2 (or later) we can use the RDPRU instruction.

Ideally we need a companion __builtin_readvariablecounter intrinsic which returns the APERF counter to calculate the effective cpu frequency (we can't use __builtin_readcyclecounter as that returns RDTSC which is a different time scale).

@RKSimon RKSimon changed the title [X86] Use __builtin_readsteadycounter to access MPERF counter (and APERF equivalent( [X86] Use __builtin_readsteadycounter to access MPERF counter (and APERF equivalent) Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants