ftrace: sysprof updates
authorIngo Molnar <mingo@elte.hu>
Mon, 12 May 2008 19:20:49 +0000 (21:20 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 23 May 2008 21:40:22 +0000 (23:40 +0200)
make the sample period configurable.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_sysprof.c

index 3271916ff0339e7cc728c1bba55e6db9de9a83c7..95b7c48a9a1d4d77f369e3f40a7ce164fc9f1c5f 100644 (file)
@@ -2800,6 +2800,9 @@ static __init void tracer_init_debugfs(void)
                pr_warning("Could not create debugfs "
                           "'dyn_ftrace_total_info' entry\n");
 #endif
+#ifdef CONFIG_SYSPROF_TRACER
+       init_tracer_sysprof_debugfs(d_tracer);
+#endif
 }
 
 static int trace_alloc_page(void)
index b2198bc830ae06b72ad034d47eeed1cf80278f6b..b7f85d9c80d7ef9b66b8e701adf465dc844e620e 100644 (file)
@@ -188,6 +188,8 @@ struct trace_iterator {
 void tracing_reset(struct trace_array_cpu *data);
 int tracing_open_generic(struct inode *inode, struct file *filp);
 struct dentry *tracing_init_dentry(void);
+void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
+
 void ftrace(struct trace_array *tr,
                            struct trace_array_cpu *data,
                            unsigned long ip,
index f9a09fe705b014066378039c1c32e0e904e478ad..19406236b67b7a1079ea953d25d3ee305b7125c5 100644 (file)
@@ -20,11 +20,12 @@ static struct trace_array   *sysprof_trace;
 static int __read_mostly       tracer_enabled;
 
 /*
- * 10 msecs for now:
+ * 1 msec sample interval by default:
  */
-static const unsigned long sample_period = 1000000;
+static unsigned long sample_period = 1000000;
 static const unsigned int sample_max_depth = 512;
 
+static DEFINE_MUTEX(sample_timer_lock);
 /*
  * Per CPU hrtimers that do the profiling:
  */
@@ -166,15 +167,19 @@ static notrace void stack_reset(struct trace_array *tr)
 
 static notrace void start_stack_trace(struct trace_array *tr)
 {
+       mutex_lock(&sample_timer_lock);
        stack_reset(tr);
        start_stack_timers();
        tracer_enabled = 1;
+       mutex_unlock(&sample_timer_lock);
 }
 
 static notrace void stop_stack_trace(struct trace_array *tr)
 {
+       mutex_lock(&sample_timer_lock);
        stop_stack_timers();
        tracer_enabled = 0;
+       mutex_unlock(&sample_timer_lock);
 }
 
 static notrace void stack_trace_init(struct trace_array *tr)
@@ -216,3 +221,64 @@ __init static int init_stack_trace(void)
        return register_tracer(&stack_trace);
 }
 device_initcall(init_stack_trace);
+
+#define MAX_LONG_DIGITS 22
+
+static ssize_t
+sysprof_sample_read(struct file *filp, char __user *ubuf,
+                   size_t cnt, loff_t *ppos)
+{
+       char buf[MAX_LONG_DIGITS];
+       int r;
+
+       r = sprintf(buf, "%ld\n", nsecs_to_usecs(sample_period));
+
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+sysprof_sample_write(struct file *filp, const char __user *ubuf,
+                    size_t cnt, loff_t *ppos)
+{
+       char buf[MAX_LONG_DIGITS];
+       unsigned long val;
+
+       if (cnt > MAX_LONG_DIGITS-1)
+               cnt = MAX_LONG_DIGITS-1;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       buf[cnt] = 0;
+
+       val = simple_strtoul(buf, NULL, 10);
+       /*
+        * Enforce a minimum sample period of 100 usecs:
+        */
+       if (val < 100)
+               val = 100;
+
+       mutex_lock(&sample_timer_lock);
+       stop_stack_timers();
+       sample_period = val * 1000;
+       start_stack_timers();
+       mutex_unlock(&sample_timer_lock);
+
+       return cnt;
+}
+
+static struct file_operations sysprof_sample_fops = {
+       .read           = sysprof_sample_read,
+       .write          = sysprof_sample_write,
+};
+
+void init_tracer_sysprof_debugfs(struct dentry *d_tracer)
+{
+       struct dentry *entry;
+
+       entry = debugfs_create_file("sysprof_sample_period", 0644,
+                       d_tracer, NULL, &sysprof_sample_fops);
+       if (entry)
+               return;
+       pr_warning("Could not create debugfs 'dyn_ftrace_total_info' entry\n");
+}
This page took 0.027733 seconds and 5 git commands to generate.