All of lore.kernel.org
 help / color / mirror / Atom feed
* + futex-restartable-futex_wait.patch added to -mm tree
@ 2007-03-11  8:14 akpm
       [not found] ` <20070312011259.3834A1801C4@magilla.sf.frob.com>
  0 siblings, 1 reply; 23+ messages in thread
From: akpm @ 2007-03-11  8:14 UTC (permalink / raw)
  To: mm-commits; +Cc: npiggin, drepper, mingo, oleg, roland, rusty


The patch titled
     futex: restartable futex_wait
has been added to the -mm tree.  Its filename is
     futex-restartable-futex_wait.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: futex: restartable futex_wait
From: Nick Piggin <npiggin@suse.de>

LTP test sigaction_16_24 fails, because it expects sem_wait to be restarted
if SA_RESTART is set.  sem_wait is implemented with futex_wait, that
currently doesn't support being restarted.  Ulrich confirms that the call
should be restartable.

Implement a restart_block method to handle the relative timeout, and allow
restarts.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: Ulrich Drepper <drepper@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Roland McGrath <roland@redhat.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 kernel/futex.c |   25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff -puN kernel/futex.c~futex-restartable-futex_wait kernel/futex.c
--- a/kernel/futex.c~futex-restartable-futex_wait
+++ a/kernel/futex.c
@@ -978,6 +978,7 @@ static void unqueue_me_pi(struct futex_q
 	drop_futex_key_refs(&q->key);
 }
 
+static long futex_wait_restart(struct restart_block *restart);
 static int futex_wait(u32 __user *uaddr, u32 val, unsigned long time)
 {
 	struct task_struct *curr = current;
@@ -1077,11 +1078,22 @@ static int futex_wait(u32 __user *uaddr,
 		return 0;
 	if (time == 0)
 		return -ETIMEDOUT;
+
 	/*
 	 * We expect signal_pending(current), but another thread may
 	 * have handled it for us already.
 	 */
-	return -EINTR;
+	if (time == MAX_SCHEDULE_TIMEOUT)
+		return -ERESTARTSYS;
+	else {
+		struct restart_block *restart;
+		restart = &current_thread_info()->restart_block;
+		restart->fn = futex_wait_restart;
+		restart->arg0 = (unsigned long)uaddr;
+		restart->arg1 = (unsigned long)val;
+		restart->arg2 = time;
+		return -ERESTART_RESTARTBLOCK;
+	}
 
  out_unlock_release_sem:
 	queue_unlock(&q, hb);
@@ -1091,6 +1103,17 @@ static int futex_wait(u32 __user *uaddr,
 	return ret;
 }
 
+static long futex_wait_restart(struct restart_block *restart)
+{
+	u32 __user *uaddr = (u32 __user *)restart->arg0;
+	u32 val = (u32)restart->arg1;
+	unsigned long time = restart->arg2;
+
+	restart->fn = do_no_restart_syscall;
+	return (long)futex_wait(uaddr, val, time);
+}
+
+
 /*
  * Userspace tried a 0 -> TID atomic transition of the futex value
  * and failed. The kernel side here does the whole locking operation:
_

Patches currently in -mm which might be from npiggin@suse.de are

mm-fix-madvise-infinine-loop.patch
futex-restartable-futex_wait.patch
mm-remove-gcc-workaround.patch
mm-more-rmap-checking.patch
mm-make-read_cache_page-synchronous.patch
fs-buffer-dont-pageuptodate-without-page-locked.patch
mm-debug-check-for-the-fault-vs-invalidate-race.patch
mm-debug-check-for-the-fault-vs-invalidate-race-tidy.patch
mm-simplify-filemap_nopage.patch
mm-fix-fault-vs-invalidate-race-for-linear-mappings.patch
mm-merge-populate-and-nopage-into-fault-fixes-nonlinear.patch
mm-merge-populate-and-nopage-into-fault-fixes-nonlinear-tidy.patch
mm-merge-nopfn-into-fault.patch
mm-remove-legacy-cruft.patch
mm-fix-clear_page_dirty_for_io-vs-fault-race.patch
exec-fix-remove_arg_zero.patch
exec-fix-remove_arg_zero-add-comment.patch

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [patch] change futex_wait() to hrtimers
@ 2007-03-15  0:03 linux
  0 siblings, 0 replies; 23+ messages in thread
From: linux @ 2007-03-15  0:03 UTC (permalink / raw)
  To: linux-kernel, npiggin; +Cc: linux

> BTW. my futex man page says timeout's contents "describe the maximum duration
> of the wait". Surely that should be *minimum*? Michael cc'ed.

Er, the intent of the wording is to say "futex will wait until uaddr
no longer contains val, or the timeout expires, whichever happens first".


One option for selecting different clock resolutions is to use the
clockid_t from the POSIX clock_gettime() family.  That is, specify the
clock that a wait uses, and then have a separate mechanism for turning
a resolution requirement into a clockid_t.

(And there can be default clocks for interfaces that don't specify one
explicitly.)

Although clockid_t is pretty generic, it's biased toward an enumerated
list of clocks rather than a continuous resolution.  Fortunately,
that seems to match the implementation ideas.  The question is how
much the timeout gets rounded, and the choices are currently jiffies
or microseconds.

A related option may be whether rounding down is acceptable.  For some
applications (periodic polling for events), it's fine.  For others,
it's not.  Thus, while it's okay to specify such clocks explicitly,
it'd probably be a good idea to forbid selecting them as the default
for interfaces that don't specify a clock explicitly.

I had some code that suffered 1 ms buzz-loops on Solaris because poll(2)
would round the timeout interval down, but the loop calling it would
explicitly check whether the timeout had expired using gettimeofday()
and would keep re-invoking poll(pollfds, npollfds, 1) until the timeout
really did expire.

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2007-03-15  0:03 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-11  8:14 + futex-restartable-futex_wait.patch added to -mm tree akpm
     [not found] ` <20070312011259.3834A1801C4@magilla.sf.frob.com>
2007-03-12  9:10   ` [patch] change futex_wait() to hrtimers Ingo Molnar
2007-03-12  9:16     ` Nick Piggin
2007-03-12 11:02       ` Ingo Molnar
2007-03-12 11:13         ` Nick Piggin
2007-03-12 11:19           ` Ingo Molnar
2007-03-12 11:29             ` Nick Piggin
2007-03-12 11:38               ` Ingo Molnar
2007-03-12 11:52                 ` Nick Piggin
2007-03-12 12:21                   ` Ingo Molnar
2007-03-12 12:36                     ` Nick Piggin
2007-03-12 11:19         ` Thomas Gleixner
2007-03-12 11:27     ` Andi Kleen
2007-03-12 11:00       ` Thomas Gleixner
2007-03-12 10:58         ` Andi Kleen
2007-03-12 11:04           ` Ingo Molnar
2007-03-12 11:20             ` Andi Kleen
2007-03-12 11:28               ` Ingo Molnar
2007-03-12 14:12           ` Theodore Tso
2007-03-12 14:22             ` Andi Kleen
2007-03-12 14:31             ` Ingo Molnar
2007-03-12 14:32             ` Nick Piggin
  -- strict thread matches above, loose matches on Subject: below --
2007-03-15  0:03 linux

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.