Module Name:    src
Committed By:   chs
Date:           Fri Dec  7 03:11:17 UTC 2012

Modified Files:
        src/external/cddl/osnet/dev/profile: profile.c

Log Message:
adapt the profile dtrace provider to netbsd.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/cddl/osnet/dev/profile/profile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/cddl/osnet/dev/profile/profile.c
diff -u src/external/cddl/osnet/dev/profile/profile.c:1.3 src/external/cddl/osnet/dev/profile/profile.c:1.4
--- src/external/cddl/osnet/dev/profile/profile.c:1.3	Sun Jul 17 20:54:33 2011
+++ src/external/cddl/osnet/dev/profile/profile.c	Fri Dec  7 03:11:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: profile.c,v 1.3 2011/07/17 20:54:33 joerg Exp $	*/
+/*	$NetBSD: profile.c,v 1.4 2012/12/07 03:11:17 chs Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -38,7 +38,9 @@
 #include <sys/cpuvar.h>
 #include <sys/fcntl.h>
 #include <sys/filio.h>
+#ifdef __FreeBSD__
 #include <sys/kdb.h>
+#endif
 #include <sys/kernel.h>
 #include <sys/kmem.h>
 #include <sys/kthread.h>
@@ -51,10 +53,18 @@
 #include <sys/poll.h>
 #include <sys/proc.h>
 #include <sys/selinfo.h>
+#ifdef __FreeBSD__
 #include <sys/smp.h>
+#endif
 #include <sys/uio.h>
 #include <sys/unistd.h>
 
+#ifdef __NetBSD__
+#include <sys/atomic.h>
+#include <sys/cpu.h>
+#define ASSERT(x) KASSERT(x)
+#endif
+
 #include <sys/cyclic.h>
 #include <sys/dtrace.h>
 #include <sys/dtrace_bsd.h>
@@ -97,6 +107,7 @@
  * and the static definition doesn't seem to be overly brittle.  Still, we
  * allow for a manual override in case we get it completely wrong.
  */
+#ifdef __FreeBSD__
 #ifdef __amd64
 #define	PROF_ARTIFICIAL_FRAMES	7
 #else
@@ -112,6 +123,11 @@
 #endif
 #endif
 #endif
