hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
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
....@@ -127,15 +133,14 @@
127133 {
128134 struct trace_array *tr = op->private;
129135 struct trace_array_cpu *data;
130
- unsigned long flags;
136
+ unsigned int trace_ctx;
131137 int bit;
132138 int cpu;
133
- int pc;
134139
135140 if (unlikely(!tr->function_enabled))
136141 return;
137142
138
- pc = preempt_count();
143
+ trace_ctx = tracing_gen_ctx();
139144 preempt_disable_notrace();
140145
141146 bit = trace_test_and_set_recursion(TRACE_FTRACE_START);
....@@ -143,11 +148,10 @@
143148 goto out;
144149
145150 cpu = smp_processor_id();
146
- data = per_cpu_ptr(tr->trace_buffer.data, cpu);
147
- if (!atomic_read(&data->disabled)) {
148
- local_save_flags(flags);
149
- trace_function(tr, ip, parent_ip, flags, pc);
150
- }
151
+ data = per_cpu_ptr(tr->array_buffer.data, cpu);
152
+ if (!atomic_read(&data->disabled))
153
+ trace_function(tr, ip, parent_ip, trace_ctx);
154
+
151155 trace_clear_recursion(bit);
152156
153157 out:
....@@ -181,7 +185,7 @@
181185 unsigned long flags;
182186 long disabled;
183187 int cpu;
184
- int pc;
188
+ unsigned int trace_ctx;
185189
186190 if (unlikely(!tr->function_enabled))
187191 return;
....@@ -192,13 +196,13 @@
192196 */
193197 local_irq_save(flags);
194198 cpu = raw_smp_processor_id();
195
- data = per_cpu_ptr(tr->trace_buffer.data, cpu);
199
+ data = per_cpu_ptr(tr->array_buffer.data, cpu);
196200 disabled = atomic_inc_return(&data->disabled);
197201
198202 if (likely(disabled == 1)) {
199
- pc = preempt_count();
200
- trace_function(tr, ip, parent_ip, flags, pc);
201
- __trace_stack(tr, flags, STACK_SKIP, pc);
203
+ trace_ctx = tracing_gen_ctx_flags(flags);
204
+ trace_function(tr, ip, parent_ip, trace_ctx);
205
+ __trace_stack(tr, trace_ctx, STACK_SKIP);
202206 }
203207
204208 atomic_dec(&data->disabled);
....@@ -401,13 +405,11 @@
401405
402406 static __always_inline void trace_stack(struct trace_array *tr)
403407 {
404
- unsigned long flags;
405
- int pc;
408
+ unsigned int trace_ctx;
406409
407
- local_save_flags(flags);
408
- pc = preempt_count();
410
+ trace_ctx = tracing_gen_ctx();
409411
410
- __trace_stack(tr, flags, FTRACE_STACK_SKIP, pc);
412
+ __trace_stack(tr, trace_ctx, FTRACE_STACK_SKIP);
411413 }
412414
413415 static void