Re: [RFC] Userspace RCU: (ab)using futexes to save cpu cycles andenergy

From: Chris Friesen
Date: Wed Sep 23 2009 - 14:06:01 EST


On 09/23/2009 11:48 AM, Mathieu Desnoyers wrote:

> Here are the primitives I've created. I'd like to have feedback on my
> futex use, just to make sure I did not do any incorrect assumptions.

> /*
> * Wake-up any waiting defer thread. Called from many concurrent threads.
> */
> static void wake_up_defer(void)
> {
> if (unlikely(atomic_read(&defer_thread_futex) == -1))
> atomic_set(&defer_thread_futex, 0);
> futex(&defer_thread_futex, FUTEX_WAKE,
> 0, NULL, NULL, 0);
> }

Is it a problem if multiple threads all hit the defer_thread_futex==-1
case simultaneously? If so, maybe this should use an atomic
test-and-set operation so that only one thread actually calls futex().

> /*
> * Defer thread waiting. Single thread.
> */
> static void wait_defer(void)
> {
> atomic_dec(&defer_thread_futex);
> if (atomic_read(&defer_thread_futex) == -1)
> futex(&defer_thread_futex, FUTEX_WAIT, -1,
> NULL, NULL, 0);
> }

Is it a problem if the value of defer_thread_futex changes to zero after
the dec but before the test?

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/