Skip to content

Commit

Permalink
Merge tag 'trace-v4.11-rc5-5' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/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
  • Loading branch information
Linus Torvalds committed Apr 20, 2017
2 parents 7f42589 + 78f7a45 commit 160062e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 14 additions & 2 deletions kernel/trace/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3405,11 +3405,23 @@ EXPORT_SYMBOL_GPL(ring_buffer_iter_reset);
int ring_buffer_iter_empty(struct ring_buffer_iter *iter)
{
struct ring_buffer_per_cpu *cpu_buffer;
struct buffer_page *reader;
struct buffer_page *head_page;
struct buffer_page *commit_page;
unsigned commit;

cpu_buffer = iter->cpu_buffer;

return iter->head_page == cpu_buffer->commit_page &&
iter->head == rb_commit_index(cpu_buffer);
/* Remember, trace recording is off when iterator is in use */
reader = cpu_buffer->reader_page;
head_page = cpu_buffer->head_page;
commit_page = cpu_buffer->commit_page;
commit = rb_page_commit(commit_page);

return ((iter->head_page == commit_page && iter->head == commit) ||
(iter->head_page == reader && commit_page == head_page &&
head_page->read == commit &&
iter->head == rb_page_commit(cpu_buffer->reader_page)));
}
EXPORT_SYMBOL_GPL(ring_buffer_iter_empty);

Expand Down
8 changes: 5 additions & 3 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6733,11 +6733,13 @@ ftrace_trace_snapshot_callback(struct ftrace_hash *hash,
return ret;

out_reg:
ret = register_ftrace_function_probe(glob, ops, count);
ret = alloc_snapshot(&global_trace);
if (ret < 0)
goto out;

if (ret >= 0)
alloc_snapshot(&global_trace);
ret = register_ftrace_function_probe(glob, ops, count);

out:
return ret < 0 ? ret : 0;
}

Expand Down

0 comments on commit 160062e

Please sign in to comment.