From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Tejun Heo <htejun@gmail.com>
Cc: zwane@linuxpower.ca, viro@zeniv.linux.org.uk,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH linux-2.6 01/04] brsem: implement big reader semaphore
Date: Sun, 25 Sep 2005 18:03:45 +1000 [thread overview]
Message-ID: <433659E1.8070905@yahoo.com.au> (raw)
In-Reply-To: <43364F70.7010705@yahoo.com.au>
[-- Attachment #1: Type: text/plain, Size: 630 bytes --]
Nick Piggin wrote:
> What would be wrong with an array of NR_CPUS rwsems? The only
> tiny trick you would have to do AFAIKS is have up_read remember
> what rwsem down_read took, but that could be returned from
> down_read as a token.
Here's something to start with. Add initialisers / cacheline
alignment / percpu_alloc to taste.
For bonus points I guess you could change the implementation
to just a single waitqueue mechanism with NR_CPUs counters.
In fact, it probably needs quite a bit of work before it is
mainline-worthy, but as a proof of concept - do you see
anything wrong with it?
Nick
--
SUSE Labs, Novell Inc.
[-- Attachment #2: brsem.patch --]
[-- Type: text/plain, Size: 1987 bytes --]
Index: linux-2.6/include/linux/brsem.h
===================================================================
--- /dev/null
+++ linux-2.6/include/linux/brsem.h
@@ -0,0 +1,18 @@
+#ifndef __BRSEM_H
+#define __BRSEM_H
+
+#include <linux/rwsem.h>
+struct brsem {
+ struct rw_semaphore cpu_sem[NR_CPUS];
+};
+
+#define BRSEM_READ_TRYLOCK_FAILED -1
+typedef int brsem_read_t;
+
+brsem_read_t brsem_down_read(struct brsem *);
+brsem_read_t brsem_down_read_trylock(struct brsem *);
+void brsem_up_read(struct brsem *, brsem_read_t);
+void brsem_down_write(struct brsem *);
+void brsem_up_write(struct brsem *);
+
+#endif
Index: linux-2.6/lib/Makefile
===================================================================
--- linux-2.6.orig/lib/Makefile
+++ linux-2.6/lib/Makefile
@@ -5,7 +5,7 @@
lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
- sha1.o
+ sha1.o brsem.o
lib-y += kobject.o kref.o kobject_uevent.o klist.o
Index: linux-2.6/lib/brsem.c
===================================================================
--- /dev/null
+++ linux-2.6/lib/brsem.c
@@ -0,0 +1,38 @@
+#include <linux/brsem.h>
+#include <linux/rwsem.h>
+#include <linux/smp.h>
+
+brsem_read_t brsem_down_read(struct brsem *brsem)
+{
+ brsem_read_t ret = smp_processor_id();
+ down_read(&brsem->cpu_sem[ret]);
+ return ret;
+}
+
+brsem_read_t brsem_down_read_trylock(struct brsem *brsem)
+{
+ brsem_read_t ret = smp_processor_id();
+ if (!down_read_trylock(&brsem->cpu_sem[ret]))
+ return BRSEM_READ_TRYLOCK_FAILED;
+ return ret;
+}
+
+void brsem_up_read(struct brsem *brsem, brsem_read_t token)
+{
+ up_read(&brsem->cpu_sem[token]);
+}
+
+void brsem_down_write(struct brsem *brsem)
+{
+ int i;
+ for (i = 0; i < NR_CPUS; i++)
+ down_write(&brsem->cpu_sem[i]);
+}
+
+void brsem_up_write(struct brsem *brsem)
+{
+ int i;
+ for (i = 0; i < NR_CPUS; i++)
+ up_write(&brsem->cpu_sem[i]);
+}
+
next prev parent reply other threads:[~2005-09-25 8:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-25 6:43 [PATCH linux-2.6 00/04] brsem: [RFC] big reader semaphore Tejun Heo
2005-09-25 6:43 ` [PATCH linux-2.6 01/04] brsem: implement " Tejun Heo
2005-09-25 7:19 ` Nick Piggin
2005-09-25 8:03 ` Nick Piggin [this message]
2005-09-25 8:11 ` Tejun Heo
2005-09-25 8:27 ` Nick Piggin
2005-09-25 8:53 ` Tejun Heo
2005-09-25 9:24 ` Nick Piggin
2005-09-25 10:05 ` Tejun Heo
2005-09-25 11:22 ` Nick Piggin
2005-09-25 6:43 ` [PATCH linux-2.6 02/04] brsem: convert super_block->s_umount to brsem Tejun Heo
2005-09-25 6:43 ` [PATCH linux-2.6 03/04] brsem: fix ro-remount <-> open race condition Tejun Heo
2005-09-25 6:43 ` [PATCH linux-2.6 04/04] brsem: convert cpucontrol to brsem Tejun Heo
2005-09-25 7:39 ` Nick Piggin
2005-09-25 8:03 ` Tejun Heo
2005-09-25 23:46 ` Nathan Lynch
2005-09-26 1:11 ` Nick Piggin
2005-09-26 4:05 ` Tejun Heo
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=433659E1.8070905@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--cc=htejun@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zwane@linuxpower.ca \
/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