Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/cddl/osnet/dev/profile adapt the profile dtrace pro...
details: https://anonhg.NetBSD.org/src/rev/5d689ebc1c0e
branches: trunk
changeset: 783130:5d689ebc1c0e
user: chs <chs%NetBSD.org@localhost>
date: Fri Dec 07 03:11:17 2012 +0000
description:
adapt the profile dtrace provider to netbsd.
diffstat:
external/cddl/osnet/dev/profile/profile.c | 76 ++++++++++++++++++++++++++----
1 files changed, 65 insertions(+), 11 deletions(-)
diffs (237 lines):
diff -r 5ca7b76e46c8 -r 5d689ebc1c0e external/cddl/osnet/dev/profile/profile.c
--- a/external/cddl/osnet/dev/profile/profile.c Fri Dec 07 02:28:19 2012 +0000
+++ b/external/cddl/osnet/dev/profile/profile.c Fri Dec 07 03:11:17 2012 +0000
@@ -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 @@
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 @@
/* 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 @@
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_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 @@
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 @@
/*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 @@
};
const struct {
- char *name;
+ const char *name;
hrtime_t mult;
} suffixes[] = {
{ "ns", NANOSEC / NANOSEC },
@@ -281,7 +303,7 @@
{ "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 @@
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 @@
}
/* ARGSUSED */
-static void
+static int
profile_enable(void *arg, dtrace_id_t id, void *parg)
{
profile_probe_t *prof = parg;
@@ -450,6 +472,7 @@
} else {
prof->prof_cyclic = cyclic_add_omni(&omni);
}
+ return 0;
}
/* ARGSUSED */
@@ -468,9 +491,11 @@
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 @@
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_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
Home |
Main Index |
Thread Index |
Old Index