hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/trace/trace_functions.c
....@@ -34,29 +34,37 @@
3434 TRACE_FUNC_OPT_STACK = 0x1,
3535 };
3636
37
-static int allocate_ftrace_ops(struct trace_array *tr)
37
+int ftrace_allocate_ftrace_ops(struct trace_array *tr)
3838 {
3939 struct ftrace_ops *ops;
40
+
41
+ /* The top level array uses the "global_ops" */
42
+ if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
43
+ return 0;
4044
4145 ops = kzalloc(sizeof(*ops), GFP_KERNEL);
4246 if (!ops)
4347 return -ENOMEM;
4448
45
- /* Currently only the non stack verision is supported */
49
+ /* Currently only the non stack version is supported */
4650 ops->func = function_trace_call;
4751 ops->flags = FTRACE_OPS_FL_RECURSION_SAFE | FTRACE_OPS_FL_PID;
4852
4953 tr->ops = ops;
5054 ops->private = tr;
55
+
5156 return 0;
5257 }
5358
59
+void ftrace_free_ftrace_ops(struct trace_array *tr)
60
+{
61
+ kfree(tr->ops);
62
+ tr->ops = NULL;
63
+}
5464
5565 int ftrace_create_function_files(struct trace_array *tr,
5666 struct dentry *parent)
5767 {
58
- int ret;
59
-
6068 /*
6169 * The top level array uses the "global_ops", and the files are
6270 * created on boot up.
....@@ -64,9 +72,8 @@
6472 if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
6573 return 0;
6674
67
- ret = allocate_ftrace_ops(tr);
68
- if (ret)
69
- return ret;
75
+ if (!tr->ops)
76
+ return -EINVAL;
7077
7178 ftrace_create_filter_files(tr->ops, parent);
7279
....@@ -76,8 +83,7 @@
7683 void ftrace_destroy_function_files(struct trace_array *tr)
7784 {
7885 ftrace_destroy_filter_files(tr->ops);
79
- kfree(tr->ops);
80
- tr->ops = NULL;
86
+ ftrace_free_ftrace_ops(tr);
8187 }
8288
8389 static int function_trace_init(struct trace_array *tr)
....@@ -101,7 +107,7 @@
101107
102108 ftrace_init_array_ops(tr, func);
103109
104
- tr->trace_buffer.cpu = get_cpu();
110
+ tr->array_buffer.cpu = get_cpu();
105111 put_cpu();
106112
107113 tracing_start_cmdline_record();
....@@ -118,7 +124,7 @@
118124
119125 static void function_trace_start(struct trace_array *tr)
120126 {
121
- tracing_reset_online_cpus(&tr->trace_buffer);
127
+ tracing_reset_online_cpus(&tr->array_buffer);
122128 }
123129
124130 static void
....@@ -143,7 +149,7 @@
143149 goto out;
144150
145151 cpu = smp_processor_id();
146
- data = per_cpu_ptr(tr->trace_buffer.data, cpu);
152
+ data = per_cpu_ptr(tr->array_buffer.data, cpu);
147153 if (!atomic_read(&data->disabled)) {
148154 local_save_flags(flags);
149155 trace_function(tr, ip, parent_ip, flags, pc);
....@@ -192,7 +198,7 @@
192198 */
193199 local_irq_save(flags);
194200 cpu = raw_smp_processor_id();
195
- data = per_cpu_ptr(tr->trace_buffer.data, cpu);
201
+ data = per_cpu_ptr(tr->array_buffer.data, cpu);
196202 disabled = atomic_inc_return(&data->disabled);
197203
198204 if (likely(disabled == 1)) {