ஒரு context switch என்பது ஒரு single core பல threads-ஐ multiplex செய்யும் வகையில், தற்போது இயங்கும் thread-இன் CPU நிலையை (registers, program counter, stack pointer) kernel சேமித்து, இன்னொரு thread-இன் நிலையை மீட்டெடுப்பது. இது ஒவ்வொரு scheduler preemption, blocking syscall, அல்லது interrupt-லும் நடக்கிறது — அது இலவசமல்ல.
செலவு எங்கே மறைந்திருக்கிறது
DIRECT cost (visible, ~1–5 µs):
save/restore registers · run scheduler logic · switch kernel stacks
if PROCESS switch: also swap page tables (CR3) → FLUSHES the TLB
INDIRECT cost (often much larger):
cold CPU CACHES → the new thread's data isn't in L1/L2/L3 → cache misses to RAM
cold TLB → address translations must be re-walked
lost pipeline / branch-predictor state
