This patch set tries to simplify the pps_capture() and pps_event() processing.
I am not sure if the rounding change is an improvement.
pps: Load timecounter once in pps_capture()
This ensures that the timecounter and the tc_get_timecount handler belong
together.
pps: Simplify capture and event processing
Use local variables for the captured timehand and timecounter in pps_event().
This fixes a potential issue in the nsec preparation for hardpps(). Here the
timecounter was accessed through the captured timehand after the generation was
checked.
Make a snapshot of the relevent timehand values early in pps_event(). Check
the timehand generation only once during the capture and event processing. Use
atomic_thread_fence_acq() similar to the other readers.
pps: Move pcount assignment in pps_event()
Move the pseq increment. This makes it possible to reuse registers earlier.
pps: Directly assign the timestamps in pps_event()
pps: Simplify the nsec calculation in pps_event()
The new calculation should have less problems with integer overflows.
Consider the following sample values with a tcount of 2000000100 and a
tc_frequency of 2000000000 (2GHz). The scale is 9223372036. Then scale *
tcount is 18446744994337203600 which is larger than
UINT64_MAX (18446744073709551615). The result is 49.
In the new calculation, 1000000000 * tcount is 2000000100000000000 which is
less than UINT64_MAX. This yields after the division with tc_frequency the
correct result of 1000000050.
pps: Round to closest integer in pps_event()
The comment above bintime2timespec() says:
When converting between timestamps on parallel timescales of differing resolutions it is historical and scientific practice to round down.
However, the nsec value is a time difference and not a timestamp. So, rounding
to the closest integer is probably slightly better.