Re: Mutual Exclusion in Kernel

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

 



On Wed, Oct 06, 2004 at 08:22:41 -0000, matrix reloaded wrote:
>    
>  
>  
> On Wed, 06 Oct 2004 peyush wrote : 
>  
> Actually, for Non-SMP you don't need spinlock as they are for SMP mutual 
> exclusion thing, because 
>  
> For UP machine with non-preemptible Kernel you don't need anything but disable 
> interrupts before entering into the critical section. 
> For UP machine with preemptible kernel you need can use semaphore 

Forget about UP kernel or preemptible UP kernel. From programmer's point
of view, EACH AND EVERY KERNEL IS SMP, unless you are hacking syscall
gateway, interrupt gateway or the mutual exclusion code itself.

The rules are roughly:

    1) If the critical section is short, fast and does not sleep, it
       must should be protected with spinlocks.
    2) If you need to sleep in the critical section, it has to be
       protected with semaphore. Since semaphores may sleep, such
       critical section may sleep and thus may not appear in other that
       process context. It also comes that you may not lock semaphore
       under spinlock.
    3) If the critical section should exclude against interrupts, you
       must use spinlock irqsave/irqrestore variant (or
       irqdisabe/irqenable if you are sure about the interrupt flag
       state). There is also a bhenable/bhdisable variant for excluding
       bottom-halves, IIRC.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

Attachment: signature.asc
Description: Digital signature


[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