Re: semaphore: lockless fastpath using atomic_{inc,dec}_return

From: Arjan van de Ven
Date: Wed Jul 09 2008 - 10:16:45 EST


On Wed, 09 Jul 2008 14:13:29 +0100
Bruno Santos <bsantos@xxxxxxxx> wrote:

> So far the machine I'm testing this (Core2 Duo) it's been up to
> almost 24H.
>
> It seems the patch got screwed by the mailer, so I'm posting it again.
>
>
> From 343d08a5d172d103e49c77e5580a45f02fab2b5e Mon Sep 17 00:00:00
> 2001 From: Bruno Santos <bsantos@xxxxxxxx>
> Date: Tue, 8 Jul 2008 23:40:53 +0100
> Subject: [PATCH] semaphore lockless fastpath
>
>
> Signed-off-by: Bruno Santos <bsantos@xxxxxxxx>
> ---
> include/linux/semaphore.h | 4 +-
> kernel/semaphore.c | 131
> +++++++++++++++++++++++++--------------------
> 2 files changed, 75 insertions(+), 60 deletions(-)
>
> diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
> index 9cae64b..d7850f0 100644
> --- a/include/linux/semaphore.h
> +++ b/include/linux/semaphore.h
> @@ -14,15 +14,15 @@
>
> /* Please don't access any members of this structure directly */
> struct semaphore {
> + atomic_t count;
> spinlock_t lock;
> - unsigned int count;
> struct list_head wait_list;
> };
>



hi,

not to ruin the party but... how is this lockless? An atomic variable
is every bit a "lock" as a spinlock is... and very much equally
expensive as well for most cases ;-(
--
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/