- Reentrant Kernel:A re-entrant kernel enables processes (or, to be more precise, their corresponding kernel threads) to give away the CPU while in kernel mode. They do not hinder other processes from also entering kernel mode.
- In the case of single processor systems multiple may be scheduled together
- An example of this case is a disk read. User program issues a system call for a disk read the scheduler will assign the CPU to another process (kernel thread) until an interrupt from the disk controller indicates that the data is available and our thread can be resumed. This process can still access I/O (which needs kernel functions), like user input. The system stays responsive and CPU time waste due to IO wait is reduced.
- In a non reentrant kernel, the original function (whatever requested data) would be blocked until the disk read was complete
- A computer program or routine is described as reentrant if it can be safely called again before its previous invocation has been completed (i.e it can be safely executed concurrently). To be reentrant, a computer program or routine:
- Must hold no static (or global) non-constant data. Further reading here.
- Must not return the address to static (or global) non-constant data.
- Must work only on the data provided to it by the caller.
- Must not rely on locks to singleton resources.
- a variable that is referred to only once
- Must not modify its own code (unless executing in its own unique thread storage)
- Must not call non-reentrant computer programs or routines.
- Reentrant kernels are still able to execute nonreentrant functions using locks to ensure only one process can execute that nonreentrant function
- Hardware interrupts are able to suspend the current process even if it is running in kernel mode (this enables things like Ctrl+c to stop execution)
- Kernel Control Path: Sequence of instructions executed by kernel to handle system call
- Normal execution will execute instructions sequentially but certain actions will cause the CPU to interleave control paths
- Process in user mode invokes system call: Scheduler selects new process to run and causes a process switch. Two control paths are executed on behalf of two different processes
- CPU detects exception: For example, accessing page not present in RAM. Suspend the process that caused the exception and starts execution of a suitable procedure, page allocation. Once allocated original control path continues
- Hardware interrupt: Hardware interrupts are higher priority processes.
- Normal execution will execute instructions sequentially but certain actions will cause the CPU to interleave control paths
Below is an example of a kernel control path