Skip to content

Commit

Permalink
UPSTREAM: tracing: Convert the tracing facility over to use tracefs
Browse files Browse the repository at this point in the history
debugfs was fine for the tracing facility as a quick way to get
an interface. Now that tracing has matured, it should separate itself
from debugfs such that it can be mounted separately without needing
to mount all of debugfs with it. That is, users resist using tracing
because it requires mounting debugfs. Having tracing have its own file
system lets users get the features of tracing without needing to bring
in the rest of the kernel's debug infrastructure.

Another reason for tracefs is that debubfs does not support mkdir.
Currently, to create instances, one does a mkdir in the tracing/instance
directory. This is implemented via a hack that forces debugfs to do
something it is not intended on doing. By converting over to tracefs, this
hack can be removed and mkdir can be properly implemented. This patch does
not address this yet, but it lays the ground work for that to be done.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Bug: 31856701
Change-Id: Iace87f5fc41eed64c3fa1e70b48e1eaa6ad076d8
(cherry picked from commit 8434dc9)
Signed-off-by: Paul Lawrence <paullawrence@google.com>
  • Loading branch information
rostedt authored and pundiramit committed Oct 28, 2016
1 parent 66819d0 commit 87c0977
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 66 deletions.
22 changes: 11 additions & 11 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <linux/kallsyms.h>
#include <linux/seq_file.h>
#include <linux/suspend.h>
#include <linux/debugfs.h>
#include <linux/tracefs.h>
#include <linux/hardirq.h>
#include <linux/kthread.h>
#include <linux/uaccess.h>
Expand Down Expand Up @@ -1002,7 +1002,7 @@ static struct tracer_stat function_stats __initdata = {
.stat_show = function_stat_show
};

static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
{
struct ftrace_profile_stat *stat;
struct dentry *entry;
Expand Down Expand Up @@ -1038,15 +1038,15 @@ static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
}
}

entry = debugfs_create_file("function_profile_enabled", 0644,
entry = tracefs_create_file("function_profile_enabled", 0644,
d_tracer, NULL, &ftrace_profile_fops);
if (!entry)
pr_warning("Could not create debugfs "
pr_warning("Could not create tracefs "
"'function_profile_enabled' entry\n");
}

#else /* CONFIG_FUNCTION_PROFILER */
static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
{
}
#endif /* CONFIG_FUNCTION_PROFILER */
Expand Down Expand Up @@ -4487,7 +4487,7 @@ void ftrace_destroy_filter_files(struct ftrace_ops *ops)
mutex_unlock(&ftrace_lock);
}

static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
static __init int ftrace_init_dyn_tracefs(struct dentry *d_tracer)
{

trace_create_file("available_filter_functions", 0444,
Expand Down Expand Up @@ -4769,7 +4769,7 @@ static int __init ftrace_nodyn_init(void)
}
core_initcall(ftrace_nodyn_init);

static inline int ftrace_init_dyn_debugfs(struct dentry *d_tracer) { return 0; }
static inline int ftrace_init_dyn_tracefs(struct dentry *d_tracer) { return 0; }
static inline void ftrace_startup_enable(int command) { }
static inline void ftrace_startup_all(int command) { }
/* Keep as macros so we do not need to define the commands */
Expand Down Expand Up @@ -5218,24 +5218,24 @@ static const struct file_operations ftrace_pid_fops = {
.release = ftrace_pid_release,
};

static __init int ftrace_init_debugfs(void)
static __init int ftrace_init_tracefs(void)
{
struct dentry *d_tracer;

d_tracer = tracing_init_dentry();
if (IS_ERR(d_tracer))
return 0;

ftrace_init_dyn_debugfs(d_tracer);
ftrace_init_dyn_tracefs(d_tracer);

trace_create_file("set_ftrace_pid", 0644, d_tracer,
NULL, &ftrace_pid_fops);

ftrace_profile_debugfs(d_tracer);
ftrace_profile_tracefs(d_tracer);

return 0;
}
fs_initcall(ftrace_init_debugfs);
fs_initcall(ftrace_init_tracefs);

/**
* ftrace_kill - kill ftrace
Expand Down
55 changes: 32 additions & 23 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/notifier.h>
#include <linux/irqflags.h>
#include <linux/debugfs.h>
#include <linux/tracefs.h>
#include <linux/pagemap.h>
#include <linux/hardirq.h>
#include <linux/linkage.h>
Expand Down Expand Up @@ -5922,6 +5923,14 @@ static inline __init int register_snapshot_cmd(void) { return 0; }

static struct dentry *tracing_get_dentry(struct trace_array *tr)
{
if (WARN_ON(!tr->dir))
return ERR_PTR(-ENODEV);

/* Top directory uses NULL as the parent */
if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
return NULL;

/* All sub buffers have a descriptor */
return tr->dir;
}

Expand All @@ -5936,10 +5945,10 @@ static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu)
if (IS_ERR(d_tracer))
return NULL;

tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer);
tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer);

WARN_ONCE(!tr->percpu_dir,
"Could not create debugfs directory 'per_cpu/%d'\n", cpu);
"Could not create tracefs directory 'per_cpu/%d'\n", cpu);

return tr->percpu_dir;
}
Expand All @@ -5956,7 +5965,7 @@ trace_create_cpu_file(const char *name, umode_t mode, struct dentry *parent,
}

static void
tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
tracing_init_tracefs_percpu(struct trace_array *tr, long cpu)
{
struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu);
struct dentry *d_cpu;
Expand All @@ -5966,9 +5975,9 @@ tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
return;

