Re: About Kernel preemption and kernel mode stack

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

 



Hi!

On 23:47 Wed 04 Mar     , sahlot arvind wrote:
> Hi All,
> 
> Just had couple of questions:
> 
> 1. kernel is preemptible if we are running in kernel mode and not holding
> any lock. What if we preempt the kernel even when we are holding lock?
> Assuming process A and B are trying to execute the same kernel path. So what
> if something like this happens:
> A gets into kernel mode and acquires a lock and then B comes, we preempt A
> and schedule B. B gets into kernel mode, tries to acquire the lock but its
> not available B goes to sleep,  A gets the CPU again goes ahead does its job
> and releases the lock. B wakes up gets the lock and proceeds normal.
> Would there be any problem? I think no. Then why cannot we preempt kernel
> when we are holding a lock in kernel mode?

The kernel can be preempted when you are holding a mutex or semaphore. This
is not the case for spinlocks. The reason is that they are used by both
interrupt handlers and "normal" kernel code. Interrupt handlers cannot go to
sleep and let some other code run to release the lock. So if there is any
code which goes to sleep while holding a spinlock the kernel will hang when
any code tries to get the lock in the meantime.

> 2. If kernel is not preemptible then do we really need a separate kernel
> mode stack for each and every process? I mean cannot we use a common kernel
> mode stack for all and every process? I think we can because since only one
> process could be in the kernel mode at a time, any process getting into
> kernel mode can easily assume that the kernel mode stack is always free
> whenever it gets into kernel mode.

Maybe... However it would need at least one stack per cpu and making the 
kernel non preemptive is bad for system responsiveness.

	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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