cputime optimize for arm64 - #3247
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to optimize cpuwide_time_ns() on ARM64 by using the architectural counter frequency (CNTFRQ_EL0) to populate detail::invariant_cpu_freq, shifting initialization away from per-call logic.
Changes:
- On
__aarch64__, routecpuwide_time_ns()to use the cycle-counter path instead of theclock_gettimepath. - Move initialization of
detail::invariant_cpu_freqinto a pre-main initializer, usingCNTFRQ_EL0on ARM64.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/butil/time.h |
Changes cpuwide_time_ns() preprocessor gating to include ARM64 in the invariant-counter fast path and removes lazy init recursion. |
src/butil/time.cpp |
Adds a pre-main initializer to set detail::invariant_cpu_freq, reading CNTFRQ_EL0 on ARM64. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3f81407 to
3cff1a7
Compare
|
LGTM |
7d1d9e0 to
869c04a
Compare
@chenBright OK,Referenced |
Update src/butil/time.cpp modify using __attribute__((constructor)) and merge init_invariant_cpu_freq to inside function read_invariant_cpu_frequency
…ginal default behavior for ARM64
…UTIL_USE_CPU_FREQUENCY=true, script argument --with-cpu-frequency. 2、Disabled by default for consistent legacy behavior.
|
@chenBright pls review again,tks |
|
LGTM |

What problem does this PR solve?
Issue Number: n/a
Problem Summary: cpugettime optimize for ARM64
What is changed and the side effects?
Changed:
detail::invariant_cpu_freq value get by CNTFRQ_EL0
Side effects:
Performance effects:
Breaking backward compatibility: 无
Check List: