Conversation
This should notably allow posix systems with timespec_get() to have access to a high resolution timer, instead of falling back to C90's clock_t.
terrelln
approved these changes
Jan 13, 2023
Merged
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.
This replaces #3168
An issue experienced last year was that posix systems without access to
timespec_get()(C11) fall back toC90clock(), which is a low resolution timer, actually indexed on process time, and therefore unable to properly measure time when there is a multi-threaded workload. This led to some confusion over performance numbers last year.Since then, we have added a warning message, and now when benchmarking in multi-threading mode with only the
clock_tlow resolution timer, users get warned that the measurement is probably incorrect.Another proposal to improve this situation was to restore support of
clock_gettime()high resolution timer, which would help allPOSIX 2001compliant systems.Unfortunately, the current interface of
timefn.hleads to potential confusion on this point, because the state ofPOSIXmacros depends on#includeorder, which is brittle. This results in situations wheretimefn.hinterface is interpreted differently depending on local#includeorder, resulting in different objects being allocated on stack.This PR changes the interface logic, so that the exposed
time_tobject is now solely define bytimefn.hand completely independent of OS peculiarity (suggestion by @terrelln). Adaptation to the local OS high resolution timer happens solely withintimefn.c. Therefore, users oftimefn.hno longer risk interpreting the interface differently.This makes it possible to re-enable
clock_gettime()(also done in this PR).Follow-up 1 : during tests, I employed
c89buildtarget to test the low resolution time. It discovered a number of places with non-C90 compliant syntax (//line comments mostly, and oneinline). This tells me that thec89buildtest is not played in CI. It should probably be added.Follow-up 2 : the symbols in
timefn.hare prefixedUTIL_*, which is oddly unspecific.I was considering to rename all symbols of this unit, typically employing the
TIME_*prefix instead.