Question about using spinlock to synchronize between kernel driver and an interrupt handler

anish singh anish198519851985 at gmail.com
Sat Feb 1 04:32:49 EST 2014


On Sat, Feb 1, 2014 at 1:15 AM, m silverstri
<michael.j.silverstri at gmail.com> wrote:
> By driver code , I mean the code which set the register values and
> wait till the values is set (via an interrupt handler) before
> continues doing something else
ok so you are looking for below code:


some_func()
{
set_register_value
x_variable=0
wait_for_event*(x_variable);
}

interrupt_handler(){
x_variable=1
wake_up();
}

request_irq(interrupt_handler);

>
>
> On Sat, Feb 1, 2014 at 1:06 AM, anish singh <anish198519851985 at gmail.com> wrote:
>> On Sat, Feb 1, 2014 at 1:03 AM, m silverstri
>> <michael.j.silverstri at gmail.com> wrote:
>>> On Sat, Feb 1, 2014 at 12:48 AM, anish singh
>>> <anish198519851985 at gmail.com> wrote:
>>>> On Sat, Feb 1, 2014 at 12:32 AM, m silverstri
>>>> <michael.j.silverstri at gmail.com> wrote:
>>>> don't top-post
>>>>
>>>>> In my driver code,
>>>>> I want to set a bit in a  HW Register 1. HW will send an interrupt
>>>> Yes this is how most drivers work.
>>>>
>>>>> when setting the register is done.
>>>>> I don't want my driver code to block until the interrupt is sent from the HW.
>>>> so i suppose this is what you want to do.
>>>>
>>>>
>>>> write ->register->interrupt happens->disable register ->handle interrupt
>>>> --->enable register.
>>>> Look at any driver code from linux kernel code and it mostly does this.
>>>>>
>>>
>>> Thanks.
>>> But I want my driver code to block until I get the interrupt from HW.
>>
>> if (driver code == interrupt handler) {
>>    it_is_not_running_anyway_as_there_is_no_interrupt
>> } else {
>>    i don't know what you mean by driver code here?
>> }
>>>
>>>
>>>
>>>>>
>>>>>
>>>>> On Sat, Feb 1, 2014 at 12:06 AM, anish singh
>>>>> <anish198519851985 at gmail.com> wrote:
>>>>>> On Fri, Jan 31, 2014 at 11:55 PM, m silverstri
>>>>>> <michael.j.silverstri at gmail.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I read this article http://www.linuxjournal.com/article/5833 to learn
>>>>>>> about spinlock. I try this to use it in my kernel driver.
>>>>>>>
>>>>>>> Here is what my driver code needs to do:
>>>>>>> In f1(), it will get the spin lock, and caller can call f2() will wait
>>>>>>> for the lock since the spin lock is not being unlock. The spin lock
>>>>>>> will be unlock in my interrupt handler (triggered by the HW).
>>>>>> Wrong design!!!
>>>>>>>
>>>>>>> void f1() {
>>>>>>> spin_lock(&mylock);
>>>>>>> // write hardware
>>>>>>> REG_ADDR += FLAG_A;
>>>>>> So here you take spinlock and release in interrupt handler.What
>>>>>> if there is no interrupt handler and someone calls this fucntion
>>>>>> he will blocked forever.
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> void f2() {
>>>>>>> spin_lock(&mylock);
>>>>>>> //...
>>>>>>> }
>>>>>>>
>>>>>>> The hardware will send the application an interrupt and my interrupt
>>>>>>> handler will call spin_unlock(&mylock);
>>>>>>>
>>>>>>> My question is if I call
>>>>>>> f1()
>>>>>>> f2() // i want this to block until the interrupt return saying settingyou
>>>>>>> REG_ADDR is done.
>>>>>>>
>>>>>>> when I run this, I get an exception in kernel saying a deadlock "
>>>>>>> INFO: possible recursive locking detected"
>>>>>>>
>>>>>>> How  can I re-write my code so that kernel does not think I have a deadlock?
>>>>>>>
>>>>>>> I want my driver code to wait until HW sends me an interrupt saying
>>>>>>> setting REG_ADDR is done.
>>>>>> Let us know what is your requirement?I am sure there must be a simple
>>>>>> way to handle than this magic done here.
>>>>>> Explain what are you trying to do in detail and I am sure lot of
>>>>>> people will jump
>>>>>> to help.
>>>>>>>
>>>>>>> Thank you.
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Kernelnewbies mailing list
>>>>>>> Kernelnewbies at kernelnewbies.org
>>>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



More information about the Kernelnewbies mailing list