Re: spin_lock_irqsave or spin_lock in work queue handlers?

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

 



On Thu, Mar 6, 2008 at 8:40 PM, Lukas Razik <linux@xxxxxxxxxx> wrote:
> Hello Peter!
>
>
>
>  >> > 2 diff things.   semap are sync mechanism used - to sync among
>  >> > CPUs/processes/tasks etc.   Just a counting mechanism.   It DOES NOT
>  >> > lock the other CPU while another CPU is using the same resources.    but
>  >> > this counting must be atomic....different arch has different instruction
>  >> > set to do it.
>  >>
>  >> I thought that because there is an 'init_MUTEX(struct semaphore *)'
>  >> macro, there would be no difference between semaphores and mutex_locks.
>  >> So, did I understand it right:
>  >> semaphores are only local (for one CPU)?
>  >> mutex_locks also lock the other CPUs?
>  >>
>  >
>  > all these API can affect other CPU's behavior.
>
>  What do you meen by "all these API"?
>  I thought the semaphores only affect the behavior of the local CPU...
>
>
>
>  > mutex does not "lock" in the sense of blocking the CPU - but in the
>  > sense that if the lock is not free, the task will be switch out and
>  > another task switch in, done by scheduler.
>
>  O.K. I understand so I ask in another way:
>  For example my work handler is running on CPU0 and holds the mutex_lock.
>  Then (on CPU1) my work handler also calls mutex_lock.
>  Will it "see" that the lock is held by the work handler on CPU0 and will
>  it be switched out by the scheduler?
>

I think one answer can answer both question:   Generally, all locking
API always work on global variable.   Global variable means the entire
linux kernel only have one copy of the variable. For eg, for varA all
spinlock(varA) are basically holding on the same variable - the same
copy in memory.

There is no meaning of individual CPU have their own private variable
- individually whatever they do, is not visible to the other CPU, so
what is the purpose of locking?

Yes, all API means semaphore/mutex/spinlocks.



-- 
Regards,
Peter Teoh

--
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