Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kernel mode preemption

I understand new linux kernel allow kernel space threads to be pre-empted. Can someone briefly explain how pre-empting works when executing in kernel mode? So, when a system call is made, a software interrupt will switch the thread into kernel mode and it will run whats necessary. Now, lets say its time slice is up - and another user thread runs and it also wants to execute in kernel space. (Or it could be a h/w interrupt). How does the kernel maintain the integrity of any structures that it was modifying for T1 when it got interrupted?

like image 482
excalibur Avatar asked Jan 09 '23 03:01

excalibur


1 Answers

The Linux kernel protects its data structures the same way as anything that runs in a multithreaded environment.

It will likely use some sort of lock to protect data structures that must be accessed atomically. Usually, these include spinlocks, mutexes and semaphores.

There are also functions that disable preemption but this isn't normally used explicitly since locking code will take care of this implicitly.

like image 186
tangrs Avatar answered Jan 18 '23 10:01

tangrs