[tip:perf/urgent] tracing: update documentation of snapshot utility

2013-03-08 Thread tip-bot for Hiraku Toyooka
Commit-ID:  1abccd7419de9829bcdf9ab1f81d5f6cf74d55d3
Gitweb: http://git.kernel.org/tip/1abccd7419de9829bcdf9ab1f81d5f6cf74d55d3
Author: Hiraku Toyooka 
AuthorDate: Fri, 8 Mar 2013 16:32:25 +0900
Committer:  Steven Rostedt 
CommitDate: Fri, 8 Mar 2013 06:27:11 -0500

tracing: update documentation of snapshot utility

Now, "snapshot" file returns success on a reset of snapshot buffer
even if the buffer wasn't allocated, instead of returning EINVAL.
This patch updates snapshot desctiption according to the change.

Link: http://lkml.kernel.org/r/51399409.4090...@hitachi.com

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Steven Rostedt 
---
 Documentation/trace/ftrace.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/trace/ftrace.txt b/Documentation/trace/ftrace.txt
index 53d6a3c..a372304 100644
--- a/Documentation/trace/ftrace.txt
+++ b/Documentation/trace/ftrace.txt
@@ -1873,7 +1873,7 @@ feature:
 
status\input  | 0  | 1  |else|
--++++
-   not allocated |(do nothing)| alloc+swap |   EINVAL   |
+   not allocated |(do nothing)| alloc+swap |(do nothing)|
--++++
allocated |free|swap|   clear|
--++++
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] tracing: Add documentation of snapshot utility

2013-02-03 Thread tip-bot for Hiraku Toyooka
Commit-ID:  c1043fcda1b9e8e5144cfdaee7be262c50dbdead
Gitweb: http://git.kernel.org/tip/c1043fcda1b9e8e5144cfdaee7be262c50dbdead
Author: Hiraku Toyooka 
AuthorDate: Wed, 26 Dec 2012 11:53:09 +0900
Committer:  Steven Rostedt 
CommitDate: Wed, 30 Jan 2013 11:02:07 -0500

tracing: Add documentation of snapshot utility

This patch adds snapshot description in ftrace documentation.
This description includes what the snapshot is and how to use it.

Link: http://lkml.kernel.org/r/20121226025309.3252.150.stgit@liselsia

Cc: Rob Landley 
Signed-off-by: Hiraku Toyooka 
Signed-off-by: Steven Rostedt 
---
 Documentation/trace/ftrace.txt | 83 ++
 1 file changed, 83 insertions(+)

diff --git a/Documentation/trace/ftrace.txt b/Documentation/trace/ftrace.txt
index 6f51fed..53d6a3c 100644
--- a/Documentation/trace/ftrace.txt
+++ b/Documentation/trace/ftrace.txt
@@ -1842,6 +1842,89 @@ an error.
  # cat buffer_size_kb
 85
 
