Commit f4e781c0 authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt

tracing: Move the tracing selftest code into its own function

Move the tracing startup selftest code into its own function and
when not enabled, always have that function succeed.

This makes the register_tracer() function much more readable.
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent f5eb5588
...@@ -818,56 +818,15 @@ static void default_wait_pipe(struct trace_iterator *iter) ...@@ -818,56 +818,15 @@ static void default_wait_pipe(struct trace_iterator *iter)
ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file); ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file);
} }
/**
* register_tracer - register a tracer with the ftrace system.
* @type - the plugin for the tracer
*
* Register a new plugin tracer.
*/
int register_tracer(struct tracer *type)
{
struct tracer *t;
int ret = 0;
if (!type->name) {
pr_info("Tracer must have a name\n");
return -1;
}
if (strlen(type->name) >= MAX_TRACER_SIZE) {
pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE);
return -1;
}
mutex_lock(&trace_types_lock);
tracing_selftest_running = true;
for (t = trace_types; t; t = t->next) {
if (strcmp(type->name, t->name) == 0) {
/* already found */
pr_info("Tracer %s already registered\n",
type->name);
ret = -1;
goto out;
}
}
if (!type->set_flag)
type->set_flag = &dummy_set_flag;
if (!type->flags)
type->flags = &dummy_tracer_flags;
else
if (!type->flags->opts)
type->flags->opts = dummy_tracer_opt;
if (!type->wait_pipe)
type->wait_pipe = default_wait_pipe;
#ifdef CONFIG_FTRACE_STARTUP_TEST #ifdef CONFIG_FTRACE_STARTUP_TEST
if (type->selftest && !tracing_selftest_disabled) { static int run_tracer_selftest(struct tracer *type)
{
struct trace_array *tr = &global_trace; struct trace_array *tr = &global_trace;
struct tracer *saved_tracer = tr->current_trace; struct tracer *saved_tracer = tr->current_trace;
int ret;
if (!type->selftest || tracing_selftest_disabled)
return 0;
/* /*
* Run a selftest on this tracer. * Run a selftest on this tracer.
...@@ -899,7 +858,7 @@ int register_tracer(struct tracer *type) ...@@ -899,7 +858,7 @@ int register_tracer(struct tracer *type)
printk(KERN_CONT "FAILED!\n"); printk(KERN_CONT "FAILED!\n");
/* Add the warning after printing 'FAILED' */ /* Add the warning after printing 'FAILED' */
WARN_ON(1); WARN_ON(1);
goto out; return -1;
} }
/* Only reset on passing, to avoid touching corrupted buffers */ /* Only reset on passing, to avoid touching corrupted buffers */
tracing_reset_online_cpus(&tr->trace_buffer); tracing_reset_online_cpus(&tr->trace_buffer);
...@@ -916,8 +875,63 @@ int register_tracer(struct tracer *type) ...@@ -916,8 +875,63 @@ int register_tracer(struct tracer *type)
#endif #endif
printk(KERN_CONT "PASSED\n"); printk(KERN_CONT "PASSED\n");
return 0;
}
#else
static inline int run_tracer_selftest(struct tracer *type)
{
return 0;
}
#endif /* CONFIG_FTRACE_STARTUP_TEST */
/**
* register_tracer - register a tracer with the ftrace system.
* @type - the plugin for the tracer
*
* Register a new plugin tracer.
*/
int register_tracer(struct tracer *type)
{
struct tracer *t;
int ret = 0;
if (!type->name) {
pr_info("Tracer must have a name\n");
return -1;
} }
#endif
if (strlen(type->name) >= MAX_TRACER_SIZE) {
pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE);
return -1;
}
mutex_lock(&trace_types_lock);
tracing_selftest_running = true;
for (t = trace_types; t; t = t->next) {
if (strcmp(type->name, t->name) == 0) {
/* already found */
pr_info("Tracer %s already registered\n",
type->name);
ret = -1;
goto out;
}
}
if (!type->set_flag)
type->set_flag = &dummy_set_flag;
if (!type->flags)
type->flags = &dummy_tracer_flags;
else
if (!type->flags->opts)
type->flags->opts = dummy_tracer_opt;
if (!type->wait_pipe)
type->wait_pipe = default_wait_pipe;
ret = run_tracer_selftest(type);
if (ret < 0)
goto out;
type->next = trace_types; type->next = trace_types;
trace_types = type; trace_types = type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment