Module Name: src Committed By: riastradh Date: Wed Mar 5 14:01:55 UTC 2025
Modified Files: src/sys/kern: sys_futex.c Log Message: futex(2): Avoid returning early on timeout. Rounding in the arithmetic leading into cv_timedwait_sig, and any skew between the timecounter used by clock_gettime and the hardclock timer used to wake cv_timedwait_sig, can lead cv_timedwait_sig to wake up before the deadline as observable by clock_gettime. futex(FUTEX_WAIT) is not supposed to do that, so ignore when cv_timedwait_sig returns EWOULDBLOCK -- we'll notice the deadline has passed in the next iteration anyway, if it has actually passed. While here, make sure that we never pass less than 1 tick to cv_timedwait_sig -- that turns it into cv_wait_sig, to wait indefinitely with no timeout. With this change, I have not seen any failures as reported in: PR kern/59132: t_futex_ops:futex_wait_timeout_* sometimes fails on early wakeup Some instrumentation in futex_wait to count when cv_timedwait_sig returns early as measured by clock_gettime (not committed in this change, just local experiments) supports this hypothesis for the symptoms observed in the PR. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/kern/sys_futex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.