Index: kern/kern_cpuset.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_cpuset.c,v retrieving revision 1.4 diff -u -p -r1.4 kern_cpuset.c --- kern/kern_cpuset.c 6 Mar 2008 20:11:24 -0000 1.4 +++ kern/kern_cpuset.c 16 Mar 2008 11:06:02 -0000 @@ -382,11 +382,9 @@ cpuset_which(cpuwhich_t which, id_t id, sx_slock(&allproc_lock); FOREACH_PROC_IN_SYSTEM(p) { PROC_LOCK(p); - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td) if (td->td_tid == id) break; - PROC_SUNLOCK(p); if (td != NULL) break; PROC_UNLOCK(p); @@ -480,11 +478,9 @@ cpuset_setproc(pid_t pid, struct cpuset error = cpuset_which(CPU_WHICH_PID, pid, &p, &td, &nset); if (error) goto out; - PROC_SLOCK(p); if (nfree >= p->p_numthreads) break; threads = p->p_numthreads; - PROC_SUNLOCK(p); PROC_UNLOCK(p); for (; nfree < threads; nfree++) { nset = uma_zalloc(cpuset_zone, M_WAITOK); @@ -492,7 +488,6 @@ cpuset_setproc(pid_t pid, struct cpuset } } PROC_LOCK_ASSERT(p, MA_OWNED); - PROC_SLOCK_ASSERT(p, MA_OWNED); /* * Now that the appropriate locks are held and we have enough cpusets, * make sure the operation will succeed before applying changes. The @@ -526,8 +521,8 @@ cpuset_setproc(pid_t pid, struct cpuset } /* * Replace each thread's cpuset while using deferred release. We - * must do this because the PROC_SLOCK has to be held while traversing - * the thread list and this limits the type of operations allowed. + * must do this because the thread lock must be held while operating + * on the thread and this limits the type of operations allowed. */ FOREACH_THREAD_IN_PROC(p, td) { thread_lock(td); @@ -561,7 +556,6 @@ cpuset_setproc(pid_t pid, struct cpuset thread_unlock(td); } unlock_out: - PROC_SUNLOCK(p); PROC_UNLOCK(p); out: while ((nset = LIST_FIRST(&droplist)) != NULL) @@ -833,13 +827,11 @@ cpuset_getaffinity(struct thread *td, st thread_unlock(ttd); break; case CPU_WHICH_PID: - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, ttd) { thread_lock(ttd); CPU_OR(mask, &ttd->td_cpuset->cs_mask); thread_unlock(ttd); } - PROC_SUNLOCK(p); break; case CPU_WHICH_CPUSET: CPU_COPY(&set->cs_mask, mask); Index: kern/kern_exit.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_exit.c,v retrieving revision 1.308 diff -u -p -r1.308 kern_exit.c --- kern/kern_exit.c 17 Feb 2008 15:28:28 -0000 1.308 +++ kern/kern_exit.c 16 Mar 2008 11:06:02 -0000 @@ -510,9 +510,7 @@ exit1(struct thread *td, int rv) * proc lock. */ wakeup(p->p_pptr); - PROC_SLOCK(p->p_pptr); sched_exit(p->p_pptr, td); - PROC_SUNLOCK(p->p_pptr); PROC_SLOCK(p); p->p_state = PRS_ZOMBIE; PROC_UNLOCK(p->p_pptr); Index: kern/kern_kthread.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_kthread.c,v retrieving revision 1.44 diff -u -p -r1.44 kern_kthread.c --- kern/kern_kthread.c 15 Nov 2007 21:45:17 -0000 1.44 +++ kern/kern_kthread.c 16 Mar 2008 11:06:02 -0000 @@ -292,14 +292,12 @@ kthread_add(void (*func)(void *), void * PROC_LOCK(p); p->p_flag |= P_HADTHREADS; newtd->td_sigmask = oldtd->td_sigmask; /* XXX dubious */ - PROC_SLOCK(p); thread_link(newtd, p); thread_lock(oldtd); /* let the scheduler know about these things. */ sched_fork_thread(oldtd, newtd); TD_SET_CAN_RUN(newtd); thread_unlock(oldtd); - PROC_SUNLOCK(p); PROC_UNLOCK(p); Index: kern/kern_lockf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_lockf.c,v retrieving revision 1.57 diff -u -p -r1.57 kern_lockf.c --- kern/kern_lockf.c 7 Aug 2007 09:04:50 -0000 1.57 +++ kern/kern_lockf.c 16 Mar 2008 11:06:02 -0000 @@ -283,7 +283,7 @@ lf_setlock(lock, vp, clean) wproc = (struct proc *)block->lf_id; restart: nproc = NULL; - PROC_SLOCK(wproc); + PROC_LOCK(wproc); FOREACH_THREAD_IN_PROC(wproc, td) { thread_lock(td); while (td->td_wchan && @@ -292,11 +292,13 @@ restart: waitblock = (struct lockf *)td->td_wchan; /* Get the owner of the blocking lock */ waitblock = waitblock->lf_next; + if (waitblock == NULL) + break; if ((waitblock->lf_flags & F_POSIX) == 0) break; nproc = (struct proc *)waitblock->lf_id; if (nproc == (struct proc *)lock->lf_id) { - PROC_SUNLOCK(wproc); + PROC_UNLOCK(wproc); thread_unlock(td); lock->lf_next = *clean; *clean = lock; @@ -305,7 +307,7 @@ restart: } thread_unlock(td); } - PROC_SUNLOCK(wproc); + PROC_UNLOCK(wproc); wproc = nproc; if (wproc) goto restart; Index: kern/kern_proc.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_proc.c,v retrieving revision 1.262 diff -u -p -r1.262 kern_proc.c --- kern/kern_proc.c 12 Mar 2008 10:11:59 -0000 1.262 +++ kern/kern_proc.c 16 Mar 2008 11:06:02 -0000 @@ -640,11 +640,11 @@ fill_kinfo_proc_only(struct proc *p, str struct ucred *cred; struct sigacts *ps; + PROC_LOCK_ASSERT(p, MA_OWNED); bzero(kp, sizeof(*kp)); kp->ki_structsize = sizeof(*kp); kp->ki_paddr = p; - PROC_LOCK_ASSERT(p, MA_OWNED); kp->ki_addr =/* p->p_addr; */0; /* XXX */ kp->ki_args = p->p_args; kp->ki_textvp = p->p_textvp; @@ -776,7 +776,7 @@ fill_kinfo_thread(struct thread *td, str struct proc *p; p = td->td_proc; - PROC_SLOCK_ASSERT(p, MA_OWNED); + PROC_LOCK_ASSERT(p, MA_OWNED); thread_lock(td); if (td->td_wmesg != NULL) @@ -851,10 +851,8 @@ fill_kinfo_proc(struct proc *p, struct k { fill_kinfo_proc_only(p, kp); - PROC_SLOCK(p); if (FIRST_THREAD_IN_PROC(p) != NULL) fill_kinfo_thread(FIRST_THREAD_IN_PROC(p), kp, 0); - PROC_SUNLOCK(p); } struct pstats * @@ -921,15 +919,12 @@ sysctl_out_proc(struct proc *p, struct s fill_kinfo_proc_only(p, &kinfo_proc); if (flags & KERN_PROC_NOTHREADS) { - PROC_SLOCK(p); if (FIRST_THREAD_IN_PROC(p) != NULL) fill_kinfo_thread(FIRST_THREAD_IN_PROC(p), &kinfo_proc, 0); - PROC_SUNLOCK(p); error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc, sizeof(kinfo_proc)); } else { - PROC_SLOCK(p); if (FIRST_THREAD_IN_PROC(p) != NULL) FOREACH_THREAD_IN_PROC(p, td) { fill_kinfo_thread(td, &kinfo_proc, 1); @@ -941,7 +936,6 @@ sysctl_out_proc(struct proc *p, struct s else error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc, sizeof(kinfo_proc)); - PROC_SUNLOCK(p); } PROC_UNLOCK(p); if (error) @@ -1483,7 +1477,7 @@ sysctl_kern_proc_kstack(SYSCTL_HANDLER_A lwpidarray = NULL; numthreads = 0; - PROC_SLOCK(p); + PROC_LOCK(p); repeat: if (numthreads < p->p_numthreads) { if (lwpidarray != NULL) { @@ -1491,13 +1485,12 @@ repeat: lwpidarray = NULL; } numthreads = p->p_numthreads; - PROC_SUNLOCK(p); + PROC_UNLOCK(p); lwpidarray = malloc(sizeof(*lwpidarray) * numthreads, M_TEMP, M_WAITOK | M_ZERO); - PROC_SLOCK(p); + PROC_LOCK(p); goto repeat; } - PROC_SUNLOCK(p); i = 0; /* @@ -1509,7 +1502,6 @@ repeat: * have changed, in which case the right to extract debug info might * no longer be assured. */ - PROC_LOCK(p); FOREACH_THREAD_IN_PROC(p, td) { KASSERT(i < numthreads, ("sysctl_kern_proc_kstack: numthreads")); Index: kern/kern_resource.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_resource.c,v retrieving revision 1.183 diff -u -p -r1.183 kern_resource.c --- kern/kern_resource.c 12 Mar 2008 10:11:59 -0000 1.183 +++ kern/kern_resource.c 16 Mar 2008 11:06:02 -0000 @@ -264,9 +264,7 @@ donice(struct thread *td, struct proc *p n = PRIO_MIN; if (n < p->p_nice && priv_check(td, PRIV_SCHED_SETPRIORITY) != 0) return (EACCES); - PROC_SLOCK(p); sched_nice(p, n); - PROC_SUNLOCK(p); return (0); } @@ -307,7 +305,6 @@ rtprio_thread(struct thread *td, struct case RTP_LOOKUP: if ((error = p_cansee(td, p))) break; - PROC_SLOCK(p); if (uap->lwpid == 0 || uap->lwpid == td->td_tid) td1 = td; else @@ -316,7 +313,6 @@ rtprio_thread(struct thread *td, struct pri_to_rtp(td1, &rtp); else error = ESRCH; - PROC_SUNLOCK(p); PROC_UNLOCK(p); return (copyout(&rtp, uap->rtp, sizeof(struct rtprio))); case RTP_SET: @@ -341,7 +337,6 @@ rtprio_thread(struct thread *td, struct break; } - PROC_SLOCK(p); if (uap->lwpid == 0 || uap->lwpid == td->td_tid) td1 = td; else @@ -350,7 +345,6 @@ rtprio_thread(struct thread *td, struct error = rtp_to_pri(&rtp, td1); else error = ESRCH; - PROC_SUNLOCK(p); break; default: error = EINVAL; @@ -401,7 +395,6 @@ rtprio(td, uap) case RTP_LOOKUP: if ((error = p_cansee(td, p))) break; - PROC_SLOCK(p); /* * Return OUR priority if no pid specified, * or if one is, report the highest priority @@ -427,7 +420,6 @@ rtprio(td, uap) } } } - PROC_SUNLOCK(p); PROC_UNLOCK(p); return (copyout(&rtp, uap->rtp, sizeof(struct rtprio))); case RTP_SET: @@ -458,7 +450,6 @@ rtprio(td, uap) * do all the threads on that process. If we * specify our own pid we do the latter. */ - PROC_SLOCK(p); if (uap->pid == 0) { error = rtp_to_pri(&rtp, td); } else { @@ -467,7 +458,6 @@ rtprio(td, uap) break; } } - PROC_SUNLOCK(p); break; default: error = EINVAL; @@ -700,9 +690,7 @@ kern_setrlimit(td, which, limp) if (limp->rlim_cur != RLIM_INFINITY && p->p_cpulimit == RLIM_INFINITY) callout_reset(&p->p_limco, hz, lim_cb, p); - PROC_SLOCK(p); p->p_cpulimit = limp->rlim_cur; - PROC_SUNLOCK(p); break; case RLIMIT_DATA: if (limp->rlim_cur > maxdsiz) @@ -958,11 +946,12 @@ kern_getrusage(td, who, rup) struct rusage *rup; { struct proc *p; + int error; + error = 0; p = td->td_proc; PROC_LOCK(p); switch (who) { - case RUSAGE_SELF: rufetchcalc(p, rup, &rup->ru_utime, &rup->ru_stime); @@ -974,11 +963,10 @@ kern_getrusage(td, who, rup) break; default: - PROC_UNLOCK(p); - return (EINVAL); + error = EINVAL; } PROC_UNLOCK(p); - return (0); + return (error); } void Index: kern/kern_sig.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_sig.c,v retrieving revision 1.358 diff -u -p -r1.358 kern_sig.c --- kern/kern_sig.c 12 Mar 2008 10:11:59 -0000 1.358 +++ kern/kern_sig.c 16 Mar 2008 11:06:02 -0000 @@ -508,10 +508,8 @@ sigqueue_delete_set_proc(struct proc *p, sigqueue_init(&worklist, NULL); sigqueue_move_set(&p->p_sigqueue, &worklist, set); - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td0) sigqueue_move_set(&td0->td_sigqueue, &worklist, set); - PROC_SUNLOCK(p); sigqueue_flush(&worklist); } @@ -734,9 +732,7 @@ kern_sigaction(td, sig, act, oact, flags (sigprop(sig) & SA_IGNORE && ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)) { /* never to be seen again */ - PROC_SLOCK(p); sigqueue_delete_proc(p, sig); - PROC_SUNLOCK(p); if (sig != SIGCONT) /* easier in psignal */ SIGADDSET(ps->ps_sigignore, sig); @@ -932,9 +928,7 @@ execsigs(struct proc *p) if (sigprop(sig) & SA_IGNORE) { if (sig != SIGCONT) SIGADDSET(ps->ps_sigignore, sig); - PROC_SLOCK(p); sigqueue_delete_proc(p, sig); - PROC_SUNLOCK(p); } ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL; } @@ -1879,7 +1873,6 @@ sigtd(struct proc *p, int sig, int prop) if (curproc == p && !SIGISMEMBER(curthread->td_sigmask, sig)) return (curthread); signal_td = NULL; - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td) { if (!SIGISMEMBER(td->td_sigmask, sig)) { signal_td = td; @@ -1888,7 +1881,6 @@ sigtd(struct proc *p, int sig, int prop) } if (signal_td == NULL) signal_td = FIRST_THREAD_IN_PROC(p); - PROC_SUNLOCK(p); return (signal_td); } @@ -2026,9 +2018,7 @@ tdsignal(struct proc *p, struct thread * ksiginfo_tryfree(ksi); return (ret); } - PROC_SLOCK(p); sigqueue_delete_proc(p, SIGCONT); - PROC_SUNLOCK(p); if (p->p_flag & P_CONTINUED) { p->p_flag &= ~P_CONTINUED; PROC_LOCK(p->p_pptr); @@ -2066,7 +2056,6 @@ tdsignal(struct proc *p, struct thread * * waking up threads so that they can cross the user boundary. * We try do the per-process part here. */ - PROC_SLOCK(p); if (P_SHOULDSTOP(p)) { /* * The process is in stopped mode. All the threads should be @@ -2078,7 +2067,6 @@ tdsignal(struct proc *p, struct thread * * so no further action is necessary. * No signal can restart us. */ - PROC_SUNLOCK(p); goto out; } @@ -2104,6 +2092,7 @@ tdsignal(struct proc *p, struct thread * * Otherwise, process goes back to sleep state. */ p->p_flag &= ~P_STOPPED_SIG; + PROC_SLOCK(p); if (p->p_numthreads == p->p_suspcount) { PROC_SUNLOCK(p); p->p_flag |= P_CONTINUED; @@ -2124,6 +2113,7 @@ tdsignal(struct proc *p, struct thread * * The process wants to catch it so it needs * to run at least one thread, but which one? */ + PROC_SUNLOCK(p); goto runfast; } /* @@ -2140,7 +2130,6 @@ tdsignal(struct proc *p, struct thread * * (If we did the shell could get confused). * Just make sure the signal STOP bit set. */ - PROC_SUNLOCK(p); p->p_flag |= P_STOPPED_SIG; sigqueue_delete(sigqueue, sig); goto out; @@ -2154,6 +2143,7 @@ tdsignal(struct proc *p, struct thread * * the PROCESS runnable, leave it stopped. * It may run a bit until it hits a thread_suspend_check(). */ + PROC_SLOCK(p); thread_lock(td); if (TD_ON_SLEEPQ(td) && (td->td_flags & TDF_SINTR)) sleepq_abort(td, intrval); @@ -2166,22 +2156,18 @@ tdsignal(struct proc *p, struct thread * */ } else if (p->p_state == PRS_NORMAL) { if (p->p_flag & P_TRACED || action == SIG_CATCH) { - thread_lock(td); tdsigwakeup(td, sig, action, intrval); - thread_unlock(td); - PROC_SUNLOCK(p); goto out; } MPASS(action == SIG_DFL); if (prop & SA_STOP) { - if (p->p_flag & P_PPWAIT) { - PROC_SUNLOCK(p); + if (p->p_flag & P_PPWAIT) goto out; - } p->p_flag |= P_STOPPED_SIG; p->p_xstat = sig; + PROC_SLOCK(p); sig_suspend_threads(td, p, 1); if (p->p_numthreads == p->p_suspcount) { /* @@ -2197,13 +2183,9 @@ tdsignal(struct proc *p, struct thread * } else PROC_SUNLOCK(p); goto out; - } - else - goto runfast; - /* NOTREACHED */ + } } else { /* Not in "NORMAL" state. discard the signal. */ - PROC_SUNLOCK(p); sigqueue_delete(sigqueue, sig); goto out; } @@ -2212,11 +2194,9 @@ tdsignal(struct proc *p, struct thread * * The process is not stopped so we need to apply the signal to all the * running threads. */ - runfast: - thread_lock(td); tdsigwakeup(td, sig, action, intrval); - thread_unlock(td); + PROC_SLOCK(p); thread_unsuspend(p); PROC_SUNLOCK(p); out: @@ -2237,17 +2217,16 @@ tdsigwakeup(struct thread *td, int sig, register int prop; PROC_LOCK_ASSERT(p, MA_OWNED); - PROC_SLOCK_ASSERT(p, MA_OWNED); - THREAD_LOCK_ASSERT(td, MA_OWNED); prop = sigprop(sig); + PROC_SLOCK(p); + thread_lock(td); /* * Bring the priority of a thread up if we want it to get * killed in this lifetime. */ if (action == SIG_DFL && (prop & SA_KILL) && td->td_priority > PUSER) sched_prio(td, PUSER); - if (TD_ON_SLEEPQ(td)) { /* * If thread is sleeping uninterruptibly @@ -2256,7 +2235,7 @@ tdsigwakeup(struct thread *td, int sig, * trap() or syscall(). */ if ((td->td_flags & TDF_SINTR) == 0) - return; + goto out; /* * If SIGCONT is default (or ignored) and process is * asleep, we are finished; the process should not @@ -2271,8 +2250,6 @@ tdsigwakeup(struct thread *td, int sig, * Remove from both for now. */ sigqueue_delete(&td->td_sigqueue, sig); - PROC_SLOCK(p); - thread_lock(td); return; } @@ -2294,6 +2271,9 @@ tdsigwakeup(struct thread *td, int sig, forward_signal(td); #endif } +out: + PROC_SUNLOCK(p); + thread_unlock(td); } static void Index: kern/kern_thr.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_thr.c,v retrieving revision 1.64 diff -u -p -r1.64 kern_thr.c --- kern/kern_thr.c 15 Nov 2007 06:35:26 -0000 1.64 +++ kern/kern_thr.c 16 Mar 2008 11:06:02 -0000 @@ -229,14 +229,12 @@ create_thread(struct thread *td, mcontex PROC_LOCK(td->td_proc); td->td_proc->p_flag |= P_HADTHREADS; newtd->td_sigmask = td->td_sigmask; - PROC_SLOCK(p); thread_link(newtd, p); bcopy(p->p_comm, newtd->td_name, sizeof(newtd->td_name)); thread_lock(td); /* let the scheduler know about these things. */ sched_fork_thread(td, newtd); thread_unlock(td); - PROC_SUNLOCK(p); PROC_UNLOCK(p); thread_lock(newtd); if (rtp != NULL) { Index: kern/kern_thread.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_thread.c,v retrieving revision 1.269 diff -u -p -r1.269 kern_thread.c --- kern/kern_thread.c 12 Mar 2008 10:11:59 -0000 1.269 +++ kern/kern_thread.c 16 Mar 2008 11:06:02 -0000 @@ -303,7 +303,8 @@ thread_alloc(void) void thread_free(struct thread *td) { - cpuset_rel(td->td_cpuset); + if (td->td_cpuset) + cpuset_rel(td->td_cpuset); td->td_cpuset = NULL; cpu_thread_free(td); if (td->td_altkstack != 0) @@ -345,9 +346,7 @@ thread_exit(void) #ifdef AUDIT AUDIT_SYSCALL_EXIT(0, td); #endif - umtx_thread_exit(td); - /* * drop FPU & debug register state storage, or any other * architecture specific resources that @@ -374,9 +373,7 @@ thread_exit(void) */ if (p->p_flag & P_HADTHREADS) { if (p->p_numthreads > 1) { - thread_lock(td); thread_unlink(td); - thread_unlock(td); td2 = FIRST_THREAD_IN_PROC(p); sched_exit_thread(td2, td); @@ -450,8 +447,8 @@ thread_link(struct thread *td, struct pr /* * XXX This can't be enabled because it's called for proc0 before - * it's spinlock has been created. - * PROC_SLOCK_ASSERT(p, MA_OWNED); + * its lock has been created. + * PROC_LOCK_ASSERT(p, MA_OWNED); */ td->td_state = TDS_INACTIVE; td->td_proc = p; @@ -487,7 +484,7 @@ thread_unlink(struct thread *td) { struct proc *p = td->td_proc; - PROC_SLOCK_ASSERT(p, MA_OWNED); + PROC_LOCK_ASSERT(p, MA_OWNED); TAILQ_REMOVE(&p->p_threads, td, td_plist); p->p_numthreads--; /* could clear a few other things here */ @@ -863,11 +860,9 @@ thread_find(struct proc *p, lwpid_t tid) struct thread *td; PROC_LOCK_ASSERT(p, MA_OWNED); - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td) { if (td->td_tid == tid) break; } - PROC_SUNLOCK(p); return (td); } Index: kern/sched_4bsd.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sched_4bsd.c,v retrieving revision 1.117 diff -u -p -r1.117 sched_4bsd.c --- kern/sched_4bsd.c 12 Mar 2008 10:11:59 -0000 1.117 +++ kern/sched_4bsd.c 16 Mar 2008 11:06:02 -0000 @@ -356,7 +356,7 @@ schedcpu(void) realstathz = stathz ? stathz : hz; sx_slock(&allproc_lock); FOREACH_PROC_IN_SYSTEM(p) { - PROC_SLOCK(p); + PROC_LOCK(p); FOREACH_THREAD_IN_PROC(p, td) { awake = 0; thread_lock(td); @@ -435,7 +435,7 @@ XXX this is broken resetpriority_thread(td); thread_unlock(td); } /* end of thread loop */ - PROC_SUNLOCK(p); + PROC_UNLOCK(p); } /* end of process loop */ sx_sunlock(&allproc_lock); } @@ -615,7 +615,7 @@ sched_exit(struct proc *p, struct thread CTR3(KTR_SCHED, "sched_exit: %p(%s) prio %d", td, td->td_name, td->td_priority); - PROC_SLOCK_ASSERT(p, MA_OWNED); + PROC_LOCK_ASSERT(p, MA_OWNED); sched_exit_thread(FIRST_THREAD_IN_PROC(p), td); } @@ -655,7 +655,6 @@ sched_nice(struct proc *p, int nice) struct thread *td; PROC_LOCK_ASSERT(p, MA_OWNED); - PROC_SLOCK_ASSERT(p, MA_OWNED); p->p_nice = nice; FOREACH_THREAD_IN_PROC(p, td) { thread_lock(td); Index: kern/sched_ule.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sched_ule.c,v retrieving revision 1.232 diff -u -p -r1.232 sched_ule.c --- kern/sched_ule.c 12 Mar 2008 10:11:59 -0000 1.232 +++ kern/sched_ule.c 16 Mar 2008 11:06:02 -0000 @@ -370,7 +370,7 @@ sched_shouldpreempt(int pri, int cpri, i * If we're realtime or better and there is timeshare or worse running * preempt only remote processors. */ - if (remote && pri <= PRI_MAX_REALTIME && cpri > PRI_MAX_REALTIME) + if (remote && pri < PRI_MAX_REALTIME && cpri > PRI_MAX_REALTIME) return (1); return (0); } @@ -1842,7 +1842,6 @@ sched_nice(struct proc *p, int nice) struct thread *td; PROC_LOCK_ASSERT(p, MA_OWNED); - PROC_SLOCK_ASSERT(p, MA_OWNED); p->p_nice = nice; FOREACH_THREAD_IN_PROC(p, td) { @@ -1867,6 +1866,8 @@ sched_sleep(struct thread *td, int prio) td->td_flags |= TDF_CANSWAP; if (static_boost && prio) sched_prio(td, prio); + else if (prio && td->td_priority > PRI_MAX_REALTIME) + sched_prio(td, PRI_MAX_REALTIME); } /* @@ -1995,7 +1996,7 @@ sched_exit(struct proc *p, struct thread CTR3(KTR_SCHED, "sched_exit: %p(%s) prio %d", child, child->td_name, child->td_priority); - PROC_SLOCK_ASSERT(p, MA_OWNED); + PROC_LOCK_ASSERT(p, MA_OWNED); td = FIRST_THREAD_IN_PROC(p); sched_exit_thread(td, child); } Index: kern/subr_sleepqueue.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_sleepqueue.c,v retrieving revision 1.48 diff -u -p -r1.48 subr_sleepqueue.c --- kern/subr_sleepqueue.c 13 Mar 2008 00:46:12 -0000 1.48 +++ kern/subr_sleepqueue.c 16 Mar 2008 11:06:02 -0000 @@ -381,12 +381,20 @@ sleepq_catch_signals(void *wchan, int pr sc = SC_LOOKUP(wchan); mtx_assert(&sc->sc_lock, MA_OWNED); MPASS(wchan != NULL); + /* + * See if there are any pending signals for this thread. If not + * we can switch immediately. Otherwise do the signal processing + * directly. + */ + thread_lock(td); + if ((td->td_flags & TDF_NEEDSIGCHK) == 0) { + sleepq_switch(wchan, pri); + return (0); + } + thread_unlock(td); + mtx_unlock_spin(&sc->sc_lock); CTR3(KTR_PROC, "sleepq catching signals: thread %p (pid %ld, %s)", (void *)td, (long)p->p_pid, td->td_name); - - mtx_unlock_spin(&sc->sc_lock); - - /* See if there are any pending signals for this thread. */ PROC_LOCK(p); ps = p->p_sigacts; mtx_lock(&ps->ps_mtx); @@ -410,8 +418,8 @@ sleepq_catch_signals(void *wchan, int pr PROC_SLOCK(p); mtx_lock_spin(&sc->sc_lock); PROC_UNLOCK(p); - thread_lock(td); PROC_SUNLOCK(p); + thread_lock(td); if (ret == 0) { sleepq_switch(wchan, pri); return (0); Index: kern/sys_generic.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sys_generic.c,v retrieving revision 1.162 diff -u -p -r1.162 sys_generic.c --- kern/sys_generic.c 7 Jan 2008 20:05:18 -0000 1.162 +++ kern/sys_generic.c 16 Mar 2008 11:06:02 -0000 @@ -1013,13 +1013,8 @@ poll(td, uap) * least enough for the current limits. We want to be reasonably * safe, but not overly restrictive. */ - PROC_LOCK(td->td_proc); - if ((nfds > lim_cur(td->td_proc, RLIMIT_NOFILE)) && - (nfds > FD_SETSIZE)) { - PROC_UNLOCK(td->td_proc); + if (nfds > maxfilesperproc && nfds > FD_SETSIZE) return (EINVAL); - } - PROC_UNLOCK(td->td_proc); ni = nfds * sizeof(struct pollfd); if (ni > sizeof(smallbits)) bits = malloc(ni, M_TEMP, M_WAITOK); Index: kern/sys_process.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sys_process.c,v retrieving revision 1.147 diff -u -p -r1.147 sys_process.c --- kern/sys_process.c 12 Mar 2008 10:11:59 -0000 1.147 +++ kern/sys_process.c 16 Mar 2008 11:06:02 -0000 @@ -528,12 +528,10 @@ kern_ptrace(struct thread *td, int req, sx_slock(&allproc_lock); FOREACH_PROC_IN_SYSTEM(p) { PROC_LOCK(p); - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td2) { if (td2->td_tid == pid) break; } - PROC_SUNLOCK(p); if (td2 != NULL) break; /* proc lock held */ PROC_UNLOCK(p); @@ -789,7 +787,6 @@ kern_ptrace(struct thread *td, int req, thread_unlock(td2); td2->td_xsig = data; - PROC_SLOCK(p); if (req == PT_DETACH) { struct thread *td3; FOREACH_THREAD_IN_PROC(p, td3) { @@ -803,6 +800,7 @@ kern_ptrace(struct thread *td, int req, * you should use PT_SUSPEND to suspend it before * continuing process. */ + PROC_SLOCK(p); p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG|P_WAITED); thread_unsuspend(p); PROC_SUNLOCK(p); @@ -957,13 +955,11 @@ kern_ptrace(struct thread *td, int req, buf = malloc(num * sizeof(lwpid_t), M_TEMP, M_WAITOK); tmp = 0; PROC_LOCK(p); - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td2) { if (tmp >= num) break; buf[tmp++] = td2->td_tid; } - PROC_SUNLOCK(p); PROC_UNLOCK(p); error = copyout(buf, addr, tmp * sizeof(lwpid_t)); free(buf, M_TEMP); Index: kern/tty.c =================================================================== RCS file: /home/ncvs/src/sys/kern/tty.c,v retrieving revision 1.274 diff -u -p -r1.274 tty.c --- kern/tty.c 8 Jan 2008 04:53:28 -0000 1.274 +++ kern/tty.c 16 Mar 2008 11:06:03 -0000 @@ -2581,7 +2581,7 @@ ttyinfo(struct tty *tp) if (proc_compare(pick, p)) pick = p; - PROC_SLOCK(pick); + PROC_LOCK(pick); picktd = NULL; td = FIRST_THREAD_IN_PROC(pick); FOREACH_THREAD_IN_PROC(pick, td) @@ -2615,7 +2615,7 @@ ttyinfo(struct tty *tp) rss = 0; else rss = pgtok(vmspace_resident_count(pick->p_vmspace)); - PROC_SUNLOCK(pick); + PROC_UNLOCK(pick); PROC_LOCK(pick); PGRP_UNLOCK(tp->t_pgrp); rufetchcalc(pick, &ru, &utime, &stime); @@ -2744,12 +2744,12 @@ proc_compare(struct proc *p1, struct pro * Fetch various stats about these processes. After we drop the * lock the information could be stale but the race is unimportant. */ - PROC_SLOCK(p1); + PROC_LOCK(p1); runa = proc_sum(p1, &esta); - PROC_SUNLOCK(p1); - PROC_SLOCK(p2); + PROC_UNLOCK(p1); + PROC_LOCK(p2); runb = proc_sum(p2, &estb); - PROC_SUNLOCK(p2); + PROC_UNLOCK(p2); /* * see if at least one of them is runnable Index: sys/proc.h =================================================================== RCS file: /home/ncvs/src/sys/sys/proc.h,v retrieving revision 1.506 diff -u -p -r1.506 proc.h --- sys/proc.h 12 Mar 2008 10:12:01 -0000 1.506 +++ sys/proc.h 16 Mar 2008 11:06:06 -0000 @@ -431,7 +431,7 @@ struct rusage_ext { */ struct proc { LIST_ENTRY(proc) p_list; /* (d) List of all processes. */ - TAILQ_HEAD(, thread) p_threads; /* (j) all threads. */ + TAILQ_HEAD(, thread) p_threads; /* (c) all threads. */ struct mtx p_slock; /* process spin lock */ struct ucred *p_ucred; /* (c) Process owner's identity. */ struct filedesc *p_fd; /* (b) Open files. */ @@ -466,7 +466,7 @@ struct proc { #define p_startzero p_oppid pid_t p_oppid; /* (c + e) Save ppid in ptrace. XXX */ struct vmspace *p_vmspace; /* (b) Address space. */ - u_int p_swtick; /* (j) Tick when swapped in or out. */ + u_int p_swtick; /* (c) Tick when swapped in or out. */ struct itimerval p_realtimer; /* (c) Alarm timer. */ struct rusage p_ru; /* (a) Exit information. */ struct rusage_ext p_rux; /* (cj) Internal resource usage. */ @@ -507,13 +507,13 @@ struct proc { struct sysentvec *p_sysent; /* (b) Syscall dispatch info. */ struct pargs *p_args; /* (c) Process arguments. */ rlim_t p_cpulimit; /* (c) Current CPU limit in seconds. */ - signed char p_nice; /* (c + j) Process "nice" value. */ + signed char p_nice; /* (c) Process "nice" value. */ /* End area that is copied on creation. */ #define p_endcopy p_xstat u_short p_xstat; /* (c) Exit status; also stop sig. */ struct knlist p_klist; /* (c) Knotes attached to this proc. */ - int p_numthreads; /* (j) Number of threads. */ + int p_numthreads; /* (c) Number of threads. */ struct mdproc p_md; /* Any machine-dependent fields. */ struct callout p_itcallout; /* (h + c) Interval timer callout. */ u_short p_acflag; /* (c) Accounting flags. */ Index: ufs/ffs/ffs_snapshot.c =================================================================== RCS file: /home/ncvs/src/sys/ufs/ffs/ffs_snapshot.c,v retrieving revision 1.140 diff -u -p -r1.140 ffs_snapshot.c --- ufs/ffs/ffs_snapshot.c 24 Jan 2008 12:34:29 -0000 1.140 +++ ufs/ffs/ffs_snapshot.c 16 Mar 2008 11:06:06 -0000 @@ -393,10 +393,8 @@ restart: p = td->td_proc; PROC_LOCK(p); - PROC_SLOCK(p); saved_nice = p->p_nice; sched_nice(p, 0); - PROC_SUNLOCK(p); PROC_UNLOCK(p); } /* @@ -816,9 +814,7 @@ out: p = td->td_proc; PROC_LOCK(p); - PROC_SLOCK(p); sched_nice(td->td_proc, saved_nice); - PROC_SUNLOCK(p); PROC_UNLOCK(td->td_proc); } UFS_LOCK(ump); Index: vm/vm_glue.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_glue.c,v retrieving revision 1.228 diff -u -p -r1.228 vm_glue.c --- vm/vm_glue.c 12 Mar 2008 10:12:01 -0000 1.228 +++ vm/vm_glue.c 16 Mar 2008 11:06:06 -0000 @@ -645,10 +645,8 @@ faultin(p) FOREACH_THREAD_IN_PROC(p, td) vm_thread_swapin(td); PROC_LOCK(p); - PROC_SLOCK(p); swapclear(p); p->p_swtick = ticks; - PROC_SUNLOCK(p); wakeup(&p->p_flag); @@ -700,7 +698,6 @@ loop: continue; } swtime = (ticks - p->p_swtick) / hz; - PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td) { /* * An otherwise runnable thread of a process @@ -726,7 +723,6 @@ loop: } thread_unlock(td); } - PROC_SUNLOCK(p); PROC_UNLOCK(p); } sx_sunlock(&allproc_lock); @@ -868,7 +864,7 @@ retry: if (p->p_lock != 0 || (p->p_flag & (P_STOPPED_SINGLE|P_TRACED|P_SYSTEM|P_WEXIT) ) != 0) { - goto nextproc2; + goto nextproc; } /* * only aiod changes vmspace, however it will be @@ -876,7 +872,7 @@ retry: * for P_SYSTEM */ if ((p->p_flag & (P_INMEM|P_SWAPPINGOUT|P_SWAPPINGIN)) != P_INMEM) - goto nextproc2; + goto nextproc; switch (p->p_state) { default: @@ -885,7 +881,6 @@ retry: break; case PRS_NORMAL: - PROC_SLOCK(p); /* * do not swapout a realtime process * Check all the thread groups.. @@ -947,17 +942,14 @@ retry: (minslptime > swap_idle_threshold2))) { if (swapout(p) == 0) didswap++; - PROC_SUNLOCK(p); PROC_UNLOCK(p); vm_map_unlock(&vm->vm_map); vmspace_free(vm); sx_sunlock(&allproc_lock); goto retry; } -nextproc: - PROC_SUNLOCK(p); } -nextproc2: +nextproc: PROC_UNLOCK(p); vm_map_unlock(&vm->vm_map); nextproc1: @@ -980,7 +972,6 @@ swapclear(p) struct thread *td; PROC_LOCK_ASSERT(p, MA_OWNED); - PROC_SLOCK_ASSERT(p, MA_OWNED); FOREACH_THREAD_IN_PROC(p, td) { thread_lock(td); @@ -1002,7 +993,6 @@ swapout(p) struct thread *td; PROC_LOCK_ASSERT(p, MA_OWNED); - PROC_SLOCK_ASSERT(p, MA_OWNED | MA_NOTRECURSED); #if defined(SWAP_DEBUG) printf("swapping out %d\n", p->p_pid); #endif @@ -1037,7 +1027,6 @@ swapout(p) } td = FIRST_THREAD_IN_PROC(p); ++td->td_ru.ru_nswap; - PROC_SUNLOCK(p); PROC_UNLOCK(p); /* @@ -1050,7 +1039,6 @@ swapout(p) PROC_LOCK(p); p->p_flag &= ~P_SWAPPINGOUT; - PROC_SLOCK(p); p->p_swtick = ticks; return (0); } Index: vm/vm_pageout.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_pageout.c,v retrieving revision 1.294 diff -u -p -r1.294 vm_pageout.c --- vm/vm_pageout.c 25 Nov 2007 20:37:29 -0000 1.294 +++ vm/vm_pageout.c 16 Mar 2008 11:06:06 -0000 @@ -1205,7 +1205,7 @@ unlock_and_continue: * If the process is in a non-running type state, * don't touch it. Check all the threads individually. */ - PROC_SLOCK(p); + PROC_LOCK(p); breakout = 0; FOREACH_THREAD_IN_PROC(p, td) { thread_lock(td); @@ -1218,7 +1218,7 @@ unlock_and_continue: } thread_unlock(td); } - PROC_SUNLOCK(p); + PROC_UNLOCK(p); if (breakout) { PROC_UNLOCK(p); continue; @@ -1248,9 +1248,7 @@ unlock_and_continue: sx_sunlock(&allproc_lock); if (bigproc != NULL) { killproc(bigproc, "out of swap space"); - PROC_SLOCK(bigproc); sched_nice(bigproc, PRIO_MIN); - PROC_SUNLOCK(bigproc); PROC_UNLOCK(bigproc); wakeup(&cnt.v_free_count); } @@ -1559,7 +1557,6 @@ vm_daemon() * if the process is in a non-running type state, * don't touch it. */ - PROC_SLOCK(p); breakout = 0; FOREACH_THREAD_IN_PROC(p, td) { thread_lock(td); @@ -1572,7 +1569,6 @@ vm_daemon() } thread_unlock(td); } - PROC_SUNLOCK(p); if (breakout) { PROC_UNLOCK(p); continue;