Convert the allproc and proctree locks from lockmgr locks to sx locks.

This commit is contained in:
John Baldwin 2001-03-28 11:52:56 +00:00
parent 11f1917f8a
commit 1005a129e5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=74927
29 changed files with 172 additions and 164 deletions

View File

@ -154,6 +154,7 @@
#include <sys/msgbuf.h>
#include <sys/vmmeter.h>
#include <sys/mman.h>
#include <sys/sx.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@ -732,14 +733,14 @@ pmap_get_asn(pmap_t pmap)
printf("pmap_get_asn: generation rollover\n");
#endif
PCPU_GET(current_asngen) = 1;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_vmspace) {
tpmap = vmspace_pmap(p->p_vmspace);
tpmap->pm_asn[PCPU_GET(cpuid)].gen = 0;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
}
/*
@ -1564,14 +1565,14 @@ pmap_growkernel(vm_offset_t addr)
newlev1 = pmap_phys_to_pte(pa)
| PG_V | PG_ASM | PG_KRE | PG_KWE;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_vmspace) {
pmap = vmspace_pmap(p->p_vmspace);
*pmap_lev1pte(pmap, kernel_vm_end) = newlev1;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
*pte = newlev1;
pmap_invalidate_all(kernel_pmap);
}
@ -3065,7 +3066,8 @@ pmap_pid_dump(int pid)
struct proc *p;
int npte = 0;
int index;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_pid != pid)
continue;
@ -3088,7 +3090,7 @@ pmap_pid_dump(int pid)
index = 0;
printf("\n");
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
pte = pmap_pte_quick( pmap, va);
@ -3113,7 +3115,7 @@ pmap_pid_dump(int pid)
}
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
#endif

View File

@ -78,6 +78,7 @@
#include <sys/msgbuf.h>
#include <sys/vmmeter.h>
#include <sys/mman.h>
#include <sys/sx.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@ -3261,7 +3262,8 @@ pmap_pid_dump(int pid)
struct proc *p;
int npte = 0;
int index;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_pid != pid)
continue;
@ -3284,7 +3286,7 @@ pmap_pid_dump(int pid)
index = 0;
printf("\n");
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
pte = pmap_pte_quick( pmap, va);
@ -3309,7 +3311,7 @@ pmap_pid_dump(int pid)
}
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
#endif

View File

@ -770,7 +770,7 @@ linprocfs_readdir(ap)
* this is for the root of the procfs filesystem
*/
if (pfs->pfs_nd == root_dir) {
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
p = LIST_FIRST(&allproc);
i = (nd - pfs->pfs_nd) / sizeof(*nd);
@ -793,7 +793,7 @@ linprocfs_readdir(ap)
break;
copied++;
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
}
done:
uio->uio_offset += copied * delen;

View File

