Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Convert the tracing facility over to use tracefs

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>

+74 -66
+11 -11
kernel/trace/ftrace.c
··· 18 18 #include <linux/kallsyms.h> 19 19 #include <linux/seq_file.h> 20 20 #include <linux/suspend.h> 21 - #include <linux/debugfs.h> 21 + #include <linux/tracefs.h> 22 22 #include <linux/hardirq.h> 23 23 #include <linux/kthread.h> 24 24 #include <linux/uaccess.h> ··· 1008 1008 .stat_show = function_stat_show 1009 1009 }; 1010 1010 1011 - static __init void ftrace_profile_debugfs(struct dentry *d_tracer) 1011 + static __init void ftrace_profile_tracefs(struct dentry *d_tracer) 1012 1012 { 1013 1013 struct ftrace_profile_stat *stat; 1014 1014 struct dentry *entry; ··· 1044 1044 } 1045 1045 } 1046 1046 1047 - entry = debugfs_create_file("function_profile_enabled", 0644, 1047 + entry = tracefs_create_file("function_profile_enabled", 0644, 1048 1048 d_tracer, NULL, &ftrace_profile_fops); 1049 1049 if (!entry) 1050 - pr_warning("Could not create debugfs " 1050 + pr_warning("Could not create tracefs " 1051 1051 "'function_profile_enabled' entry\n"); 1052 1052 } 1053 1053 1054 1054 #else /* CONFIG_FUNCTION_PROFILER */ 1055 - static __init void ftrace_profile_debugfs(struct dentry *d_tracer) 1055 + static __init void ftrace_profile_tracefs(struct dentry *d_tracer) 1056 1056 { 1057 1057 } 1058 1058 #endif /* CONFIG_FUNCTION_PROFILER */ ··· 4690 4690 mutex_unlock(&ftrace_lock); 4691 4691 } 4692 4692 4693 - static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer) 4693 + static __init int ftrace_init_dyn_tracefs(struct dentry *d_tracer) 4694 4694 { 4695 4695 4696 4696 trace_create_file("available_filter_functions", 0444, ··· 4998 4998 } 4999 4999 core_initcall(ftrace_nodyn_init); 5000 5000 5001 - static inline int ftrace_init_dyn_debugfs(struct dentry *d_tracer) { return 0; } 5001 + static inline int ftrace_init_dyn_tracefs(struct dentry *d_tracer) { return 0; } 5002 5002 static inline void ftrace_startup_enable(int command) { } 5003 5003 static inline void ftrace_startup_all(int command) { } 5004 5004 /* Keep as macros so we do not need to define the commands */ ··· 5451 5451 .release = ftrace_pid_release, 5452 5452 }; 5453 5453 5454 - static __init int ftrace_init_debugfs(void) 5454 + static __init int ftrace_init_tracefs(void) 5455 5455 { 5456 5456 struct dentry *d_tracer; 5457 5457 ··· 5459 5459 if (IS_ERR(d_tracer)) 5460 5460 return 0; 5461 5461 5462 - ftrace_init_dyn_debugfs(d_tracer); 5462 + ftrace_init_dyn_tracefs(d_tracer); 5463 5463 5464 5464 trace_create_file("set_ftrace_pid", 0644, d_tracer, 5465 5465 NULL, &ftrace_pid_fops); 5466 5466 5467 - ftrace_profile_debugfs(d_tracer); 5467 + ftrace_profile_tracefs(d_tracer); 5468 5468 5469 5469 return 0; 5470 5470 } 5471 - fs_initcall(ftrace_init_debugfs); 5471 + fs_initcall(ftrace_init_tracefs); 5472 5472 5473 5473 /** 5474 5474 * ftrace_kill - kill ftrace
+32 -23
kernel/trace/trace.c
··· 20 20 #include <linux/notifier.h> 21 21 #include <linux/irqflags.h> 22 22 #include <linux/debugfs.h> 23 + #include <linux/tracefs.h> 23 24 #include <linux/pagemap.h> 24 25 #include <linux/hardirq.h> 25 26 #include <linux/linkage.h> ··· 5829 5828 5830 5829 static struct dentry *tracing_get_dentry(struct trace_array *tr) 5831 5830 { 5831 + if (WARN_ON(!tr->dir)) 5832 + return ERR_PTR(-ENODEV); 5833 + 5834 + /* Top directory uses NULL as the parent */ 5835 + if (tr->flags & TRACE_ARRAY_FL_GLOBAL) 5836 + return NULL; 5837 + 5838 + /* All sub buffers have a descriptor */ 5832 5839 return tr->dir; 5833 5840 } 5834 5841 ··· 5851 5842 if (IS_ERR(d_tracer)) 5852 5843 return NULL; 5853 5844 5854 - tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer); 5845 + tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer); 5855 5846 5856 5847 WARN_ONCE(!tr->percpu_dir, 5857 - "Could not create debugfs directory 'per_cpu/%d'\n", cpu); 5848 + "Could not create tracefs directory 'per_cpu/%d'\n", cpu); 5858 5849 5859 5850 return tr->percpu_dir; 5860 5851 } ··· 5871 5862 } 5872 5863 5873 5864 static void 5874 - tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) 5865 + tracing_init_tracefs_percpu(struct trace_array *tr, long cpu) 5875 5866 { 5876 5867 struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); 5877 5868 struct dentry *d_cpu; ··· 5881 5872 return; 5882 5873 5883 5874 snprintf(cpu_dir, 30, "cpu%ld", cpu); 5884 - d_cpu = debugfs_create_dir(cpu_dir, d_percpu); 5875 + d_cpu = tracefs_create_dir(cpu_dir, d_percpu); 5885 5876 if (!d_cpu) { 5886 - pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); 5877 + pr_warning("Could not create tracefs '%s' entry\n", cpu_dir); 5887 5878 return; 5888 5879 } 5889 5880 ··· 6035 6026 { 6036 6027 struct dentry *ret; 6037 6028 6038 - ret = debugfs_create_file(name, mode, parent, data, fops); 6029 + ret = tracefs_create_file(name, mode, parent, data, fops); 6039 6030 if (!ret) 6040 - pr_warning("Could not create debugfs '%s' entry\n", name); 6031 + pr_warning("Could not create tracefs '%s' entry\n", name); 6041 6032 6042 6033 return ret; 6043 6034 } ··· 6054 6045 if (IS_ERR(d_tracer)) 6055 6046 return NULL; 6056 6047 6057 - tr->options = debugfs_create_dir("options", d_tracer); 6048 + tr->options = tracefs_create_dir("options", d_tracer); 6058 6049 if (!tr->options) { 6059 - pr_warning("Could not create debugfs directory 'options'\n"); 6050 + pr_warning("Could not create tracefs directory 'options'\n"); 6060 6051 return NULL; 6061 6052 } 6062 6053 ··· 6125 6116 return; 6126 6117 6127 6118 for (cnt = 0; topts[cnt].opt; cnt++) 6128 - debugfs_remove(topts[cnt].entry); 6119 + tracefs_remove(topts[cnt].entry); 6129 6120 6130 6121 kfree(topts); 6131 6122 } ··· 6214 6205 struct dentry *trace_instance_dir; 6215 6206 6216 6207 static void 6217 - init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer); 6208 + init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer); 6218 6209 6219 6210 static int 6220 6211 allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size) ··· 6330 6321 if (allocate_trace_buffers(tr, trace_buf_size) < 0) 6331 6322 goto out_free_tr; 6332 6323 6333 - tr->dir = debugfs_create_dir(name, trace_instance_dir); 6324 + tr->dir = tracefs_create_dir(name, trace_instance_dir); 6334 6325 if (!tr->dir) 6335 6326 goto out_free_tr; 6336 6327 6337 6328 ret = event_trace_add_tracer(tr->dir, tr); 6338 6329 if (ret) { 6339 - debugfs_remove_recursive(tr->dir); 6330 + tracefs_remove_recursive(tr->dir); 6340 6331 goto out_free_tr; 6341 6332 } 6342 6333 6343 - init_tracer_debugfs(tr, tr->dir); 6334 + init_tracer_tracefs(tr, tr->dir); 6344 6335 6345 6336 list_add(&tr->list, &ftrace_trace_arrays); 6346 6337 ··· 6413 6404 return -ENOENT; 6414 6405 6415 6406 /* 6416 - * The inode mutex is locked, but debugfs_create_dir() will also 6407 + * The inode mutex is locked, but tracefs_create_dir() will also 6417 6408 * take the mutex. As the instances directory can not be destroyed 6418 6409 * or changed in any other way, it is safe to unlock it, and 6419 6410 * let the dentry try. If two users try to make the same dir at ··· 6443 6434 mutex_unlock(&dentry->d_inode->i_mutex); 6444 6435 6445 6436 /* 6446 - * The inode mutex is locked, but debugfs_create_dir() will also 6437 + * The inode mutex is locked, but tracefs_create_dir() will also 6447 6438 * take the mutex. As the instances directory can not be destroyed 6448 6439 * or changed in any other way, it is safe to unlock it, and 6449 6440 * let the dentry try. If two users try to make the same dir at ··· 6468 6459 6469 6460 static __init void create_trace_instances(struct dentry *d_tracer) 6470 6461 { 6471 - trace_instance_dir = debugfs_create_dir("instances", d_tracer); 6462 + trace_instance_dir = tracefs_create_dir("instances", d_tracer); 6472 6463 if (WARN_ON(!trace_instance_dir)) 6473 6464 return; 6474 6465 ··· 6477 6468 } 6478 6469 6479 6470 static void 6480 - init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) 6471 + init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) 6481 6472 { 6482 6473 int cpu; 6483 6474 ··· 6531 6522 #endif 6532 6523 6533 6524 for_each_tracing_cpu(cpu) 6534 - tracing_init_debugfs_percpu(tr, cpu); 6525 + tracing_init_tracefs_percpu(tr, cpu); 6535 6526 6536 6527 } 6537 6528 ··· 6559 6550 return ERR_PTR(-ENOMEM); 6560 6551 } 6561 6552 6562 - return tr->dir; 6553 + return NULL; 6563 6554 } 6564 6555 6565 - static __init int tracer_init_debugfs(void) 6556 + static __init int tracer_init_tracefs(void) 6566 6557 { 6567 6558 struct dentry *d_tracer; 6568 6559 ··· 6572 6563 if (IS_ERR(d_tracer)) 6573 6564 return 0; 6574 6565 6575 - init_tracer_debugfs(&global_trace, d_tracer); 6566 + init_tracer_tracefs(&global_trace, d_tracer); 6576 6567 6577 6568 trace_create_file("tracing_thresh", 0644, d_tracer, 6578 6569 &global_trace, &tracing_thresh_fops); ··· 6934 6925 return 0; 6935 6926 } 6936 6927 6937 - fs_initcall(tracer_init_debugfs); 6928 + fs_initcall(tracer_init_tracefs); 6938 6929 late_initcall(clear_boot_tracer);
+1 -1
kernel/trace/trace.h
··· 334 334 335 335 336 336 /** 337 - * struct tracer - a specific tracer and its callbacks to interact with debugfs 337 + * struct tracer - a specific tracer and its callbacks to interact with tracefs 338 338 * @name: the name chosen to select it on the available_tracers file 339 339 * @init: called when one switches to this tracer (echo name > current_tracer) 340 340 * @reset: called when one switches to another tracer
+16 -16
kernel/trace/trace_events.c
··· 13 13 #include <linux/workqueue.h> 14 14 #include <linux/spinlock.h> 15 15 #include <linux/kthread.h> 16 - #include <linux/debugfs.h> 16 + #include <linux/tracefs.h> 17 17 #include <linux/uaccess.h> 18 18 #include <linux/module.h> 19 19 #include <linux/ctype.h> ··· 480 480 return; 481 481 482 482 if (!--dir->nr_events) { 483 - debugfs_remove_recursive(dir->entry); 483 + tracefs_remove_recursive(dir->entry); 484 484 list_del(&dir->list); 485 485 __put_system_dir(dir); 486 486 } ··· 499 499 } 500 500 spin_unlock(&dir->d_lock); 501 501 502 - debugfs_remove_recursive(dir); 502 + tracefs_remove_recursive(dir); 503 503 } 504 504 505 505 list_del(&file->list); ··· 1526 1526 } else 1527 1527 __get_system(system); 1528 1528 1529 - dir->entry = debugfs_create_dir(name, parent); 1529 + dir->entry = tracefs_create_dir(name, parent); 1530 1530 if (!dir->entry) { 1531 1531 pr_warn("Failed to create system directory %s\n", name); 1532 1532 __put_system(system); ··· 1539 1539 dir->subsystem = system; 1540 1540 file->system = dir; 1541 1541 1542 - entry = debugfs_create_file("filter", 0644, dir->entry, dir, 1542 + entry = tracefs_create_file("filter", 0644, dir->entry, dir, 1543 1543 &ftrace_subsystem_filter_fops); 1544 1544 if (!entry) { 1545 1545 kfree(system->filter); 1546 1546 system->filter = NULL; 1547 - pr_warn("Could not create debugfs '%s/filter' entry\n", name); 1547 + pr_warn("Could not create tracefs '%s/filter' entry\n", name); 1548 1548 } 1549 1549 1550 1550 trace_create_file("enable", 0644, dir->entry, dir, ··· 1585 1585 d_events = parent; 1586 1586 1587 1587 name = ftrace_event_name(call); 1588 - file->dir = debugfs_create_dir(name, d_events); 1588 + file->dir = tracefs_create_dir(name, d_events); 1589 1589 if (!file->dir) { 1590 - pr_warn("Could not create debugfs '%s' directory\n", name); 1590 + pr_warn("Could not create tracefs '%s' directory\n", name); 1591 1591 return -1; 1592 1592 } 1593 1593 ··· 2228 2228 /* 2229 2229 * The top level array has already had its ftrace_event_file 2230 2230 * descriptors created in order to allow for early events to 2231 - * be recorded. This function is called after the debugfs has been 2231 + * be recorded. This function is called after the tracefs has been 2232 2232 * initialized, and we now have to create the files associated 2233 2233 * to the events. 2234 2234 */ ··· 2311 2311 struct dentry *d_events; 2312 2312 struct dentry *entry; 2313 2313 2314 - entry = debugfs_create_file("set_event", 0644, parent, 2314 + entry = tracefs_create_file("set_event", 0644, parent, 2315 2315 tr, &ftrace_set_event_fops); 2316 2316 if (!entry) { 2317 - pr_warn("Could not create debugfs 'set_event' entry\n"); 2317 + pr_warn("Could not create tracefs 'set_event' entry\n"); 2318 2318 return -ENOMEM; 2319 2319 } 2320 2320 2321 - d_events = debugfs_create_dir("events", parent); 2321 + d_events = tracefs_create_dir("events", parent); 2322 2322 if (!d_events) { 2323 - pr_warn("Could not create debugfs 'events' directory\n"); 2323 + pr_warn("Could not create tracefs 'events' directory\n"); 2324 2324 return -ENOMEM; 2325 2325 } 2326 2326 ··· 2412 2412 2413 2413 down_write(&trace_event_sem); 2414 2414 __trace_remove_event_dirs(tr); 2415 - debugfs_remove_recursive(tr->event_dir); 2415 + tracefs_remove_recursive(tr->event_dir); 2416 2416 up_write(&trace_event_sem); 2417 2417 2418 2418 tr->event_dir = NULL; ··· 2534 2534 if (IS_ERR(d_tracer)) 2535 2535 return 0; 2536 2536 2537 - entry = debugfs_create_file("available_events", 0444, d_tracer, 2537 + entry = tracefs_create_file("available_events", 0444, d_tracer, 2538 2538 tr, &ftrace_avail_fops); 2539 2539 if (!entry) 2540 - pr_warn("Could not create debugfs 'available_events' entry\n"); 2540 + pr_warn("Could not create tracefs 'available_events' entry\n"); 2541 2541 2542 2542 if (trace_define_common_fields()) 2543 2543 pr_warn("tracing: Failed to allocate common fields");
+3 -4
kernel/trace/trace_functions_graph.c
··· 6 6 * is Copyright (c) Steven Rostedt <srostedt@redhat.com> 7 7 * 8 8 */ 9 - #include <linux/debugfs.h> 10 9 #include <linux/uaccess.h> 11 10 #include <linux/ftrace.h> 12 11 #include <linux/slab.h> ··· 150 151 * The curr_ret_stack is initialized to -1 and get increased 151 152 * in this function. So it can be less than -1 only if it was 152 153 * filtered out via ftrace_graph_notrace_addr() which can be 153 - * set from set_graph_notrace file in debugfs by user. 154 + * set from set_graph_notrace file in tracefs by user. 154 155 */ 155 156 if (current->curr_ret_stack < -1) 156 157 return -EBUSY; ··· 1431 1432 .llseek = generic_file_llseek, 1432 1433 }; 1433 1434 1434 - static __init int init_graph_debugfs(void) 1435 + static __init int init_graph_tracefs(void) 1435 1436 { 1436 1437 struct dentry *d_tracer; 1437 1438 ··· 1444 1445 1445 1446 return 0; 1446 1447 } 1447 - fs_initcall(init_graph_debugfs); 1448 + fs_initcall(init_graph_tracefs); 1448 1449 1449 1450 static __init int init_graph_trace(void) 1450 1451 {
+5 -5
kernel/trace/trace_kprobe.c
··· 1310 1310 return ret; 1311 1311 } 1312 1312 1313 - /* Make a debugfs interface for controlling probe points */ 1313 + /* Make a tracefs interface for controlling probe points */ 1314 1314 static __init int init_kprobe_trace(void) 1315 1315 { 1316 1316 struct dentry *d_tracer; ··· 1323 1323 if (IS_ERR(d_tracer)) 1324 1324 return 0; 1325 1325 1326 - entry = debugfs_create_file("kprobe_events", 0644, d_tracer, 1326 + entry = tracefs_create_file("kprobe_events", 0644, d_tracer, 1327 1327 NULL, &kprobe_events_ops); 1328 1328 1329 1329 /* Event list interface */ 1330 1330 if (!entry) 1331 - pr_warning("Could not create debugfs " 1331 + pr_warning("Could not create tracefs " 1332 1332 "'kprobe_events' entry\n"); 1333 1333 1334 1334 /* Profile interface */ 1335 - entry = debugfs_create_file("kprobe_profile", 0444, d_tracer, 1335 + entry = tracefs_create_file("kprobe_profile", 0444, d_tracer, 1336 1336 NULL, &kprobe_profile_ops); 1337 1337 1338 1338 if (!entry) 1339 - pr_warning("Could not create debugfs " 1339 + pr_warning("Could not create tracefs " 1340 1340 "'kprobe_profile' entry\n"); 1341 1341 return 0; 1342 1342 }
+1 -1
kernel/trace/trace_probe.h
··· 25 25 #include <linux/seq_file.h> 26 26 #include <linux/slab.h> 27 27 #include <linux/smp.h> 28 - #include <linux/debugfs.h> 28 + #include <linux/tracefs.h> 29 29 #include <linux/types.h> 30 30 #include <linux/string.h> 31 31 #include <linux/ctype.h>
+5 -5
kernel/trace/trace_stat.c
··· 12 12 #include <linux/list.h> 13 13 #include <linux/slab.h> 14 14 #include <linux/rbtree.h> 15 - #include <linux/debugfs.h> 15 + #include <linux/tracefs.h> 16 16 #include "trace_stat.h" 17 17 #include "trace.h" 18 18 ··· 65 65 66 66 static void destroy_session(struct stat_session *session) 67 67 { 68 - debugfs_remove(session->file); 68 + tracefs_remove(session->file); 69 69 __reset_stat_session(session); 70 70 mutex_destroy(&session->stat_mutex); 71 71 kfree(session); ··· 279 279 if (IS_ERR(d_tracing)) 280 280 return 0; 281 281 282 - stat_dir = debugfs_create_dir("trace_stat", d_tracing); 282 + stat_dir = tracefs_create_dir("trace_stat", d_tracing); 283 283 if (!stat_dir) 284 - pr_warning("Could not create debugfs " 284 + pr_warning("Could not create tracefs " 285 285 "'trace_stat' entry\n"); 286 286 return 0; 287 287 } ··· 291 291 if (!stat_dir && tracing_stat_init()) 292 292 return -ENODEV; 293 293 294 - session->file = debugfs_create_file(session->ts->name, 0644, 294 + session->file = tracefs_create_file(session->ts->name, 0644, 295 295 stat_dir, 296 296 session, &tracing_stat_fops); 297 297 if (!session->file)