Page MenuHomeFreeBSD

FFclock: Fix counter origin initialization, implement bypass mode
Needs ReviewPublic

Authored by Darryl.Veitch_uts.edu.au on Dec 7 2023, 12:39 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sep 19 2024, 11:55 PM
Unknown Object (File)
Sep 13 2024, 7:08 AM
Unknown Object (File)
Sep 5 2024, 8:21 AM
Unknown Object (File)
Aug 16 2024, 4:24 PM
Unknown Object (File)
Aug 2 2024, 1:16 PM
Unknown Object (File)
Jul 24 2024, 3:38 AM
Unknown Object (File)
Jul 22 2024, 12:56 PM
Unknown Object (File)
Jul 4 2024, 3:13 AM
Subscribers

Details

Reviewers
phk
imp
Summary

Context: the goal of bypass is to access the chosen counter more
directly, bypassing the FFclock counter synthesis mechanism, to reduce
timestamping latency. It is essential that the direct and FFclock based
counters correspond, that is have the same width and origin.
The main use case is for TSC-derived counters, as they are natively
FFclock compatible, and are directly accessible from userspace as well
as the kernel via rdtsc(), dramatically reducing access latency.

BYPASS

Currently the bypass variable sysctl_kern_ffclock_ffcounter_bypass is
defined (as static in kern_ffclock.c) but never used. This commit makes
it available as an extern in timeffc.c, the employs it as originally
intended in kern_tc.c :

  • ffclock_read_counter : via rdtsc
  • sysclock_getsnapshot : via rdtsc32 combined with th->th_offset_count to provide a consistent (FB,FF) snapshot.

Also in sysclock_getsnapshot, on the same theme of latency reduction,
the counter read is moved up as early as possible to optimize the raw
timestamp. The comment block is improved to describe the role and
benefit of the function and bypass.

The use of bypass is only supported for TSC-derived counters. The onus
is on the operator to set sysctl_kern_ffclock_ffcounter_bypass
appropriately. User applications can detect if bypass is active, and
choose to exploit it, or use the slower syscall access to the FFclock
counter instead.

COUNTER ORIGIN

Unlike FB clocks, the origin of the underlying counter in FFclocks plays
a key role. When the timecounter is changed, the FF counter synthesized
by FFclock is changed and its origin must be carefully set.
Changes in kern_tc.c:ffclock_change_tc :

  • bug: the origin was not set coherently for the new counter. It is now set properly, and in such a way that the FB and FF counters are fully consistent. This requires the addition of new argument passing the new FBclock counter read.
  • in the case of TSC counters, where bypass is possible, the origin setting requirements are more detailed (see comments in code). The new code supports a consistent underlying TSC counter which never changes origin between boots, irrespective of now many times the selected timecounter is changed, thereby always being in agreement with the hardware counter and rdtsc.
  • some reorganisation to better structure the resetting of FFclock parameters for this tick.
  • addition of verbosity to flag a change in the FFcounter, a rare and significant event.
  • improved comment block.

kern_tc.c:tc_windup :

  • addition of verbosity to flag a change in the selected counter, a rare and significant event.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 54831
Build 51720: arc lint + arc unit

Event Timeline

brooks added inline comments.
sys/kern/kern_tc.c
826–830

Is this for debugging? If not, I'm not sure if printing is the right thing.

sys/sys/timeffc.h
71