mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Imre Deak <imre.deak@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Dave Jones <davej@redhat.com>,
	David Howells <dhowells@redhat.com>, Jens Axboe <axboe@kernel.dk>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Lukas Czerner <lczerner@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] wait: fix false timeouts when using wait_event_timeout()
Date: Wed, 5 Jun 2013 18:45:07 -0700	[thread overview]
Message-ID: <20130606014507.GR10693@mtj.dyndns.org> (raw)
In-Reply-To: <20130605190723.GA4957@redhat.com>

Hello, Oleg.

On Wed, Jun 05, 2013 at 09:07:23PM +0200, Oleg Nesterov wrote:
> And in fact, perhaps we can implement wait_event_common() and avoid the
> code duplications?
> 
> 	#define __wait_no_timeout(timeout)	\
> 		(__builtin_constant_p(timeout) && (timeout) == MAX_SCHEDULE_TIMEOUT)
> 
> 	/* uglified signal_pending_state() */
> 	#define __wait_signal_pending(state)					\
> 		((state == TASK_INTERRUPTIBLE) ? signal_pending(current) :	\
> 		 (state == TASK_KILLABLE) ? fatal_signal_pending(current) :	\
> 		  0)
> 
> 	#define __wait_event_common(wq, condition, state, tout)			\
> 	({									\
> 		DEFINE_WAIT(__wait);						\
> 		long __ret = 0, __tout = tout;					\
> 										\
> 		for (;;) {							\
> 			prepare_to_wait(&wq, &__wait, state);			\
> 			if (condition) {					\
> 				__ret = __wait_no_timeout(tout) ?: __tout ?: 1;	\
> 				break;						\
> 			}							\
> 										\
> 			if (__wait_signal_pending(state)) {			\
> 				__ret = -ERESTARTSYS;				\
> 				break;						\
> 			}							\
> 										\
> 			if (__wait_no_timeout(tout))				\
> 				schedule();					\
> 			else if (__tout)					\
> 				__tout = schedule_timeout(__tout);		\
> 			else							\
> 				break;						\
> 		}								\
> 		finish_wait(&wq, &__wait);					\
> 		__ret;								\
> 	})

Heh, yeah, this looks good to me and a lot better than trying to do
the same thing over and over again and ending up with subtle
differences.

> Hmm. I compiled the kernel with the patch below,
> 
> 		$ size vmlinux
> 		   text	   data	    bss	    dec	    hex	filename
> 	-	4978601	2935080	10104832	18018513	112f0d1	vmlinux
> 	+	4977769	2930984	10104832	18013585	112dd91	vmlinux

Nice.  Provided you went over assembly outputs of at least some
combinations, please feel free to add

 Reviewed-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

  reply	other threads:[~2013-06-06  1:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-04 19:28 Oleg Nesterov
2013-06-04 21:35 ` Imre Deak
2013-06-04 21:40   ` Imre Deak
2013-06-05 16:37     ` Oleg Nesterov
2013-06-05 19:07       ` Oleg Nesterov
2013-06-06  1:45         ` Tejun Heo [this message]
2013-06-06 18:47           ` Oleg Nesterov
  -- strict thread matches above, loose matches on Subject: below --
2013-05-02  8:58 Imre Deak
2013-05-02  9:36 ` Daniel Vetter
2013-05-07 23:12   ` Andrew Morton
2013-05-08  9:49     ` Imre Deak
2013-05-02 10:29 ` David Howells
2013-05-02 12:02   ` Imre Deak
2013-05-02 12:13   ` Daniel Vetter
2013-05-02 12:23     ` Jens Axboe
2013-05-02 12:34       ` Imre Deak
2013-05-02 12:54         ` Jens Axboe
2013-05-02 13:56           ` Imre Deak
2013-05-02 14:04             ` Daniel Vetter
2013-05-02 12:29     ` David Howells
2013-05-02 12:29 ` David Howells
2013-05-02 12:35   ` Jens Axboe
2013-05-02 19:56     ` Imre Deak

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=20130606014507.GR10693@mtj.dyndns.org \
    --to=tj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=davej@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=imre.deak@intel.com \
    --cc=lczerner@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=torvalds@linux-foundation.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 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®