snprintf(cpu_dir, 30, "cpu%ld", cpu);
d_cpu = debugfs_create_dir(cpu_dir, d_percpu);
d_cpu = tracefs_create_dir(cpu_dir, d_percpu);
if (!d_cpu) {
pr_warning("Could not create debugfs '%s' entry\n", cpu_dir);
pr_warning("Could not create tracefs '%s' entry\n", cpu_dir);
return;
}

Expand Down Expand Up @@ -6120,9 +6129,9 @@ struct dentry *trace_create_file(const char *name,
{
struct dentry *ret;

ret = debugfs_create_file(name, mode, parent, data, fops);
ret = tracefs_create_file(name, mode, parent, data, fops);
if (!ret)
pr_warning("Could not create debugfs '%s' entry\n", name);
pr_warning("Could not create tracefs '%s' entry\n", name);

return ret;
}
Expand All @@ -6139,9 +6148,9 @@ static struct dentry *trace_options_init_dentry(struct trace_array *tr)
if (IS_ERR(d_tracer))
return NULL;

tr->options = debugfs_create_dir("options", d_tracer);
tr->options = tracefs_create_dir("options", d_tracer);
if (!tr->options) {
pr_warning("Could not create debugfs directory 'options'\n");
pr_warning("Could not create tracefs directory 'options'\n");
return NULL;
}

Expand Down Expand Up @@ -6210,7 +6219,7 @@ destroy_trace_option_files(struct trace_option_dentry *topts)
return;

for (cnt = 0; topts[cnt].opt; cnt++)
debugfs_remove(topts[cnt].entry);
tracefs_remove(topts[cnt].entry);

kfree(topts);
}
Expand Down Expand Up @@ -6299,7 +6308,7 @@ static const struct file_operations rb_simple_fops = {
struct dentry *trace_instance_dir;

static void
init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer);
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);

static int
allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size)
Expand Down Expand Up @@ -6415,17 +6424,17 @@ static int new_instance_create(const char *name)
if (allocate_trace_buffers(tr, trace_buf_size) < 0)
goto out_free_tr;

tr->dir = debugfs_create_dir(name, trace_instance_dir);
tr->dir = tracefs_create_dir(name, trace_instance_dir);
if (!tr->dir)
goto out_free_tr;

ret = event_trace_add_tracer(tr->dir, tr);
if (ret) {
debugfs_remove_recursive(tr->dir);
tracefs_remove_recursive(tr->dir);
goto out_free_tr;
}

init_tracer_debugfs(tr, tr->dir);
init_tracer_tracefs(tr, tr->dir);

list_add(&tr->list, &ftrace_trace_arrays);

Expand Down Expand Up @@ -6498,7 +6507,7 @@ static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t m
return -ENOENT;

/*
* The inode mutex is locked, but debugfs_create_dir() will also
* The inode mutex is locked, but tracefs_create_dir() will also
* take the mutex. As the instances directory can not be destroyed
* or changed in any other way, it is safe to unlock it, and
* let the dentry try. If two users try to make the same dir at
Expand Down Expand Up @@ -6528,7 +6537,7 @@ static int instance_rmdir(struct inode *inode, struct dentry *dentry)
mutex_unlock(&dentry->d_inode->i_mutex);

/*
* The inode mutex is locked, but debugfs_create_dir() will also
* The inode mutex is locked, but tracefs_create_dir() will also
* take the mutex. As the instances directory can not be destroyed
* or changed in any other way, it is safe to unlock it, and
* let the dentry try. If two users try to make the same dir at
Expand All @@ -6553,7 +6562,7 @@ static const struct inode_operations instance_dir_inode_operations = {

static __init void create_trace_instances(struct dentry *d_tracer)
{
trace_instance_dir = debugfs_create_dir("instances", d_tracer);
trace_instance_dir = tracefs_create_dir("instances", d_tracer);
if (WARN_ON(!trace_instance_dir))
return;

Expand All @@ -6562,7 +6571,7 @@ static __init void create_trace_instances(struct dentry *d_tracer)
}

static void
init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
{
int cpu;

Expand Down Expand Up @@ -6619,7 +6628,7 @@ init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
#endif

for_each_tracing_cpu(cpu)
tracing_init_debugfs_percpu(tr, cpu);
tracing_init_tracefs_percpu(tr, cpu);

}

Expand Down Expand Up @@ -6647,10 +6656,10 @@ struct dentry *tracing_init_dentry(void)
return ERR_PTR(-ENOMEM);
}

return tr->dir;
return NULL;
}

static __init int tracer_init_debugfs(void)
static __init int tracer_init_tracefs(void)
{
struct dentry *d_tracer;

Expand All @@ -6660,7 +6669,7 @@ static __init int tracer_init_debugfs(void)
if (IS_ERR(d_tracer))
return 0;

init_tracer_debugfs(&global_trace, d_tracer);
init_tracer_tracefs(&global_trace, d_tracer);

trace_create_file("tracing_thresh", 0644, d_tracer,
&global_trace, &tracing_thresh_fops);
Expand Down Expand Up @@ -7005,5 +7014,5 @@ __init static int clear_boot_tracer(void)
return 0;
}

fs_initcall(tracer_init_debugfs);
fs_initcall(tracer_init_tracefs);
late_initcall(clear_boot_tracer);
2 changes: 1 addition & 1 deletion kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ struct tracer_flags {


/**
* struct tracer - a specific tracer and its callbacks to interact with debugfs
* struct tracer - a specific tracer and its callbacks to interact with tracefs
* @name: the name chosen to select it on the available_tracers file
* @init: called when one switches to this tracer (echo name > current_tracer)
* @reset: called when one switches to another tracer
Expand Down
Loading

0 comments on commit 87c0977

Please sign in to comment.