Page MenuHomeFreeBSD

man9: Add man page for kern_yield() and friends
ClosedPublic

Authored by mhorne on Jan 24 2023, 9:51 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 22 2024, 7:17 PM
Unknown Object (File)
Jan 12 2024, 9:52 PM
Unknown Object (File)
Jan 9 2024, 10:04 PM
Unknown Object (File)
Jan 9 2024, 10:04 PM
Unknown Object (File)
Jan 9 2024, 10:03 PM
Unknown Object (File)
Jan 9 2024, 10:03 PM
Unknown Object (File)
Jan 1 2024, 1:05 PM
Unknown Object (File)
Jan 1 2024, 12:53 PM
Subscribers

Details

Summary

It is simple and will be referenced by mi_switch(9).

Diff Detail

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

Event Timeline

mhorne added a parent revision: D38181: Boolify should_yield().
markj added inline comments.
share/man/man9/kern_yield.9
73

Maybe note that it's really mostly meant to be used by threads doing a lot of work in the kernel, which don't readily preempt each other (see preempt_thresh) and thus rely on each other to yield the CPU. The function effectively checks whether it's been a long time (relative to the scheduling quantum) since the thread yielded voluntarily and thus might be hogging a CPU.

90

It's also a good idea to release locks before yielding, when possible.

This revision is now accepted and ready to land.Jan 24 2023, 10:41 PM

Two notes about priorities

  1. the kernel implements involuntary switching, so a thread hogging CPU should have special properties comparing to other threads that are starved.
  2. yielding does not guarantee that the yielding thread is removed from CPU, see note 1.

Explaining these two connected points in more details would be a useful service to the reader, IMO.

Also, the priority requested by kern_prio() is sticky until thread returns to usermode, which might be a surprise, AFAIR.

In D38182#867832, @kib wrote:

Two notes about priorities

  1. the kernel implements involuntary switching, so a thread hogging CPU should have special properties comparing to other threads that are starved.
  2. yielding does not guarantee that the yielding thread is removed from CPU, see note 1.

Explaining these two connected points in more details would be a useful service to the reader, IMO.

I think I understand these points, but to be clear you are mainly referring to interactivity score in ULE? As in, threads with a low voluntary sleep count could be categorized as non-interactive, and scheduled with lower priority than interactive timesharing threads. Therefore, the yielding thread may end up being the highest priority thread on the CPU's runqueues, and would be picked to continue running.

Also, the priority requested by kern_prio() is sticky until thread returns to usermode, which might be a surprise, AFAIR.

Handle review comments, mainly by expanding USAGE NOTES.

This revision now requires review to proceed.Jan 30 2023, 6:15 PM
share/man/man9/kern_yield.9
95

I do not think this statement is true

share/man/man9/kern_yield.9
95

Remarkably, with the default tuning of kern.sched.preempt_thresh, it is.

sched_shouldpreempt() contains the logic. I did overlook one case, which is that interactive or better threads will preempt non-interactive (batch) threads running on remote CPUs.

Nonetheless I will relax the language here slightly.

Slight tweaks to the first paragraph in USAGE NOTES.

This revision is now accepted and ready to land.Feb 8 2023, 1:25 AM