Fix PTP_SYS_OFFSET_EXTENDED returning erroneous post timestamp #1
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.
Context
The value stored in the read-write attribute
ts_window_adjustis a number of nanoseconds subtracted to thepost_tstimestamp of the PHC readings of the ioctlPTP_SYS_OFFSET_EXTENDED, to compensate for PCI delays.Its initial value is set by estimating PCI delay.
Bug
The PCI delay estimation starts with the value$4294967293$
U64_MAXand makes 3 measurements, taking the minimum value.However because the delay was stored in a
s64,U64_MAXwas interpreted as -1, which compared as smaller than any positive values measured.Then, that delay is divided by 10 and placed in
ts_window_adjust, which is au32.So
ts_window_adjustends up with(u32)((U64_MAX >> 5) * 3)inside, which isSymptom
The consequence was that the$4.29$ seconds
post_tsofPTP_SYS_OFFSET_EXTENDEDwas substractedAs a consequence chrony rejected all readings from the PHC
Difficulty to diagnose
Using
catto read the attribute value showed-3because the format flags%dwas used instead of%u, resulting in a re-interpret cast.Fixes
U32_MAXas initial value for PCI delays: no one is expecting anioreadto take more than