From: Andrew Morton <akpm@linux-foundation.org>
To: Lukas Czerner <lczerner@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
axboe@kernel.dk, jmoyer@redhat.com, Neil Brown <neilb@suse.de>,
David Howells <dhowells@redhat.com>, Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH 1/2 v2] wait: add wait_event_lock_irq() interface
Date: Tue, 27 Nov 2012 15:25:16 -0800 [thread overview]
Message-ID: <20121127152516.ce512600.akpm@linux-foundation.org> (raw)
In-Reply-To: <1353572315-4508-1-git-send-email-lczerner@redhat.com>
On Thu, 22 Nov 2012 09:18:34 +0100
Lukas Czerner <lczerner@redhat.com> wrote:
> New wait_event{_interruptible}_lock_irq{_cmd} macros added. This commit
> moves the private wait_event_lock_irq() macro from MD to regular wait
> includes, introduces new macro wait_event_lock_irq_cmd() instead of using
> the old method with omitting cmd parameter which is ugly and makes a use
> of new macros in the MD. It also introduces the _interruptible_ variant.
>
> The use of new interface is when one have a special lock to protect data
> structures used in the condition, or one also needs to invoke "cmd"
> before putting it to sleep. "cmd" is always invoked before checking the
> "condition" so in case it will change the condition outcome we would not
> have to sleep unnecessarily.
>
> All new macros are expected to be called with the lock taken. The lock
> is released before sleep and is reacquired afterwards. We will leave the
> macro with the lock held.
>
> Note to DM: IMO this should also fix theoretical race on waitqueue while
> using simultaneously wait_event_lock_irq() and wait_event() because of
> lack of locking around current state setting and wait queue removal.
>
> ...
>
> +#define __wait_event_lock_irq(wq, condition, lock, cmd) \
> +do { \
> + DEFINE_WAIT(__wait); \
> + \
> + cmd; \
> + for (;;) { \
> + prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
> + if (condition) \
> + break; \
> + spin_unlock_irq(&lock); \
> + schedule(); \
> + cmd; \
> + spin_lock_irq(&lock); \
> + } \
> + finish_wait(&wq, &__wait); \
> +} while (0)
>
> ...
>
> +#define __wait_event_interruptible_lock_irq(wq, condition, \
> + lock, ret, cmd) \
> +do { \
> + DEFINE_WAIT(__wait); \
> + \
> + cmd; \
> + for (;;) { \
> + prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
> + if (condition) \
> + break; \
> + if (signal_pending(current)) { \
> + ret = -ERESTARTSYS; \
> + break; \
> + } \
> + spin_unlock_irq(&lock); \
> + schedule(); \
> + cmd; \
> + spin_lock_irq(&lock); \
> + } \
> + finish_wait(&wq, &__wait); \
> +} while (0)
These could be combined - use
if (flags == TASK_INTERRUPTIBLE && signal_pending(current)) { \
ret = -ERESTARTSYS; \
break; \
} \
and the compiler will fully remove that code for the
__wait_event_lock_irq() case.
But that's all a pretty small gain, IMO.
prev parent reply other threads:[~2012-11-27 23:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-22 8:18 Lukas Czerner
2012-11-22 8:18 ` [PATCH 2/2 v5] loop: Limit the number of requests in the bio list Lukas Czerner
2012-11-27 16:58 ` Jeff Moyer
2012-11-27 23:25 ` Andrew Morton [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=20121127152516.ce512600.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=a.p.zijlstra@chello.nl \
--cc=axboe@kernel.dk \
--cc=dhowells@redhat.com \
--cc=jmoyer@redhat.com \
--cc=lczerner@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=neilb@suse.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®