Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Change SDT (Statically Defined Tracing) probes to use li...



details:   https://anonhg.NetBSD.org/src/rev/70b74b2a276d
branches:  trunk
changeset: 810940:70b74b2a276d
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Oct 02 16:54:15 2015 +0000

description:
Change SDT (Statically Defined Tracing) probes to use link sets so that it
is easier to add probes. (From FreeBSD)

diffstat:

 sys/kern/kern_exec.c |   28 +-
 sys/kern/kern_exit.c |   14 +-
 sys/kern/kern_fork.c |   17 +-
 sys/kern/kern_lwp.c  |   27 +-
 sys/kern/kern_sdt.c  |   22 ++-
 sys/kern/kern_sig.c  |   62 +++---
 sys/kern/sys_sig.c   |   17 +-
 sys/kern/vfs_cache.c |   53 +++++-
 sys/sys/sdt.h        |  482 ++++++++++++++++++++++++++++++++++++++++----------
 9 files changed, 539 insertions(+), 183 deletions(-)

diffs (truncated from 1186 to 300 lines):

diff -r 3364c7638114 -r 70b74b2a276d sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Fri Oct 02 16:04:40 2015 +0000
+++ b/sys/kern/kern_exec.c      Fri Oct 02 16:54:15 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.417 2015/09/26 16:12:24 maxv Exp $     */
+/*     $NetBSD: kern_exec.c,v 1.418 2015/10/02 16:54:15 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.417 2015/09/26 16:12:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.418 2015/10/02 16:54:15 christos Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -148,18 +148,10 @@
 /*
  * DTrace SDT provider definitions
  */
-SDT_PROBE_DEFINE(proc,,,exec,exec,
-           "char *", NULL,
-           NULL, NULL, NULL, NULL,
-           NULL, NULL, NULL, NULL);
-SDT_PROBE_DEFINE(proc,,,exec_success,exec-success, 
-           "char *", NULL,
-           NULL, NULL, NULL, NULL,
-           NULL, NULL, NULL, NULL);
-SDT_PROBE_DEFINE(proc,,,exec_failure,exec-failure, 
-           "int", NULL,
-           NULL, NULL, NULL, NULL,
-           NULL, NULL, NULL, NULL);
+SDT_PROVIDER_DECLARE(proc);
+SDT_PROBE_DEFINE1(proc, kernel, , exec, "char *");
+SDT_PROBE_DEFINE1(proc, kernel, , exec__success, "char *");
+SDT_PROBE_DEFINE1(proc, kernel, , exec__failure, "int");
 
 /*
  * Exec function switch:
@@ -660,7 +652,7 @@
        p = l->l_proc;
        modgen = 0;
 
-       SDT_PROBE(proc,,,exec, path, 0, 0, 0, 0);
+       SDT_PROBE(proc, kernel, , exec, path, 0, 0, 0, 0);
 
        /*
         * Check if we have exceeded our number of processes limit.
@@ -822,7 +814,7 @@
                goto retry;
        }
 
-       SDT_PROBE(proc,,,exec_failure, error, 0, 0, 0, 0);
+       SDT_PROBE(proc, kernel, , exec__failure, error, 0, 0, 0, 0);
        return error;
 }
 
@@ -1265,7 +1257,7 @@
 
        kmem_free(epp->ep_hdr, epp->ep_hdrlen);
 
-       SDT_PROBE(proc,,,exec_success, epp->ep_kname, 0, 0, 0, 0);
+       SDT_PROBE(proc, kernel, , exec__success, epp->ep_kname, 0, 0, 0, 0);
 
        emulexec(l, epp);
 
@@ -1316,7 +1308,7 @@
        return EJUSTRETURN;
 
  exec_abort:
-       SDT_PROBE(proc,,,exec_failure, error, 0, 0, 0, 0);
+       SDT_PROBE(proc, kernel, , exec__failure, error, 0, 0, 0, 0);
        rw_exit(&p->p_reflock);
        if (!no_local_exec_lock)
                rw_exit(&exec_lock);
diff -r 3364c7638114 -r 70b74b2a276d sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Fri Oct 02 16:04:40 2015 +0000
+++ b/sys/kern/kern_exit.c      Fri Oct 02 16:54:15 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exit.c,v 1.244 2014/05/05 15:45:32 christos Exp $ */
+/*     $NetBSD: kern_exit.c,v 1.245 2015/10/02 16:54:15 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,9 +67,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.244 2014/05/05 15:45:32 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.245 2015/10/02 16:54:15 christos Exp $");
 
 #include "opt_ktrace.h"
+#include "opt_dtrace.h"
 #include "opt_perfctrs.h"
 #include "opt_sysv.h"
 
@@ -123,10 +124,9 @@
 /*
  * DTrace SDT provider definitions
  */
