Exporting running_sample_length value through the debugfs,
via per cpu files:
  /sys/kernel/debug/irq/cpuX/sample_length

and reset file to zero it:
  /sys/kernel/debug/irq/reset

to allow some basic meassurements of the NMI time length.

Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
 kernel/events/core.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4676fbf681c7..582913b7aba9 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -51,6 +51,7 @@
 #include <linux/proc_ns.h>
 #include <linux/mount.h>
 #include <linux/task_work.h>
+#include <linux/debugfs.h>
 
 #include "internal.h"
 
@@ -554,6 +555,72 @@ void perf_sample_event_took(u64 sample_len_ns)
        }
 }
 
+static int get_sample_length(void *data, u64 *val)
+{
+       unsigned long cpu = (unsigned long) data;
+
+       *val = per_cpu(running_sample_length, cpu);
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(sample_length_fops, get_sample_length, NULL, "%llu\n");
+
+
+static int reset_sample_length(void *data, u64 val)
+{
+       int cpu;
+
+       for_each_possible_cpu(cpu) {
+               per_cpu(running_sample_length, cpu) = val;
+       }
+
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(reset_fops, NULL, reset_sample_length, "%llu\n");
+
+static __init int init_perf_debugfs(void)
+{
+       struct dentry *root, *irq, *icpu, *file;
+       int cpu, ret = 0;
+
+       root = debugfs_create_dir("perf", NULL);
+       if (!root)
+               return -1;
+
+       irq = debugfs_create_dir("irq", root);
+       if (!irq)
+               return -1;
+
+       for_each_possible_cpu(cpu) {
+               char buf[50];
+
+               snprintf(buf, sizeof(buf), "cpu%d", cpu);
+
+               icpu = debugfs_create_dir(buf, irq);
+               if (!icpu)
+                       return -1;
+
+               file = debugfs_create_file("sample_length", 0444, icpu,
+                                          (void *)(unsigned long) cpu,
+                                          &sample_length_fops);
+               if (!file) {
+                       ret = -1;
+                       break;
+               }
+       }
+
+       if (!ret) {
+               file = debugfs_create_file("reset", S_IWUSR, irq, NULL, 
&reset_fops);
+               if (!file)
+                       ret = -1;
+       }
+
+       return ret;
+}
+
+late_initcall(init_perf_debugfs);
+
 static atomic64_t perf_event_id;
 
 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
-- 
2.13.6

Reply via email to