I don’t fully understand this.
What exactly does “thread context” mean in this case?
Specifically not interrupt context. Meaning execution can be suspended and resumed while waiting for other things to complete.
Thanks for replying.
When are we in kernel-space but not because of an interrupt?
Why wouldn’t one want a “thread waiting around all the time”? Why is using a “job” resource better than a thread?
You can be running in the kernel to handle a system call from userspace.
Classically, you would have lots of kernel threads. I’ve got a reaper, a swapper, an acpi thread, a usb thread, another usb thread, a sensors, a i915, a i915-hangcheck, and so on. But it’s a bit of clutter.
More pragmatically, the guts of all these threads tends to be very similar, a short loop sleeping and processing a list when something appears. Easier to just use a common API.
As a particular use case, in OpenBSD, you push the volume down key, so we want to lower the volume. But you don’t know the state of the audio system. And it’s bad to block and wait until audio is ready to adjust. So you add a task, which will run a little bit later, but allows the keyboard code to keep running.
Ok. I think I understand this now.
So the ACPI handler or whatever recognises the media key, and kicks off the job.
The scheduler schedules the threadpool, and noting it’s got a ready job runs it. Timer ISR fires and schedular treats it just like any other (kernel) thread.
It’s “better” than a thread because it doesn’t show up in the process list, and you have less code (since you don’t have to emulate unix inside the unix kernel).
That about right?
“More pragmatically, the guts of all these threads tends to be very similar, a short loop sleeping and processing a list when something appears. Easier to just use a common API.”
Yall are inching closer and closer to microkernel architecture. They just do that with everything in the system. :) Plus some optimizations…
Though hopefully not all of it in ring 0.
That’s exactly what Apple did. ;)
In the scope of a thread