Commit 4231b23dc for llama.cpp
commit 4231b23dc2c46661d01157aac5245bdcf03ce4b1
Author: Kartik Gulia <kgulia@nvidia.com>
Date: Fri Oct 23 18:26:59 2026 +0530
ggml : fix time overflow in ggml_time_us (#30969)
* fix time overflow
* use double
diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c
index 004970db0..0b2adf6e4 100644
--- a/ggml/src/ggml.c
+++ b/ggml/src/ggml.c
@@ -546,9 +546,6 @@ static BOOL CALLBACK ggml_time_init_once(PINIT_ONCE once, PVOID param, PVOID *ct
QueryPerformanceFrequency(&t);
timer_freq = t.QuadPart;
- // The multiplication by 1000 or 1000000 below can cause an overflow if timer_freq
- // and the uptime is high enough.
- // We subtract the program start time to reduce the likelihood of that happening.
QueryPerformanceCounter(&t);
timer_start = t.QuadPart;
@@ -561,12 +558,12 @@ void ggml_time_init(void) {
int64_t ggml_time_ms(void) {
LARGE_INTEGER t;
QueryPerformanceCounter(&t);
- return ((t.QuadPart-timer_start) * 1000) / timer_freq;
+ return (int64_t) (((double) (t.QuadPart - timer_start) / timer_freq) * 1000);
}
int64_t ggml_time_us(void) {
LARGE_INTEGER t;
QueryPerformanceCounter(&t);
- return ((t.QuadPart-timer_start) * 1000000) / timer_freq;
+ return (int64_t) (((double) (t.QuadPart - timer_start) / timer_freq) * 1000000);
}
#else
void ggml_time_init(void) {}