[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130607130723.GA2777@redhat.com>
Date: Fri, 7 Jun 2013 15:07:23 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Tejun Heo <tj@...nel.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Daniel Vetter <daniel.vetter@...ll.ch>,
Dave Jones <davej@...hat.com>,
David Howells <dhowells@...hat.com>,
Imre Deak <imre.deak@...el.com>, Jens Axboe <axboe@...nel.dk>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Lukas Czerner <lczerner@...hat.com>,
"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] wait: introduce prepare_to_wait_event()
Hi Tejun,
On 06/06, Tejun Heo wrote:
>
> Which tree are the patches based on? I'm getting conflicts on
> linus#master, mmotd and next.
Hmm. linus#master. I just verified that the patches apply cleanly
after git-pull.
> Reviewed-by: Tejun Heo <tj@...nel.org>
Thanks,
> But a couple nits.
>
> > +int
>
> I don't think we need to keep the unnecessary line break here. All
> other functions in the file don't do it except for the two
> prepare_to_wait functions. No need to give the weirdos more power. :)
Yes, I tried to follow the style around the new helper, but the extra
line is not needed.
Please see v2 below, no other changes.
> > +prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state)
> > +{
> > + if (signal_pending_state(state, current))
> > + return -ERESTARTSYS;
> > +
> > + wait->private = current;
> > + wait->func = autoremove_wake_function;
> > + prepare_to_wait(q, wait, state);
>
> I wonder whether it'd be worthwhile to make prepare_to_wait() inline
> so that it can be inlined into the above. I think gcc is smart enough
> to emit inline for in-file stuff and then build a proper function for
> external references. No biggie. Just wondering.
Not sure... As you can see from this patch, I like -Os more than -O2 ;)
------------------------------------------------------------------------------
Subject: [PATCH v2 2/2] wait: introduce prepare_to_wait_event()
Add the new helper, prepare_to_wait_event() which should only be used
by wait_event_common/etc.
prepare_to_wait_event() returns -ERESTARTSYS if signal_pending_state()
is true, otherwise it calls prepare_to_wait(). This allows to uninline
the signal-pending checks in wait_event_*.
Also, it can initialize wait->private/func. We do not care they were
already initialized, the values are the same. This also shaves a couple
of insns from the inlined code.
Unlike the previous change, this patch "reliably" shrinks the size of
generated code for every wait_event*() call.
Signed-off-by: Oleg Nesterov <oleg@...hat.com>
Reviewed-by: Tejun Heo <tj@...nel.org>
---
include/linux/wait.h | 22 +++++++++++-----------
kernel/wait.c | 13 +++++++++++++
2 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 392c54d..a2314dd 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -176,28 +176,27 @@ wait_queue_head_t *bit_waitqueue(void *, int);
#define __wait_no_timeout(tout) \
(__builtin_constant_p(tout) && (tout) == MAX_SCHEDULE_TIMEOUT)
-/* uglified signal_pending_state() optimized for constant state */
-#define __wait_signal_pending(state) \
- ((state == TASK_INTERRUPTIBLE) ? signal_pending(current) : \
- (state == TASK_KILLABLE) ? fatal_signal_pending(current) : \
- 0)
+#define __wait_interruptible(state) \
+ (!__builtin_constant_p(state) || \
+ state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE)
#define __wait_event_common(wq, condition, state, tout) \
({ \
- DEFINE_WAIT(__wait); \
- long __ret = 0, __tout = tout; \
+ long __ret, __tout = tout; \
+ wait_queue_t __wait; \
+ \
+ INIT_LIST_HEAD(&__wait.task_list); \
+ __wait.flags = 0; \
\
for (;;) { \
- prepare_to_wait(&wq, &__wait, state); \
+ __ret = prepare_to_wait_event(&wq, &__wait, state); \
if (condition) { \
__ret = __wait_no_timeout(tout) ?: __tout ?: 1; \
break; \
} \
\
- if (__wait_signal_pending(state)) { \
- __ret = -ERESTARTSYS; \
+ if (__wait_interruptible(state) && __ret) \
break; \
- } \
\
if (__wait_no_timeout(tout)) \
schedule(); \
@@ -781,6 +780,7 @@ extern long interruptible_sleep_on_timeout(wait_queue_head_t *q,
* Waitqueues which are removed from the waitqueue_head at wakeup time
*/
void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state);
+int prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state);
void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state);
void finish_wait(wait_queue_head_t *q, wait_queue_t *wait);
void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait,
diff --git a/kernel/wait.c b/kernel/wait.c
index 6698e0c..3b8619a 100644
--- a/kernel/wait.c
+++ b/kernel/wait.c
@@ -78,6 +78,19 @@ prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
}
EXPORT_SYMBOL(prepare_to_wait);
+int prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state)
+{
+ if (signal_pending_state(state, current))
+ return -ERESTARTSYS;
+
+ wait->private = current;
+ wait->func = autoremove_wake_function;
+ prepare_to_wait(q, wait, state);
+
+ return 0;
+}
+EXPORT_SYMBOL(prepare_to_wait_event);
+
void
prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state)
{
--
1.5.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists