Browse Source

more function name changes

Colin Davidson 2 years ago
parent
commit
91dccf8d62
4 changed files with 47 additions and 53 deletions
  1. 3 3
      core/time/perf.odin
  2. 8 10
      core/time/tsc_darwin.odin
  3. 24 26
      core/time/tsc_linux.odin
  4. 12 14
      core/time/tsc_windows.odin

+ 3 - 3
core/time/perf.odin

@@ -54,10 +54,10 @@ when ODIN_ARCH == .amd64 {
 		_, _, _, edx := intrinsics.x86_cpuid(0x80_000_007, 0)
 		_, _, _, edx := intrinsics.x86_cpuid(0x80_000_007, 0)
 		return (edx & (1 << 8)) != 0
 		return (edx & (1 << 8)) != 0
 	}
 	}
+}
 
 
-	x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
-		return _x86_get_tsc_frequency()
-	}
+get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
+	return _get_tsc_frequency()
 }
 }
 
 
 /*
 /*

+ 8 - 10
core/time/tsc_darwin.odin

@@ -9,15 +9,13 @@ 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 ---
 }
 }
 
 
-when ODIN_ARCH == .amd64 {
-	_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
-		tmp_freq : u64 = 0
-		tmp_size : i64 = size_of(tmp_freq)
-		ret := _sysctlbyname("machdep.tsc.frequency", &tmp_freq, &tmp_size, nil, 0)
-		if ret < 0 {
-			return 0, false
-		}
-
-		return tmp_freq, true
+_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
+	tmp_freq : u64 = 0
+	tmp_size : i64 = size_of(tmp_freq)
+	ret := _sysctlbyname("machdep.tsc.frequency", &tmp_freq, &tmp_size, nil, 0)
+	if ret < 0 {
+		return 0, false
 	}
 	}
+
+	return tmp_freq, true
 }
 }

+ 24 - 26
core/time/tsc_linux.odin

@@ -5,33 +5,31 @@ package time
 import "core:intrinsics"
 import "core:intrinsics"
 import "core:sys/unix"
 import "core:sys/unix"
 
 
-when ODIN_ARCH == .amd64 {
-	_x86_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)
-		perf_attr.size = size_of(perf_attr)
-		perf_attr.flags = {.Disabled, .Exclude_Kernel, .Exclude_HV}
-		fd := unix.sys_perf_event_open(&perf_attr, 0, -1, -1, 0)
-		if fd == -1 {
-			return 0, false
-		}
-		defer unix.sys_close(fd)
-
-		page_size : uint = 4096
-		ret := unix.sys_mmap(nil, page_size, unix.PROT_READ, unix.MAP_SHARED, fd, 0)
-		if ret < 0 && ret > -4096 {
-			return 0, false
-		}
-		addr := rawptr(uintptr(ret))
-		defer unix.sys_munmap(addr, page_size)
+_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)
+	perf_attr.size = size_of(perf_attr)
+	perf_attr.flags = {.Disabled, .Exclude_Kernel, .Exclude_HV}
+	fd := unix.sys_perf_event_open(&perf_attr, 0, -1, -1, 0)
+	if fd == -1 {
+		return 0, false
+	}
+	defer unix.sys_close(fd)
 
 
-		event_page := (^unix.Perf_Event_mmap_Page)(addr)
-		if .User_Time not_in event_page.cap.flags {
-			return 0, false
-		}
+	page_size : uint = 4096
+	ret := unix.sys_mmap(nil, page_size, unix.PROT_READ, unix.MAP_SHARED, fd, 0)
+	if ret < 0 && ret > -4096 {
+		return 0, false
+	}
+	addr := rawptr(uintptr(ret))
+	defer unix.sys_munmap(addr, page_size)
 
 
-		frequency := u64((u128(1_000_000_000) << u128(event_page.time_shift)) / u128(event_page.time_mult))
-		return frequency, true
+	event_page := (^unix.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
 }
 }

+ 12 - 14
core/time/tsc_windows.odin

@@ -5,22 +5,20 @@ package time
 import "core:intrinsics"
 import "core:intrinsics"
 import win32 "core:sys/windows"
 import win32 "core:sys/windows"
 
 
-when ODIN_ARCH == .amd64 {
-	_x86_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
-		qpc_begin: win32.LARGE_INTEGER
-		win32.QueryPerformanceCounter(&qpc_begin)
-		tsc_begin := intrinsics.read_cycle_counter()
+_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
+	qpc_begin: win32.LARGE_INTEGER
+	win32.QueryPerformanceCounter(&qpc_begin)
+	tsc_begin := intrinsics.read_cycle_counter()
 
 
-		win32.Sleep(2)
+	win32.Sleep(2)
 
 
-		qpc_end: win32.LARGE_INTEGER
-		win32.QueryPerformanceCounter(&qpc_end)
-		tsc_end := intrinsics.read_cycle_counter()
+	qpc_end: win32.LARGE_INTEGER
+	win32.QueryPerformanceCounter(&qpc_end)
+	tsc_end := intrinsics.read_cycle_counter()
 
 
-		qpc_frequency: win32.LARGE_INTEGER
-		win32.QueryPerformanceFrequency(&qpc_frequency)
+	qpc_frequency: win32.LARGE_INTEGER
+	win32.QueryPerformanceFrequency(&qpc_frequency)
 
 
-		frequency = u64((u128(tsc_end - tsc_begin) * u128(qpc_frequency)) / u128(qpc_end - qpc_begin))
-		return frequency, true
-	}
+	frequency = u64((u128(tsc_end - tsc_begin) * u128(qpc_frequency)) / u128(qpc_end - qpc_begin))
+	return frequency, true
 }
 }