Re: About kernel preemption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2004-09-09 at 17:12 +0000, Martim Carbone wrote:

Carbone!  Hello!

> Why can't the kernel be preempted when locks are being held inside it?
> 
> If a thread executing in kernel space enters a critical region and
> gets preempted, the lock will protect the critical region from other
> threads, so I don't see what is the problem.

This would work for semaphores (which in Linux are sleeping locks) but
not for spinlocks (which are busy-wait locks).

So, in fact, you can preempt while a semaphore is held but not while a
spin lock is held.

The reason is because you can deadlock (acquire lock A, preempt, new
thread acquires lock A).

It goes further than this, too, in that code holding a spin locks
believes itself to be atomic.  If it suddenly was scheduled away for
awhile, that might annoy whatever it is doing.  It would also not help
lock contention.

This might beg the question "well, why not make spinlocks into sleeping
locks?"

This is totally possible, if interrupt handlers were threaded.  Right
now they are not threaded, so they cannot sleep.

Hope this helps,

	Robert Love



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux