Hi,

> 
> Will this work for multiple writers to solve:
> 
> * contention between ISR and write
> * contention between 2 or more writers
> 
> In the write() method:
> Grab spin_lock_irq
> Copy from interrupt buffer to local buffer
> spin_unlock_irq
> copy_to_user from local buffer
> 
> If so, How? How is it different from irqsave call?

It will work only if you are absolutely sure that interrupts will be enabled 
when this code gets executed. If you are not sure about the current state of 
interrupts when you are trying to grab a spinlock, use spin_lock_irqsave(). 
This will be more clearer below:

>> 
>> Suppose 2 writers are contending for spinlock. and if the code is as
>> follows: 
>> 
>> write()  {
>>           spin_lock_irqsave()             /*critical lock    */     
>>           x++; spin_unlock_irqsave()         /*critical unlock */ }
>> 
>> If the second writen tries to acquire the lock, when the first writer
>> is already holding it, how are flags managed. Will they not get
>> overwitten by the second write. when happens when restoring?

The "flags" is going to be a local / automatic variable (i.e. stored on the 
stack). And hence each of the writer threads will have its own copy. Even 
though an interrupt handler shares the stack with the process it interrupts, 
each of these will have its own copy of flags.

>> 
>> I am looking for clarification w.r.t contention between writers
>> rather 
>> than with ISR.
>> I know the 'flags' variable is the one thing that sets the difference
>> between spin_lock_irqsave()  & spin_lock_irq().
>> 
>> On an SMP, if the writer has disabled interrupts by acquiring
>> respective spinlock and followed by it there occurs an ISR that is
>> beng handled bo another CPU, then what? Are we not deadlocking?

No. because the ISR will busy loop waiting for the spinlock, and the first 
processor (actually holding the lock) is eventually going to release it. At 
this point the second processor can have it.

Thanks,

Rajat


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to