+Snapshot
+
+CONFIG_TRACER_SNAPSHOT makes a generic snapshot feature
+available to all non latency tracers. (Latency tracers which
+record max latency, such as "irqsoff" or "wakeup", can't use
+this feature, since those are already using the snapshot
+mechanism internally.)
+
+Snapshot preserves a current trace buffer at a particular point
+in time without stopping tracing. Ftrace swaps the current
+buffer with a spare buffer, and tracing continues in the new
+current (=previous spare) buffer.
+
+The following debugfs files in "tracing" are related to this
+feature:
+
+  snapshot:
+
+   This is used to take a snapshot and to read the output
+   of the snapshot. Echo 1 into this file to allocate a
+   spare buffer and to take a snapshot (swap), then read
+   the snapshot from this file in the same format as
+   "trace" (described above in the section "The File
+   System"). Both reads snapshot and tracing are executable
+   in parallel. When the spare buffer is allocated, echoing
+   0 frees it, and echoing else (positive) values clear the
+   snapshot contents.
+   More details are shown in the table below.
+
+   status\input  | 0  | 1  |else|
+   --++++
+   not allocated |(do nothing)| alloc+swap |   EINVAL   |
+   --++++
+   allocated |free|swap|   clear|
+   --++++
+
+Here is an example of using the snapshot feature.
+
+ # echo 1 > events/sched/enable
+ # echo 1 > snapshot
+ # cat snapshot
+# tracer: nop
+#
+# entries-in-buffer/entries-written: 71/71   #P:8
+#
+#  _-=> irqs-off
+# / _=> need-resched
+#| / _---=> hardirq/softirq
+#|| / _--=> preempt-depth
+#||| / delay
+#   TASK-PID   CPU#  TIMESTAMP  FUNCTION
+#  | |   |      | |
+  -0 [005] d...  2440.603828: sched_switch: 
prev_comm=swapper/5 prev_pid=0 prev_prio=120 prev_state=R ==> 
next_comm=snapshot-test-2 next_pid=2242 next_prio=120
+   sleep-2242  [005] d...  2440.603846: sched_switch: 
prev_comm=snapshot-test-2 prev_pid=2242 prev_prio=120 prev_state=R ==> 
next_comm=kworker/5:1 next_pid=60 next_prio=120
+[...]
+  -0 [002] d...  2440.707230: sched_switch: 
prev_comm=swapper/2 prev_pid=0 prev_prio=120 prev_state=R ==> 
next_comm=snapshot-test-2 next_pid=2229 next_prio=120
+
+ # cat trace
+# tracer: nop
+#
+# entries-in-buffer/entries-written: 77/77   #P:8
+#
+#  _-=> irqs-off
+# / _=> need-resched
+#| / _---=> hardirq/softirq
+#|| / _--=> preempt-depth
+#||| / delay
+#   TASK-PID   CPU#  TIMESTAMP  FUNCTION
+#  | |   |      | |
+  -0 [007] d...  2440.707395: sched_switch: 
prev_comm=swapper/7 prev_pid=0 prev_prio=120 prev_state=R ==> 
next_comm=snapshot-test-2 next_pid=2243 next_prio=120
+ snapshot-test-2-2229  [002] d...  2440.707438: sched_switch: 
prev_comm=snapshot-test-2 prev_pid=2229 prev_prio=120 prev_state=S ==> 
next_comm=swapper/2 next_pid=0 next_prio=120
+[...]
+
+
+If you try to use this snapshot feature when current tracer is
+one of the latency tracers, you will get the following results.
+
+ # echo wakeup > current_tracer
+ # echo 1 > snapshot
+bash: echo: write error: Device or resource busy
+ # cat snapshot
+cat: snapshot: Device or resource busy
+
 ---
 
 More details can be found in the source code, in the
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org

[tip:perf/core] tracing: Make a snapshot feature available from userspace

2013-02-03 Thread tip-bot for Hiraku Toyooka
Commit-ID:  debdd57f5145f3c6a4b3f8d0126abd1a2def7fc6
Gitweb: http://git.kernel.org/tip/debdd57f5145f3c6a4b3f8d0126abd1a2def7fc6
Author: Hiraku Toyooka 
AuthorDate: Wed, 26 Dec 2012 11:53:00 +0900
Committer:  Steven Rostedt 
CommitDate: Wed, 30 Jan 2013 11:02:06 -0500

tracing: Make a snapshot feature available from userspace

Ftrace has a snapshot feature available from kernel space and
latency tracers (e.g. irqsoff) are using it. This patch enables
user applictions to take a snapshot via debugfs.

Add "snapshot" debugfs file in "tracing" directory.

  snapshot:
This is used to take a snapshot and to read the output of the
snapshot.

 # echo 1 > snapshot

This will allocate the spare buffer for snapshot (if it is
not allocated), and take a snapshot.

 # cat snapshot

This will show contents of the snapshot.

 # echo 0 > snapshot

This will free the snapshot if it is allocated.

Any other positive values will clear the snapshot contents if
the snapshot is allocated, or return EINVAL if it is not allocated.

Link: http://lkml.kernel.org/r/20121226025300.3252.86850.stgit@liselsia

Cc: Jiri Olsa 
Cc: David Sharp 
Signed-off-by: Hiraku Toyooka 
[
   Fixed irqsoff selftest and also a conflict with a change
   that fixes the update_max_tr.
]
Signed-off-by: Steven Rostedt 
---
 include/linux/ftrace_event.h |   3 +
 kernel/trace/Kconfig |  10 +++
 kernel/trace/trace.c | 166 ---
 kernel/trace/trace.h |   1 +
 4 files changed, 154 insertions(+), 26 deletions(-)

diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 6f8d0b7..13a54d0 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -83,6 +83,9 @@ struct trace_iterator {
longidx;
 
cpumask_var_t   started;
+
+   /* it's true when current open file is snapshot */
+   boolsnapshot;
 };
 
 enum trace_iter_flags {
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index cdc9d28..3656756 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -253,6 +253,16 @@ config FTRACE_SYSCALLS
help
  Basic tracer to catch the syscall entry and exit events.
 
+config TRACER_SNAPSHOT
+   bool "Create a snapshot trace buffer"
+   select TRACER_MAX_TRACE
+   help
+ Allow tracing users to take snapshot of the current buffer using the
+ ftrace interface, e.g.:
+
+ echo 1 > /sys/kernel/debug/tracing/snapshot
+ cat snapshot
+
 config TRACE_BRANCH_PROFILING
bool
select GENERIC_TRACER
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2c72466..70dce64 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -710,12 +710,11 @@ update_max_tr(struct trace_array *tr, struct task_struct 
*tsk, int cpu)
 
WARN_ON_ONCE(!irqs_disabled());
 
-   /* If we disabled the tracer, stop now */
-   if (current_trace == &nop_trace)
-   return;
-
-   if (WARN_ON_ONCE(!current_trace->use_max_tr))
+   if (!current_trace->allocated_snapshot) {
+   /* Only the nop tracer should hit this when disabling */
+   WARN_ON_ONCE(current_trace != &nop_trace);
return;
+   }
 
arch_spin_lock(&ftrace_max_lock);
 
@@ -743,10 +742,8 @@ update_max_tr_single(struct trace_array *tr, struct 
task_struct *tsk, int cpu)
return;
 
WARN_ON_ONCE(!irqs_disabled());
-   if (!current_trace->use_max_tr) {
-   WARN_ON_ONCE(1);
+   if (WARN_ON_ONCE(!current_trace->allocated_snapshot))
return;
-   }
 
arch_spin_lock(&ftrace_max_lock);
 
@@ -866,10 +863,13 @@ int register_tracer(struct tracer *type)
 
current_trace = type;
 
-   /* If we expanded the buffers, make sure the max is expanded 
too */
-   if (ring_buffer_expanded && type->use_max_tr)
-   ring_buffer_resize(max_tr.buffer, trace_buf_size,
-   RING_BUFFER_ALL_CPUS);
+   if (type->use_max_tr) {
+   /* If we expanded the buffers, make sure the max is 
expanded too */
+   if (ring_buffer_expanded)
+   ring_buffer_resize(max_tr.buffer, 
trace_buf_size,
+  RING_BUFFER_ALL_CPUS);
+   type->allocated_snapshot = true;
+   }
 
/* the test is responsible for initializing and enabling */
pr_info("Testing tracer %s: ", type->name);
@@ -885,10 +885,14 @@ int register_tracer(struct tracer *type)
/* Only reset on passing, to avoid touching corrupted buffers */
tracing_reset_online_cpus(tr);
 
-   /* Shrink the max buffer again */
-   if (ring_buffe

[tip:perf/core] tracing: Replace static old_tracer check of tracer name

2013-02-03 Thread tip-bot for Hiraku Toyooka
Commit-ID:  2fd196ec1eab2623096e7fc7e6f3976160392bce
Gitweb: http://git.kernel.org/tip/2fd196ec1eab2623096e7fc7e6f3976160392bce
Author: Hiraku Toyooka 
AuthorDate: Wed, 26 Dec 2012 11:52:52 +0900
Committer:  Steven Rostedt 
CommitDate: Wed, 30 Jan 2013 11:02:05 -0500

tracing: Replace static old_tracer check of tracer name

Currently the trace buffer read functions use a static variable
"old_tracer" for detecting if the current tracer changes. This
was suitable for a single trace file ("trace"), but to add a
snapshot feature that will use the same function for its file,
a check against a static variable is not sufficient.

To use the output functions for two different files, instead of
storing the current tracer in a static variable, as the trace
iterator descriptor contains a pointer to the original current
tracer's name, that pointer can now be used to check if the
current tracer has changed between different reads of the trace
file.

Link: http://lkml.kernel.org/r/20121226025252.3252.9276.stgit@liselsia

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Steven Rostedt 
---
 kernel/trace/trace.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 90a1c71..2c72466 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1948,18 +1948,20 @@ void tracing_iter_reset(struct trace_iterator *iter, 
int cpu)
 static void *s_start(struct seq_file *m, loff_t *pos)
 {
struct trace_iterator *iter = m->private;
-   static struct tracer *old_tracer;
int cpu_file = iter->cpu_file;
void *p = NULL;
loff_t l = 0;
int cpu;
 
-   /* copy the tracer to avoid using a global lock all around */
+   /*
+* copy the tracer to avoid using a global lock all around.
+* iter->trace is a copy of current_trace, the pointer to the
+* name may be used instead of a strcmp(), as iter->trace->name
+* will point to the same string as current_trace->name.
+*/
mutex_lock(&trace_types_lock);
-   if (unlikely(old_tracer != current_trace && current_trace)) {
-   old_tracer = current_trace;
+   if (unlikely(current_trace && iter->trace->name != current_trace->name))
*iter->trace = *current_trace;
-   }
mutex_unlock(&trace_types_lock);
 
atomic_inc(&trace_record_cmdline_disabled);
@@ -3494,7 +3496,6 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
  size_t cnt, loff_t *ppos)
 {
struct trace_iterator *iter = filp->private_data;
-   static struct tracer *old_tracer;
ssize_t sret;
 
/* return any leftover data */
@@ -3506,10 +3507,8 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
 
/* copy the tracer to avoid using a global lock all around */
mutex_lock(&trace_types_lock);
-   if (unlikely(old_tracer != current_trace && current_trace)) {
-   old_tracer = current_trace;
+   if (unlikely(current_trace && iter->trace->name != current_trace->name))
*iter->trace = *current_trace;
-   }
mutex_unlock(&trace_types_lock);
 
/*
@@ -3665,7 +3664,6 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
.ops= &tracing_pipe_buf_ops,
.spd_release= tracing_spd_release_pipe,
};
-   static struct tracer *old_tracer;
ssize_t ret;
size_t rem;
unsigned int i;
@@ -3675,10 +3673,8 @@ static ssize_t tracing_splice_read_pipe(struct file 
*filp,
 
/* copy the tracer to avoid using a global lock all around */
mutex_lock(&trace_types_lock);
-   if (unlikely(old_tracer != current_trace && current_trace)) {
-   old_tracer = current_trace;
+   if (unlikely(current_trace && iter->trace->name != current_trace->name))
*iter->trace = *current_trace;
-   }
mutex_unlock(&trace_types_lock);
 
mutex_lock(&iter->mutex);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] tracing: Add checks if tr-> buffer is NULL in tracing_reset{_online_cpus}

2013-01-24 Thread tip-bot for Hiraku Toyooka
Commit-ID:  a54164114b96b4693b42cdb553260eec41ea4393
Gitweb: http://git.kernel.org/tip/a54164114b96b4693b42cdb553260eec41ea4393
Author: Hiraku Toyooka 
AuthorDate: Wed, 19 Dec 2012 16:02:34 +0900
Committer:  Steven Rostedt 
CommitDate: Mon, 21 Jan 2013 13:22:32 -0500

tracing: Add checks if tr->buffer is NULL in tracing_reset{_online_cpus}

max_tr->buffer could be NULL in the tracing_reset{_online_cpus}. In this
case, a NULL pointer dereference happens, so we should return immediately
from these functions.

Note, the current code does not call tracing_reset*() with max_tr when
its buffer is NULL, but future code will. This patch is needed to prevent
the future code from crashing.

Link: http://lkml.kernel.org/r/20121219070234.31200.93863.stgit@liselsia

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Steven Rostedt 
---
 kernel/trace/trace.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index f8b7c62..72b171b 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -922,6 +922,9 @@ void tracing_reset(struct trace_array *tr, int cpu)
 {
struct ring_buffer *buffer = tr->buffer;
 
+   if (!buffer)
+   return;
+
ring_buffer_record_disable(buffer);
 
/* Make sure all commits have finished */
@@ -936,6 +939,9 @@ void tracing_reset_online_cpus(struct trace_array *tr)
struct ring_buffer *buffer = tr->buffer;
int cpu;
 
+   if (!buffer)
+   return;
+
ring_buffer_record_disable(buffer);
 
/* Make sure all commits have finished */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] tracing: Change tracer's integer flags to bool

2012-11-13 Thread tip-bot for Hiraku Toyooka
Commit-ID:  f43c738bfa8608424610e4fc1aef4d4644e2ce11
Gitweb: http://git.kernel.org/tip/f43c738bfa8608424610e4fc1aef4d4644e2ce11
Author: Hiraku Toyooka 
AuthorDate: Tue, 2 Oct 2012 17:27:10 +0900
Committer:  Steven Rostedt 
CommitDate: Wed, 31 Oct 2012 16:45:25 -0400

tracing: Change tracer's integer flags to bool

print_max and use_max_tr in struct tracer are "int" variables and
used like flags. This is wasteful, so change the type to "bool".

Link: http://lkml.kernel.org/r/20121002082710.9807.86393.stgit@falsita

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Steven Rostedt 
---
 kernel/trace/trace.h  |4 ++--
 kernel/trace/trace_irqsoff.c  |   12 ++--
 kernel/trace/trace_sched_wakeup.c |8 
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index c15f528..c56a233 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -285,8 +285,8 @@ struct tracer {
int (*set_flag)(u32 old_flags, u32 bit, int set);
struct tracer   *next;
struct tracer_flags *flags;
-   int print_max;
-   int use_max_tr;
+   boolprint_max;
+   booluse_max_tr;
 };
 
 
diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c
index 11edebd..5ffce7b 100644
--- a/kernel/trace/trace_irqsoff.c
+++ b/kernel/trace/trace_irqsoff.c
@@ -604,7 +604,7 @@ static struct tracer irqsoff_tracer __read_mostly =
.reset  = irqsoff_tracer_reset,
.start  = irqsoff_tracer_start,
.stop   = irqsoff_tracer_stop,
-   .print_max  = 1,
+   .print_max  = true,
.print_header   = irqsoff_print_header,
.print_line = irqsoff_print_line,
.flags  = &tracer_flags,
@@ -614,7 +614,7 @@ static struct tracer irqsoff_tracer __read_mostly =
 #endif
.open   = irqsoff_trace_open,
.close  = irqsoff_trace_close,
-   .use_max_tr = 1,
+   .use_max_tr = true,
 };
 # define register_irqsoff(trace) register_tracer(&trace)
 #else
@@ -637,7 +637,7 @@ static struct tracer preemptoff_tracer __read_mostly =
.reset  = irqsoff_tracer_reset,
.start  = irqsoff_tracer_start,
.stop   = irqsoff_tracer_stop,
-   .print_max  = 1,
+   .print_max  = true,
.print_header   = irqsoff_print_header,
.print_line = irqsoff_print_line,
.flags  = &tracer_flags,
@@ -647,7 +647,7 @@ static struct tracer preemptoff_tracer __read_mostly =
 #endif
.open   = irqsoff_trace_open,
.close  = irqsoff_trace_close,
-   .use_max_tr = 1,
+   .use_max_tr = true,
 };
 # define register_preemptoff(trace) register_tracer(&trace)
 #else
@@ -672,7 +672,7 @@ static struct tracer preemptirqsoff_tracer __read_mostly =
.reset  = irqsoff_tracer_reset,
.start  = irqsoff_tracer_start,
.stop   = irqsoff_tracer_stop,
-   .print_max  = 1,
+   .print_max  = true,
.print_header   = irqsoff_print_header,
.print_line = irqsoff_print_line,
.flags  = &tracer_flags,
@@ -682,7 +682,7 @@ static struct tracer preemptirqsoff_tracer __read_mostly =
 #endif
.open   = irqsoff_trace_open,
.close  = irqsoff_trace_close,
-   .use_max_tr = 1,
+   .use_max_tr = true,
 };
 
 # define register_preemptirqsoff(trace) register_tracer(&trace)
