CSE451 Notes for 4/14/03 Compiled by Cameron Tom ************************* The point of this lecture was that the concept of context-switching allows the compiler to do multiple procedure calls, the OS to schedule mulitiple processes, and the OS to schedule multiple threads within a task. A context for a procedure consists of: - pc - registers - stack frame pointer Key points: - Whether using LIFO (last in, first out) or co-routine (switching between two or more), always save the context and then call the another function/process. - The compiler handles procedure calls by implementing LIFO with a stack, and the OS does the more complex scheduling of processes (in any order) by implementing co-routine using a queue. ************************* LIFO (Stack): ************************* // example // the context for p is saved, then q is called // q returns to p p() { q(); } q(){ return; } Scheduling context in LIFO order is a fancy word for "procedure call." Stack frames are contiguous. Why LIFO? The processor and compiler like really simple things. ************************* Co-routine (Queue): ************************* // example: // the context for p is saved, then q runs // the context for q is saved, then p runs again p(){ switch to q(); } q(){ switch to p(); } The OS uses a queue to schedule processes. Process = program (pile of code) in (currently) execution (issuing a sequence of instructions in predetermined order given a set of inputs) When we define tasks, we modify the definition to "any order". See "Tasks:" below. Who benefits? User, resource utilization is increased. Who doesn't? Programmer, programs are still written the same way. Context switching is transparent to the process. The OS considers a processes as data in the form of process control block (PCB) which includes (but not limited to): - PID - User - Context - ASID (gives a unique translation of addresses) ************************* Tasks: ************************* In the OS, if one process requests I/O, the OS can schedule another process to run to make use of the I/O wait time. To do this within the same program, the OS can offer support to schedule multiple threads within the same task. Visualization ---> exec ---> I/O ---> exec ---> I/O