Skip to content

Commit cf6ab6d

Browse files
committed
tracing: Add ref count to tracer for when they are being read by pipe
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 <[email protected]>
1 parent 97bf6af commit cf6ab6d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

kernel/trace/trace.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4140,6 +4140,12 @@ static int tracing_set_tracer(struct trace_array *tr, const char *buf)
41404140
goto out;
41414141
}
41424142

4143+
/* If trace pipe files are being read, we can't change the tracer */
4144+
if (tr->current_trace->ref) {
4145+
ret = -EBUSY;
4146+
goto out;
4147+
}
4148+
41434149
trace_branch_disable();
41444150

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

43654371
nonseekable_open(inode, filp);
4372+
4373+
tr->current_trace->ref++;
43664374
out:
43674375
mutex_unlock(&trace_types_lock);
43684376
return ret;
@@ -4382,6 +4390,8 @@ static int tracing_release_pipe(struct inode *inode, struct file *file)
43824390

43834391
mutex_lock(&trace_types_lock);
43844392

4393+
tr->current_trace->ref--;
4394+
43854395
if (iter->trace->pipe_close)
43864396
iter->trace->pipe_close(iter);
43874397

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

53325342
filp->private_data = info;
53335343

5344+
tr->current_trace->ref++;
5345+
53345346
mutex_unlock(&trace_types_lock);
53355347

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

54385450
mutex_lock(&trace_types_lock);
54395451

5452+
iter->tr->current_trace->ref--;
5453+
54405454
__trace_array_put(iter->tr);
54415455

54425456
if (info->spare)
@@ -6416,7 +6430,7 @@ static int instance_delete(const char *name)
64166430
goto out_unlock;
64176431

64186432
ret = -EBUSY;
6419-
if (tr->ref)
6433+
if (tr->ref || (tr->current_trace && tr->current_trace->ref))
64206434
goto out_unlock;
64216435

64226436
list_del(&tr->list);

kernel/trace/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ struct tracer {
388388
struct tracer *next;
389389
struct tracer_flags *flags;
390390
int enabled;
391+
int ref;
391392
bool print_max;
392393
bool allow_instances;
393394
#ifdef CONFIG_TRACER_MAX_TRACE

0 commit comments

Comments
 (0)