Date: Tue, 22 Apr 2003 13:58:48 -0700 (PDT) From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 29438 for review Message-ID: <200304222058.h3MKwmcj083931@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=29438 Change 29438 by jhb@jhb_laptop on 2003/04/22 13:58:32 IFC @29437 (more proc locking). Affected files ... .. //depot/projects/smpng/sys/kern/kern_clock.c#26 integrate .. //depot/projects/smpng/sys/kern/kern_fork.c#57 integrate .. //depot/projects/smpng/sys/kern/kern_resource.c#35 integrate .. //depot/projects/smpng/sys/kern/sched_4bsd.c#8 integrate .. //depot/projects/smpng/sys/kern/sched_ule.c#8 integrate .. //depot/projects/smpng/sys/kern/subr_prof.c#19 integrate .. //depot/projects/smpng/sys/kern/subr_trap.c#51 integrate .. //depot/projects/smpng/sys/sys/proc.h#82 integrate .. //depot/projects/smpng/sys/ufs/ffs/ffs_snapshot.c#27 integrate Differences ... ==== //depot/projects/smpng/sys/kern/kern_clock.c#26 (text+ko) ==== @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 - * $FreeBSD: src/sys/kern/kern_clock.c,v 1.156 2003/04/11 03:39:07 jeff Exp $ + * $FreeBSD: src/sys/kern/kern_clock.c,v 1.157 2003/04/22 20:54:04 jhb Exp $ */ #include "opt_ntp.h" @@ -303,17 +303,16 @@ * it should be protected later on by a time_lock, which would * cover psdiv, etc. as well. */ - mtx_lock_spin(&sched_lock); - if (p->p_sflag & PS_STOPPROF) { - mtx_unlock_spin(&sched_lock); + PROC_LOCK_ASSERT(p, MA_OWNED); + if (p->p_flag & P_STOPPROF) return; - } - if ((p->p_sflag & PS_PROFIL) == 0) { - p->p_sflag |= PS_PROFIL; + if ((p->p_flag & P_PROFIL) == 0) { + mtx_lock_spin(&sched_lock); + p->p_flag |= P_PROFIL; if (++profprocs == 1) cpu_startprofclock(); + mtx_unlock_spin(&sched_lock); } - mtx_unlock_spin(&sched_lock); } /* @@ -325,21 +324,20 @@ { PROC_LOCK_ASSERT(p, MA_OWNED); -retry: - mtx_lock_spin(&sched_lock); - if (p->p_sflag & PS_PROFIL) { - if (p->p_profthreads) { - p->p_sflag |= PS_STOPPROF; - mtx_unlock_spin(&sched_lock); - msleep(&p->p_profthreads, &p->p_mtx, PPAUSE, - "stopprof", NULL); - goto retry; + if (p->p_flag & P_PROFIL) { + if (p->p_profthreads != 0) { + p->p_flag |= P_STOPPROF; + while (p->p_profthreads != 0) + msleep(&p->p_profthreads, &p->p_mtx, PPAUSE, + "stopprof", NULL); + p->p_flag &= ~P_STOPPROF; } - p->p_sflag &= ~(PS_PROFIL|PS_STOPPROF); + mtx_lock_spin(&sched_lock); + p->p_flag &= ~P_PROFIL; if (--profprocs == 0) cpu_stopprofclock(); + mtx_unlock_spin(&sched_lock); } - mtx_unlock_spin(&sched_lock); } /* @@ -440,7 +438,7 @@ * bother trying to count it. */ td = curthread; - if (td->td_proc->p_sflag & PS_PROFIL) + if (td->td_proc->p_flag & P_PROFIL) addupc_intr(td, CLKF_PC(frame), 1); } #ifdef GPROF ==== //depot/projects/smpng/sys/kern/kern_fork.c#57 (text+ko) ==== @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94 - * $FreeBSD: src/sys/kern/kern_fork.c,v 1.192 2003/04/17 22:24:59 jhb Exp $ + * $FreeBSD: src/sys/kern/kern_fork.c,v 1.193 2003/04/22 20:54:04 jhb Exp $ */ #include "opt_ktrace.h" @@ -483,10 +483,10 @@ * The p_stats and p_sigacts substructs are set in vm_forkproc. */ p2->p_flag = 0; + if (p1->p_flag & P_PROFIL) + startprofclock(p2); mtx_lock_spin(&sched_lock); p2->p_sflag = PS_INMEM; - if (p1->p_sflag & PS_PROFIL) - startprofclock(p2); /* * Allow the scheduler to adjust the priority of the child and * parent while we hold the sched_lock. @@ -580,7 +580,7 @@ PROC_LOCK(p1); /* - * Preserve some more flags in subprocess. PS_PROFIL has already + * Preserve some more flags in subprocess. P_PROFIL has already * been preserved. */ p2->p_flag |= p1->p_flag & (P_SUGID | P_ALTSTACK); ==== //depot/projects/smpng/sys/kern/kern_resource.c#35 (text+ko) ==== @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 - * $FreeBSD: src/sys/kern/kern_resource.c,v 1.123 2003/04/18 20:17:47 jhb Exp $ + * $FreeBSD: src/sys/kern/kern_resource.c,v 1.124 2003/04/22 20:45:38 jhb Exp $ */ #include "opt_compat.h" @@ -295,9 +295,11 @@ } if (n < low && suser(td)) return (EACCES); + mtx_lock_spin(&sched_lock); FOREACH_KSEGRP_IN_PROC(p, kg) { sched_nice(kg, n); } + mtx_unlock_spin(&sched_lock); return (0); } ==== //depot/projects/smpng/sys/kern/sched_4bsd.c#8 (text+ko) ==== @@ -35,7 +35,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/kern/sched_4bsd.c,v 1.15 2003/04/11 03:39:48 jeff Exp $ + * $FreeBSD: src/sys/kern/sched_4bsd.c,v 1.16 2003/04/22 20:50:38 jhb Exp $ */ #include <sys/param.h> @@ -378,7 +378,6 @@ register unsigned int newpriority; struct thread *td; - mtx_lock_spin(&sched_lock); if (kg->kg_pri_class == PRI_TIMESHARE) { newpriority = PUSER + kg->kg_estcpu / INVERSE_ESTCPU_WEIGHT + NICE_WEIGHT * (kg->kg_nice - PRIO_MIN); @@ -389,7 +388,6 @@ FOREACH_THREAD_IN_GROUP(kg, td) { maybe_resched(td); /* XXXKSE silly */ } - mtx_unlock_spin(&sched_lock); } /* ARGSUSED */ @@ -514,6 +512,9 @@ void sched_nice(struct ksegrp *kg, int nice) { + + PROC_LOCK_ASSERT(kg->kg_proc, MA_OWNED); + mtx_assert(&sched_lock, MA_OWNED); kg->kg_nice = nice; resetpriority(kg); } ==== //depot/projects/smpng/sys/kern/sched_ule.c#8 (text+ko) ==== @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/kern/sched_ule.c,v 1.30 2003/04/22 19:48:25 jhb Exp $ + * $FreeBSD: src/sys/kern/sched_ule.c,v 1.31 2003/04/22 20:50:38 jhb Exp $ */ #include <sys/param.h> @@ -693,6 +693,8 @@ struct thread *td; struct kseq *kseq; + PROC_LOCK_ASSERT(kg->kg_proc, MA_OWNED); + mtx_assert(&sched_lock, MA_OWNED); /* * We need to adjust the nice counts for running KSEs. */ ==== //depot/projects/smpng/sys/kern/subr_prof.c#19 (text+ko) ==== @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)subr_prof.c 8.3 (Berkeley) 9/23/93 - * $FreeBSD: src/sys/kern/subr_prof.c,v 1.63 2003/02/19 05:47:25 imp Exp $ + * $FreeBSD: src/sys/kern/subr_prof.c,v 1.64 2003/04/22 20:54:04 jhb Exp $ */ #include <sys/param.h> @@ -366,7 +366,9 @@ gp->state = GMON_PROF_OFF; stopguprof(gp); gp->profrate = profhz; + PROC_LOCK(&proc0); startprofclock(&proc0); + PROC_UNLOCK(&proc0); gp->state = state; #ifdef GUPROF } else if (state == GMON_PROF_HIRES) { @@ -424,35 +426,28 @@ register struct profil_args *uap; { struct uprof *upp; - int s; - int error = 0; + struct proc *p; - mtx_lock(&Giant); + if (uap->scale > (1 << 16)) + return (EINVAL); - if (uap->scale > (1 << 16)) { - error = EINVAL; - goto done2; - } + p = td->td_proc; if (uap->scale == 0) { PROC_LOCK(td->td_proc); stopprofclock(td->td_proc); PROC_UNLOCK(td->td_proc); - goto done2; + return (0); } upp = &td->td_proc->p_stats->p_prof; - - /* Block profile interrupts while changing state. */ - s = splstatclock(); upp->pr_off = uap->offset; upp->pr_scale = uap->scale; upp->pr_base = uap->samples; upp->pr_size = uap->size; - startprofclock(td->td_proc); - splx(s); + PROC_LOCK(p); + startprofclock(p); + PROC_UNLOCK(p); -done2: - mtx_unlock(&Giant); - return (error); + return (0); } /* @@ -521,14 +516,11 @@ return; PROC_LOCK(p); - mtx_lock_spin(&sched_lock); - if (!(p->p_sflag & PS_PROFIL)) { - mtx_unlock_spin(&sched_lock); + if (!(p->p_flag & P_PROFIL)) { PROC_UNLOCK(p); return; } p->p_profthreads++; - mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); prof = &p->p_stats->p_prof; if (pc < prof->pr_off || @@ -547,7 +539,7 @@ out: PROC_LOCK(p); if (--p->p_profthreads == 0) { - if (p->p_sflag & PS_STOPPROF) { + if (p->p_flag & P_STOPPROF) { wakeup(&p->p_profthreads); stop = 0; } ==== //depot/projects/smpng/sys/kern/subr_trap.c#51 (text+ko) ==== @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $FreeBSD: src/sys/kern/subr_trap.c,v 1.251 2003/04/17 22:33:04 jhb Exp $ + * $FreeBSD: src/sys/kern/subr_trap.c,v 1.252 2003/04/22 20:54:04 jhb Exp $ */ #include "opt_mac.h" @@ -115,11 +115,8 @@ /* * Charge system time if profiling. - * - * XXX should move PS_PROFIL to a place that can obviously be - * accessed safely without sched_lock. */ - if (p->p_sflag & PS_PROFIL) { + if (p->p_flag & P_PROFIL) { quad_t ticks; mtx_lock_spin(&sched_lock); @@ -182,7 +179,7 @@ TDF_NEEDRESCHED | TDF_OWEUPC); cnt.v_soft++; prticks = 0; - if (flags & TDF_OWEUPC && sflag & PS_PROFIL) { + if (flags & TDF_OWEUPC && p->p_flag & P_PROFIL) { prticks = p->p_stats->p_prof.pr_ticks; p->p_stats->p_prof.pr_ticks = 0; } @@ -197,7 +194,7 @@ if (td->td_ucred != p->p_ucred) cred_update_thread(td); - if (flags & TDF_OWEUPC && sflag & PS_PROFIL) + if (flags & TDF_OWEUPC && p->p_flag & P_PROFIL) addupc_task(td, p->p_stats->p_prof.pr_addr, prticks); if (sflag & PS_ALRMPEND) { PROC_LOCK(p); ==== //depot/projects/smpng/sys/sys/proc.h#82 (text+ko) ==== @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)proc.h 8.15 (Berkeley) 5/19/95 - * $FreeBSD: src/sys/sys/proc.h,v 1.320 2003/04/22 20:00:25 jhb Exp $ + * $FreeBSD: src/sys/sys/proc.h,v 1.321 2003/04/22 20:54:04 jhb Exp $ */ #ifndef _SYS_PROC_H_ @@ -630,6 +630,8 @@ #define P_KTHREAD 0x00004 /* Kernel thread. (*)*/ #define P_NOLOAD 0x00008 /* Ignore during load avg calculations. */ #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */ +#define P_PROFIL 0x00020 /* Has started profiling. */ +#define P_STOPPROF 0x00040 /* Has thread in requesting to stop prof */ #define P_SUGID 0x00100 /* Had set id privileges since last exec. */ #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */ #define P_WAITED 0x01000 /* Someone is waiting for us */ @@ -661,8 +663,6 @@ /* These flags are kept in p_sflag and are protected with sched_lock. */ #define PS_INMEM 0x00001 /* Loaded into memory. */ #define PS_XCPU 0x00002 /* Exceeded CPU limit. */ -#define PS_PROFIL 0x00004 /* Has started profiling. */ -#define PS_STOPPROF 0x00008 /* Has thread in requesting to stop prof */ #define PS_ALRMPEND 0x00020 /* Pending SIGVTALRM needs to be posted. */ #define PS_PROFPEND 0x00040 /* Pending SIGPROF needs to be posted. */ #define PS_SWAPINREQ 0x00100 /* Swapin request due to wakeup. */ ==== //depot/projects/smpng/sys/ufs/ffs/ffs_snapshot.c#27 (text+ko) ==== @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ffs_snapshot.c 8.11 (McKusick) 7/23/00 - * $FreeBSD: src/sys/ufs/ffs/ffs_snapshot.c,v 1.67 2003/04/12 01:05:19 jeff Exp $ + * $FreeBSD: src/sys/ufs/ffs/ffs_snapshot.c,v 1.68 2003/04/22 20:45:38 jhb Exp $ */ #include <sys/param.h> @@ -300,8 +300,12 @@ * Recind nice scheduling while running with the filesystem suspended. */ if (td->td_ksegrp->kg_nice > 0) { + PROC_LOCK(td->td_proc); + mtx_lock_spin(&sched_lock); saved_nice = td->td_ksegrp->kg_nice; sched_nice(td->td_ksegrp, 0); + mtx_unlock_spin(&sched_lock); + PROC_UNLOCK(td->td_proc); } /* * Suspend operation on filesystem. @@ -644,8 +648,13 @@ free(copy_fs->fs_csp, M_UFSMNT); bawrite(sbp); out: - if (saved_nice > 0) + if (saved_nice > 0) { + PROC_LOCK(td->td_proc); + mtx_lock_spin(&sched_lock); sched_nice(td->td_ksegrp, saved_nice); + mtx_unlock_spin(&sched_lock); + PROC_UNLOCK(td->td_proc); + } if (fs->fs_active != 0) { FREE(fs->fs_active, M_DEVBUF); fs->fs_active = 0;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200304222058.h3MKwmcj083931>