Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How preemption is handled in single core systems?

Given a single core system that employs preemption for multitasking, how does the OS carry out thread interrupts when a user mode application is executing on the system? Since the processor is handling the user code when does it get a chance to ask the thread scheduler for context switch. Is it handled similarly to page faults? And if it is, how often it happens and isn't it causing a performance hit?

like image 598
Matan Shahar Avatar asked Dec 03 '22 15:12

Matan Shahar


1 Answers

Read up on hardware interrupts.

The hardware timer issues periodic interrupts. When one happens, the CPU switches into kernel mode and executes a routine, the interrupt handler. That's where context switching takes place. When the CPU comes back from kernel to user mode, it returns control to a different thread than the one that the interrupt happened in. The state of the preempted thread is saved, naturally.

like image 105
Seva Alekseyev Avatar answered Dec 11 '22 08:12

Seva Alekseyev