Skip to content

Commit 160062e

Browse files
committed
Merge tag 'trace-v4.11-rc5-5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull two more ftrace fixes from Steven Rostedt: "While continuing my development, I uncovered two more small bugs. One is a race condition when enabling the snapshot function probe trigger. It enables the probe before allocating the snapshot, and if the probe triggers first, it stops tracing with a warning that the snapshot buffer was not allocated. The seconds is that the snapshot file should show how to use it when it is empty. But a bug fix from long ago broke the "is empty" test and the snapshot file no longer displays the help message" * tag 'trace-v4.11-rc5-5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: ring-buffer: Have ring_buffer_iter_empty() return true when empty tracing: Allocate the snapshot buffer before enabling probe
2 parents 7f42589 + 78f7a45 commit 160062e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

kernel/trace/ring_buffer.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,11 +3405,23 @@ EXPORT_SYMBOL_GPL(ring_buffer_iter_reset);
34053405
int ring_buffer_iter_empty(struct ring_buffer_iter *iter)
34063406
{
34073407
struct ring_buffer_per_cpu *cpu_buffer;
3408+
struct buffer_page *reader;
3409+
struct buffer_page *head_page;
3410+
struct buffer_page *commit_page;
3411+
unsigned commit;
34083412

34093413
cpu_buffer = iter->cpu_buffer;
34103414

3411-
return iter->head_page == cpu_buffer->commit_page &&
3412-
iter->head == rb_commit_index(cpu_buffer);
3415+
/* Remember, trace recording is off when iterator is in use */
3416+
reader = cpu_buffer->reader_page;
3417+
head_page = cpu_buffer->head_page;
3418+
commit_page = cpu_buffer->commit_page;
3419+
commit = rb_page_commit(commit_page);
3420+
3421+
return ((iter->head_page == commit_page && iter->head == commit) ||
3422+
(iter->head_page == reader && commit_page == head_page &&
3423+
head_page->read == commit &&
3424+
iter->head == rb_page_commit(cpu_buffer->reader_page)));
34133425
}
34143426
EXPORT_SYMBOL_GPL(ring_buffer_iter_empty);
34153427

kernel/trace/trace.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6733,11 +6733,13 @@ ftrace_trace_snapshot_callback(struct ftrace_hash *hash,
67336733
return ret;
67346734

67356735
out_reg:
6736-
ret = register_ftrace_function_probe(glob, ops, count);
6736+
ret = alloc_snapshot(&global_trace);
6737+
if (ret < 0)
6738+
goto out;
67376739

6738-
if (ret >= 0)
6739-
alloc_snapshot(&global_trace);
6740+
ret = register_ftrace_function_probe(glob, ops, count);
67406741

6742+
out:
67416743
return ret < 0 ? ret : 0;
67426744
}
67436745

0 commit comments

Comments
 (0)