What Happens at Context Switch? Context switch is the mechanism to change running process (see last lecture) Switch out currently running process, switch in an alternative runnable process Save state of old process (program counter, stack pointer, register values) to thread_info struct (Linux) or thread_struct_t (MentOS) Restore previous state of new running process Change mapping for virtual memory How long does process execute for, before it is context-switched out? Linux specifies a scheduling quantum amount of time each process will be executed in a round-robin style before a context switch cat /proc/sys/kernel/sched_rr_timeslice_ms - 100ms on an RPi 4 How much data needs saving at a context switch? For each thread, there is a thread_info struct, to capture saved register values and other processor context - around 500 bytes on a 32-bit Arm processor with hardware floating-point support How long does a context switch take? context switch overhead measures the time taken to suspend one process and resume another. overhead must be made as low as possible on interactive systems, to enable rapid and smooth context switching