Context switch in Linux Gabriel Kliot, Technion 1 Context switch in Linux OS course
Memory layout general picture Stack Stack Stack Process X user memory Process Y user memory Process Z user memory Stack Stack Stack of CPU i Process X kernel stack and Process Y kernel stack and Process Z kernel stack and Kernel memory Gabriel Kliot, Technion 2 Context switch in Linux OS course
#1 kernel stack after any system call, before context switch Schedule() function frame Gabriel Kliot, Technion 3 Context switch in Linux OS course ss eflags cs eip orig_eax es ds eax ebp edi esi edx ecx ebx User Stack User Code Saved on the kernel stack during a transition to kernel mode by a jump to interrupt and by SAVE_ALL macro
#2 stack of before switch_to macro in schedule() func Gabriel Kliot, Technion 4 Context switch in Linux OS course
#3 switch_to: save esi, edi, ebp on the stack of Gabriel Kliot, Technion 5 Context switch in Linux OS course
#4 switch_to: save in -> Gabriel Kliot, Technion 6 Context switch in Linux OS course
#5 switch_to: load next-> into next Gabriel Kliot, Technion 7 Context switch in Linux OS course
#6 switch_to: save return address in the -> next Gabriel Kliot, Technion 8 Context switch in Linux OS course
#7 switch_to: save return address on the stack of next next Gabriel Kliot, Technion 9 Context switch in Linux OS course
#8 switch_to func: save the base of next s s stack in next Gabriel Kliot, Technion 10 Context switch in Linux OS course
#9 back in switch_to: eip points to instruction label next eip 1: Gabriel Kliot, Technion 11 Context switch in Linux OS course
#10 switch_to: restore esi, edi, ebp from the stack of next next Gabriel Kliot, Technion 12 Context switch in Linux OS course