From owner-svn-src-head@FreeBSD.ORG Thu Sep 9 09:58:05 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0E2C10656F2; Thu, 9 Sep 2010 09:58:05 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AE7F18FC08; Thu, 9 Sep 2010 09:58:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o899w5DG060836; Thu, 9 Sep 2010 09:58:05 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o899w522060831; Thu, 9 Sep 2010 09:58:05 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <201009090958.o899w522060831@svn.freebsd.org> From: Rui Paulo Date: Thu, 9 Sep 2010 09:58:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212357 - in head/sys: cddl/contrib/opensolaris/uts/common/dtrace cddl/contrib/opensolaris/uts/common/sys kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Sep 2010 09:58:05 -0000 Author: rpaulo Date: Thu Sep 9 09:58:05 2010 New Revision: 212357 URL: http://svn.freebsd.org/changeset/base/212357 Log: Fix two bugs in DTrace: * when the process exits, remove the associated USDT probes * when the process forks, duplicate the USDT probes. Sponsored by: The FreeBSD Foundation Modified: head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c head/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h head/sys/kern/kern_fork.c Modified: head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c Thu Sep 9 07:55:13 2010 (r212356) +++ head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c Thu Sep 9 09:58:05 2010 (r212357) @@ -9218,7 +9218,6 @@ dtrace_difo_init(dtrace_difo_t *dp, dtra dtrace_difo_hold(dp); } -#if defined(sun) static dtrace_difo_t * dtrace_difo_duplicate(dtrace_difo_t *dp, dtrace_vstate_t *vstate) { @@ -9262,7 +9261,6 @@ dtrace_difo_duplicate(dtrace_difo_t *dp, dtrace_difo_init(new, vstate); return (new); } -#endif static void dtrace_difo_destroy(dtrace_difo_t *dp, dtrace_vstate_t *vstate) @@ -14615,12 +14613,16 @@ dtrace_helpers_create(proc_t *p) } #if defined(sun) -static void -dtrace_helpers_destroy(void) +static +#endif +void +dtrace_helpers_destroy(proc_t *p) { dtrace_helpers_t *help; dtrace_vstate_t *vstate; +#if defined(sun) proc_t *p = curproc; +#endif int i; mutex_enter(&dtrace_lock); @@ -14707,7 +14709,10 @@ dtrace_helpers_destroy(void) mutex_exit(&dtrace_lock); } -static void +#if defined(sun) +static +#endif +void dtrace_helpers_duplicate(proc_t *from, proc_t *to) { dtrace_helpers_t *help, *newhelp; @@ -14788,7 +14793,6 @@ dtrace_helpers_duplicate(proc_t *from, p if (hasprovs) dtrace_helper_provider_register(to, newhelp, NULL); } -#endif #if defined(sun) /* Modified: head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c Thu Sep 9 07:55:13 2010 (r212356) +++ head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c Thu Sep 9 09:58:05 2010 (r212357) @@ -456,6 +456,16 @@ fasttrap_fork(proc_t *p, proc_t *cp) #if defined(sun) ASSERT(p->p_dtrace_count > 0); #else + if (p->p_dtrace_helpers) { + /* + * dtrace_helpers_duplicate() allocates memory. + */ + PROC_UNLOCK(p); + PROC_UNLOCK(cp); + dtrace_helpers_duplicate(p, cp); + PROC_LOCK(cp); + PROC_LOCK(p); + } /* * This check is purposely here instead of in kern_fork.c because, * for legal resons, we cannot include the dtrace_cddl.h header @@ -539,6 +549,10 @@ fasttrap_exec_exit(proc_t *p) * static probes are handled by the meta-provider remove entry point. */ fasttrap_provider_retire(p->p_pid, FASTTRAP_PID_NAME, 0); +#if !defined(sun) + if (p->p_dtrace_helpers) + dtrace_helpers_destroy(p); +#endif PROC_LOCK(p); } Modified: head/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h Thu Sep 9 07:55:13 2010 (r212356) +++ head/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h Thu Sep 9 09:58:05 2010 (r212357) @@ -2289,6 +2289,11 @@ extern int dtrace_blksuword32(uintptr_t, extern void dtrace_getfsr(uint64_t *); #endif +#if !defined(sun) +extern void dtrace_helpers_duplicate(proc_t *, proc_t *); +extern void dtrace_helpers_destroy(proc_t *); +#endif + #define DTRACE_CPUFLAG_ISSET(flag) \ (cpu_core[curcpu].cpuc_dtrace_flags & (flag)) Modified: head/sys/kern/kern_fork.c ============================================================================== --- head/sys/kern/kern_fork.c Thu Sep 9 07:55:13 2010 (r212356) +++ head/sys/kern/kern_fork.c Thu Sep 9 09:58:05 2010 (r212357) @@ -671,15 +671,6 @@ again: p2->p_pfsflags = p1->p_pfsflags; } -#ifdef KDTRACE_HOOKS - /* - * Tell the DTrace fasttrap provider about the new process - * if it has registered an interest. - */ - if (dtrace_fasttrap_fork) - dtrace_fasttrap_fork(p1, p2); -#endif - /* * This begins the section where we must prevent the parent * from being swapped. @@ -744,6 +735,21 @@ again: PROC_SLOCK(p2); p2->p_state = PRS_NORMAL; PROC_SUNLOCK(p2); +#ifdef KDTRACE_HOOKS + /* + * Tell the DTrace fasttrap provider about the new process + * if it has registered an interest. We have to do this only after + * p_state is PRS_NORMAL since the fasttrap module will use pfind() + * later on. + */ + if (dtrace_fasttrap_fork) { + PROC_LOCK(p1); + PROC_LOCK(p2); + dtrace_fasttrap_fork(p1, p2); + PROC_UNLOCK(p2); + PROC_UNLOCK(p1); + } +#endif /* * If RFSTOPPED not requested, make child runnable and add to