Repository navigation
ggml : make ggml_time_init idempotent - #24422
Merged
Merged
Conversation
ggml_time_init idempotent
ggerganov
approved these changes
Jul 6, 2026
satindergrewal
pushed a commit
to satindergrewal/llama.cpp
that referenced
this pull request
Aug 12, 2026
zbrad
pushed a commit
to zbrad/llama.cpp
that referenced
this pull request
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ggml_time_init()is not idempotent: each call resetstimer_startto the currentQueryPerformanceCountervalue, so calling it more than once shifts the timer baseline and breaks any elapsed-time delta computed against an earlier timestamp (it can even go negative).ggml_init()already calls it once behind anis_first_callguard, but that is not the only entry point. Some code callsggml_time_init()directly beforeggml_init()to time the initialization itself (e.g. main-ctx.cpp), and a user unaware thatggml_init()already initializes the timer may call it again, silently resetting the baseline.Since the function only has a real implementation on Windows (a no-op elsewhere), this uses the native
InitOnceExecuteOnce/INIT_ONCEprimitive to capture the baseline exactly once. It is also thread-safe, so concurrent first calls are handled correctly. Minimal change, no extra dependency, andwindows.his already included.