From cf07da2f1a9c11bd6217a035a0030e534abf083b Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 8 Feb 2003 02:58:16 +0000 Subject: A little infrastructure, preceding some upcoming changes to the profiling and statistics code. Submitted by: DavidXu@ Reviewed by: peter@ --- sys/kern/kern_clock.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'sys/kern/kern_clock.c') diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 5c6756b..25e558a 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -313,6 +313,10 @@ startprofclock(p) * cover psdiv, etc. as well. */ mtx_lock_spin(&sched_lock); + if (p->p_sflag & PS_STOPPROF) { + mtx_unlock_spin(&sched_lock); + return; + } if ((p->p_sflag & PS_PROFIL) == 0) { p->p_sflag |= PS_PROFIL; if (++profprocs == 1) @@ -329,9 +333,18 @@ stopprofclock(p) register struct proc *p; { + PROC_LOCK_ASSERT(p, MA_OWNED); +retry: mtx_lock_spin(&sched_lock); if (p->p_sflag & PS_PROFIL) { - 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; + } + p->p_sflag &= ~(PS_PROFIL|PS_STOPPROF); if (--profprocs == 0) cpu_stopprofclock(); } @@ -400,7 +413,7 @@ statclock(frame) } } - sched_clock(ke->ke_thread); + sched_clock(td); /* Update resource usage integrals and maximums. */ if ((pstats = p->p_stats) != NULL && @@ -430,9 +443,12 @@ profclock(frame) /* * Came from user mode; CPU was in user state. * If this process is being profiled, record the tick. + * if there is no related user location yet, don't + * bother trying to count it. */ td = curthread; - if (td->td_proc->p_sflag & PS_PROFIL) + if ((td->td_proc->p_sflag & PS_PROFIL) && + !(td->td_flags & TDF_UPCALLING)) addupc_intr(td->td_kse, CLKF_PC(frame), 1); } #ifdef GPROF -- cgit v1.1