Page MenuHomeFreeBSD

Simplify pps_capture() and pps_event()
AbandonedPublic

Authored by sebastian.huber_embedded-brains.de on Jul 26 2022, 6:16 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 10 2024, 9:40 PM
Unknown Object (File)
Dec 23 2023, 2:59 AM
Unknown Object (File)
Dec 22 2023, 4:36 PM
Unknown Object (File)
Dec 12 2023, 8:56 PM
Unknown Object (File)
Nov 10 2023, 1:43 AM
Unknown Object (File)
Oct 9 2023, 12:34 AM
Unknown Object (File)
Sep 30 2023, 7:13 PM
Unknown Object (File)
Sep 21 2023, 10:17 PM

Details

Reviewers
None
Summary

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.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 46576
Build 43465: arc lint + arc unit