Repository navigation
Fix SIGFPE at startup when CPUID leaf 0x15 is unusable with tpause - #43
Merged
Merged
Conversation
With DTO_WAIT_METHOD=tpause, init_dto() converts the wait from ns to TSC cycles using CPUID leaf 0x15 and divides by the denominator unconditionally. If the leaf is absent (__get_cpuid() returns 0 with the outputs uninitialized) or reports den=0, as on many VMs, the constructor dies with SIGFPE before main(). It also ran after dsa_init() had failed and the library was falling back to CPU, where the value is unused. Only do the conversion when DSA is in use and tpause is selected, and require the leaf to be present with non-zero den, num and frequency. Otherwise log an error and fall back to busypoll. Also fix waitpkg detection in dsa_init(), which queried CPUID leaf 0 instead of leaf 7. Leaf 0's ECX is the ASCII "ntel", which has bit 5 set, so waitpkg_support was always 1 and tpause/umwait on a CPU without WAITPKG would SIGILL instead of falling back.
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.
Fixes a startup crash reported on systems without DSA.
With
DTO_WAIT_METHOD=tpause,init_dto()converts the tpause wait from nsto TSC cycles using CPUID leaf 0x15 and divides by the denominator
unconditionally. If the leaf is absent (
__get_cpuid()returns 0 and leavesits outputs uninitialized) or reports
den=0, as on many VMs, theconstructor dies with SIGFPE before
main(). It also ran afterdsa_init()had already failed and the library was falling back to CPU, where the value
is never used.
leaf 0x15 to be present with non-zero
den,numand crystal frequency,otherwise log an error and fall back to busypoll (matching the existing
"tpause not supported" fallback).
dsa_init(), which queried CPUID leaf 0 insteadof leaf 7. Leaf 0's ECX is the ASCII
"ntel", which has bit 5 set, sowaitpkg_supportwas always 1 and selecting tpause/umwait on a CPUwithout WAITPKG would SIGILL rather than fall back.