Skip to content

Commit 28575c6

Browse files
committed
ring-buffer: Add recording of ring buffer recursion into recursed_functions
Add a new config RING_BUFFER_RECORD_RECURSION that will place functions that recurse from the ring buffer into the ftrace recused_functions file. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 7b68621 commit 28575c6

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎kernel/trace/Kconfig‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,20 @@ config FTRACE_RECORD_RECURSION_SIZE
752752
This file can be reset, but the limit can not change in
753753
size at runtime.
754754

755+
config RING_BUFFER_RECORD_RECURSION
756+
bool "Record functions that recurse in the ring buffer"
757+
depends on FTRACE_RECORD_RECURSION
758+
# default y, because it is coupled with FTRACE_RECORD_RECURSION
759+
default y
760+
help
761+
The ring buffer has its own internal recursion. Although when
762+
recursion happens it wont cause harm because of the protection,
763+
but it does cause an unwanted overhead. Enabling this option will
764+
place where recursion was detected into the ftrace "recursed_functions"
765+
file.
766+
767+
This will add more overhead to cases that have recursion.
768+
755769
config GCOV_PROFILE_FTRACE
756770
bool "Enable GCOV profiling on ftrace subsystem"
757771
depends on GCOV_KERNEL

‎kernel/trace/ring_buffer.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com>
66
*/
7+
#include <linux/trace_recursion.h>
78
#include <linux/trace_events.h>
89
#include <linux/ring_buffer.h>
910
#include <linux/trace_clock.h>
@@ -3006,6 +3007,13 @@ rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
30063007
irq_work_queue(&cpu_buffer->irq_work.work);
30073008
}
30083009

3010+
#ifdef CONFIG_RING_BUFFER_RECORD_RECURSION
3011+
# define do_ring_buffer_record_recursion() \
3012+
do_ftrace_record_recursion(_THIS_IP_, _RET_IP_)
3013+
#else
3014+
# define do_ring_buffer_record_recursion() do { } while (0)
3015+
#endif
3016+
30093017
/*
30103018
* The lock and unlock are done within a preempt disable section.
30113019
* The current_context per_cpu variable can only be modified
@@ -3088,8 +3096,10 @@ trace_recursive_lock(struct ring_buffer_per_cpu *cpu_buffer)
30883096
* been updated yet. In this case, use the TRANSITION bit.
30893097
*/
30903098
bit = RB_CTX_TRANSITION;
3091-
if (val & (1 << (bit + cpu_buffer->nest)))
3099+
if (val & (1 << (bit + cpu_buffer->nest))) {
3100+
do_ring_buffer_record_recursion();
30923101
return 1;
3102+
}
30933103
}
30943104

30953105
val |= (1 << (bit + cpu_buffer->nest));

0 commit comments

Comments
 (0)