+#endif
+
+#ifdef __NetBSD__
+#define	PROF_ARTIFICIAL_FRAMES	3
+#endif
 
 typedef struct profile_probe {
 	char		prof_name[PROF_NAMELEN];
@@ -127,14 +143,16 @@ typedef struct profile_probe_percpu {
 	profile_probe_t	*profc_probe;
 } profile_probe_percpu_t;
 
+#ifdef __FreeBSD__
 static d_open_t	profile_open;
+#endif
 static int	profile_unload(void);
 static void	profile_create(hrtime_t, char *, int);
 static void	profile_destroy(void *, dtrace_id_t, void *);
-static void	profile_enable(void *, dtrace_id_t, void *);
+static int	profile_enable(void *, dtrace_id_t, void *);
 static void	profile_disable(void *, dtrace_id_t, void *);
 static void	profile_load(void *);
-static void	profile_provide(void *, dtrace_probedesc_t *);
+static void	profile_provide(void *, const dtrace_probedesc_t *);
 
 static int profile_rates[] = {
     97, 199, 499, 997, 1999,
@@ -161,11 +179,13 @@ static uint32_t profile_max = PROFILE_MA
 					/* maximum number of profile probes */
 static uint32_t profile_total;		/* current number of profile probes */
 
+#ifdef __FreeBSD__
 static struct cdevsw profile_cdevsw = {
 	.d_version	= D_VERSION,
 	.d_open		= profile_open,
 	.d_name		= "profile",
 };
+#endif
 
 static dtrace_pattr_t profile_attr = {
 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
@@ -188,7 +208,9 @@ static dtrace_pops_t profile_pops = {
 	profile_destroy
 };
 
+#ifdef __FreeBSD__
 static struct cdev		*profile_cdev;
+#endif
 static dtrace_provider_id_t	profile_id;
 static hrtime_t			profile_interval_min = NANOSEC / 5000;	/* 5000 hz */
 static int			profile_aframes = 0;			/* override */
@@ -199,7 +221,7 @@ profile_fire(void *arg)
 	profile_probe_percpu_t *pcpu = arg;
 	profile_probe_t *prof = pcpu->profc_probe;
 	hrtime_t late;
-	solaris_cpu_t *c = &solaris_cpu[curcpu];
+	solaris_cpu_t *c = &solaris_cpu[cpu_number()];
 
 	late = gethrtime() - pcpu->profc_expected;
 	pcpu->profc_expected += pcpu->profc_interval;
@@ -212,7 +234,7 @@ static void
 profile_tick(void *arg)
 {
 	profile_probe_t *prof = arg;
-	solaris_cpu_t *c = &solaris_cpu[curcpu];
+	solaris_cpu_t *c = &solaris_cpu[cpu_number()];
 
 	dtrace_probe(prof->prof_id, c->cpu_profile_pc,
 	    c->cpu_profile_upc, 0, 0, 0);
@@ -247,14 +269,14 @@ profile_create(hrtime_t interval, char *
 
 /*ARGSUSED*/
 static void
-profile_provide(void *arg, dtrace_probedesc_t *desc)
+profile_provide(void *arg, const dtrace_probedesc_t *desc)
 {
 	int i, j, rate, kind;
 	hrtime_t val = 0, mult = 1, len = 0;
 	char *name, *suffix = NULL;
 
 	const struct {
-		char *prefix;
+		const char *prefix;
 		int kind;
 	} types[] = {
 		{ PROF_PREFIX_PROFILE, PROF_PROFILE },
@@ -263,7 +285,7 @@ profile_provide(void *arg, dtrace_probed
 	};
 
 	const struct {
-		char *name;
+		const char *name;
 		hrtime_t mult;
 	} suffixes[] = {
 		{ "ns", 	NANOSEC / NANOSEC },
@@ -281,7 +303,7 @@ profile_provide(void *arg, dtrace_probed
 		{ "d",		NANOSEC * (hrtime_t)(24 * 60 * 60) },
 		{ "day",	NANOSEC * (hrtime_t)(24 * 60 * 60) },
 		{ "hz",		0 },
-		{ NULL }
+		{ NULL,		0 }
 	};
 
 	if (desc == NULL) {
@@ -311,7 +333,7 @@ profile_provide(void *arg, dtrace_probed
 		return;
 	}
 
-	name = desc->dtpd_name;
+	name = (char *)desc->dtpd_name;
 
 	for (i = 0; types[i].prefix != NULL; i++) {
 		len = strlen(types[i].prefix);
@@ -421,7 +443,7 @@ profile_offline(void *arg, cpu_t *cpu, v
 }
 
 /* ARGSUSED */
-static void
+static int
 profile_enable(void *arg, dtrace_id_t id, void *parg)
 {
 	profile_probe_t *prof = parg;
@@ -450,6 +472,7 @@ profile_enable(void *arg, dtrace_id_t id
 	} else {
 		prof->prof_cyclic = cyclic_add_omni(&omni);
 	}
+	return 0;
 }
 
 /* ARGSUSED */
@@ -468,9 +491,11 @@ profile_disable(void *arg, dtrace_id_t i
 static void
 profile_load(void *dummy)
 {
+#ifdef __FreeBSD__
 	/* Create the /dev/dtrace/profile entry. */
 	profile_cdev = make_dev(&profile_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
 	    "dtrace/profile");
+#endif
 
 	if (dtrace_register("profile", &profile_attr, DTRACE_PRIV_USER,
 	    NULL, &profile_pops, NULL, &profile_id) != 0)
@@ -486,11 +511,15 @@ profile_unload()
 	if ((error = dtrace_unregister(profile_id)) != 0)
 		return (error);
 
+#ifdef __FreeBSD__
 	destroy_dev(profile_cdev);
+#endif
 
 	return (error);
 }
 
+#ifdef __FreeBSD__
+
 /* ARGSUSED */
 static int
 profile_modevent(module_t mod __unused, int type, void *data __unused)
@@ -530,3 +559,28 @@ MODULE_VERSION(profile, 1);
 MODULE_DEPEND(profile, dtrace, 1, 1, 1);
 MODULE_DEPEND(profile, cyclic, 1, 1, 1);
 MODULE_DEPEND(profile, opensolaris, 1, 1, 1);
+
+#endif
+
+#ifdef __NetBSD__
+
+static int
+profile_modcmd(modcmd_t cmd, void *data)
+{
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		profile_load(NULL);
+		return 0;
+
+	case MODULE_CMD_FINI:
+		profile_unload();
+		return 0;
+
+	default:
+		return ENOTTY;
+	}
+}
+
+MODULE(MODULE_CLASS_MISC, profile, "dtrace,cyclic");
+
+#endif

Reply via email to