mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
block all x86 tsc functions in when block
This commit is contained in:
@@ -9,7 +9,8 @@ foreign libc {
|
|||||||
@(link_name="sysctlbyname") _sysctlbyname :: proc(path: cstring, oldp: rawptr, oldlenp: rawptr, newp: rawptr, newlen: int) -> c.int ---
|
@(link_name="sysctlbyname") _sysctlbyname :: proc(path: cstring, oldp: rawptr, oldlenp: rawptr, newp: rawptr, newlen: int) -> c.int ---
|
||||||
}
|
}
|
||||||
|
|
||||||
_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
when ODIN_ARCH == .amd64 {
|
||||||
|
_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
||||||
tmp_freq : u64 = 0
|
tmp_freq : u64 = 0
|
||||||
tmp_size : i64 = size_of(tmp_freq)
|
tmp_size : i64 = size_of(tmp_freq)
|
||||||
ret := _sysctlbyname("machdep.tsc.frequency", &tmp_freq, &tmp_size, nil, 0)
|
ret := _sysctlbyname("machdep.tsc.frequency", &tmp_freq, &tmp_size, nil, 0)
|
||||||
@@ -18,4 +19,5 @@ _x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return tmp_freq, true
|
return tmp_freq, true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ package time
|
|||||||
import "core:intrinsics"
|
import "core:intrinsics"
|
||||||
import "core:sys/unix"
|
import "core:sys/unix"
|
||||||
|
|
||||||
_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
when ODIN_ARCH == .amd64 {
|
||||||
|
_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
||||||
perf_attr := unix.Perf_Event_Attr{}
|
perf_attr := unix.Perf_Event_Attr{}
|
||||||
perf_attr.type = u32(unix.Perf_Type_Id.Hardware)
|
perf_attr.type = u32(unix.Perf_Type_Id.Hardware)
|
||||||
perf_attr.config = u64(unix.Perf_Hardware_Id.Instructions)
|
perf_attr.config = u64(unix.Perf_Hardware_Id.Instructions)
|
||||||
@@ -32,4 +33,5 @@ _x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
|||||||
|
|
||||||
frequency := u64((u128(1_000_000_000) << u128(event_page.time_shift)) / u128(event_page.time_mult))
|
frequency := u64((u128(1_000_000_000) << u128(event_page.time_shift)) / u128(event_page.time_mult))
|
||||||
return frequency, true
|
return frequency, true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ package time
|
|||||||
import "core:intrinsics"
|
import "core:intrinsics"
|
||||||
import win32 "core:sys/windows"
|
import win32 "core:sys/windows"
|
||||||
|
|
||||||
_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
when ODIN_ARCH == .amd64 {
|
||||||
|
_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
||||||
qpc_begin: win32.LARGE_INTEGER
|
qpc_begin: win32.LARGE_INTEGER
|
||||||
win32.QueryPerformanceCounter(&qpc_begin)
|
win32.QueryPerformanceCounter(&qpc_begin)
|
||||||
tsc_begin := intrinsics.read_cycle_counter()
|
tsc_begin := intrinsics.read_cycle_counter()
|
||||||
@@ -21,4 +22,5 @@ _x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
|||||||
|
|
||||||
frequency = u64((u128(tsc_end - tsc_begin) * u128(qpc_frequency)) / u128(qpc_end - qpc_begin))
|
frequency = u64((u128(tsc_end - tsc_begin) * u128(qpc_frequency)) / u128(qpc_end - qpc_begin))
|
||||||
return frequency, true
|
return frequency, true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user