HomeFreeBSD

sys/time: Add saturating sbt conversions

Description

sys/time: Add saturating sbt conversions

When converting from timespec to sbintime, the timespec's 64-bit tv_sec
component is shifted to the left 32 bits, causing any information in the
upper 32 bits to be lost.

This data loss during conversion can turn timespecs with very large
tv_sec counters into sbintimes that represent much smaller time
durations.

Add tstosbt_sat() and tvtosbt_sat(), which are saturating versions of
tstosbt and tvtosbt. With these routines, any overflow resulting from
the conversion is clamped to [-SBT_MAX - 1, SBT_MAX].

Reviewed by: imp, markj
Differential Revision: https://reviews.freebsd.org/D55791
MFC after: 2 weeks

Details

Provenance
jfreeAuthored on Mar 20 2026, 6:33 AM
Reviewer
imp
Differential Revision
D55791: sys/time: Add saturating sbt conversions
Parents
rG85c0f1a87da1: timerfd: Fix interval callout scheduling
Branches
Unknown
Tags
Unknown