Skip to content

Commit

Permalink
tracing: Add ref count to tracer for when they are being read by pipe
Browse files Browse the repository at this point in the history
When one of the trace pipe files are being read (by either the trace_pipe
or trace_pipe_raw), do not allow the current_trace to change. By adding
a ref count that is incremented when the pipe files are opened, will
prevent the current_trace from being changed.

This will allow for the removal of the global trace_types_lock from
reading the pipe buffers (which is currently a bottle neck).

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (Red Hat) committed Dec 22, 2014
1 parent 97bf6af commit cf6ab6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4140,6 +4140,12 @@ static int tracing_set_tracer(struct trace_array *tr, const char *buf)
goto out;
}

/* If trace pipe files are being read, we can't change the tracer */
if (tr->current_trace->ref) {
ret = -EBUSY;
goto out;
}

trace_branch_disable();

tr->current_trace->enabled--;
Expand Down Expand Up @@ -4363,6 +4369,8 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
iter->trace->pipe_open(iter);

nonseekable_open(inode, filp);

tr->current_trace->ref++;
out:
mutex_unlock(&trace_types_lock);
return ret;
Expand All @@ -4382,6 +4390,8 @@ static int tracing_release_pipe(struct inode *inode, struct file *file)

mutex_lock(&trace_types_lock);

tr->current_trace->ref--;

if (iter->trace->pipe_close)
iter->trace->pipe_close(iter);

Expand Down Expand Up @@ -5331,6 +5341,8 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)

filp->private_data = info;

tr->current_trace->ref++;

mutex_unlock(&trace_types_lock);

ret = nonseekable_open(inode, filp);
Expand Down Expand Up @@ -5437,6 +5449,8 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)

mutex_lock(&trace_types_lock);

iter->tr->current_trace->ref--;

__trace_array_put(iter->tr);

if (info->spare)
Expand Down Expand Up @@ -6416,7 +6430,7 @@ static int instance_delete(const char *name)
goto out_unlock;

ret = -EBUSY;
if (tr->ref)
if (tr->ref || (tr->current_trace && tr->current_trace->ref))
goto out_unlock;

list_del(&tr->list);
Expand Down
1 change: 1 addition & 0 deletions kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ struct tracer {
struct tracer *next;
struct tracer_flags *flags;
int enabled;
int ref;
bool print_max;
bool allow_instances;
#ifdef CONFIG_TRACER_MAX_TRACE
Expand Down

0 comments on commit cf6ab6d

Please sign in to comment.