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)
Mon, May 13, 6:04 AM
Unknown Object (File)
Mon, May 13, 6:03 AM
Unknown Object (File)
Mon, May 13, 1:37 AM
Unknown Object (File)
Feb 1 2024, 10:40 AM
Unknown Object (File)
Feb 1 2024, 6:06 AM
Unknown Object (File)
Jan 28 2024, 6:33 AM
Unknown Object (File)
Jan 26 2024, 11:10 PM
Unknown Object (File)
Jan 24 2024, 2:36 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 Not Applicable
Unit
Tests Not Applicable

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–273

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.