diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 3d232cf744c5..79a294d37e3d 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -668,11 +668,11 @@ stopprofclock(p) PROC_LOCK_ASSERT(p, MA_OWNED); if (p->p_flag & P_PROFIL) { if (p->p_profthreads != 0) { - p->p_flag |= P_STOPPROF; - while (p->p_profthreads != 0) + while (p->p_profthreads != 0) { + p->p_flag |= P_STOPPROF; msleep(&p->p_profthreads, &p->p_mtx, PPAUSE, "stopprof", 0); - p->p_flag &= ~P_STOPPROF; + } } if ((p->p_flag & P_PROFIL) == 0) return; diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c index efd66b274ea5..cedfc1b3d1db 100644 --- a/sys/kern/subr_prof.c +++ b/sys/kern/subr_prof.c @@ -533,6 +533,7 @@ addupc_task(struct thread *td, uintfptr_t pc, u_int ticks) if (--p->p_profthreads == 0) { if (p->p_flag & P_STOPPROF) { wakeup(&p->p_profthreads); + p->p_flag &= ~P_STOPPROF; stop = 0; } }