Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: src



Module Name:    src
Committed By:   riastradh
Date:           Tue Apr  1 23:14:23 UTC 2025

Modified Files:
        src/sys/kern: subr_time_arith.c
        src/tests/kernel: t_time_arith.c

Log Message:
itimer(9): Fix various bugs in arithmetic.

The arithmetic still spuriously rejects very large inputs, but we
don't have to deal with them for another century, so I'll do that in
a separate commit later without too much urgency.

In particular, when the clock reads later than the year 2262, we
can't represent it in a signed 64-bit number of nanoseconds since
1970.  It is possible to compute a two-digit mixed-radix 96-bit
quotient and remainder in struct timespec arithmetic, but it's a lot
more trouble to write out the details.

In particular, even if we limit intervals to be positive 63-bit
numbers of nanoseconds, computing the 64-bit remainder (1e9 * tv_sec)
% interval is annoying; we could break it into (1e9 % interval) *
(tv_sec % interval) but that's still a 30-bit x 63-bit product.  We
can break it down further into the high 31 bits and the low 32 bits
of tv_sec but that's getting into a lot of details of multiprecision
arithmetic.  And this is good enough for more than the next century.

PR kern/58922: itimer(9): arithmetic overflow
PR kern/58925: itimer(9) responds erratically to clock wound back
PR kern/58926: itimer(9) integer overflow in overrun counting
PR kern/58927: itimer(9): overrun accounting is broken


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/kern/subr_time_arith.c
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_time_arith.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.




Home | Main Index | Thread Index | Old Index