aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Davidson <colrdavidson@gmail.com>2025-07-28 16:32:10 -0700
committerColin Davidson <colrdavidson@gmail.com>2025-07-28 16:32:10 -0700
commit1a9b128bfc4edff7b2651d68d1d350ec39b7e3a5 (patch)
tree95fd7bdede874095251389cdd2a342045dfb80d7
parent76b00c046b3c58670c60badbf5f15a66cbe25f85 (diff)
update linux-arm to use the asm intrin for freq
-rw-r--r--core/time/tsc_linux.odin53
1 files changed, 29 insertions, 24 deletions
diff --git a/core/time/tsc_linux.odin b/core/time/tsc_linux.odin
index a83634414..92712f136 100644
--- a/core/time/tsc_linux.odin
+++ b/core/time/tsc_linux.odin
@@ -5,29 +5,34 @@ package time
import linux "core:sys/linux"
_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
- // Get the file descriptor for the perf mapping
- perf_attr := linux.Perf_Event_Attr{}
- perf_attr.size = size_of(perf_attr)
- perf_attr.type = .HARDWARE
- perf_attr.config.hw = .INSTRUCTIONS
- perf_attr.flags = {.Disabled, .Exclude_Kernel, .Exclude_HV}
- fd, perf_errno := linux.perf_event_open(&perf_attr, linux.Pid(0), -1, linux.Fd(-1), {})
- if perf_errno != nil {
- return 0, false
+ if ODIN_ARCH == .arm64 {
+ freq = u64(intrinsics.arm64_read_cycle_counter_frequency())
+ return frequency, true
+ } else {
+ // Get the file descriptor for the perf mapping
+ perf_attr := linux.Perf_Event_Attr{}
+ perf_attr.size = size_of(perf_attr)
+ perf_attr.type = .HARDWARE
+ perf_attr.config.hw = .INSTRUCTIONS
+ perf_attr.flags = {.Disabled, .Exclude_Kernel, .Exclude_HV}
+ fd, perf_errno := linux.perf_event_open(&perf_attr, linux.Pid(0), -1, linux.Fd(-1), {})
+ if perf_errno != nil {
+ return 0, false
+ }
+ defer linux.close(fd)
+ // Map it into the memory
+ page_size : uint = 4096
+ addr, mmap_errno := linux.mmap(0, page_size, {.READ}, {.SHARED}, fd)
+ if mmap_errno != nil {
+ return 0, false
+ }
+ defer linux.munmap(addr, page_size)
+ // Get the frequency from the mapped page
+ event_page := cast(^linux.Perf_Event_Mmap_Page) addr
+ if .User_Time not_in event_page.cap.flags {
+ return 0, false
+ }
+ frequency := u64((u128(1_000_000_000) << u128(event_page.time_shift)) / u128(event_page.time_mult))
+ return frequency, true
}
- defer linux.close(fd)
- // Map it into the memory
- page_size : uint = 4096
- addr, mmap_errno := linux.mmap(0, page_size, {.READ}, {.SHARED}, fd)
- if mmap_errno != nil {
- return 0, false
- }
- defer linux.munmap(addr, page_size)
- // Get the frequency from the mapped page
- event_page := cast(^linux.Perf_Event_Mmap_Page) addr
- if .User_Time not_in event_page.cap.flags {
- return 0, false
- }
- frequency := u64((u128(1_000_000_000) << u128(event_page.time_shift)) / u128(event_page.time_mult))
- return frequency, true
}