From 128ae3c8d893885f814d7838d0d6b55e38ebd5a9 Mon Sep 17 00:00:00 2001 From: jhb Date: Tue, 22 Apr 2003 20:54:04 +0000 Subject: - Move PS_PROFIL and its new cousin PS_STOPPROF back over to p_flag and rename them appropriately. Protect both flags with both the proc lock and the sched_lock. - Protect p_profthreads with the proc lock. - Remove Giant from profil(2). --- sys/kern/kern_clock.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'sys/kern/kern_clock.c') diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index d6c49d2..3d04cf0 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -303,17 +303,16 @@ startprofclock(p) * 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 @@ stopprofclock(p) { 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 @@ profclock(frame) * 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 -- cgit v1.1