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
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to