Page MenuHomeFreeBSD

sched_ule: Enable preemption of curthread in the load balancer
ClosedPublic

Authored by markj on Jul 7 2022, 6:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, May 6, 4:56 AM
Unknown Object (File)
Apr 16 2024, 7:21 PM
Unknown Object (File)
Apr 16 2024, 5:50 PM
Unknown Object (File)
Apr 5 2024, 5:31 PM
Unknown Object (File)
Mar 29 2024, 5:27 AM
Unknown Object (File)
Mar 21 2024, 4:45 PM
Unknown Object (File)
Jan 7 2024, 7:55 AM
Unknown Object (File)
Dec 20 2023, 6:49 AM
Subscribers

Details

Summary

The load balancer executes from statclock and periodically tries to move
threads among CPUs in order to balance load. It may move a thread to
the current CPU (the loader balancer always runs on CPU 0). When it
does so, it may need to schedule preemption of the interrupted thread.
Use sched_setpreempt() to do so, same as sched_add().

PR: 264867

Test Plan

Using schedgraph.d I saw a softclock thread sit on CPU 0's runqueue for 50ms while
a batch-priority thread was running. Some reading of the individual trace entries
showed that the softclock thread was enqueued while running the load balancer. I
haven't been able to reproduce the problem with this patch applied.

Diff Detail

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

Event Timeline

markj requested review of this revision.Jul 7 2022, 6:25 PM
markj edited the test plan for this revision. (Show Details)

Not to this change, but it would be good if the load balancer could somehow prefer to migrate long running threads, not some random interrupt threads it may spot by pure luck.

sys/kern/sched_ule.c
2646–2648

Just a cosmetics and not yours, but in this particular case variable initialization in declaration would make more sense to me to assert the thread lock more specifically.

This revision is now accepted and ready to land.Jul 7 2022, 7:48 PM
kib added inline comments.
sys/kern/sched_ule.c
955

Where is an AST is scheduled?

markj added inline comments.
sys/kern/sched_ule.c
955

In sched_setpreempt(). Probably it should be "preemption" instead?

markj marked an inline comment as done.

Address review feedback.

This revision now requires review to proceed.Jul 10 2022, 4:21 PM
kib added inline comments.
sys/kern/sched_ule.c
955

You mean setting td_owepreempt, which is definitely not an ast. Might be, finish the sentence as schedule a preemption by setting td_owepreempt for current thread.

This revision is now accepted and ready to land.Jul 10 2022, 6:49 PM
sys/kern/sched_ule.c
955

If the interrupted thread was in user mode, then preemption is triggered by setting TDF_NEEDRESCHED, which is handled in ast(). td_owepreempt is set as well, but this mechanism only affects kernel mode interruptions.

jhb added inline comments.
sys/kern/sched_ule.c
953