Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Introduce DTrace SDT probes instead of custom debug messages.

  • Loading branch information...
commit 0e43f06bf1ae5cdccca6c44b1c4c26d55a520223 1 parent 60901d7
@pgj authored
View
3  packages/mirage-platform/Makefile
@@ -21,7 +21,8 @@ CFLAGS= -O2 -DCAML_NAME_SPACE -DNATIVE_CODE -DSYS_bsd_elf \
-Wredundant-decls -Wnested-externs -Wstrict-prototypes \
-Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
-Wundef -Wno-pointer-sign -fformat-extensions \
- -Wmissing-include-dirs -fdiagnostics-show-option -mno-sse
+ -Wmissing-include-dirs -fdiagnostics-show-option -mno-sse \
+ -DKDTRACE_HOOKS
DEPS= lwt
View
80 packages/mirage-platform/dtrace/generic.d
@@ -0,0 +1,80 @@
+#!/usr/sbin/dtrace -s
+
+#pragma D option quiet
+
+mirage:kernel:kthread:entry
+{
+ printf("-> %s()\n", probefunc);
+}
+
+mirage:kernel:kthread:return
+{
+ printf("<- %s()\n", probefunc);
+}
+
+mirage:kernel:caml_startup:start
+{
+ printf("kernel thread activated, caml run-time starts\n");
+}
+
+mirage:kernel:caml_startup:finish
+{
+ printf("caml run-time finished\n");
+}
+
+mirage:kernel:kthread_loop:start
+{
+ printf("main function found, kicking off the main loop\n");
+}
+
+mirage:kernel:kthread_loop:stop
+{
+ printf("main loop exited: (%d,%d)\n", arg0, arg1);
+}
+
+mirage:kernel:kthread_init:entry
+{
+ printf("-> mirage_kthread_init()\n");
+}
+
+mirage:kernel:kthread_init:return
+{
+ printf("<- mirage_kthread_init()\n");
+}
+
+mirage:kernel:kthread_deinit:entry
+{
+ printf("-> mirage_kthread_deinit()\n");
+}
+
+mirage:kernel:kthread_deinit:return
+{
+ printf("<- mirage_kthread_deinit()\n");
+}
+
+mirage:kernel:kthread_launch:entry
+{
+ printf("-> mirage_kthread_launch()\n");
+}
+
+mirage:kernel:kthread_launch:return
+{
+ printf("<- mirage_kthread_launch()\n");
+}
+
+mirage:kernel:block_kernel:entry
+{
+ printf("blocking kernel for %d us\n", arg0);
+}
+
+mirage:kernel:block_kernel:return {}
+
+mirage:kernel:alloc_pages:entry
+{
+ printf("-> %s(%d)\n", probefunc, arg0);
+}
+
+mirage:kernel:alloc_pages:return
+{
+ printf("<- %s()\n", probefunc);
+}
View
67 packages/mirage-platform/runtime/kernel/kmod.c
@@ -39,6 +39,8 @@
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/sysctl.h>
+#include <sys/kernel.h>
+#include <sys/sdt.h>
#include "caml/mlvalues.h"
#include "caml/callback.h"
@@ -46,20 +48,28 @@
CAMLprim value caml_block_kernel(value v_timeout);
-
static char mir_rtparams[64] = "";
-static int mir_debug = 3;
-
-#define MIR_DEBUG(l, x) \
- do { \
- if (mir_debug >= l) { \
- (x); \
- } \
- } while (0)
-
static char* argv[] = { "mirage", NULL };
MALLOC_DEFINE(M_MIRAGE, "mirage", "Mirage run-time");
+SDT_PROVIDER_DEFINE(mirage);
+
+SDT_PROBE_DEFINE(mirage, kernel, kthread, entry, entry);
+SDT_PROBE_DEFINE(mirage, kernel, kthread, return, return);
+SDT_PROBE_DEFINE(mirage, kernel, caml_startup, start, start);
+SDT_PROBE_DEFINE(mirage, kernel, caml_startup, finish, finish);
+SDT_PROBE_DEFINE(mirage, kernel, kthread_init, entry, entry);
+SDT_PROBE_DEFINE(mirage, kernel, kthread_init, return, return);
+SDT_PROBE_ARGTYPE(mirage, kernel, kthread_init, return, 0, "int");
+SDT_PROBE_DEFINE(mirage, kernel, kthread_deinit, entry, entry);
+SDT_PROBE_DEFINE(mirage, kernel, kthread_deinit, return, return);
+SDT_PROBE_DEFINE(mirage, kernel, kthread_loop, start, start);
+SDT_PROBE_DEFINE(mirage, kernel, kthread_loop, stop, stop);
+SDT_PROBE_DEFINE(mirage, kernel, kthread_launch, entry, entry);
+SDT_PROBE_DEFINE(mirage, kernel, kthread_launch, return, return);
+SDT_PROBE_DEFINE(mirage, kernel, block_kernel, entry, entry);
+SDT_PROBE_ARGTYPE(mirage, kernel, block_kernel, entry, 0, "int");
+SDT_PROBE_DEFINE(mirage, kernel, block_kernel, return, return);
static SYSCTL_NODE(_kern, OID_AUTO, mirage, CTLFLAG_RD, NULL, "mirage");
@@ -80,10 +90,10 @@ mirage_kthread_body(void *arg __unused)
int caml_completed = 0;
mirage_kthread_state = THR_RUNNING;
- MIR_DEBUG(1, printf("--> mirage_kthread_body()\n"));
- MIR_DEBUG(2, printf("mirage: kernel thread actived, caml run-time starts\n"));
+ SDT_PROBE(mirage, kernel, kthread, entry, 0, 0, 0, 0, 0);
+ SDT_PROBE(mirage, kernel, caml_startup, start, 0, 0, 0, 0, 0);
caml_startup(argv);
- MIR_DEBUG(2, printf("mirage: caml run-time finished, searching the main function\n"));
+ SDT_PROBE(mirage, kernel, caml_startup, finish, 0, 0, 0, 0, 0);
v_main = caml_named_value("OS.Main.run");
if (v_main == NULL) {
@@ -91,20 +101,19 @@ mirage_kthread_body(void *arg __unused)
goto done;
}
- MIR_DEBUG(2, printf("mirage: main function found, kicking off the main loop\n"));
+ SDT_PROBE(mirage, kernel, kthread_loop, start, 0, 0, 0, 0, 0);
for (; (caml_completed == 0) && (mirage_kthread_state == THR_RUNNING);) {
caml_completed = Bool_val(caml_callback(*v_main, Val_unit));
}
- MIR_DEBUG(2, printf("mirage: main loop exited = (%d,%d)\n",
- caml_completed, (int) mirage_kthread_state));
+ SDT_PROBE(mirage, kernel, kthread_loop, stop, caml_completed,
+ (int) mirage_kthread_state, 0, 0, 0);
done:
- MIR_DEBUG(2, printf("mirage: kernel thread exiting\n"));
if (mirage_kthread_state == THR_STOPPED)
wakeup(&mirage_kthread_state);
mirage_kthread_state = THR_NONE;
+ SDT_PROBE(mirage, kernel, kthread, return, 0, 0, 0, 0, 0);
kthread_exit();
- MIR_DEBUG(1, printf("<-- mirage_kthread_body()\n"));
}
static int
@@ -112,8 +121,7 @@ mirage_kthread_init(void)
{
int error;
- error = 0;
- MIR_DEBUG(1, printf("--> mirage_kthread_init()\n"));
+ SDT_PROBE(mirage, kernel, kthread_init, entry, 0, 0, 0, 0, 0);
error = kthread_add(mirage_kthread_body, NULL, NULL, &mirage_kthread,
RFSTOPPED, 40, "mirage");
mirage_kthread_state = THR_STOPPED;
@@ -123,34 +131,34 @@ mirage_kthread_init(void)
}
done:
- MIR_DEBUG(1, printf("<-- mirage_kthread_init()\n"));
+ SDT_PROBE(mirage, kernel, kthread_init, return, error, 0, 0, 0, 0);
return error;
}
static int
mirage_kthread_deinit(void)
{
- MIR_DEBUG(1, printf("--> mirage_kthread_deinit()\n"));
+ SDT_PROBE(mirage, kernel, kthread_deinit, entry, 0, 0, 0, 0, 0);
if (mirage_kthread_state == THR_RUNNING) {
mirage_kthread_state = THR_STOPPED;
tsleep((void *) &mirage_kthread_state, 0,
"mirage_kthread_deinit", 0);
pause("mirage_kthread_deinit", 1);
}
- MIR_DEBUG(1, printf("<-- mirage_kthread_deinit()\n"));
+ SDT_PROBE(mirage, kernel, kthread_deinit, return, 0, 0, 0, 0, 0);
return 0;
}
static void
mirage_kthread_launch(void)
{
- MIR_DEBUG(1, printf("--> mirage_kthread_launch()\n"));
+ SDT_PROBE(mirage, kernel, kthread_launch, entry, 0, 0, 0, 0, 0);
thread_lock(mirage_kthread);
sched_add(mirage_kthread, SRQ_BORING);
sched_class(mirage_kthread, PRI_TIMESHARE);
sched_prio(mirage_kthread, PRI_MAX_IDLE);
thread_unlock(mirage_kthread);
- MIR_DEBUG(1, printf("<-- mirage_kthread_launch()\n"));
+ SDT_PROBE(mirage, kernel, kthread_launch, return, 0, 0, 0, 0, 0);
}
static int
@@ -171,7 +179,7 @@ sysctl_kern_mirage_run(SYSCTL_HANDLER_ARGS)
mirage_kthread_launch();
}
else {
- MIR_DEBUG(1, printf("mirage: a kernel thread has been already launched.\n"));
+ printf("[MIRAGE] Kernel thread is already running.\n");
}
}
return (0);
@@ -180,9 +188,6 @@ sysctl_kern_mirage_run(SYSCTL_HANDLER_ARGS)
SYSCTL_PROC(_kern_mirage, OID_AUTO, run, CTLTYPE_INT | CTLFLAG_RW, 0,
sizeof(int), sysctl_kern_mirage_run, "I", "start module");
-SYSCTL_INT(_kern_mirage, OID_AUTO, debug, CTLFLAG_RW, &mir_debug, 0,
- "debug level");
-
SYSCTL_STRING(_kern_mirage, OID_AUTO, rtparams, CTLFLAG_RW, &mir_rtparams,
sizeof(mir_rtparams), "parameters for the run-time");
@@ -222,8 +227,10 @@ CAMLprim value
caml_block_kernel(value v_timeout)
{
CAMLparam1(v_timeout);
+
block_timo = Int_val(v_timeout);
- MIR_DEBUG(2, printf("mirage: Blocking kernel for %d us\n", block_timo));
+ SDT_PROBE(mirage, kernel, block_kernel, entry, block_timo, 0, 0, 0, 0);
pause("caml_block_kernel", (block_timo * hz) / 1000000);
+ SDT_PROBE(mirage, kernel, block_kernel, return, 0, 0, 0, 0, 0);
CAMLreturn(Val_unit);
}
View
9 packages/mirage-platform/runtime/kernel/netif_stubs.c
@@ -28,6 +28,9 @@
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/socket.h>
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/sdt.h>
#include <net/if.h>
#include <net/if_dl.h>
@@ -38,6 +41,11 @@
#include "caml/memory.h"
#include "caml/alloc.h"
+SDT_PROVIDER_DECLARE(mirage);
+
+SDT_PROBE_DEFINE(mirage, kernel, kern_get_vifs, entry, entry);
+SDT_PROBE_DEFINE(mirage, kernel, kern_get_vifs, return, return);
+
/* Currently only Ethernet interfaces are returned. */
CAMLprim value kern_get_vifs(value v_unit);
@@ -70,5 +78,6 @@ kern_get_vifs(value v_unit)
IF_ADDR_RUNLOCK(ifp);
}
IFNET_RUNLOCK_NOSLEEP();
+ SDT_PROBE(mirage, kernel, kern_get_vifs, return, 0, 0, 0, 0, 0);
CAMLreturn(result);
}
View
10 packages/mirage-platform/runtime/kernel/page_stubs.c
@@ -27,6 +27,8 @@
#include <sys/types.h>
#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/sdt.h>
#include "caml/misc.h"
#include "caml/mlvalues.h"
@@ -35,6 +37,12 @@
#include "caml/fail.h"
#include "caml/bigarray.h"
+SDT_PROVIDER_DECLARE(mirage);
+
+SDT_PROBE_DEFINE(mirage, kernel, alloc_pages, entry, entry);
+SDT_PROBE_ARGTYPE(mirage, kernel, alloc_pages, entry, 0, "size_t");
+SDT_PROBE_DEFINE(mirage, kernel, alloc_pages, return, return);
+
CAMLprim value caml_alloc_pages(value n_pages);
CAMLprim value
@@ -47,6 +55,7 @@ caml_alloc_pages(value n_pages)
unsigned long block;
len = Int_val(n_pages);
+ SDT_PROBE(mirage, kernel, alloc_pages, entry, len, 0, 0, 0, 0);
block = (unsigned long) contigmalloc(PAGE_SIZE * len, M_MIRAGE,
M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0ul);
if (block == 0)
@@ -58,5 +67,6 @@ caml_alloc_pages(value n_pages)
Store_field(result, i, page);
block += (PAGE_SIZE / sizeof(unsigned long));
};
+ SDT_PROBE(mirage, kernel, alloc_pages, return, 0, 0, 0, 0, 0);
CAMLreturn(result);
}
Please sign in to comment.
Something went wrong with that request. Please try again.