HomeFreeBSD

sched_ule: Ensure we hold the thread lock when modifying td_flags

Description

sched_ule: Ensure we hold the thread lock when modifying td_flags

The load balancer may force a running thread to reschedule and pick a
new CPU. To do this it sets some flags in the thread running on a
loaded CPU. But the code assumed that a running thread's lock is the
same as that of the corresponding runqueue, and there are small windows
where this is not true. In this case, we can end up with non-atomic
modifications to td_flags.

Since this load balancing is best-effort, simply give up if the thread's
lock doesn't match; in this case the thread is about to enter the
scheduler anyway.

Reviewed by: kib
Reported by: glebius
Fixes: e745d729be60 ("sched_ule(4): Improve long-term load balancer.")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit bd980ca847b76439bd27a4144cf0dd69d48b33af)

Details

Provenance
markjAuthored on Jul 18 2022, 7:50 PM
Parents
rG211c9ad8b532: sched_ule: Use the correct atomic_load variant for tdq_lowpri
Branches
Unknown
Tags
Unknown