Re: [LIP] Question about Linux kernel
Arun Sharma <[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Message-ID | <[email protected]> |
On Mon, May 31, 2004 at 12:13:26PM +0530, Rakesh Avichal Ughreja wrote:
> Is Linux kernel pre-emptive ?
> [...]
> How do I take care of mutual exclusion here ? One obvious thing is whenever
> ISR is getting executed I am sure its an atomic operation and my reader
> process will not get chance to run, but I don't know what will happen if an
> interrupt comes while reader is dequeueing the packet from the queue.
>
> How can I make enqueue and dequeue functions atomic ?
Using spinlocks. This is what many network drivers (drivers/net) do.
BTW, this has nothing to do with whether your kernel is preemptible or
not. On UP, if you don't disable interrupts in your device read function, you
need to worry about mutual exclusion.
If your driver needs to function on a SMP box, you must use
spinlocks, because the device read could be on one cpu and the interrupt
may happen on a different cpu. So disabling interrupts doesn't guarantee
mutual exclusion.
The term "preemptible" is used to describe kernels where a process
executing in kernel mode may be scheduled out, without actually calling
schedule(). This places some extra constraints on kernel code.
foo()
{
/* Check condition */
spinlock(); <-- may preempt
spinunlock();
/* May need to check the condition again */
}
-Arun
-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504