<div dir="ltr"><div><div><div><div><div>Hi,<br></div><br></div>In kernel driver, using Semaphore to block on resources (Descriptors and memory). <br>Semaphore is initialized in locking state using call "init_MTEX_LOCKED()", when resources are not available process calls down_interruptible() and blocks. Once resources are freed up() is called, and blocked process is unblocked. up() is called from interrupt context which frees resources on receiving ACK-Interrupt.<br>
</div><div>Following is the code snippet for blocking:<br></div><div>do {<br> ret = down_interruptible(sem)<br></div><div> if (ret == 0) {<br></div><div> break;<br></div><div> } else {<br></div><div> printk("Semaphore is not acquired try again\n");<br>
</div><div> continue;<br> }<br></div><div>} while (1);<br><br></div><div>While loop is used to make sure down_interrptible() is called until process acquires the semaphore. If process receives signal, process unblocks from down_interrptible() without acquiring the semaphore.<br>
</div><div>Issue am seeing is once signal is received under the blocking state, again trying to acquire semaphore using down_interruptible() return value is always non-zero and process is looping in while loop.<br><br></div>
<div>Can someone explain this behavior, I wrote the code with expectation that after signal is received again trying to acquire lock will either block the process or process will get semaphore.<br></div><div>Please help me on this. <br>
</div><br></div>Thanks,<br></div>Mushtaq Khan<br></div>