summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/alpha/alpha/machdep.c16
-rw-r--r--sys/amd64/amd64/machdep.c11
-rw-r--r--sys/i386/i386/machdep.c11
-rw-r--r--sys/ia64/ia64/machdep.c23
-rw-r--r--sys/kern/kern_mutex.c27
-rw-r--r--sys/kern/subr_turnstile.c27
-rw-r--r--sys/pc98/i386/machdep.c11
-rw-r--r--sys/pc98/pc98/machdep.c11
-rw-r--r--sys/powerpc/aim/machdep.c26
-rw-r--r--sys/powerpc/powerpc/machdep.c26
-rw-r--r--sys/sparc64/sparc64/machdep.c13
-rw-r--r--sys/sys/mutex.h3
12 files changed, 74 insertions, 131 deletions
diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c
index 2b12d2d..e9e47ef 100644
--- a/sys/alpha/alpha/machdep.c
+++ b/sys/alpha/alpha/machdep.c
@@ -154,8 +154,6 @@ struct platform platform;
alpha_chipset_t chipset;
struct bootinfo_kernel bootinfo;
-struct mtx sched_lock;
-struct mtx Giant;
struct mtx icu_lock;
struct user *proc0uarea;
@@ -916,6 +914,7 @@ alpha_init(pfn, ptb, bim, bip, biv)
pcpu_init(pcpup, alpha_pal_whami(), sz);
alpha_pal_wrval((u_int64_t) pcpup);
PCPU_GET(next_asn) = 1; /* 0 used for proc0 pmap */
+ PCPU_SET(curthread, &thread0);
#ifdef SMP
thread0.td_md.md_kernnest = 1;
#endif
@@ -945,20 +944,9 @@ alpha_init(pfn, ptb, bim, bip, biv)
thread0.td_frame = (struct trapframe *)thread0.td_pcb - 1;
thread0.td_pcb->pcb_hw.apcb_ksp = (u_int64_t)thread0.td_frame;
- /* Setup curthread so that mutexes work */
- PCPU_SET(curthread, &thread0);
-
- LIST_INIT(&thread0.td_contested);
-
- /*
- * Initialise mutexes.
- */
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
+ mutex_init();
mtx_init(&clock_lock, "clk", MTX_SPIN | MTX_RECURSE);
mtx_init(&icu_lock, "icu", MTX_SPIN);
- mtx_lock(&Giant);
/*
* Look at arguments passed to us and compute boothowto.
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 485a69e..ffb2094 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -210,8 +210,6 @@ static struct trapframe proc0_tf;
static struct pcpu __pcpu;
#endif
-struct mtx sched_lock;
-struct mtx Giant;
struct mtx icu_lock;
static void
@@ -1693,12 +1691,8 @@ init386(first)
pcpu_init(pc, 0, sizeof(struct pcpu));
PCPU_SET(prvspace, pc);
-
- /* setup curproc so that mutexes work */
PCPU_SET(curthread, &thread0);
- LIST_INIT(&thread0.td_contested);
-
/*
* Initialize mutexes.
*
@@ -1707,12 +1701,9 @@ init386(first)
* must be able to get the icu lock, so it can't be
* under witness.
*/
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
+ mutex_init();
mtx_init(&clock_lock, "clk", MTX_SPIN | MTX_RECURSE);
mtx_init(&icu_lock, "icu", MTX_SPIN | MTX_NOWITNESS);
- mtx_lock(&Giant);
/* make ldt memory segments */
/*
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c
index 485a69e..ffb2094 100644
--- a/sys/i386/i386/machdep.c
+++ b/sys/i386/i386/machdep.c
@@ -210,8 +210,6 @@ static struct trapframe proc0_tf;
static struct pcpu __pcpu;
#endif
-struct mtx sched_lock;
-struct mtx Giant;
struct mtx icu_lock;
static void
@@ -1693,12 +1691,8 @@ init386(first)
pcpu_init(pc, 0, sizeof(struct pcpu));
PCPU_SET(prvspace, pc);
-
- /* setup curproc so that mutexes work */
PCPU_SET(curthread, &thread0);
- LIST_INIT(&thread0.td_contested);
-
/*
* Initialize mutexes.
*
@@ -1707,12 +1701,9 @@ init386(first)
* must be able to get the icu lock, so it can't be
* under witness.
*/
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
+ mutex_init();
mtx_init(&clock_lock, "clk", MTX_SPIN | MTX_RECURSE);
mtx_init(&icu_lock, "icu", MTX_SPIN | MTX_NOWITNESS);
- mtx_lock(&Giant);
/* make ldt memory segments */
/*
diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c
index 2fffbc5..d1b68e7 100644
--- a/sys/ia64/ia64/machdep.c
+++ b/sys/ia64/ia64/machdep.c
@@ -96,9 +96,6 @@ u_int64_t va_bootinfo;
struct bootinfo bootinfo;
int bootinfo_error; /* XXX temporary ad-hoc error mask to help debugging */
-struct mtx sched_lock;
-struct mtx Giant;
-
extern char kstack[];
struct user *proc0uarea;
vm_offset_t proc0kstack;
@@ -688,6 +685,10 @@ ia64_init(u_int64_t arg1, u_int64_t arg2)
pcpu_init(pcpup, 0, PAGE_SIZE);
pcpup->pc_current_pmap = kernel_pmap;
ia64_set_k4((u_int64_t) pcpup);
+ PCPU_SET(curthread, &thread0);
+
+ /* We pretend to own FP state so that ia64_fpstate_check() works */
+ PCPU_SET(fpcurthread, &thread0);
/*
* Initialize the rest of proc 0's PCB.
@@ -702,21 +703,7 @@ ia64_init(u_int64_t arg1, u_int64_t arg2)
thread0.td_pcb->pcb_sp = (u_int64_t)thread0.td_frame - 16;
thread0.td_pcb->pcb_bspstore = (u_int64_t)proc0kstack;
- /* Setup curproc so that mutexes work */
- PCPU_SET(curthread, &thread0);
-
- /* We pretend to own FP state so that ia64_fpstate_check() works */
- PCPU_SET(fpcurthread, &thread0);
-
- LIST_INIT(&thread0.td_contested);
-
- /*
- * Initialise mutexes.
- */
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
- mtx_lock(&Giant);
+ mutex_init();
/*
* Initialize the virtual memory system.
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index d547519..3207ee1 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -81,6 +81,12 @@ struct lock_class lock_class_mtx_spin = {
};
/*
+ * System-wide mutexes
+ */
+struct mtx sched_lock;
+struct mtx Giant;
+
+/*
* Prototypes for non-exported routines.
*/
static void propagate_priority(struct thread *);
@@ -863,6 +869,27 @@ mtx_destroy(struct mtx *m)
}
/*
+ * Intialize the mutex code and system mutexes. This is called from the MD
+ * startup code prior to mi_startup(). The per-CPU data space needs to be
+ * setup before this is called.
+ */
+void
+mutex_init(void)
+{
+
+ /* Setup thread0 so that mutexes work. */
+ LIST_INIT(&thread0.td_contested);
+
+ /*
+ * Initialize mutexes.
+ */
+ mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
+ mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
+ mtx_init(&proc0.p_mtx, "process lock", MTX_DEF | MTX_DUPOK);
+ mtx_lock(&Giant);
+}
+
+/*
* Encapsulated Giant mutex routines. These routines provide encapsulation
* control for the Giant mutex, allowing sysctls to be used to turn on and
* off Giant around certain subsystems. The default value for the sysctls
diff --git a/sys/kern/subr_turnstile.c b/sys/kern/subr_turnstile.c
index d547519..3207ee1 100644
--- a/sys/kern/subr_turnstile.c
+++ b/sys/kern/subr_turnstile.c
@@ -81,6 +81,12 @@ struct lock_class lock_class_mtx_spin = {
};
/*
+ * System-wide mutexes
+ */
+struct mtx sched_lock;
+struct mtx Giant;
+
+/*
* Prototypes for non-exported routines.
*/
static void propagate_priority(struct thread *);
@@ -863,6 +869,27 @@ mtx_destroy(struct mtx *m)
}
/*
+ * Intialize the mutex code and system mutexes. This is called from the MD
+ * startup code prior to mi_startup(). The per-CPU data space needs to be
+ * setup before this is called.
+ */
+void
+mutex_init(void)
+{
+
+ /* Setup thread0 so that mutexes work. */
+ LIST_INIT(&thread0.td_contested);
+
+ /*
+ * Initialize mutexes.
+ */
+ mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
+ mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
+ mtx_init(&proc0.p_mtx, "process lock", MTX_DEF | MTX_DUPOK);
+ mtx_lock(&Giant);
+}
+
+/*
* Encapsulated Giant mutex routines. These routines provide encapsulation
* control for the Giant mutex, allowing sysctls to be used to turn on and
* off Giant around certain subsystems. The default value for the sysctls
diff --git a/sys/pc98/i386/machdep.c b/sys/pc98/i386/machdep.c
index 8c904dc..9e63dcc 100644
--- a/sys/pc98/i386/machdep.c
+++ b/sys/pc98/i386/machdep.c
@@ -223,8 +223,6 @@ static struct trapframe proc0_tf;
static struct pcpu __pcpu;
#endif
-struct mtx sched_lock;
-struct mtx Giant;
struct mtx icu_lock;
static void
@@ -1757,12 +1755,8 @@ init386(first)
pcpu_init(pc, 0, sizeof(struct pcpu));
PCPU_SET(prvspace, pc);
-
- /* setup curproc so that mutexes work */
PCPU_SET(curthread, &thread0);
- LIST_INIT(&thread0.td_contested);
-
/*
* Initialize mutexes.
*
@@ -1771,12 +1765,9 @@ init386(first)
* must be able to get the icu lock, so it can't be
* under witness.
*/
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
+ mutex_init();
mtx_init(&clock_lock, "clk", MTX_SPIN | MTX_RECURSE);
mtx_init(&icu_lock, "icu", MTX_SPIN | MTX_NOWITNESS);
- mtx_lock(&Giant);
/* make ldt memory segments */
/*
diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c
index 8c904dc..9e63dcc 100644
--- a/sys/pc98/pc98/machdep.c
+++ b/sys/pc98/pc98/machdep.c
@@ -223,8 +223,6 @@ static struct trapframe proc0_tf;
static struct pcpu __pcpu;
#endif
-struct mtx sched_lock;
-struct mtx Giant;
struct mtx icu_lock;
static void
@@ -1757,12 +1755,8 @@ init386(first)
pcpu_init(pc, 0, sizeof(struct pcpu));
PCPU_SET(prvspace, pc);
-
- /* setup curproc so that mutexes work */
PCPU_SET(curthread, &thread0);
- LIST_INIT(&thread0.td_contested);
-
/*
* Initialize mutexes.
*
@@ -1771,12 +1765,9 @@ init386(first)
* must be able to get the icu lock, so it can't be
* under witness.
*/
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
+ mutex_init();
mtx_init(&clock_lock, "clk", MTX_SPIN | MTX_RECURSE);
mtx_init(&icu_lock, "icu", MTX_SPIN | MTX_NOWITNESS);
- mtx_lock(&Giant);
/* make ldt memory segments */
/*
diff --git a/sys/powerpc/aim/machdep.c b/sys/powerpc/aim/machdep.c
index e078d12..6007f15 100644
--- a/sys/powerpc/aim/machdep.c
+++ b/sys/powerpc/aim/machdep.c
@@ -114,9 +114,6 @@ static const char rcsid[] =
int physmem = 0;
int cold = 1;
-struct mtx sched_lock;
-struct mtx Giant;
-
char pcpu0[PAGE_SIZE];
char uarea0[UAREA_PAGES * PAGE_SIZE];
struct trapframe frame0;
@@ -373,7 +370,6 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, char *args)
proc0.p_uarea = (struct user *)uarea0;
proc0.p_stats = &proc0.p_uarea->u_stats;
thread0.td_frame = &frame0;
- LIST_INIT(&thread0.td_contested);
/*
* Set up per-cpu data.
@@ -387,13 +383,7 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, char *args)
__asm __volatile("mtsprg 0, %0" :: "r"(pc));
- /*
- * Initialize mutexes.
- */
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
- mtx_lock(&Giant);
+ mutex_init();
/*
* Initialise virtual memory.
@@ -514,24 +504,14 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, char *args)
init_param1();
init_param2(physmem);
- /* setup curproc so the mutexes work */
-
PCPU_SET(curthread, &thread0);
- LIST_INIT(&thread0.td_contested);
-
/* XXX: NetBSDism I _think_. Not sure yet. */
#if 0
curpm = PCPU_GET(curpcb)->pcb_pmreal = PCPU_GET(curpcb)->pcb_pm = kernel_pmap;
#endif
-
- /*
- * Initialise some mutexes.
- */
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF);
- mtx_lock(&Giant);
+
+ mutex_init();
/*
* Initialise console.
diff --git a/sys/powerpc/powerpc/machdep.c b/sys/powerpc/powerpc/machdep.c
index e078d12..6007f15 100644
--- a/sys/powerpc/powerpc/machdep.c
+++ b/sys/powerpc/powerpc/machdep.c
@@ -114,9 +114,6 @@ static const char rcsid[] =
int physmem = 0;
int cold = 1;
-struct mtx sched_lock;
-struct mtx Giant;
-
char pcpu0[PAGE_SIZE];
char uarea0[UAREA_PAGES * PAGE_SIZE];
struct trapframe frame0;
@@ -373,7 +370,6 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, char *args)
proc0.p_uarea = (struct user *)uarea0;
proc0.p_stats = &proc0.p_uarea->u_stats;
thread0.td_frame = &frame0;
- LIST_INIT(&thread0.td_contested);
/*
* Set up per-cpu data.
@@ -387,13 +383,7 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, char *args)
__asm __volatile("mtsprg 0, %0" :: "r"(pc));
- /*
- * Initialize mutexes.
- */
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
- mtx_lock(&Giant);
+ mutex_init();
/*
* Initialise virtual memory.
@@ -514,24 +504,14 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, char *args)
init_param1();
init_param2(physmem);
- /* setup curproc so the mutexes work */
-
PCPU_SET(curthread, &thread0);
- LIST_INIT(&thread0.td_contested);
-
/* XXX: NetBSDism I _think_. Not sure yet. */
#if 0
curpm = PCPU_GET(curpcb)->pcb_pmreal = PCPU_GET(curpcb)->pcb_pm = kernel_pmap;
#endif
-
- /*
- * Initialise some mutexes.
- */
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF);
- mtx_lock(&Giant);
+
+ mutex_init();
/*
* Initialise console.
diff --git a/sys/sparc64/sparc64/machdep.c b/sys/sparc64/sparc64/machdep.c
index 9f1615f..2042a8d 100644
--- a/sys/sparc64/sparc64/machdep.c
+++ b/sys/sparc64/sparc64/machdep.c
@@ -115,9 +115,6 @@ int cold = 1;
long dumplo;
int Maxmem;
-struct mtx Giant;
-struct mtx sched_lock;
-
char pcpu0[PCPU_PAGES * PAGE_SIZE];
char uarea0[UAREA_PAGES * PAGE_SIZE];
struct trapframe frame0;
@@ -294,7 +291,6 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
(thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
frame0.tf_tstate = TSTATE_IE | TSTATE_PEF;
thread0.td_frame = &frame0;
- LIST_INIT(&thread0.td_contested);
/*
* Prime our per-cpu data page for use. Note, we are using it for our
@@ -323,15 +319,8 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
pmap_kenter((vm_offset_t)msgbufp + off, msgbuf_phys + off);
msgbufinit(msgbufp, MSGBUF_SIZE);
- /*
- * Initialize mutexes.
- */
- mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE);
- mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE);
- mtx_init(&proc0.p_mtx, "process lock", MTX_DEF|MTX_DUPOK);
+ mutex_init();
intr_init2();
-
- mtx_lock(&Giant);
}
void
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index 038319d..fb60711 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -97,9 +97,10 @@
* [See below for descriptions]
*
*/
-void mtx_sysinit(void *arg);
void mtx_init(struct mtx *m, const char *description, int opts);
void mtx_destroy(struct mtx *m);
+void mtx_sysinit(void *arg);
+void mutex_init(void);
void _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line);
void _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line);
void _mtx_lock_spin(struct mtx *m, int opts, const char *file, int line);
OpenPOWER on IntegriCloud