Agenda: To understand different kernel execution contexts. Please refresh the following before the class from your favorite OS book(s) and/or other reference materials. - user vs. kernel mode - system calls - processes and threads - interrupt processing Notes for class --------------- - Execution context: From OS perspective, an execution context consists of a set of CPU registers which represent the state of the currently executing entity. This could be processes/threads in execution either in user mode or kernel mode, exception handlers, interrupt handlers or kernel threads. Some important elements of an execution context are: stack pointed to by stack pointer (e.g., esp), page table pointer (e.g., CR3), current privilege level (CPL) etc.. During a context switch, some of this elements in the CPU change. Note: Normal function call/return should not be considered as a context switch as only general purpose CPU registers are saved and restored using the same stack (while stack pointer can move up and down). We discussed the following kernel execution contexts, - exception handlers - system-call handlers (a special case for exception handlers) - interrupt handlers - kernel threads - What would change in the following context switch scenarios 1) Process P1 is replaced by another process P2 by the OS scheduler. 2) Thread T1 of P1 is replaced by thread T2 of P1. - For Exception/system call handlers, interrupt handlers and kernel threads we discussed the following points. 1) What should change? - CPL - stack (why not use the user stack?) - page tables (should we use the process page tables?) 2) # of kernel stacks for each of the above case is equal to - number of tasks? - number of CPUs? - number of exceptions/syscalls/interrupts? - For all of the above kernel execution contexts, we tried to find answers to the following questions, - Can it sleep? - Which execution context(s) can preempt? - What could be the issues in accessing user memory? - How to identify the current execution context in case of exception/syscall handlers?