diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/uts/common/disp/priocntl.c | 39 | ||||
-rw-r--r-- | usr/src/uts/common/os/pool.c | 17 | ||||
-rw-r--r-- | usr/src/uts/common/os/procset.c | 76 |
3 files changed, 85 insertions, 47 deletions
diff --git a/usr/src/uts/common/disp/priocntl.c b/usr/src/uts/common/disp/priocntl.c index ae863472b0..4ba3c77869 100644 --- a/usr/src/uts/common/disp/priocntl.c +++ b/usr/src/uts/common/disp/priocntl.c @@ -539,11 +539,16 @@ priocntl_common(int pc_version, procset_t *psp, int cmd, caddr_t arg, * setting them, we want to make sure init is not * excluded if it is in the set. */ - if (initpp != NULL && - procinset(initpp, &procset) && - (retthreadp != NULL) && - ttoproc(retthreadp) != initpp) - (void) proccmp(initpp, &pcmpargs); + if (initpp != NULL && retthreadp != NULL && + ttoproc(retthreadp) != initpp) { + mutex_enter(&initpp->p_lock); + if (procinset(initpp, &procset)) { + mutex_exit(&initpp->p_lock); + (void) proccmp(initpp, &pcmpargs); + } else { + mutex_exit(&initpp->p_lock); + } + } /* * If dotoprocs returned success it found at least @@ -1039,9 +1044,15 @@ donice(procset_t *procset, pcnice_t *pcnice) proc_t *initpp; mutex_enter(&pidlock); - initpp = prfind(P_INITPID); - if (initpp != NULL && procinset(initpp, procset)) - err = setprocnice(initpp, pcnice); + if ((initpp = prfind(P_INITPID)) != NULL) { + mutex_enter(&initpp->p_lock); + if (procinset(initpp, procset)) { + mutex_exit(&initpp->p_lock); + err = setprocnice(initpp, pcnice); + } else { + mutex_exit(&initpp->p_lock); + } + } mutex_exit(&pidlock); } @@ -1206,9 +1217,15 @@ doprio(procset_t *procset, pcprio_t *pcprio) proc_t *initpp; mutex_enter(&pidlock); - initpp = prfind(P_INITPID); - if (initpp != NULL && procinset(initpp, procset)) - err = setprocprio(initpp, pcprio); + if ((initpp = prfind(P_INITPID)) != NULL) { + mutex_enter(&initpp->p_lock); + if (procinset(initpp, procset)) { + mutex_exit(&initpp->p_lock); + err = setprocprio(initpp, pcprio); + } else { + mutex_exit(&initpp->p_lock); + } + } mutex_exit(&pidlock); } diff --git a/usr/src/uts/common/os/pool.c b/usr/src/uts/common/os/pool.c index 80b05f90e0..d0d89b1023 100644 --- a/usr/src/uts/common/os/pool.c +++ b/usr/src/uts/common/os/pool.c @@ -1534,15 +1534,22 @@ skip: #ifdef DEBUG /* - * All processes in the array should have PBWAIT set, and none should - * be in the critical section. Even though p_poolflag is protected by - * the p_lock, these assertions should be stable across the dropping of - * p_lock. + * All processes in the array should have PBWAIT set, and none + * should be in the critical section. Thus, although p_poolflag + * and p_poolcnt are protected by p_lock, their ASSERTions below + * should be stable without it. procinset(), however, ASSERTs that + * the p_lock is held upon entry. */ for (pp = procs; (p = *pp) != NULL; pp++) { + int in_set; + + mutex_enter(&p->p_lock); + in_set = procinset(p, &set); + mutex_exit(&p->p_lock); + + ASSERT(in_set); ASSERT(p->p_poolflag & PBWAIT); ASSERT(p->p_poolcnt == 0); - ASSERT(procinset(p, &set)); } #endif diff --git a/usr/src/uts/common/os/procset.c b/usr/src/uts/common/os/procset.c index 860e012933..117fe1f906 100644 --- a/usr/src/uts/common/os/procset.c +++ b/usr/src/uts/common/os/procset.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -168,10 +168,20 @@ dotoprocs(procset_t *psp, int (*funcp)(), char *arg) */ if (!HASZONEACCESS(curproc, prp->p_zone->zone_id)) continue; - if (prp->p_stat == SIDL || prp->p_stat == SZOMB || - prp->p_tlist == NULL || prp->p_flag & SSYS) + + /* + * Ignore this process if it's coming or going, + * if it's a system process or if it's not in + * the given procset_t. + */ + if (prp->p_stat == SIDL || prp->p_stat == SZOMB) continue; - if (procinset(prp, psp)) { + + mutex_enter(&prp->p_lock); + if (prp->p_flag & SSYS || procinset(prp, psp) == 0) { + mutex_exit(&prp->p_lock); + } else { + mutex_exit(&prp->p_lock); nfound++; lastprp = prp; if (prp != proc_init) { @@ -258,10 +268,12 @@ checkprocset(procset_t *psp) } /* - * procinset returns 1 if the process pointed to - * by pp is in the process set specified by psp, otherwise 0 is returned. - * The caller should check that the process is not exiting and is not - * in the SYS scheduling class. + * procinset returns 1 if the process pointed to by pp is in the process + * set specified by psp, otherwise 0 is returned. A process that is + * exiting, by which we mean that its p_tlist is NULL, cannot belong + * to any set; pp's p_lock must be held across the call to this function. + * The caller should ensure that the process does not belong to the SYS + * scheduling class. * * This function expects to be called with a valid procset_t. * The set should be checked using checkprocset() before calling @@ -276,6 +288,11 @@ procinset(proc_t *pp, procset_t *psp) int lwprinproc = 0; kthread_t *tp = proctot(pp); + ASSERT(MUTEX_HELD(&pp->p_lock)); + + if (tp == NULL) + return (0); + switch (psp->p_lidtype) { case P_LWPID: @@ -721,9 +738,9 @@ lwpinset(proc_t *pp, procset_t *psp, kthread_t *tp, int *done) case POP_XOR: if (((loperand || lwplinset) && - !(lwprinset || roperand)) || + !(lwprinset || roperand)) || ((roperand || lwprinset) && - !(lwplinset || loperand))) + !(lwplinset || loperand))) return (1); else return (0); @@ -748,22 +765,22 @@ boolean_t cur_inset_only(procset_t *psp) { if (((psp->p_lidtype == P_PID && - (psp->p_lid == P_MYID || - psp->p_lid == ttoproc(curthread)->p_pid)) || - ((psp->p_lidtype == P_LWPID) && - (psp->p_lid == P_MYID || - psp->p_lid == curthread->t_tid))) && - psp->p_op == POP_AND && psp->p_ridtype == P_ALL) - return (B_TRUE); + (psp->p_lid == P_MYID || + psp->p_lid == ttoproc(curthread)->p_pid)) || + ((psp->p_lidtype == P_LWPID) && + (psp->p_lid == P_MYID || + psp->p_lid == curthread->t_tid))) && + psp->p_op == POP_AND && psp->p_ridtype == P_ALL) + return (B_TRUE); if (((psp->p_ridtype == P_PID && - (psp->p_rid == P_MYID || - psp->p_rid == ttoproc(curthread)->p_pid)) || - ((psp->p_ridtype == P_LWPID) && - (psp->p_rid == P_MYID || - psp->p_rid == curthread->t_tid))) && - psp->p_op == POP_AND && psp->p_lidtype == P_ALL) - return (B_TRUE); + (psp->p_rid == P_MYID || + psp->p_rid == ttoproc(curthread)->p_pid)) || + ((psp->p_ridtype == P_LWPID) && + (psp->p_rid == P_MYID || + psp->p_rid == curthread->t_tid))) && + psp->p_op == POP_AND && psp->p_lidtype == P_ALL) + return (B_TRUE); return (B_FALSE); } @@ -844,13 +861,13 @@ getlwpptr(id_t id) proc_t *p; kthread_t *t; + ASSERT(MUTEX_HELD(&(ttoproc(curthread)->p_lock))); + if (id == P_MYID) t = curthread; else { p = ttoproc(curthread); - mutex_enter(&p->p_lock); t = idtot(p, id); - mutex_exit(&p->p_lock); } return (t); @@ -903,12 +920,9 @@ dotolwp(procset_t *psp, int (*funcp)(), char *arg) pp = ttoproc(curthread); - if (procinset(pp, psp)) { - mutex_exit(&pidlock); - return (0); - } mutex_enter(&pp->p_lock); - if ((tp = pp->p_tlist) == NULL) { + if (procinset(pp, psp) || + (tp = pp->p_tlist) == NULL) { mutex_exit(&pp->p_lock); mutex_exit(&pidlock); return (0); |