-SDT_PROBE_DEFINE(proc,,,exit,exit,
-           "int", NULL,                /* reason */
-           NULL, NULL, NULL, NULL,
-           NULL, NULL, NULL, NULL);
+SDT_PROVIDER_DECLARE(proc);
+SDT_PROBE_DEFINE1(proc, kernel, , exit, "int");
+
 /*
  * Fill in the appropriate signal information, and signal the parent.
  */
@@ -414,7 +414,7 @@
         */
        KNOTE(&p->p_klist, NOTE_EXIT);
 
-       SDT_PROBE(proc,,,exit,
+       SDT_PROBE(proc, kernel, , exit,
                (WCOREDUMP(rv) ? CLD_DUMPED :
                 (WIFSIGNALED(rv) ? CLD_KILLED : CLD_EXITED)),
                0,0,0,0);
diff -r 3364c7638114 -r 70b74b2a276d sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c      Fri Oct 02 16:04:40 2015 +0000
+++ b/sys/kern/kern_fork.c      Fri Oct 02 16:54:15 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_fork.c,v 1.193 2013/11/22 21:04:11 christos Exp $ */
+/*     $NetBSD: kern_fork.c,v 1.194 2015/10/02 16:54:15 christos Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,9 +67,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.193 2013/11/22 21:04:11 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.194 2015/10/02 16:54:15 christos Exp $");
 
 #include "opt_ktrace.h"
+#include "opt_dtrace.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -98,11 +99,11 @@
 /*
  * DTrace SDT provider definitions
  */
-SDT_PROBE_DEFINE(proc,,,create,create,
-           "struct proc *", NULL,      /* new process */
-           "struct proc *", NULL,      /* parent process */
-           "int", NULL,                /* flags */
-           NULL, NULL, NULL, NULL);
+SDT_PROVIDER_DECLARE(proc);
+SDT_PROBE_DEFINE3(proc, kernel, , create,
+    "struct proc *", /* new process */
+    "struct proc *", /* parent process */
+    "int" /* flags */);
 
 u_int  nprocs __cacheline_aligned = 1;         /* process 0 */
 
@@ -455,7 +456,7 @@
         */
        doforkhooks(p2, p1);
 
-       SDT_PROBE(proc,,,create, p2, p1, flags, 0, 0);
+       SDT_PROBE(proc, kernel, , create, p2, p1, flags, 0, 0);
 
        /*
         * It's now safe for the scheduler and other processes to see the
diff -r 3364c7638114 -r 70b74b2a276d sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Fri Oct 02 16:04:40 2015 +0000
+++ b/sys/kern/kern_lwp.c       Fri Oct 02 16:54:15 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lwp.c,v 1.179 2014/10/18 08:33:29 snj Exp $       */
+/*     $NetBSD: kern_lwp.c,v 1.180 2015/10/02 16:54:15 christos Exp $  */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.179 2014/10/18 08:33:29 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.180 2015/10/02 16:54:15 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -251,18 +251,11 @@
 static void            lwp_dtor(void *, void *);
 
 /* DTrace proc provider probes */
-SDT_PROBE_DEFINE(proc,,,lwp_create,lwp-create,
-       "struct lwp *", NULL,
-       NULL, NULL, NULL, NULL,
-       NULL, NULL, NULL, NULL);
-SDT_PROBE_DEFINE(proc,,,lwp_start,lwp-start,
-       "struct lwp *", NULL,
-       NULL, NULL, NULL, NULL,
-       NULL, NULL, NULL, NULL);
-SDT_PROBE_DEFINE(proc,,,lwp_exit,lwp-exit,
-       "struct lwp *", NULL,
-       NULL, NULL, NULL, NULL,
-       NULL, NULL, NULL, NULL);
+SDT_PROVIDER_DEFINE(proc);
+
+SDT_PROBE_DEFINE1(proc, kernel, , lwp__create, "struct lwp *");
+SDT_PROBE_DEFINE1(proc, kernel, , lwp__start, "struct lwp *");
+SDT_PROBE_DEFINE1(proc, kernel, , lwp__exit, "struct lwp *");
 
 struct turnstile turnstile0;
 struct lwp lwp0 __aligned(MIN_LWP_ALIGNMENT) = {
@@ -961,7 +954,7 @@
        }
        mutex_exit(p2->p_lock);
 
-       SDT_PROBE(proc,,,lwp_create, l2, 0,0,0,0);
+       SDT_PROBE(proc, kernel, , lwp__create, l2, 0, 0, 0, 0);
 
        mutex_enter(proc_lock);
        LIST_INSERT_HEAD(&alllwp, l2, l_list);
@@ -985,7 +978,7 @@
 {
        KASSERTMSG(new_lwp == curlwp, "l %p curlwp %p prevlwp %p", new_lwp, curlwp, prev);
 
-       SDT_PROBE(proc,,,lwp_start, new_lwp, 0,0,0,0);
+       SDT_PROBE(proc, kernel, , lwp__start, new_lwp, 0, 0, 0, 0);
 
        KASSERT(kpreempt_disabled());
        if (prev != NULL) {
@@ -1028,7 +1021,7 @@
        KASSERT(current || (l->l_stat == LSIDL && l->l_target_cpu == NULL));
        KASSERT(p == curproc);
 
-       SDT_PROBE(proc,,,lwp_exit, l, 0,0,0,0);
+       SDT_PROBE(proc, kernel, , lwp__exit, l, 0, 0, 0, 0);
 
        /*
         * Verify that we hold no locks other than the kernel lock.
diff -r 3364c7638114 -r 70b74b2a276d sys/kern/kern_sdt.c
--- a/sys/kern/kern_sdt.c       Fri Oct 02 16:04:40 2015 +0000
+++ b/sys/kern/kern_sdt.c       Fri Oct 02 16:54:15 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sdt.c,v 1.1 2010/03/01 21:10:17 darran Exp $      */
+/*     $NetBSD: kern_sdt.c,v 1.2 2015/10/02 16:54:15 christos Exp $    */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -62,6 +62,9 @@
  * not be present. A module may be built with SDT probes in it.
  *
  */
+#ifdef _KERNEL_OPT
+#include "opt_dtrace.h"
+#endif
 
 #include <sys/cdefs.h>
 #include <sys/param.h>
@@ -71,6 +74,10 @@
 void sdt_probe_stub(u_int32_t, uintptr_t, uintptr_t,
        uintptr_t, uintptr_t, uintptr_t);
 
+__link_set_decl(sdt_providers_set, struct sdt_provider);
+__link_set_decl(sdt_probes_set, struct sdt_probe);
+__link_set_decl(sdt_argtypes_set, struct sdt_argtype);
+
 /*
  * Hook for the DTrace probe function. The 'sdt' provider will set this
  * to dtrace_probe when it loads.
@@ -86,7 +93,20 @@
 sdt_probe_stub(u_int32_t id, uintptr_t arg0, uintptr_t arg1,
     uintptr_t arg2, uintptr_t arg3, uintptr_t arg4)
 {
+       struct sdt_provider * const * provider;
+       struct sdt_probe * const * probe;
+       struct sdt_argtype * const * argtype;
        printf("%s: XXX should not be called\n", __func__);
+       printf("providers: ");
+       __link_set_foreach(provider, sdt_providers_set)
+               printf("%s ", (*provider)->name);
+       printf("\nprobes: ");
+       __link_set_foreach(probe, sdt_probes_set)
+               printf("%s ", (*probe)->name);
+       printf("\nargtypes: ");
+       __link_set_foreach(argtype, sdt_argtypes_set)
+               printf("%s ", (*argtype)->type);
+       printf("\n");
 }
 
 /*
diff -r 3364c7638114 -r 70b74b2a276d sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Fri Oct 02 16:04:40 2015 +0000
+++ b/sys/kern/kern_sig.c       Fri Oct 02 16:54:15 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.319 2013/11/22 21:04:11 christos Exp $  */
+/*     $NetBSD: kern_sig.c,v 1.320 2015/10/02 16:54:15 christos Exp $  */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,9 +70,10 @@
  */
 



Home | Main Index | Thread Index | Old Index