@ -1215,7 +1215,7 @@ svr4_sys_waitsys(p, uap)
loop:
nfound = 0;
PROCTREE_LOCK(PT_SHARED);
sx_slock(&proctree_lock);
LIST_FOREACH(q, &p->p_children, p_sibling) {
if (SCARG(uap, id) != WAIT_ANY &&
q->p_pid != SCARG(uap, id) &&
@ -1231,7 +1231,7 @@ svr4_sys_waitsys(p, uap)
((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(q);
PROCTREE_LOCK(PT_RELEASE);
sx_sunlock(&proctree_lock);
*retval = 0;
DPRINTF(("found %d\n", q->p_pid));
error = svr4_setinfo(q, q->p_xstat, SCARG(uap, info));
@ -1252,7 +1252,7 @@ svr4_sys_waitsys(p, uap)
* parent a SIGCHLD. The rest of the cleanup will be
* done when the old parent waits on the child.
*/
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
PROC_LOCK(q);
if (q->p_flag & P_TRACED) {
if (q->p_oppid != q->p_pptr->p_pid) {
@ -1266,13 +1266,13 @@ svr4_sys_waitsys(p, uap)
PROC_LOCK(t);
psignal(t, SIGCHLD);
PROC_UNLOCK(t);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
wakeup(t);
return 0;
}
}
PROC_UNLOCK(q);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
q->p_xstat = 0;
ruadd(&p->p_stats->p_cru, q->p_ru);
FREE(q->p_ru, M_ZOMBIE);
@ -1313,13 +1313,13 @@ svr4_sys_waitsys(p, uap)
*/
leavepgrp(q);
ALLPROC_LOCK(AP_EXCLUSIVE);
sx_xlock(&allproc_lock);
LIST_REMOVE(q, p_list); /* off zombproc */
ALLPROC_LOCK(AP_RELEASE);
sx_xunlock(&allproc_lock);
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
LIST_REMOVE(q, p_sibling);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
PROC_LOCK(q);
if (--q->p_procsig->ps_refcnt == 0) {

View File

@ -46,6 +46,7 @@
#include <sys/vnode.h>
#include <sys/ptrace.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <miscfs/procfs/procfs.h>
#include <vm/vm.h>
@ -108,7 +109,7 @@ procfs_control(curp, p, op)
struct proc *p;
int op;
{
int error;
int error = 0;
/*
* Authorization check: rely on normal debugging protection, except
@ -125,20 +126,18 @@ procfs_control(curp, p, op)
* by the calling process.
*/
if (op == PROCFS_CTL_ATTACH) {
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
PROC_LOCK(p);
/* check whether already being traced */
if (p->p_flag & P_TRACED) {
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
return (EBUSY);
error = EBUSY;
goto out;
}
/* can't trace yourself! */
if (p->p_pid == curp->p_pid) {
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
return (EINVAL);
error = EINVAL;
goto out;
}
/*
@ -157,8 +156,9 @@ procfs_control(curp, p, op)
proc_reparent(p, curp);
}
psignal(p, SIGSTOP);
out:
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
return (0);
}
@ -221,7 +221,7 @@ procfs_control(curp, p, op)
PROC_UNLOCK(p);
/* give process back to original parent */
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
if (p->p_oppid != p->p_pptr->p_pid) {
struct proc *pp;
@ -234,7 +234,7 @@ procfs_control(curp, p, op)
p->p_oppid = 0;
p->p_flag &= ~P_WAITED; /* XXX ? */
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
wakeup((caddr_t) curp); /* XXX for CTL_WAIT below ? */

View File

@ -51,6 +51,7 @@
#include <sys/fcntl.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <sys/vnode.h>
#include <sys/uio.h>
#include <sys/mount.h>
@ -858,7 +859,7 @@ procfs_readdir(ap)
int pcnt = 0;
struct proc *p;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
p = LIST_FIRST(&allproc);
for (; p && uio->uio_resid >= delen; i++, pcnt++) {
bzero((char *) dp, delen);
@ -916,7 +917,7 @@ procfs_readdir(ap)
}
#endif
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
break;
}

View File

@ -78,6 +78,7 @@
#include <sys/msgbuf.h>
#include <sys/vmmeter.h>
#include <sys/mman.h>
#include <sys/sx.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@ -3261,7 +3262,8 @@ pmap_pid_dump(int pid)
struct proc *p;
int npte = 0;
int index;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_pid != pid)
continue;
@ -3284,7 +3286,7 @@ pmap_pid_dump(int pid)
index = 0;
printf("\n");
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
pte = pmap_pte_quick( pmap, va);
@ -3309,7 +3311,7 @@ pmap_pid_dump(int pid)
}
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
#endif

View File

@ -81,14 +81,14 @@ ibcs2_modevent(module_t mod, int type, void *unused)
switch(type) {
case MOD_UNLOAD:
/* if this was an ELF module we'd use elf_brand_inuse()... */
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_sysent == &ibcs2_svr3_sysvec) {
rval = EBUSY;
break;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
default:
/* do not care */
}

View File

@ -101,6 +101,7 @@
#include <sys/mman.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/sx.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@ -2237,7 +2238,8 @@ pmap_pid_dump(int pid)
struct proc *p;
int npte = 0;
int index;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_pid != pid)
continue;
@ -2260,7 +2262,7 @@ pmap_pid_dump(int pid)
index = 0;
printf("\n");
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
pte = pmap_pte_quick( pmap, va);
@ -2285,7 +2287,7 @@ pmap_pid_dump(int pid)
}
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return npte;
}
#endif

View File

@ -50,6 +50,7 @@
#include <sys/systm.h>
#include <sys/signalvar.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/syscall.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
@ -59,7 +60,6 @@
#include <vm/vm_kern.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <sys/lock.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_extern.h>
@ -157,14 +157,14 @@ elf_brand_inuse(Elf_Brandinfo *entry)
struct proc *p;
int rval = FALSE;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_sysent == entry->sysvec) {
rval = TRUE;
break;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return (rval);
}

View File

@ -49,6 +49,7 @@
#include <sys/filedesc.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/sysctl.h>
@ -59,6 +60,7 @@
#include <sys/vnode.h>
#include <sys/sysent.h>
#include <sys/reboot.h>
#include <sys/sx.h>
#include <sys/sysproto.h>
#include <sys/vmmeter.h>
#include <sys/unistd.h>
@ -70,7 +72,6 @@
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <sys/lock.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <sys/user.h>
@ -393,12 +394,12 @@ proc0_post(void *dummy __unused)
* Now we can look at the time, having had a chance to verify the
* time from the file system. Pretend that proc0 started now.
*/
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
microtime(&p->p_stats->p_start);
p->p_runtime = 0;
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
microuptime(PCPU_PTR(switchtime));
PCPU_SET(switchticks, ticks);

View File

@ -56,6 +56,7 @@
#include <sys/vnode.h>
#include <sys/resourcevar.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <sys/ptrace.h>
#include <sys/acct.h> /* for acct_process() function prototype */
#include <sys/filedesc.h>
@ -279,13 +280,13 @@ exit1(p, rv)
* Remove proc from allproc queue and pidhash chain.
* Place onto zombproc. Unlink from parent's child list.
*/
ALLPROC_LOCK(AP_EXCLUSIVE);
sx_xlock(&allproc_lock);
LIST_REMOVE(p, p_list);
LIST_INSERT_HEAD(&zombproc, p, p_list);
LIST_REMOVE(p, p_hash);
ALLPROC_LOCK(AP_RELEASE);
sx_xunlock(&allproc_lock);
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
q = LIST_FIRST(&p->p_children);
if (q != NULL) /* only need this if any child is S_ZOMB */
wakeup((caddr_t) initproc);
@ -357,7 +358,7 @@ exit1(p, rv)
psignal(p->p_pptr, SIGCHLD);
PROC_UNLOCK(p->p_pptr);
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
/*
* Clear curproc after we've done all operations
@ -435,7 +436,7 @@ wait1(q, uap, compat)
return (EINVAL);
loop:
nfound = 0;
PROCTREE_LOCK(PT_SHARED);
sx_slock(&proctree_lock);
LIST_FOREACH(p, &q->p_children, p_sibling) {
if (uap->pid != WAIT_ANY &&
p->p_pid != uap->pid && p->p_pgid != -uap->pid)
@ -467,7 +468,7 @@ wait1(q, uap, compat)
mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_sunlock(&proctree_lock);
q->p_retval[0] = p->p_pid;
#ifdef COMPAT_43
@ -488,7 +489,7 @@ wait1(q, uap, compat)
* If we got the child via a ptrace 'attach',
* we need to give it back to the old parent.
*/
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
if (p->p_oppid) {
if ((t = pfind(p->p_oppid)) != NULL) {
PROC_LOCK(p);
@ -498,12 +499,12 @@ wait1(q, uap, compat)
PROC_LOCK(t);
psignal(t, SIGCHLD);
PROC_UNLOCK(t);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
wakeup((caddr_t)t);
return (0);
}
}
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
PROC_LOCK(p);
p->p_xstat = 0;
PROC_UNLOCK(p);
@ -546,13 +547,13 @@ wait1(q, uap, compat)
*/
leavepgrp(p);
ALLPROC_LOCK(AP_EXCLUSIVE);
sx_xlock(&allproc_lock);
LIST_REMOVE(p, p_list); /* off zombproc */
ALLPROC_LOCK(AP_RELEASE);
sx_xunlock(&allproc_lock);
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
LIST_REMOVE(p, p_sibling);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
PROC_LOCK(p);
if (--p->p_procsig->ps_refcnt == 0) {
@ -579,7 +580,7 @@ wait1(q, uap, compat)
mtx_unlock_spin(&sched_lock);
p->p_flag |= P_WAITED;
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_sunlock(&proctree_lock);
q->p_retval[0] = p->p_pid;
#ifdef COMPAT_43
if (compat) {
@ -598,7 +599,7 @@ wait1(q, uap, compat)
mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
}
PROCTREE_LOCK(PT_RELEASE);
sx_sunlock(&proctree_lock);
if (nfound == 0)
return (ECHILD);
if (uap->options & WNOHANG) {
@ -620,7 +621,7 @@ proc_reparent(child, parent)
register struct proc *parent;
{
PROCTREE_ASSERT(PT_EXCLUSIVE);
SX_ASSERT_XLOCKED(&proctree_lock);
PROC_LOCK_ASSERT(child, MA_OWNED);
if (child->p_pptr == parent)
return;

View File

@ -306,7 +306,7 @@ fork1(p1, flags, procp)
* If RFHIGHPID is set (used during system boot), do not allocate
* low-numbered pids.
*/
ALLPROC_LOCK(AP_EXCLUSIVE);
sx_xlock(&allproc_lock);
trypid = nextpid + 1;
if (flags & RFHIGHPID) {
if (trypid < 10) {
@ -376,7 +376,7 @@ fork1(p1, flags, procp)
p2->p_pid = trypid;
LIST_INSERT_HEAD(&allproc, p2, p_list);
LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
ALLPROC_LOCK(AP_RELEASE);
sx_xunlock(&allproc_lock);
/*
* Make a proc table entry for the new process.
@ -516,12 +516,12 @@ fork1(p1, flags, procp)
pptr = initproc;
else
pptr = p1;
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
PROC_LOCK(p2);
p2->p_pptr = pptr;
PROC_UNLOCK(p2);
LIST_INSERT_HEAD(&pptr->p_children, p2, p_sibling);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
PROC_LOCK(p2);
LIST_INIT(&p2->p_children);
LIST_INIT(&p2->p_contested);

View File

@ -28,11 +28,13 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/kthread.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/wait.h>
@ -118,11 +120,11 @@ void
kthread_exit(int ecode)
{
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
PROC_LOCK(curproc);
proc_reparent(curproc, initproc);
PROC_UNLOCK(curproc);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
exit1(curproc, W_EXITCODE(ecode, 0));
}

View File

@ -47,6 +47,7 @@
#include <sys/vnode.h>
#include <sys/ktrace.h>
#include <sys/malloc.h>
#include <sys/sx.h>
#include <sys/syslog.h>
#include <sys/jail.h>
@ -279,7 +280,7 @@ ktrace(curp, uap)
* Clear all uses of the tracefile
*/
if (ops == KTROP_CLEARFILE) {
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_tracep == vp) {
if (ktrcanset(curp, p)) {
@ -291,7 +292,7 @@ ktrace(curp, uap)
error = EPERM;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
goto done;
}
/*
@ -428,7 +429,7 @@ ktrsetchildren(curp, top, ops, facs, vp)
register int ret = 0;
p = top;
PROCTREE_LOCK(PT_SHARED);
sx_slock(&proctree_lock);
for (;;) {
ret |= ktrops(curp, p, ops, facs, vp);
/*
@ -440,7 +441,7 @@ ktrsetchildren(curp, top, ops, facs, vp)
p = LIST_FIRST(&p->p_children);
else for (;;) {
if (p == top) {
PROCTREE_LOCK(PT_RELEASE);
sx_sunlock(&proctree_lock);
return (ret);
}
if (LIST_NEXT(p, p_sibling)) {
@ -501,7 +502,7 @@ ktrwrite(vp, kth, uio)
*/
log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n",
error);
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_tracep == vp) {
p->p_tracep = NULL;
@ -509,7 +510,7 @@ ktrwrite(vp, kth, uio)
vrele(vp);
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
}
/*

View File

@ -43,6 +43,7 @@
#include <sys/filedesc.h>
#include <sys/tty.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <vm/vm.h>
#include <sys/lock.h>
#include <vm/pmap.h>
@ -73,8 +74,8 @@ struct pgrphashhead *pgrphashtbl;
u_long pgrphash;
struct proclist allproc;
struct proclist zombproc;
struct lock allproc_lock;
struct lock proctree_lock;
struct sx allproc_lock;
struct sx proctree_lock;
vm_zone_t proc_zone;
vm_zone_t ithread_zone;
@ -86,8 +87,8 @@ procinit()
{
int i, j;
lockinit(&allproc_lock, PZERO, "allproc", 0, 0);
lockinit(&proctree_lock, PZERO, "proctree", 0, 0);
sx_init(&allproc_lock, "allproc");
sx_init(&proctree_lock, "proctree");
LIST_INIT(&allproc);
LIST_INIT(&zombproc);
pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash);
@ -120,13 +121,13 @@ inferior(p)
{
int rval = 1;
PROCTREE_LOCK(PT_SHARED);
sx_slock(&proctree_lock);
for (; p != curproc; p = p->p_pptr)
if (p->p_pid == 0) {
rval = 0;
break;
}
PROCTREE_LOCK(PT_RELEASE);
sx_sunlock(&proctree_lock);
return (rval);
}
@ -139,11 +140,11 @@ pfind(pid)
{
register struct proc *p;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, PIDHASH(pid), p_hash)
if (p->p_pid == pid)
break;
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return (p);
}
@ -308,7 +309,7 @@ fixjobc(p, pgrp, entering)
* Check p's parent to see whether p qualifies its own process
* group; if so, adjust count for p's process group.
*/
PROCTREE_LOCK(PT_SHARED);
sx_slock(&proctree_lock);
if ((hispgrp = p->p_pptr->p_pgrp) != pgrp &&
hispgrp->pg_session == mysession) {
if (entering)
@ -331,7 +332,7 @@ fixjobc(p, pgrp, entering)
else if (--hispgrp->pg_jobc == 0)
orphanpg(hispgrp);
}
PROCTREE_LOCK(PT_RELEASE);
sx_sunlock(&proctree_lock);
}
/*
@ -520,11 +521,11 @@ zpfind(pid_t pid)
{
struct proc *p;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &zombproc, p_list)
if (p->p_pid == pid)
break;
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return (p);
}
@ -580,7 +581,7 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
if (error)
return (error);
}
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
for (doingzomb=0 ; doingzomb < 2 ; doingzomb++) {
if (!doingzomb)
p = LIST_FIRST(&allproc);
@ -637,12 +638,12 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
error = sysctl_out_proc(p, req, doingzomb);
if (error) {
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return (error);
}
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return (0);
}

View File

@ -52,6 +52,7 @@
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/sx.h>
#include <sys/time.h>
#include <vm/vm.h>
@ -120,13 +121,13 @@ getpriority(curp, uap)
case PRIO_USER:
if (uap->who == 0)
uap->who = curp->p_ucred->cr_uid;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list)
if (!p_can(curp, p, P_CAN_SEE, NULL) &&
p->p_ucred->cr_uid == uap->who &&
p->p_nice < low)
low = p->p_nice;
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
break;
default:
@ -188,14 +189,14 @@ setpriority(curp, uap)
case PRIO_USER:
if (uap->who == 0)
uap->who = curp->p_ucred->cr_uid;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list)
if (p->p_ucred->cr_uid == uap->who &&
!p_can(curp, p, P_CAN_SEE, NULL)) {
error = donice(curp, p, uap->prio);
found++;
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
break;
default:

View File

@ -62,8 +62,9 @@
#include <sys/ktr.h>
#include <sys/ktrace.h>
#include <sys/resourcevar.h>
#include <sys/syslog.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/syslog.h>
#include <sys/sysent.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
@ -897,7 +898,7 @@ killpg1(cp, sig, pgid, all)
/*
* broadcast
*/
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
PROC_LOCK(p);
if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || p == cp) {
@ -918,7 +919,7 @@ killpg1(cp, sig, pgid, all)
PROC_UNLOCK(p);
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
} else {
if (pgid == 0)
/*

View File

@ -43,18 +43,19 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/condvar.h>
#include <sys/ipl.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/condvar.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/signalvar.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/vmmeter.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/vmmeter.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
#ifdef KTRACE
@ -241,7 +242,7 @@ schedcpu(arg)
register int realstathz, s;
realstathz = stathz ? stathz : hz;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
/*
* Increment time in/out of memory and sleep time
@ -302,7 +303,7 @@ schedcpu(arg)
mtx_unlock_spin(&sched_lock);
splx(s);
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
vmmeter();
wakeup((caddr_t)&lbolt);
callout_reset(&schedcpu_callout, hz, schedcpu, NULL);

View File

@ -37,6 +37,7 @@
#include <sys/proc.h>
#include <sys/vnode.h>
#include <sys/ptrace.h>
#include <sys/sx.h>
#include <machine/reg.h>
#include <vm/vm.h>
@ -320,24 +321,24 @@ ptrace(curp, uap)
switch (uap->req) {
case PT_TRACE_ME:
/* set my trace flag and "owner" so it can read/write me */
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
PROC_LOCK(p);
p->p_flag |= P_TRACED;
p->p_oppid = p->p_pptr->p_pid;
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
return 0;
case PT_ATTACH:
/* security check done above */
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
PROC_LOCK(p);
p->p_flag |= P_TRACED;
p->p_oppid = p->p_pptr->p_pid;
if (p->p_pptr != curp)
proc_reparent(p, curp);
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
uap->data = SIGSTOP;
goto sendsig; /* in PT_CONTINUE below */
@ -368,7 +369,7 @@ ptrace(curp, uap)
if (uap->req == PT_DETACH) {
/* reset process parent */
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
if (p->p_oppid != p->p_pptr->p_pid) {
struct proc *pp;
@ -381,7 +382,7 @@ ptrace(curp, uap)
p->p_oppid = 0;
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
/* should we send SIGCHLD? */

View File

@ -59,6 +59,7 @@
#include <sys/file.h>
#include <sys/linker.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/vnode.h>
#include <sys/proc.h>
@ -415,7 +416,7 @@ checkdirs(olddp, newdp)
if (olddp->v_usecount == 1)
return;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
fdp = p->p_fd;
if (fdp == NULL)
@ -431,7 +432,7 @@ checkdirs(olddp, newdp)
fdp->fd_rdir = newdp;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
if (rootvnode == olddp) {
vrele(rootvnode);
VREF(newdp);

View File

@ -59,6 +59,7 @@
#include <sys/file.h>
#include <sys/linker.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/vnode.h>
#include <sys/proc.h>
@ -415,7 +416,7 @@ checkdirs(olddp, newdp)
if (olddp->v_usecount == 1)
return;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
fdp = p->p_fd;
if (fdp == NULL)
@ -431,7 +432,7 @@ checkdirs(olddp, newdp)
fdp->fd_rdir = newdp;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
if (rootvnode == olddp) {
vrele(rootvnode);
VREF(newdp);

View File

@ -46,6 +46,7 @@
#include <sys/vnode.h>
#include <sys/ptrace.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <miscfs/procfs/procfs.h>
#include <vm/vm.h>
@ -108,7 +109,7 @@ procfs_control(curp, p, op)
struct proc *p;
int op;
{
int error;
int error = 0;
/*
* Authorization check: rely on normal debugging protection, except
@ -125,20 +126,18 @@ procfs_control(curp, p, op)
* by the calling process.
*/
if (op == PROCFS_CTL_ATTACH) {
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
PROC_LOCK(p);
/* check whether already being traced */
if (p->p_flag & P_TRACED) {
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
return (EBUSY);
error = EBUSY;
goto out;
}
/* can't trace yourself! */
if (p->p_pid == curp->p_pid) {
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
return (EINVAL);
error = EINVAL;
goto out;
}
/*
@ -157,8 +156,9 @@ procfs_control(curp, p, op)
proc_reparent(p, curp);
}
psignal(p, SIGSTOP);
out:
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
return (0);
}
@ -221,7 +221,7 @@ procfs_control(curp, p, op)
PROC_UNLOCK(p);
/* give process back to original parent */
PROCTREE_LOCK(PT_EXCLUSIVE);
sx_xlock(&proctree_lock);
if (p->p_oppid != p->p_pptr->p_pid) {
struct proc *pp;
@ -234,7 +234,7 @@ procfs_control(curp, p, op)
p->p_oppid = 0;
p->p_flag &= ~P_WAITED; /* XXX ? */
PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
sx_xunlock(&proctree_lock);
wakeup((caddr_t) curp); /* XXX for CTL_WAIT below ? */

View File

@ -51,6 +51,7 @@
#include <sys/fcntl.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
#include <sys/vnode.h>
#include <sys/uio.h>
#include <sys/mount.h>
@ -858,7 +859,7 @@ procfs_readdir(ap)
int pcnt = 0;
struct proc *p;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
p = LIST_FIRST(&allproc);
for (; p && uio->uio_resid >= delen; i++, pcnt++) {
bzero((char *) dp, delen);
@ -916,7 +917,7 @@ procfs_readdir(ap)
}
#endif
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
break;
}

View File

@ -448,25 +448,6 @@ sigonstack(size_t sp)
mtx_unlock_flags(&(p)->p_mtx, MTX_NOSWITCH)
#define PROC_LOCK_ASSERT(p, type) mtx_assert(&(p)->p_mtx, (type))
/* Lock and unlock the proc lists. */
#define ALLPROC_LOCK(how) \
lockmgr(&allproc_lock, (how), NULL, CURPROC)
#define AP_SHARED LK_SHARED
#define AP_EXCLUSIVE LK_EXCLUSIVE
#define AP_RELEASE LK_RELEASE
/* Lock and unlock the proc child and sibling lists. */
#define PROCTREE_LOCK(how) \
lockmgr(&proctree_lock, (how), NULL, CURPROC)
#define PROCTREE_ASSERT(what) \
LOCKMGR_ASSERT(&proctree_lock, (what), CURPROC)
#define PT_SHARED LK_SHARED
#define PT_EXCLUSIVE LK_EXCLUSIVE
#define PT_RELEASE LK_RELEASE
/* Hold process U-area in memory, normally for ptrace/procfs work. */
#define PHOLD(p) do { \
PROC_LOCK(p); \
@ -497,8 +478,8 @@ extern u_long pidhash;
extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
extern u_long pgrphash;
extern struct lock allproc_lock;
extern struct lock proctree_lock;
extern struct sx allproc_lock;
extern struct sx proctree_lock;
extern struct proc proc0; /* Process slot for swapper. */
extern int hogticks; /* Limit on kernel cpu hogs. */
extern int nprocs, maxproc; /* Current and max number of procs. */

View File

@ -71,6 +71,7 @@
#include <sys/resourcevar.h>
#include <sys/shm.h>
#include <sys/vmmeter.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/kernel.h>
@ -364,7 +365,7 @@ scheduler(dummy)
pp = NULL;
ppri = INT_MIN;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
mtx_lock_spin(&sched_lock);
if (p->p_stat == SRUN &&
@ -387,7 +388,7 @@ scheduler(dummy)
}
mtx_unlock_spin(&sched_lock);
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
/*
* Nothing to do, back to sleep.
@ -448,7 +449,7 @@ int action;
outp = outp2 = NULL;
outpri = outpri2 = INT_MIN;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
retry:
LIST_FOREACH(p, &allproc, p_list) {
struct vmspace *vm;
@ -535,7 +536,7 @@ int action;
mtx_unlock_spin(&sched_lock);
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
/*
* If we swapped something out, and another process needed memory,
* then wakeup the sched process.

View File

@ -39,6 +39,7 @@
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/resource.h>
#include <sys/sx.h>
#include <sys/vmmeter.h>
#include <vm/vm.h>
@ -78,7 +79,7 @@ loadav(struct loadavg *avg)
register int i, nrun;
register struct proc *p;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
for (nrun = 0, p = LIST_FIRST(&allproc); p != 0; p = LIST_NEXT(p, p_list)) {
switch (p->p_stat) {
case SSLEEP:
@ -94,7 +95,7 @@ loadav(struct loadavg *avg)
nrun++;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
for (i = 0; i < 3; i++)
avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
@ -150,7 +151,7 @@ vmtotal(SYSCTL_HANDLER_ARGS)
/*
* Calculate process statistics.
*/
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if (p->p_flag & P_SYSTEM)
continue;
@ -208,7 +209,7 @@ vmtotal(SYSCTL_HANDLER_ARGS)
if (paging)
totalp->t_pw++;
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
/*
* Calculate object memory usage statistics.
*/

View File

@ -76,6 +76,7 @@
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/sx.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@ -1614,16 +1615,17 @@ vm_object_in_map( object)
vm_object_t object;
{
struct proc *p;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
if( !p->p_vmspace /* || (p->p_flag & (P_SYSTEM|P_WEXIT)) */)
continue;
if( _vm_object_in_map(&p->p_vmspace->vm_map, object, 0)) {
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
return 1;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
if( _vm_object_in_map( kernel_map, object, 0))
return 1;
if( _vm_object_in_map( kmem_map, object, 0))

View File

@ -83,6 +83,7 @@
#include <sys/signalvar.h>
#include <sys/vnode.h>
#include <sys/vmmeter.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
@ -1123,7 +1124,7 @@ vm_pageout_scan(int pass)
if ((vm_swap_size < 64 || swap_pager_full) && vm_page_count_min()) {
bigproc = NULL;
bigsize = 0;
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
/*
* if this is a system process, skip it
@ -1159,7 +1160,7 @@ vm_pageout_scan(int pass)
bigsize = size;
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
if (bigproc != NULL) {
killproc(bigproc, "out of swap space");
mtx_lock_spin(&sched_lock);
@ -1462,7 +1463,7 @@ vm_daemon()
* process is swapped out -- deactivate pages
*/
ALLPROC_LOCK(AP_SHARED);
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
vm_pindex_t limit, size;
@ -1504,7 +1505,7 @@ vm_daemon()
&p->p_vmspace->vm_map, limit);
}
}
ALLPROC_LOCK(AP_RELEASE);
sx_sunlock(&allproc_lock);
}
}
#endif