From: joshc@eso.teric.us (Josh Cartwright)
To: kernelnewbies@lists.kernelnewbies.org
Subject: down_interruptible() return non-zero value once signal is received and trying down_interruptible again in loop return value is always non-zero
Date: Sun, 20 Oct 2013 10:32:21 -0500 [thread overview]
Message-ID: <20131020153221.GO12992@kryptos> (raw)
In-Reply-To: <CAGX0epbsnjTpKpw4jmaroxq9t5ne=8z0dchiofEVmqfEetn9_w@mail.gmail.com>
On Fri, Oct 18, 2013 at 05:56:41PM +0530, Mushtaq Khan wrote:
> Hi,
>
> In kernel driver, using Semaphore to block on resources (Descriptors and
> memory).
> 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.
> Following is the code snippet for blocking:
> do {
> ret = down_interruptible(sem)
> if (ret == 0) {
> break;
> } else {
> printk("Semaphore is not acquired try again\n");
> continue;
> }
> } while (1);
>
> 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.
> 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.
Yes. This happens because there is a signal pending for the calling
thread. If you follow the down_interruptible() code path, you see that
the first thing in the loop in __down_common (kernel/semaphore.c) is
that signal_pending_state() is called to see if there is a pending
signal, and if so, it immediately returns -EINTR.
Using down_interruptible() in the method above is ill-advised. It's
expected that if you are interrupted, you will propagate that
'interrupted' condition to your caller (and eventually back out to
usermode).
Josh
prev parent reply other threads:[~2013-10-20 15:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-18 12:26 down_interruptible() return non-zero value once signal is received and trying down_interruptible again in loop return value is always non-zero Mushtaq Khan
2013-10-20 7:51 ` anish singh
2013-10-20 15:32 ` Josh Cartwright [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131020153221.GO12992@kryptos \
--to=joshc@eso.teric.us \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.