Information Technology Reference
In-Depth Information
A zero-thread kernel
Not only can we have a single-threaded kernel or a multi-threaded kernel, it is actually
possible to have a kernel with no threads of its own—a zero-threaded kernel! In fact,
this used to be quite common.
Consider the simple picture of an operating system we sketched in Chapter 2. Once
the system has booted, initialized its device drivers, and started some user-level pro-
cesses like a login shell, everything else the kernel does is event-driven—done in re-
sponse to an interrupt, exception, or trap.
In a simple operating system like this, there is no need for a “kernel thread” or “kernel
thread control block” to keep track of an ongoing computation. Instead, when an inter-
rupt, trap, or exception occurs, the stack pointer gets set to the base of the exception
stack, the instruction pointer gets set to the address of the handler. Then the handler
executes and either returns immediately to the interrupted user-level process or sus-
pends the user-level process and “returns” to some other user-level process. In either
case, the next event (interrupt, trap, or exception) starts this process anew.
Multi-threaded kernel with single-threaded processes
Figure 4.14 illustrates two single-threaded user-level processes running on a
multi-threaded kernel with three kernel threads. Notice that each user-level
process includes the process's thread. But, each process is more than just a
thread because each process has its own address space|process 1 has its own
view of memory, its own code, its own heap, and its own global variables that
differ from those of process 2 (and differ from those of the kernel).
Because a process is more than just a thread, each process's process control
block (PCB) needs more information than a thread control block (TCB) for a
kernel thread, and switching between processes|or between a kernel thread and
a user-level process|needs to do a bit more work.
PCB v. TCB. The a kernel thread's TCB and a user-level process's PCB are
similar, but it has some additional information. Like a TCB, a PCB must store
the processor registers when the process's thread is not running. In addition,
the PCB has information about the process's address space so that when we
context switch from one process to another or between a process and the kernel,
the right virtual memory mappings are used.
We discuss virtual memory in
Chapter ??.
With respect to concurrency and threads, the PCB and TCB each represents
one thread, and the kernel's ready list contains a mix of PCBs for processes and
TCBs for kernel thread. When the scheduler chooses the next thread to run, it
can pick either kind.
Search WWH ::




Custom Search