[PATCH v4 -tip 1/3] tracing: replace static old_tracer with trace iterator's pointer to the original tracer's name

2012-12-25 Thread Hiraku Toyooka
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.

Signed-off-by: Hiraku Toyooka 
Cc: Steven Rostedt 
Cc: Frederic Weisbecker 
Cc: Ingo Molnar 
Cc: linux-kernel@vger.kernel.org
---
 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 a8ce008..1787304 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(_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(_types_lock);
 
atomic_inc(_record_cmdline_disabled);
@@ -3481,7 +3483,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 */
@@ -3493,10 +3494,8 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
 
/* copy the tracer to avoid using a global lock all around */
mutex_lock(_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(_types_lock);
 
/*
@@ -3652,7 +3651,6 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
.ops= _pipe_buf_ops,
.spd_release= tracing_spd_release_pipe,
};
-   static struct tracer *old_tracer;
ssize_t ret;
size_t rem;
unsigned int i;
@@ -3662,10 +3660,8 @@ static ssize_t tracing_splice_read_pipe(struct file 
*filp,
 
/* copy the tracer to avoid using a global lock all around */
mutex_lock(_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(_types_lock);
 
mutex_lock(>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/


[PATCH v4 -tip 1/3] tracing: replace static old_tracer with trace iterator's pointer to the original tracer's name

2012-12-25 Thread Hiraku Toyooka
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.

Signed-off-by: Hiraku Toyooka hiraku.toyooka...@hitachi.com
Cc: Steven Rostedt rost...@goodmis.org
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: Ingo Molnar mi...@redhat.com
Cc: linux-kernel@vger.kernel.org
---
 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 a8ce008..1787304 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);
@@ -3481,7 +3483,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 */
@@ -3493,10 +3494,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);
 
/*
@@ -3652,7 +3651,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;
@@ -3662,10 +3660,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/