Skip to content

Commit d39cdd2

Browse files
Chunyu-Hurostedt
authored andcommitted
tracing: Make tracer_flags use the right set_flag callback
When I was updating the ftrace_stress test of ltp. I encountered a strange phenomemon, excute following steps: echo nop > /sys/kernel/debug/tracing/current_tracer echo 0 > /sys/kernel/debug/tracing/options/funcgraph-cpu bash: echo: write error: Invalid argument check dmesg: [ 1024.903855] nop_test_refuse flag set to 0: we refuse.Now cat trace_options to see the result The reason is that the trace option test will randomly setup trace option under tracing/options no matter what the current_tracer is. but the set_tracer_option is always using the set_flag callback from the current_tracer. This patch adds a pointer to tracer_flags and make it point to the tracer it belongs to. When the option is setup, the set_flag of the right tracer will be used no matter what the the current_tracer is. And the old dummy_tracer_flags is used for all the tracers which doesn't have a tracer_flags, having issue to use it to save the pointer of a tracer. So remove it and use dynamic dummy tracer_flags for tracers needing a dummy tracer_flags, as a result, there are no tracers sharing tracer_flags, so remove the check code. And save the current tracer to trace_option_dentry seems not good as it may waste mem space when mount the debug/trace fs more than one time. Link: http://lkml.kernel.org/r/1457444222-8654-1-git-send-email-chuhu@redhat.com Signed-off-by: Chunyu Hu <chuhu@redhat.com> [ Fixed up function tracer options to work with the change ] Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent f6cede5 commit d39cdd2

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ static struct tracer_opt dummy_tracer_opt[] = {
7474
{ }
7575
};
7676

77-
static struct tracer_flags dummy_tracer_flags = {
78-
.val = 0,
79-
.opts = dummy_tracer_opt
80-
};
81-
8277
static int
8378
dummy_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
8479
{
@@ -1258,12 +1253,20 @@ int __init register_tracer(struct tracer *type)
12581253

12591254
if (!type->set_flag)
12601255
type->set_flag = &dummy_set_flag;
1261-
if (!type->flags)
1262-
type->flags = &dummy_tracer_flags;
1263-
else
1256+
if (!type->flags) {
1257+
/*allocate a dummy tracer_flags*/
1258+
type->flags = kmalloc(sizeof(*type->flags), GFP_KERNEL);
1259+
if (!type->flags)
1260+
return -ENOMEM;
1261+
type->flags->val = 0;
1262+
type->flags->opts = dummy_tracer_opt;
1263+
} else
12641264
if (!type->flags->opts)
12651265
type->flags->opts = dummy_tracer_opt;
12661266

1267+
/* store the tracer for __set_tracer_option */
1268+
type->flags->trace = type;
1269+
12671270
ret = run_tracer_selftest(type);
12681271
if (ret < 0)
12691272
goto out;
@@ -3505,7 +3508,7 @@ static int __set_tracer_option(struct trace_array *tr,
35053508
struct tracer_flags *tracer_flags,
35063509
struct tracer_opt *opts, int neg)
35073510
{
3508-
struct tracer *trace = tr->current_trace;
3511+
struct tracer *trace = tracer_flags->trace;
35093512
int ret;
35103513

35113514
ret = trace->set_flag(tr, tracer_flags->val, opts->bit, !neg);
@@ -6391,11 +6394,8 @@ create_trace_option_files(struct trace_array *tr, struct tracer *tracer)
63916394
return;
63926395

63936396
for (i = 0; i < tr->nr_topts; i++) {
6394-
/*
6395-
* Check if these flags have already been added.
6396-
* Some tracers share flags.
6397-
*/
6398-
if (tr->topts[i].tracer->flags == tracer->flags)
6397+
/* Make sure there's no duplicate flags. */
6398+
if (WARN_ON_ONCE(tr->topts[i].tracer->flags == tracer->flags))
63996399
return;
64006400
}
64016401

‎kernel/trace/trace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ struct tracer_opt {
345345
struct tracer_flags {
346346
u32 val;
347347
struct tracer_opt *opts;
348+
struct tracer *trace;
348349
};
349350

350351
/* Makes more easy to define a tracer opt */

‎kernel/trace/trace_functions.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ static void tracing_stop_function_trace(struct trace_array *tr)
219219
unregister_ftrace_function(tr->ops);
220220
}
221221

222+
static struct tracer function_trace;
223+
222224
static int
223225
func_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
224226
{
@@ -228,6 +230,10 @@ func_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
228230
if (!!set == !!(func_flags.val & TRACE_FUNC_OPT_STACK))
229231
break;
230232

233+
/* We can change this flag when not running. */
234+
if (tr->current_trace != &function_trace)
235+
break;
236+
231237
unregister_ftrace_function(tr->ops);
232238

233239
if (set) {

0 commit comments

Comments
 (0)