summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_kse.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2003-11-11 22:07:29 +0000
committerjhb <jhb@FreeBSD.org>2003-11-11 22:07:29 +0000
commit6cc1f7e330af947861a2d58058a4736bd8e21df3 (patch)
tree36b8de06ad4037f5e371960980d0d088dfd98235 /sys/kern/kern_kse.c
parenta3bf20009f70eba5aa2a79bfd38c9363d624f530 (diff)
downloadFreeBSD-src-6cc1f7e330af947861a2d58058a4736bd8e21df3.zip
FreeBSD-src-6cc1f7e330af947861a2d58058a4736bd8e21df3.tar.gz
Add an implementation of turnstiles and change the sleep mutex code to use
turnstiles to implement blocking isntead of implementing a thread queue directly. These turnstiles are somewhat similar to those used in Solaris 7 as described in Solaris Internals but are also different. Turnstiles do not come out of a fixed-sized pool. Rather, each thread is assigned a turnstile when it is created that it frees when it is destroyed. When a thread blocks on a lock, it donates its turnstile to that lock to serve as queue of blocked threads. The queue associated with a given lock is found by a lookup in a simple hash table. The turnstile itself is protected by a lock associated with its entry in the hash table. This means that sched_lock is no longer needed to contest on a mutex. Instead, sched_lock is only used when manipulating run queues or thread priorities. Turnstiles also implement priority propagation inherently. Currently turnstiles only support mutexes. Eventually, however, turnstiles may grow two queue's to support a non-sleepable reader/writer lock implementation. For more details, see the comments in sys/turnstile.h and kern/subr_turnstile.c. The two primary advantages from the turnstile code include: 1) the size of struct mutex shrinks by four pointers as it no longer stores the thread queue linkages directly, and 2) less contention on sched_lock in SMP systems including the ability for multiple CPUs to contend on different locks simultaneously (not that this last detail is necessarily that much of a big win). Note that 1) means that this commit is a kernel ABI breaker, so don't mix old modules with a new kernel and vice versa. Tested on: i386 SMP, sparc64 SMP, alpha SMP
Diffstat (limited to 'sys/kern/kern_kse.c')
-rw-r--r--sys/kern/kern_kse.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sys/kern/kern_kse.c b/sys/kern/kern_kse.c
index 10831cf..3683de8 100644
--- a/sys/kern/kern_kse.c
+++ b/sys/kern/kern_kse.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <sys/tty.h>
+#include <sys/turnstile.h>
#include <sys/user.h>
#include <sys/jail.h>
#include <sys/kse.h>
@@ -190,6 +191,7 @@ thread_init(void *mem, int size)
vm_thread_new(td, 0);
mtx_unlock(&Giant);
cpu_thread_setup(td);
+ td->td_turnstile = turnstile_alloc();
td->td_sched = (struct td_sched *)&td[1];
}
@@ -202,6 +204,7 @@ thread_fini(void *mem, int size)
struct thread *td;
td = (struct thread *)mem;
+ turnstile_free(td->td_turnstile);
vm_thread_dispose(td);
}
OpenPOWER on IntegriCloud