Page MenuHomeFreeBSD

nanosleep(2): Fix bogus incrementing of rmtp by tc_tick_sbt on [EINTR].
ClosedPublic

Authored by bdrewery on Feb 13 2018, 10:30 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 16, 1:43 PM
Unknown Object (File)
Fri, Nov 15, 6:31 PM
Unknown Object (File)
Sep 24 2024, 8:54 AM
Unknown Object (File)
Sep 15 2024, 4:11 AM
Unknown Object (File)
Sep 11 2024, 10:37 PM
Unknown Object (File)
Sep 9 2024, 6:44 AM
Unknown Object (File)
Sep 9 2024, 3:59 AM
Unknown Object (File)
Sep 8 2024, 8:27 AM
Subscribers

Details

Summary

sbt is the time in the future that the tsleep_sbt() is expected to be completed
at. sbtt is the current time. Depending on the precision with sysctl
kern.timecounter.alloweddeviation the start time may be incremented by
tc_tick_sbt. The same increment is needed for the current time of sbtt before
calculating the difference. The impact of missing this increment is that rmtp
may increase by one tc_tick_sbt on every early [EINTR] return. If the same
struct is passed in for rqtp as rmtp this can result in rqtp effectively
incrementing by tc_tick_sbt and sleeping longer than originally intended .

Sponsored by: Dell EMC
MFC after: 2 weeks

Test Plan

Before:

/usr/tests/lib/libc/sys # /usr/bin/time ./nanosleep_test nanosleep_eintr
nanosleep_test: WARNING: Running test cases outside of kyua(1) is unsupported
nanosleep_test: WARNING: No isolation nor timeout control is being applied; you may get unexpected failures; see atf-test-case(4)
failed: /root/git/freebsd/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c:231: errno: 4 got_info: 1 ts=5.000000242 should be <= tso=5.000000000

failed: nanosleep(2) handled rtmp incorrectly
        0.05 real         0.00 user         0.00 sys

After:

/usr/tests/lib/libc/sys # /usr/bin/time ./nanosleep_test nanosleep_eintr
nanosleep_test: WARNING: Running test cases outside of kyua(1) is unsupported
nanosleep_test: WARNING: No isolation nor timeout control is being applied; you may get unexpected failures; see atf-test-case(4)
passed
        5.00 real         0.00 user         0.00 sys

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Remove unneeded leftover debugging

This revision is now accepted and ready to land.Feb 14 2018, 1:59 PM
markj added inline comments.
contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c
215 ↗(On Diff #39285)

I'm not sure that ATF_REQUIRE will DTRT in a child process.

251 ↗(On Diff #39285)

I think it's reasonable to use ATF_REQUIRE to check the return values of these syscalls.

contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c
215 ↗(On Diff #39285)

It ends up exiting non-zero which the later wait does pickup on. See my testing example.

251 ↗(On Diff #39285)

Sure

This revision was automatically updated to reflect the committed changes.