Page MenuHomeFreeBSD

softclock: Use dedicated ithreads for running callouts.
ClosedPublic

Authored by jhb on Dec 28 2021, 7:33 PM.
Tags
None
Referenced Files
F101955540: D33683.diff
Tue, Nov 5, 6:55 PM
Unknown Object (File)
Oct 1 2024, 2:39 AM
Unknown Object (File)
Oct 1 2024, 2:35 AM
Unknown Object (File)
Oct 1 2024, 12:32 AM
Unknown Object (File)
Sep 19 2024, 12:26 AM
Unknown Object (File)
Sep 18 2024, 10:20 AM
Unknown Object (File)
Sep 18 2024, 10:14 AM
Unknown Object (File)
Sep 17 2024, 4:19 PM
Subscribers

Details

Summary

Rather than using the swi infrastructure, rewrite softclock() as a
thread loop (softclock_thread()) and use it as the main routine of the
softclock threads. The threads use the CC_LOCK as the thread lock
when idle.

Sponsored by: Netflix

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 43641
Build 40529: arc lint + arc unit

Event Timeline

jhb requested review of this revision.Dec 28 2021, 7:33 PM

The use of cc_lock as thread lock is to avoid lost wakeups from callout_process()?

It is a bit like particle physics, but I don't see anything wrong here.

This revision is now accepted and ready to land.Dec 28 2021, 8:34 PM

One possible downside I can guess in sched_add() calling sched_pickcpu() under the CC_LOCK, if I understand it right, but may be it will be some compensated by reduced complexity.

This seems fine... Have a question about the locks that likely could be clarified with a few words...

sys/kern/kern_timeout.c
839

A comment somewhere would be useful about the weird locking that's going on here...

In D33683#761169, @kib wrote:

The use of cc_lock as thread lock is to avoid lost wakeups from callout_process()?

Yes, but in general a thread needs some sort of thread_lock when it is idle. When you are asleep on a sleep queue it is the associated SC_LOCK, or when blocked on a turnstile the TC_LOCK. ithreads are currently a bit of an odd ball as they end up staying with the "running lock" even when idle. Reusing the cc_lock as the thread lock means you don't have to grab the "running lock" just to schedule the thread but can instead reuse the spin lock that is already held to interlock against going to sleep in softclock_thread().

sys/kern/kern_timeout.c
839

It's actually a bit typical in other places like sleepq_switch() and turnstile_wait(). However, it is certainly not immediately obvious (it wasn't to me) that mi_switch() drops the current thread_lock and returns without it held.

  • Add some comments on thread_lock locking.
  • Reset profile counters in each loop iteration.
This revision now requires review to proceed.Dec 30 2021, 12:35 AM
This revision is now accepted and ready to land.Dec 30 2021, 2:29 AM