Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src DTrace: Add an SDT (Statically Defined Tracing) provider fra...
details: https://anonhg.NetBSD.org/src/rev/ec7568a0a083
branches: trunk
changeset: 752587:ec7568a0a083
user: darran <darran%NetBSD.org@localhost>
date: Mon Mar 01 21:10:13 2010 +0000
description:
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
diffstat:
distrib/sets/lists/modules/mi | 8 +-
external/cddl/osnet/dev/sdt/sdt.c | 514 +++++++++++++++++++++++++++----------
sys/conf/Makefile.kern.inc | 26 +-
sys/conf/files | 3 +-
sys/kern/kern_exec.c | 27 +-
sys/kern/kern_exit.c | 17 +-
sys/kern/kern_fork.c | 16 +-
sys/kern/kern_ksyms.c | 74 ++++-
sys/kern/kern_lwp.c | 25 +-
sys/kern/kern_sdt.c | 110 ++++++++
sys/kern/kern_sig.c | 35 ++-
sys/modules/dtrace/Makefile | 4 +-
sys/modules/dtrace/sdt/Makefile | 13 +
sys/sys/Makefile | 4 +-
sys/sys/ksyms.h | 9 +-
sys/sys/sdt.h | 128 +++++++++
16 files changed, 831 insertions(+), 182 deletions(-)
diffs (truncated from 1575 to 300 lines):
diff -r af4ff2345397 -r ec7568a0a083 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi Mon Mar 01 20:38:19 2010 +0000
+++ b/distrib/sets/lists/modules/mi Mon Mar 01 21:10:13 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.7 2010/02/21 03:18:47 darran Exp $
+# $NetBSD: mi,v 1.8 2010/03/01 21:10:19 darran Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -92,6 +92,8 @@
./@MODULEDIR@/puffs/puffs.kmod base-kernel-modules kmod
./@MODULEDIR@/putter base-kernel-modules kmod
./@MODULEDIR@/putter/putter.kmod base-kernel-modules kmod
+./@MODULEDIR@/sdt base-kernel-modules kmod,dtrace
+./@MODULEDIR@/sdt/sdt.kmod base-kernel-modules kmod,dtrace
./@MODULEDIR@/secmodel_bsd44 base-kernel-modules kmod
./@MODULEDIR@/secmodel_bsd44/secmodel_bsd44.kmod base-kernel-modules kmod
./@MODULEDIR@/secmodel_overlay base-kernel-modules kmod
@@ -100,8 +102,8 @@
./@MODULEDIR@/securelevel/securelevel.kmod base-kernel-modules kmod
./@MODULEDIR@/smbfs base-kernel-modules kmod
./@MODULEDIR@/smbfs/smbfs.kmod base-kernel-modules kmod
-./@MODULEDIR@/solaris base-kernel-modules kmod,zfs
-./@MODULEDIR@/solaris/solaris.kmod base-kernel-modules kmod,zfs
+./@MODULEDIR@/solaris base-kernel-modules kmod,dtrace
+./@MODULEDIR@/solaris/solaris.kmod base-kernel-modules kmod,dtrace
./@MODULEDIR@/suser base-kernel-modules kmod
./@MODULEDIR@/suser/suser.kmod base-kernel-modules kmod
./@MODULEDIR@/sysvbfs base-kernel-modules kmod
diff -r af4ff2345397 -r ec7568a0a083 external/cddl/osnet/dev/sdt/sdt.c
--- a/external/cddl/osnet/dev/sdt/sdt.c Mon Mar 01 20:38:19 2010 +0000
+++ b/external/cddl/osnet/dev/sdt/sdt.c Mon Mar 01 21:10:13 2010 +0000
@@ -1,33 +1,38 @@
-/* $NetBSD: sdt.c,v 1.2 2010/02/21 01:46:33 darran Exp $ */
+/* $NetBSD: sdt.c,v 1.3 2010/03/01 21:10:19 darran Exp $ */
-/*
- * CDDL HEADER START
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
*
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by CoyotePoint Systems, Inc. It was developed under contract to
+ * CoyotePoint by Darran Hunt.
*
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
*
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- * Portions Copyright 2006-2008 John Birrell jb%freebsd.org@localhost
- *
- * $FreeBSD: src/sys/cddl/dev/sdt/sdt.c,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
- *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDTRACE_HOOKS
-#define KDTRACE_HOOKS
+#ifdef _KERNEL_OPT
+#include "opt_dtrace.h"
#endif
#include <sys/cdefs.h>
@@ -35,42 +40,34 @@
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/kernel.h>
-#include <sys/limits.h>
-#include <sys/lock.h>
-#include <sys/linker.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/dtrace.h>
+
+#define KDTRACE_HOOKS
#include <sys/sdt.h>
-#define SDT_ADDR2NDX(addr) (((uintptr_t)(addr)) >> 4)
+#undef SDT_DEBUG
-static d_open_t sdt_open;
+static dev_type_open(sdt_open);
+
static int sdt_unload(void);
static void sdt_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
-static void sdt_provide_probes(void *, dtrace_probedesc_t *);
+static void sdt_provide(void *, dtrace_probedesc_t *);
static void sdt_destroy(void *, dtrace_id_t, void *);
static void sdt_enable(void *, dtrace_id_t, void *);
static void sdt_disable(void *, dtrace_id_t, void *);
static void sdt_load(void *);
-static struct cdevsw sdt_cdevsw = {
- .d_version = D_VERSION,
- .d_open = sdt_open,
- .d_name = "sdt",
-};
-
-static dtrace_pattr_t sdt_attr = {
-{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
-{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
-{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
-{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
-{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+static const struct cdevsw sdt_cdevsw = {
+ sdt_open, noclose, noread, nowrite, noioctl,
+ nostop, notty, nopoll, nommap, nokqfilter,
+ D_OTHER
};
static dtrace_pops_t sdt_pops = {
- sdt_provide_probes,
+ sdt_provide,
NULL,
sdt_enable,
sdt_disable,
@@ -84,173 +81,396 @@
static struct cdev *sdt_cdev;
-static int
-sdt_argtype_callback(struct sdt_argtype *argtype, void *arg)
-{
- dtrace_argdesc_t *desc = arg;
+/*
+ * Provider and probe definitions
+ */
+
+/*
+ * proc provider
+ */
+
+/* declare all probes belonging to the provider */
+SDT_PROBE_DECLARE(proc,,,create);
+SDT_PROBE_DECLARE(proc,,,exec);
+SDT_PROBE_DECLARE(proc,,,exec_success);
+SDT_PROBE_DECLARE(proc,,,exec_failure);
+SDT_PROBE_DECLARE(proc,,,signal_send);
+SDT_PROBE_DECLARE(proc,,,signal_discard);
+SDT_PROBE_DECLARE(proc,,,signal_clear);
+SDT_PROBE_DECLARE(proc,,,signal_handle);
+SDT_PROBE_DECLARE(proc,,,lwp_create);
+SDT_PROBE_DECLARE(proc,,,lwp_start);
+SDT_PROBE_DECLARE(proc,,,lwp_exit);
- if (desc->dtargd_ndx == argtype->ndx) {
- desc->dtargd_mapping = desc->dtargd_ndx; /* XXX */
- strlcpy(desc->dtargd_native, argtype->type,
- sizeof(desc->dtargd_native));
- desc->dtargd_xlate[0] = '\0'; /* XXX */
- }
+/* define the provider */
+static sdt_provider_t l7_provider = {
+ "proc", /* provider name */
+ 0, /* registered ID - leave as 0 */
+ {
+ { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+ { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+ { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+ { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+ { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+ },
- return (0);
-}
+ /* list all probes belonging to the provider */
+ {
+ &SDT_NAME(proc,,,create),
+ &SDT_NAME(proc,,,exec),
+ &SDT_NAME(proc,,,exec_success),
+ &SDT_NAME(proc,,,exec_failure),
+ &SDT_NAME(proc,,,signal_send),
+ &SDT_NAME(proc,,,signal_discard),
+ &SDT_NAME(proc,,,signal_clear),
+ &SDT_NAME(proc,,,signal_handle),
+ &SDT_NAME(proc,,,lwp_create),
+ &SDT_NAME(proc,,,lwp_start),
+ &SDT_NAME(proc,,,lwp_exit),
+ NULL /* NULL terminated list */
+ }
+};
+
+/* list of local providers to register with DTrace */
+static sdt_provider_t *sdt_providers[] = {
+ &l7_provider,
+ NULL /* NULL terminated list */
+};
+
+static sdt_provider_t **sdt_list = NULL; /* registered provider list */
+static kmutex_t sdt_mutex;
+static int sdt_count = 0; /* number of registered providers */
static void
sdt_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
{
- struct sdt_probe *probe = parg;
-
- if (desc->dtargd_ndx < probe->n_args)
- (void) (sdt_argtype_listall(probe, sdt_argtype_callback, desc));
- else
- desc->dtargd_ndx = DTRACE_ARGNONE;
+ sdt_provider_t *sprov = arg;
+ sdt_probe_t *sprobe = parg;
+ int res;
+ int ind;
- return;
-}
-
-static int
-sdt_probe_callback(struct sdt_probe *probe, void *arg __unused)
-{
- struct sdt_provider *prov = probe->prov;
- char mod[64];
- char func[64];
- char name[64];
+#ifdef SDT_DEBUG
+ printf("sdt: %s probe %d\n", __func__, id);
+ printf("%s: probe %d (%s:%s:%s:%s).%d\n",
+ __func__, id,
+ sprobe->provider,
+ sprobe->module,
+ sprobe->function,
+ sprobe->name,
+ desc->dtargd_ndx);
+#endif
- /*
- * Unfortunately this is necessary because the Solaris DTrace
- * code mixes consts and non-consts with casts to override
- * the incompatibilies. On FreeBSD, we use strict warnings
- * in gcc, so we have to respect const vs non-const.
- */
- strlcpy(mod, probe->mod, sizeof(mod));
- strlcpy(func, probe->func, sizeof(func));
- strlcpy(name, probe->name, sizeof(name));
-
- if (dtrace_probe_lookup(prov->id, mod, func, name) != 0)
- return (0);
-
- (void) dtrace_probe_create(prov->id, probe->mod, probe->func,
- probe->name, 0, probe);
-
- return (0);
-}
-
-static int
-sdt_provider_entry(struct sdt_provider *prov, void *arg)
-{
- return (sdt_probe_listall(prov, sdt_probe_callback, NULL));
+ /* provide up to 5 arguments */
+ if ((desc->dtargd_ndx < SDT_MAX_ARGS) &&
+ (sprobe->argv[desc->dtargd_ndx] != NULL)) {
+ strncpy(desc->dtargd_native, sprobe->argv[desc->dtargd_ndx],
+ sizeof(desc->dtargd_native));
+ desc->dtargd_mapping = desc->dtargd_ndx;
+ if (sprobe->argx[desc->dtargd_ndx] != NULL) {
+ strncpy(desc->dtargd_xlate, sprobe->argx[desc->dtargd_ndx],
+ sizeof(desc->dtargd_xlate));
+ }
+#ifdef SDT_DEBUG
+ printf("%s: probe %d (%s:%s:%s:%s).%d = %s\n",
+ __func__, id,
+ sprobe->provider,
+ sprobe->module,
+ sprobe->function,
+ sprobe->name,
Home |
Main Index |
Thread Index |
Old Index