Page MenuHomeFreeBSD

SCHEDULER_STOPPED(): Rely on a global variable
ClosedPublic

Authored by olce on Jan 24 2024, 1:26 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 10, 6:13 PM
Unknown Object (File)
Fri, Nov 8, 5:26 AM
Unknown Object (File)
Thu, Nov 7, 9:47 AM
Unknown Object (File)
Tue, Nov 5, 8:26 AM
Unknown Object (File)
Tue, Nov 5, 7:28 AM
Unknown Object (File)
Tue, Oct 22, 4:35 PM
Unknown Object (File)
Oct 16 2024, 6:01 PM
Unknown Object (File)
Oct 15 2024, 12:41 PM
Subscribers

Details

Summary

A commit from 2012 (5d7380f8e34f0083, r228424) introduced
'td_stopsched', on the ground that a global variable would cause all
CPUs to have a copy of it in their cache, and consequently of all other
variables sharing the same cache line.

This is really a problem only if that cache line sees relatively
frequent modifications. This was unlikely to be the case back then
because nearby variables are almost never modified as well. In any
case, today we have a new tool at our disposal to ensure that this
variable goes into a read-mostly section containing frequently-accessed
variables ('__read_frequently'). Most of the cache lines covering this
section are likely to always be in every CPU cache. This makes the
second reason stated in the commit message (ensuring the field is in the
same cache line as some lock-related fields, since these are accessed in
close proximity) moot, as well as the second order effect of requiring
an additional line to be present in the cache (the one containing the
new 'scheduler_stopped' boolean, see below).

From a pure logical point of view, whether the scheduler is stopped is
a global state and is certainly not a per-thread quality.

Consequently, remove 'td_stopsched', which immediately frees a byte in
'struct thread'. Currently, the latter's size (and layout) stays
unchanged, but some of the later re-orderings will probably benefit from
this removal. Store the global state in the new 'scheduler_stopped'
boolean, which is annotated with '__read_frequently'.

Replace uses of SCHEDULER_STOPPED_TD() with SCHEDULER_STOPPER(). Remove
the now unnecessary SCHEDULER_STOPPED_TD().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 55590
Build 52479: arc lint + arc unit

Event Timeline

olce requested review of this revision.Jan 24 2024, 1:26 PM
This revision is now accepted and ready to land.Jan 24 2024, 10:21 PM
kib added inline comments.
sys/sys/proc.h
272

There is two chars hole after td_tsqueue; it is useful to mark it as eg. td_padXXX[2] field.

This revision was automatically updated to reflect the committed changes.