diff --git a/kernel/trace/trace_sched_wakeup.c 
b/kernel/trace/trace_sched_wakeup.c
index 2f6af78..bc64fc1 100644
--- a/kernel/trace/trace_sched_wakeup.c
+++ b/kernel/trace/trace_sched_wakeup.c
@@ -589,7 +589,7 @@ static struct tracer wakeup_tracer __read_mostly =
.reset  = wakeup_tracer_reset,
.start  = wakeup_tracer_start,
.stop   = wakeup_tracer_stop,
-   .print_max  = 1,
+   .print_max  = true,
.print_header   = wakeup_print_header,
.print_line = wakeup_print_line,
.flags  = &tracer_flags,
@@ -599,7 +599,7 @@ static struct tracer wakeup_tracer __read_mostly =
 #endif
.open   = wakeup_trace_open,
.close  = wakeup_trace_close,
-   .use_max_tr = 1,
+   .use_max_tr = true,
 };
 
 static struct tracer wakeup_rt_tracer __read_mostly =
@@ -610,7 +610,7 @@ static struct tracer wakeup_rt_tracer __read_mostly =
.start  = wakeup_tracer_start,
.stop   = wakeup_tracer_stop,
.wait_pipe  = poll_wait_pipe,
-   .print_max  = 1,
+   .print_max  = true,
.print_header   = wakeup_print_header,
.print_line = wakeup_print_line,
.flags  = &tracer_flags,
@@ -620,7 +620,7 @@ static struct tracer wakeup_r