aboutsummaryrefslogtreecommitdiff
path: root/sys/sys
diff options
context:
space:
mode:
authorStephan Uphoff <ups@FreeBSD.org>2007-11-08 14:47:55 +0000
committerStephan Uphoff <ups@FreeBSD.org>2007-11-08 14:47:55 +0000
commitf53d15fe1b8a7a7df972f253b38c698f6ca45b71 (patch)
treee657852bc96f8f77553f7abb0596889a6b8d5e00 /sys/sys
parent0559b904bc69c95a21b7b5a286242091064aa485 (diff)
downloadsrc-f53d15fe1b8a7a7df972f253b38c698f6ca45b71.tar.gz
src-f53d15fe1b8a7a7df972f253b38c698f6ca45b71.zip
Initial checkin for rmlock (read mostly lock) a multi reader single writer
lock optimized for almost exclusive reader access. (see also rmlock.9) TODO: Convert to per cpu variables linkerset as soon as it is available. Optimize UP (single processor) case.
Notes
Notes: svn path=/head/; revision=173444
Diffstat (limited to 'sys/sys')
-rw-r--r--sys/sys/_rmlock.h62
-rw-r--r--sys/sys/lock.h1
-rw-r--r--sys/sys/pcpu.h22
-rw-r--r--sys/sys/rmlock.h109
-rw-r--r--sys/sys/smp.h1
5 files changed, 195 insertions, 0 deletions
diff --git a/sys/sys/_rmlock.h b/sys/sys/_rmlock.h
new file mode 100644
index 000000000000..e5c68d54732d
--- /dev/null
+++ b/sys/sys/_rmlock.h
@@ -0,0 +1,62 @@
+/*-
+ * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS__RMLOCK_H_
+#define _SYS__RMLOCK_H_
+
+/*
+ * XXXUPS remove as soon as we have per cpu variable
+ * linker sets and can define rm_queue in _rm_lock.h
+*/
+#include <sys/pcpu.h>
+/*
+ * Mostly reader/occasional writer lock.
+ */
+
+LIST_HEAD(rmpriolist,rm_priotracker);
+
+struct rmlock {
+ struct lock_object lock_object;
+ volatile int rm_noreadtoken;
+ LIST_HEAD(,rm_priotracker) rm_activeReaders;
+ struct mtx rm_lock;
+
+};
+
+struct rm_priotracker {
+ struct rm_queue rmp_cpuQueue; /* Must be first */
+ struct rmlock *rmp_rmlock;
+ struct thread *rmp_thread;
+ int rmp_flags;
+ LIST_ENTRY(rm_priotracker) rmp_qentry;
+};
+
+#endif /* !_SYS__RMLOCK_H_ */
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index 6d35ce58be32..2a9c4aa7ddd2 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -222,6 +222,7 @@ extern struct lock_class lock_class_mtx_sleep;
extern struct lock_class lock_class_mtx_spin;
extern struct lock_class lock_class_sx;
extern struct lock_class lock_class_rw;
+extern struct lock_class lock_class_rm;
extern struct lock_class lock_class_lockmgr;
extern struct lock_class *lock_classes[];
diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h
index b2fd6281a6fe..8757fe63968b 100644
--- a/sys/sys/pcpu.h
+++ b/sys/sys/pcpu.h
@@ -48,6 +48,15 @@
struct pcb;
struct thread;
+/*
+ * XXXUPS remove as soon as we have per cpu variable
+ * linker sets and can define rm_queue in _rm_lock.h
+*/
+struct rm_queue {
+ struct rm_queue* volatile rmq_next;
+ struct rm_queue* volatile rmq_prev;
+};
+
/*
* This structure maps out the global data that needs to be kept on a
* per-cpu basis. The members are accessed via the PCPU_GET/SET/PTR
@@ -74,6 +83,15 @@ struct pcpu {
PCPU_MD_FIELDS;
struct vmmeter pc_cnt; /* VM stats counters */
struct device *pc_device;
+
+ /*
+ * Stuff for read mostly lock
+ *
+ * XXXUPS remove as soon as we have per cpu variable
+ * linker sets.
+ */
+ struct rm_queue pc_rm_queue;
+
};
SLIST_HEAD(cpuhead, pcpu);
@@ -92,6 +110,10 @@ extern struct cpuhead cpuhead;
* db_show_mdpcpu() is responsible for handling machine dependent
* fields for the DDB 'show pcpu' command.
*/
+
+extern struct pcpu *cpuid_to_pcpu[MAXCPU];
+
+
void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size);
void db_show_mdpcpu(struct pcpu *pcpu);
diff --git a/sys/sys/rmlock.h b/sys/sys/rmlock.h
new file mode 100644
index 000000000000..04ccb3820e6b
--- /dev/null
+++ b/sys/sys/rmlock.h
@@ -0,0 +1,109 @@
+/*-
+ * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS_RMLOCK_H_
+#define _SYS_RMLOCK_H_
+
+#include <sys/mutex.h>
+
+#include <sys/_lock.h>
+#include <sys/_rmlock.h>
+
+#ifdef _KERNEL
+
+
+void rm_init(struct rmlock *rm, const char *name, int opts);
+void rm_destroy(struct rmlock *rm);
+void rm_sysinit(void *arg);
+
+
+void _rm_wlock_debug(struct rmlock *rm, const char *file, int line);
+void _rm_wunlock_debug(struct rmlock *rm, const char *file, int line);
+void _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
+ const char *file, int line);
+void _rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
+ const char *file, int line);
+
+
+void _rm_wlock(struct rmlock *rm);
+void _rm_wunlock(struct rmlock *rm);
+void _rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker);
+void _rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker);
+
+/*
+ * Public interface for lock operations.
+ *
+ */
+
+#ifndef LOCK_DEBUG
+#error LOCK_DEBUG not defined, include <sys/lock.h> before <sys/rmlock.h>
+#endif
+
+#if LOCK_DEBUG > 0
+
+#define rm_wlock(rm) _rm_wlock_debug((rm), LOCK_FILE, LOCK_LINE)
+#define rm_wunlock(rm) _rm_wunlock_debug((rm), LOCK_FILE, LOCK_LINE)
+#define rm_rlock(rm,tracker) \
+ _rm_rlock_debug((rm),(tracker), LOCK_FILE, LOCK_LINE )
+#define rm_runlock(rm,tracker) \
+ _rm_runlock_debug((rm), (tracker), LOCK_FILE, LOCK_LINE )
+
+#else
+
+#define rm_wlock(rm) _rm_wlock((rm))
+#define rm_wunlock(rm) _rm_wunlock((rm))
+#define rm_rlock(rm,tracker) _rm_rlock((rm),(tracker))
+#define rm_runlock(rm,tracker) _rm_runlock((rm), (tracker))
+
+#endif
+
+#define rm_initialized(rm) lock_initalized(&(rm)->lock_object)
+
+struct rm_args {
+ struct rmlock *ra_rm;
+ const char *ra_desc;
+ int ra_opts;
+};
+
+#define RM_SYSINIT(name, rm, desc, opts) \
+ static struct rm_args name##_args = { \
+ (rm), \
+ (desc), \
+ (opts), \
+ }; \
+ SYSINIT(name##_rm_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
+ rm_sysinit, &name##_args); \
+ SYSUNINIT(name##_rm_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
+ rm_destroy, (rm))
+
+
+#endif /* _KERNEL */
+#endif /* !_SYS_RMLOCK_H_ */
diff --git a/sys/sys/smp.h b/sys/sys/smp.h
index f2b2f523213f..7c79bb9eb2e0 100644
--- a/sys/sys/smp.h
+++ b/sys/sys/smp.h
@@ -100,6 +100,7 @@ void forward_roundrobin(void);
int restart_cpus(cpumask_t);
int stop_cpus(cpumask_t);
void smp_rendezvous_action(void);
+void smp_no_rendevous_barrier(void *);
extern struct mtx smp_ipi_mtx;
#endif /* SMP */