Page MenuHomeFreeBSD

umtx: allow to configure minimal timeout (in nanoseconds)
ClosedPublic

Authored by kib on Apr 15 2023, 5:48 PM.
Tags
None
Referenced Files
Unknown Object (File)
Apr 30 2024, 3:53 AM
Unknown Object (File)
Apr 24 2024, 1:28 AM
Unknown Object (File)
Apr 23 2024, 8:07 AM
Unknown Object (File)
Mar 22 2024, 9:23 PM
Unknown Object (File)
Mar 22 2024, 9:23 PM
Unknown Object (File)
Mar 22 2024, 9:23 PM
Unknown Object (File)
Mar 22 2024, 9:23 PM
Unknown Object (File)
Mar 22 2024, 9:23 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Apr 15 2023, 5:48 PM

The value of the *sbt result is absolute.

s/getbintime/getbinuptime/

kib added reviewers: mav, markj, vangyzen.

Adjust for min timeout before aligning to the next tick, not after.
Add documentation.

sys/kern/kern_umtx.c
712

I suppose this will work only at the beginning of each hardclock tick, but not later due to get*() returning stale values.

And I would not like to have additional binuptime() call here. I think it would be cheaper but almost as good to pass non-zero precision to msleep_sbt().

I also wonder if we should make the same tunable to affect other forms of sleep, or not. Is this the most pathological in implementations? May be so. considering there were no complains about others.

sys/kern/kern_umtx.c
712

The semantic of umtx_min_timeout is quite different from the precision lowering. It works around similar but different app issues.

I agree with the note about binuptime vs. getbinuptime, but please note that the call is only added for non-default configuration. IMO if user is going to slower down his machine responsiveness in this way, one more RDTSCP instruction does not matter.

sys/kern/kern_umtx.c
712

Yes, the semantics is different, precision does not always increase the time, but if the CPU is otherwise idle -- it does. And it is free. But I understand that is would depend on current implementation details, so I won't press this more.

I've grown in the age of slow timecounters, I am still trying to avoid those pains. ;)

sys/kern/kern_umtx.c
712

And BTW, there is sbinuptime() to slightly compact the code.

Back to sbinuptime(). Mark the path as non-default.

The Linux approach of letting this be specified on a per-process basis is perhaps nicer. In the case of the PR, only one (or maybe several?) processes require this special treatment. OTOH, I think Linux applies this setting to all user-initiated sleeps, which isn't necessary here.

lib/libthr/libthr.3
230
This revision is now accepted and ready to land.Apr 17 2023, 2:03 PM
kib marked an inline comment as done.Apr 17 2023, 2:11 PM

IMO proccontrol(2) knob there would be an overkill. Might be I would look some day to add some bits to umtx(2).

Switch to per-process LIBPTHREAD_UMTX_MIN_TIMEOUT env var knob.

This revision now requires review to proceed.Apr 17 2023, 3:03 PM

Harmonize get against set, use long for result.

This revision is now accepted and ready to land.Apr 17 2023, 5:50 PM

The implementation looks ok, but this looks like it should be done via procctl instead. If, someday, one wants a similar workaround for a different sleeping system call (e.g., kevent/EVFILT_TIMER), they cannot reasonably reuse UMTX_OP. procctl() would also allow the use of proccontrol to modify the setting, the extra flexibility could be useful.