Skip to content

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

@RKSimon

Description

@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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions