- Move the MI mutexes sched_lock and Giant from being declared in the

various machdep.c's to being declared in kern_mutex.c.
- Add a new function mutex_init() used to perform early initialization
  needed for mutexes such as setting up thread0's contested lock list
  and initializing MI mutexes.  Change the various MD startup routines
  to call this function instead of duplicating all the code themselves.

Tested on:	alpha, i386
This commit is contained in:
John Baldwin 2002-04-02 22:19:16 +00:00
parent 43e73ba0c2
commit c53c013bae
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=93702
12 changed files with 74 additions and 131 deletions

View File

@ -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.

View File

@ -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 */
/*

View File

@ -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 */
/*

View File

@ -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.

View File

@ -80,6 +80,12 @@ struct lock_class lock_class_mtx_spin = {
LC_SPINLOCK | LC_RECURSABLE
};
/*
* System-wide mutexes
*/
struct mtx sched_lock;
struct mtx Giant;
/*
* Prototypes for non-exported routines.
*/
@ -862,6 +868,27 @@ mtx_destroy(struct mtx *m)
WITNESS_DESTROY(&m->mtx_object);
}
/*
* 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

View File

@ -80,6 +80,12 @@ struct lock_class lock_class_mtx_spin = {
LC_SPINLOCK | LC_RECURSABLE
};
/*
* System-wide mutexes
*/
struct mtx sched_lock;
struct mtx Giant;
/*
* Prototypes for non-exported routines.
*/
@ -862,6 +868,27 @@ mtx_destroy(struct mtx *m)
WITNESS_DESTROY(&m->mtx_object);
}
/*
* 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

View File

@ -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 */
/*

View File

@ -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 */
/*

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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);