Skip to content

Commit 5e6d2b9

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Use one prologue for the preempt irqs off tracer function tracers
The preempt and irqsoff tracers have three types of function tracers. Normal function tracer, function graph entry, and function graph return. Each of these use a complex dance to prevent recursion and whether to trace the data or not (depending if interrupts are enabled or not). This patch moves the duplicate code into a single routine, to prevent future mistakes with modifying duplicate complex code. Cc: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 542181d commit 5e6d2b9

1 file changed

Lines changed: 48 additions & 48 deletions

File tree

‎kernel/trace/trace_irqsoff.c‎

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,22 @@ static __cacheline_aligned_in_smp unsigned long max_sequence;
8787

8888
#ifdef CONFIG_FUNCTION_TRACER
8989
/*
90-
* irqsoff uses its own tracer function to keep the overhead down:
90+
* Prologue for the preempt and irqs off function tracers.
91+
*
92+
* Returns 1 if it is OK to continue, and data->disabled is
93+
* incremented.
94+
* 0 if the trace is to be ignored, and data->disabled
95+
* is kept the same.
96+
*
97+
* Note, this function is also used outside this ifdef but
98+
* inside the #ifdef of the function graph tracer below.
99+
* This is OK, since the function graph tracer is
100+
* dependent on the function tracer.
91101
*/
92-
static void
93-
irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
102+
static int func_prolog_dec(struct trace_array *tr,
103+
struct trace_array_cpu **data,
104+
unsigned long *flags)
94105
{
95-
struct trace_array *tr = irqsoff_trace;
96-
struct trace_array_cpu *data;
97-
unsigned long flags;
98106
long disabled;
99107
int cpu;
100108

@@ -106,18 +114,38 @@ irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
106114
*/
107115
cpu = raw_smp_processor_id();
108116
if (likely(!per_cpu(tracing_cpu, cpu)))
109-
return;
117+
return 0;
110118

111-
local_save_flags(flags);
119+
local_save_flags(*flags);
112120
/* slight chance to get a false positive on tracing_cpu */
113-
if (!irqs_disabled_flags(flags))
114-
return;
121+
if (!irqs_disabled_flags(*flags))
122+
return 0;
115123

116-
data = tr->data[cpu];
117-
disabled = atomic_inc_return(&data->disabled);
124+
*data = tr->data[cpu];
125+
disabled = atomic_inc_return(&(*data)->disabled);
118126

119127
if (likely(disabled == 1))
120-
trace_function(tr, ip, parent_ip, flags, preempt_count());
128+
return 1;
129+
130+
atomic_dec(&(*data)->disabled);
131+
132+
return 0;
133+
}
134+
135+
/*
136+
* irqsoff uses its own tracer function to keep the overhead down:
137+
*/
138+
static void
139+
irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
140+
{
141+
struct trace_array *tr = irqsoff_trace;
142+
struct trace_array_cpu *data;
143+
unsigned long flags;
144+
145+
if (!func_prolog_dec(tr, &data, &flags))
146+
return;
147+
148+
trace_function(tr, ip, parent_ip, flags, preempt_count());
121149

122150
atomic_dec(&data->disabled);
123151
}
@@ -155,30 +183,16 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
155183
struct trace_array *tr = irqsoff_trace;
156184
struct trace_array_cpu *data;
157185
unsigned long flags;
158-
long disabled;
159186
int ret;
160-
int cpu;
161187
int pc;
162188

163-
cpu = raw_smp_processor_id();
164-
if (likely(!per_cpu(tracing_cpu, cpu)))
165-
return 0;
166-
167-
local_save_flags(flags);
168-
/* slight chance to get a false positive on tracing_cpu */
169-
if (!irqs_disabled_flags(flags))
189+
if (!func_prolog_dec(tr, &data, &flags))
170190
return 0;
171191

172-
data = tr->data[cpu];
173-
disabled = atomic_inc_return(&data->disabled);
174-
175-
if (likely(disabled == 1)) {
176-
pc = preempt_count();
177-
ret = __trace_graph_entry(tr, trace, flags, pc);
178-
} else
179-
ret = 0;
180-
192+
pc = preempt_count();
193+
ret = __trace_graph_entry(tr, trace, flags, pc);
181194
atomic_dec(&data->disabled);
195+
182196
return ret;
183197
}
184198

@@ -187,27 +201,13 @@ static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
187201
struct trace_array *tr = irqsoff_trace;
188202
struct trace_array_cpu *data;
189203
unsigned long flags;
190-
long disabled;
191-
int cpu;
192204
int pc;
193205

194-
cpu = raw_smp_processor_id();
195-
if (likely(!per_cpu(tracing_cpu, cpu)))
196-
return;
197-
198-
local_save_flags(flags);
199-
/* slight chance to get a false positive on tracing_cpu */
200-
if (!irqs_disabled_flags(flags))
206+
if (!func_prolog_dec(tr, &data, &flags))
201207
return;
202208

203-
data = tr->data[cpu];
204-
disabled = atomic_inc_return(&data->disabled);
205-
206-
if (likely(disabled == 1)) {
207-
pc = preempt_count();
208-
__trace_graph_return(tr, trace, flags, pc);
209-
}
210-
209+
pc = preempt_count();
210+
__trace_graph_return(tr, trace, flags, pc);
211211
atomic_dec(&data->disabled);
212212
}
213213

0 commit comments

Comments
 (0)