aboutsummaryrefslogtreecommitdiff
path: root/core/time
diff options
context:
space:
mode:
authorflysand7 <yyakut.ac@gmail.com>2023-10-18 01:57:26 +1100
committerflysand7 <yyakut.ac@gmail.com>2023-10-27 10:51:21 +1100
commit4d65b1ab9cb86bcbbfb0e5b26e3552f6f3582004 (patch)
treeb61fb2dbcfe8fbd8574cbda546c27ed91e49d44a /core/time
parent8e4bdcfb9837d70e94634db02e79a06036a3dde7 (diff)
Implement new sys/unix package
Diffstat (limited to 'core/time')
-rw-r--r--core/time/tsc_linux.odin30
1 files changed, 14 insertions, 16 deletions
diff --git a/core/time/tsc_linux.odin b/core/time/tsc_linux.odin
index c5f2902e9..77a79fe52 100644
--- a/core/time/tsc_linux.odin
+++ b/core/time/tsc_linux.odin
@@ -2,34 +2,32 @@
//+build linux
package time
-import "core:intrinsics"
-import "core:sys/unix"
+import linux "core:sys/linux"
_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
- perf_attr := unix.Perf_Event_Attr{}
- perf_attr.type = u32(unix.Perf_Type_Id.Hardware)
- perf_attr.config = u64(unix.Perf_Hardware_Id.Instructions)
+ // 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 := unix.sys_perf_event_open(&perf_attr, 0, -1, -1, 0)
- if fd == -1 {
+ fd, perf_errno := linux.perf_event_open(&perf_attr, linux.Pid(0), -1, linux.Fd(-1), {})
+ if perf_errno != nil {
return 0, false
}
- defer unix.sys_close(fd)
-
+ defer linux.close(fd)
+ // Map it into the memory
page_size : uint = 4096
- ret := unix.sys_mmap(nil, page_size, unix.PROT_READ, unix.MAP_SHARED, fd, 0)
- if ret < 0 && ret > -4096 {
+ addr, mmap_errno := linux.mmap(0, page_size, {.READ}, {.SHARED}, fd)
+ if mmap_errno != nil {
return 0, false
}
- addr := rawptr(uintptr(ret))
- defer unix.sys_munmap(addr, page_size)
-
- event_page := (^unix.Perf_Event_mmap_Page)(addr)
+ 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
}