mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Merge pull request #2520 from matias-eduardo/master
Allow for custom sleep duration in tsc frequency fallback
This commit is contained in:
@@ -67,16 +67,15 @@ Buffer :: struct {
|
|||||||
BUFFER_DEFAULT_SIZE :: 0x10_0000
|
BUFFER_DEFAULT_SIZE :: 0x10_0000
|
||||||
|
|
||||||
|
|
||||||
context_create :: proc(filename: string) -> (ctx: Context, ok: bool) #optional_ok {
|
context_create_with_scale :: proc(filename: string, precise_time: bool, timestamp_scale: f64) -> (ctx: Context, ok: bool) #optional_ok {
|
||||||
fd, err := os.open(filename, os.O_WRONLY | os.O_APPEND | os.O_CREATE | os.O_TRUNC, 0o600)
|
fd, err := os.open(filename, os.O_WRONLY | os.O_APPEND | os.O_CREATE | os.O_TRUNC, 0o600)
|
||||||
if err != os.ERROR_NONE {
|
if err != os.ERROR_NONE {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.fd = fd
|
|
||||||
|
|
||||||
freq, freq_ok := time.tsc_frequency()
|
ctx.fd = fd
|
||||||
ctx.precise_time = freq_ok
|
ctx.precise_time = precise_time
|
||||||
ctx.timestamp_scale = ((1 / f64(freq)) * 1_000_000) if freq_ok else 1
|
ctx.timestamp_scale = timestamp_scale
|
||||||
|
|
||||||
temp := [size_of(Manual_Header)]u8{}
|
temp := [size_of(Manual_Header)]u8{}
|
||||||
_build_header(temp[:], ctx.timestamp_scale)
|
_build_header(temp[:], ctx.timestamp_scale)
|
||||||
@@ -85,6 +84,14 @@ context_create :: proc(filename: string) -> (ctx: Context, ok: bool) #optional_o
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context_create_with_sleep :: proc(filename: string, sleep := 2 * time.Second) -> (ctx: Context, ok: bool) #optional_ok {
|
||||||
|
freq, freq_ok := time.tsc_frequency(sleep)
|
||||||
|
timestamp_scale: f64 = ((1 / f64(freq)) * 1_000_000) if freq_ok else 1
|
||||||
|
return context_create_with_scale(filename, freq_ok, timestamp_scale)
|
||||||
|
}
|
||||||
|
|
||||||
|
context_create :: proc{context_create_with_scale, context_create_with_sleep}
|
||||||
|
|
||||||
context_destroy :: proc(ctx: ^Context) {
|
context_destroy :: proc(ctx: ^Context) {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return
|
return
|
||||||
|
|||||||
+2
-2
@@ -70,7 +70,7 @@ has_invariant_tsc :: proc "contextless" () -> bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
tsc_frequency :: proc "contextless" (fallback_sleep := 2 * Second) -> (u64, bool) {
|
||||||
if !has_invariant_tsc() {
|
if !has_invariant_tsc() {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ tsc_frequency :: proc "contextless" () -> (u64, bool) {
|
|||||||
tsc_begin := intrinsics.read_cycle_counter()
|
tsc_begin := intrinsics.read_cycle_counter()
|
||||||
tick_begin := tick_now()
|
tick_begin := tick_now()
|
||||||
|
|
||||||
sleep(2 * Second)
|
sleep(fallback_sleep)
|
||||||
|
|
||||||
tsc_end := intrinsics.read_cycle_counter()
|
tsc_end := intrinsics.read_cycle_counter()
|
||||||
tick_end := tick_now()
|
tick_end := tick_now()
|
||||||
|
|||||||
Reference in New Issue
Block a user