kprof: Allow clearing the kptrace buffer
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 11 Jul 2017 15:10:26 +0000 (11:10 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 20 Jul 2017 12:19:46 +0000 (08:19 -0400)
This also adds a slimmed down version of dmesg, which also supports -c.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/kprof.c
kern/kfs/bin/dmesg [new file with mode: 0755]

index 9e48de9..67ffacd 100644 (file)
@@ -36,6 +36,7 @@ enum {
        Kprofdirqid = 0,
        Kprofdataqid,
        Kprofctlqid,
+       Kptracectlqid,
        Kptraceqid,
        Kprintxqid,
        Kmpstatqid,
@@ -59,6 +60,7 @@ struct dirtab kproftab[] = {
        {".",                   {Kprofdirqid,           0, QTDIR}, 0,   DMDIR|0550},
        {"kpdata",              {Kprofdataqid},         0,      0600},
        {"kpctl",               {Kprofctlqid},          0,      0600},
+       {"kptrace_ctl", {Kptracectlqid},        0,      0660},
        {"kptrace",             {Kptraceqid},           0,      0600},
        {"kprintx",             {Kprintxqid},           0,      0600},
        {"mpstat",              {Kmpstatqid},           0,      0600},
@@ -375,6 +377,15 @@ static long kprof_write(struct chan *c, void *a, long n, int64_t unused)
                        error(EFAIL, kprof_control_usage);
                }
                break;
+       case Kptracectlqid:
+               if (cb->nf < 1)
+                       error(EFAIL, "Bad kptrace_ctl option (reset)");
+               if (!strcmp(cb->f[0], "clear")) {
+                       spin_lock_irqsave(&ktrace_lock);
+                       circular_buffer_clear(&ktrace_data);
+                       spin_unlock_irqsave(&ktrace_lock);
+               }
+               break;
        case Kptraceqid:
                if (a && (n > 0)) {
                        char *uptr = user_strdup_errno(current, a, n);
diff --git a/kern/kfs/bin/dmesg b/kern/kfs/bin/dmesg
new file mode 100755 (executable)
index 0000000..1ca1376
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+if [[ x$1 == x"-C" ]]
+then
+       echo "clear" > "#kprof/kptrace_ctl"
+       exit
+fi
+
+cat "#kprof/kptrace"
+
+if [[ x$1 == x"-c" ]]
+then
+       echo "clear" > "#kprof/kptrace_ctl"
+fi