<p><br>
On Feb 1, 2014 2:48 PM, "m silverstri" <<a href="mailto:michael.j.silverstri@gmail.com">michael.j.silverstri@gmail.com</a>> wrote:<br>
><br>
> By driver code , I mean the code which set the register values and<br>
> wait till the values is set (via an interrupt handler) before<br>
> continues doing something else<br>
><br>
><br>
> On Sat, Feb 1, 2014 at 1:06 AM, anish singh <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>> wrote:<br>
> > On Sat, Feb 1, 2014 at 1:03 AM, m silverstri<br>
> > <<a href="mailto:michael.j.silverstri@gmail.com">michael.j.silverstri@gmail.com</a>> wrote:<br>
> >> On Sat, Feb 1, 2014 at 12:48 AM, anish singh<br>
> >> <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>> wrote:<br>
> >>> On Sat, Feb 1, 2014 at 12:32 AM, m silverstri<br>
> >>> <<a href="mailto:michael.j.silverstri@gmail.com">michael.j.silverstri@gmail.com</a>> wrote:<br>
> >>> don't top-post<br>
> >>><br>
> >>>> In my driver code,<br>
> >>>> I want to set a bit in a HW Register 1. HW will send an interrupt<br>
> >>> Yes this is how most drivers work.<br>
> >>><br>
> >>>> when setting the register is done.<br>
> >>>> I don't want my driver code to block until the interrupt is sent from the HW.<br>
> >>> so i suppose this is what you want to do.<br>
> >>><br>
> >>><br>
> >>> write ->register->interrupt happens->disable register ->handle interrupt<br>
> >>> --->enable register.<br>
> >>> Look at any driver code from linux kernel code and it mostly does this.<br>
> >>>><br>
> >><br>
> >> Thanks.<br>
> >> But I want my driver code to block until I get the interrupt from HW.<br>
> ><br>
> > if (driver code == interrupt handler) {<br>
> > it_is_not_running_anyway_as_there_is_no_interrupt<br>
> > } else {<br>
> > i don't know what you mean by driver code here?<br>
> > }<br>
> >><br>
> >><br>
> >><br>
> >>>><br>
> >>>><br>
> >>>> On Sat, Feb 1, 2014 at 12:06 AM, anish singh<br>
> >>>> <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>> wrote:<br>
> >>>>> On Fri, Jan 31, 2014 at 11:55 PM, m silverstri<br>
> >>>>> <<a href="mailto:michael.j.silverstri@gmail.com">michael.j.silverstri@gmail.com</a>> wrote:<br>
> >>>>>> Hi,<br>
> >>>>>><br>
> >>>>>> I read this article <a href="http://www.linuxjournal.com/article/5833">http://www.linuxjournal.com/article/5833</a> to learn<br>
> >>>>>> about spinlock. I try this to use it in my kernel driver.<br>
> >>>>>><br>
> >>>>>> Here is what my driver code needs to do:<br>
> >>>>>> In f1(), it will get the spin lock, and caller can call f2() will wait<br>
> >>>>>> for the lock since the spin lock is not being unlock. The spin lock<br>
> >>>>>> will be unlock in my interrupt handler (triggered by the HW).<br>
> >>>>> Wrong design!!!<br>
> >>>>>><br>
> >>>>>> void f1() {<br>
> >>>>>> spin_lock(&mylock);<br>
> >>>>>> // write hardware<br>
> >>>>>> REG_ADDR += FLAG_A;<br>
> >>>>> So here you take spinlock and release in interrupt handler.What<br>
> >>>>> if there is no interrupt handler and someone calls this fucntion<br>
> >>>>> he will blocked forever.<br>
> >>>>>><br>
> >>>>>> }<br>
> >>>>>><br>
> >>>>>> void f2() {<br>
> >>>>>> spin_lock(&mylock);<br>
> >>>>>> //...<br>
> >>>>>> }<br>
> >>>>>><br>
> >>>>>> The hardware will send the application an interrupt and my interrupt<br>
> >>>>>> handler will call spin_unlock(&mylock);<br>
> >>>>>><br>
> >>>>>> My question is if I call<br>
> >>>>>> f1()<br>
> >>>>>> f2() // i want this to block until the interrupt return saying settingyou</p>
<p>I think you want to block a task for an event to happen. That event is triggered by HW. </p>
<p>What i would suggest is that you use completion variable which would be per request. Don't make it global otherwise you'll again need locks to protect global variable. Try to pass this completion variable along with request to your driver.</p>
<p>Also i suppose that your driver could implement a list where requests from tasks can be queued and each task would wait for completion which already is per task embedded in its request.</p>
<p>The driver would deque requests one by one or depending on how many requests can your hw handle and will trigger completion waking up the task that triggered it.</p>
<p>So you'll have a clean api design where locks are held and unlocked at same layer instead of current design.<br><br></p>
<p>> >>>>>> REG_ADDR is done.<br>
> >>>>>><br>
> >>>>>> when I run this, I get an exception in kernel saying a deadlock "<br>
> >>>>>> INFO: possible recursive locking detected"<br>
> >>>>>><br>
> >>>>>> How can I re-write my code so that kernel does not think I have a deadlock?<br>
> >>>>>><br>
> >>>>>> I want my driver code to wait until HW sends me an interrupt saying<br>
> >>>>>> setting REG_ADDR is done.<br>
> >>>>> Let us know what is your requirement?I am sure there must be a simple<br>
> >>>>> way to handle than this magic done here.<br>
> >>>>> Explain what are you trying to do in detail and I am sure lot of<br>
> >>>>> people will jump<br>
> >>>>> to help.<br>
> >>>>>><br>
> >>>>>> Thank you.<br>
> >>>>>><br>
> >>>>>> _______________________________________________<br>
> >>>>>> Kernelnewbies mailing list<br>
> >>>>>> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> >>>>>> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
><br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a></p>
<p> ---P.K.S</p>