-
Notifications
You must be signed in to change notification settings - Fork 4.1k
cputime optimize for arm64 #3247
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -153,6 +153,18 @@ int64_t read_invariant_cpu_frequency() { | |||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| int64_t invariant_cpu_freq = -1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| static void __attribute__((constructor)) init_invariant_cpu_freq() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| int64_t baseFreq = -1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| #if defined(__aarch64__) | ||||||||||||||||||||||||||||||||||||||||||||||||
| __asm__ __volatile__("mrs %0, CNTFRQ_EL0" : "=r"(baseFreq)); | ||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||
| baseFreq = detail::read_invariant_cpu_frequency(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| detail::invariant_cpu_freq = baseFreq; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+161
to
+166
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
155
to
+167
|
||||||||||||||||||||||||||||||||||||||||||||||||
| int64_t invariant_cpu_freq = -1; | |
| static void __attribute__((constructor)) init_invariant_cpu_freq() { | |
| int64_t baseFreq = -1; | |
| #if defined(__aarch64__) | |
| __asm__ __volatile__("mrs %0, CNTFRQ_EL0" : "=r"(baseFreq)); | |
| #else | |
| baseFreq = detail::read_invariant_cpu_frequency(); | |
| #endif | |
| detail::invariant_cpu_freq = baseFreq; | |
| } | |
| static int64_t init_invariant_cpu_freq() { | |
| int64_t baseFreq = -1; | |
| #if defined(__aarch64__) | |
| __asm__ __volatile__("mrs %0, CNTFRQ_EL0" : "=r"(baseFreq)); | |
| #else | |
| baseFreq = detail::read_invariant_cpu_frequency(); | |
| #endif | |
| return baseFreq; | |
| } | |
| int64_t invariant_cpu_freq = init_invariant_cpu_freq(); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -279,7 +279,7 @@ extern int64_t invariant_cpu_freq; | |||||||||||||
| // note: Inlining shortens time cost per-call for 15ns in a loop of many | ||||||||||||||
| // calls to this function. | ||||||||||||||
| inline int64_t cpuwide_time_ns() { | ||||||||||||||
| #if !defined(BAIDU_INTERNAL) | ||||||||||||||
| #if !defined(BAIDU_INTERNAL) && !defined(__aarch64__) | ||||||||||||||
| // nearly impossible to get the correct invariant cpu frequency on | ||||||||||||||
| // different CPU and machines. CPU-ID rarely works and frequencies | ||||||||||||||
| // in "model name" and "cpu Mhz" are both unreliable. | ||||||||||||||
|
|
@@ -301,11 +301,6 @@ inline int64_t cpuwide_time_ns() { | |||||||||||||
| } else if (!cpu_freq) { | ||||||||||||||
| // Lack of necessary features, return system-wide monotonic time instead. | ||||||||||||||
| return monotonic_time_ns(); | ||||||||||||||
|
||||||||||||||
| return monotonic_time_ns(); | |
| return monotonic_time_ns(); | |
| } else { | |
| // Negative frequency (e.g. uninitialized or failed initialization), | |
| // fall back to system-wide monotonic time to avoid undefined behavior. | |
| return monotonic_time_ns(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Local variable name
baseFreqdoesn’t match the surrounding naming style in this file (which predominantly uses snake_case likeinvariant_tsc,seen_decpoint,endp). Renaming to something likebase_freq(and ideally indicating units, e.g._hz) would improve consistency and readability.