Răsfoiți Sursa

Allow custom sleep on tsc fallback.

This gives the user more control over the spectrum of precision vs. load time on Windows. Spall's output with much lower sleep times is still useful in my experience.

NOTE: A better API might be to allow the user to pass the freq as a param to "create_context" in case they already paid for it beforehand, but this seems fine for now.
Matias Fernandez 2 ani în urmă
părinte
comite
57c14f6a9b
2 a modificat fișierele cu 4 adăugiri și 4 ștergeri
  1. 2 2
      core/prof/spall/spall.odin
  2. 2 2
      core/time/perf.odin

+ 2 - 2
core/prof/spall/spall.odin

@@ -67,14 +67,14 @@ 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 :: proc(filename: string, freq_fallback_sleep := 2 * time.Second) -> (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
 	ctx.fd = fd
 
 
-	freq, freq_ok := time.tsc_frequency()
+	freq, freq_ok := time.tsc_frequency(freq_fallback_sleep)
 	ctx.precise_time = freq_ok
 	ctx.precise_time = freq_ok
 	ctx.timestamp_scale = ((1 / f64(freq)) * 1_000_000) if freq_ok else 1
 	ctx.timestamp_scale = ((1 / f64(freq)) * 1_000_000) if freq_ok else 1
 
 

+ 2 - 2
core/time/perf.odin

@@ -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()