forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/kernel/trace/trace_irqsoff.c
....@@ -14,6 +14,7 @@
1414 #include <linux/uaccess.h>
1515 #include <linux/module.h>
1616 #include <linux/ftrace.h>
17
+#include <linux/kprobes.h>
1718
1819 #include "trace.h"
1920
....@@ -121,7 +122,7 @@
121122 if (!irqs_disabled_flags(*flags) && !preempt_count())
122123 return 0;
123124
124
- *data = per_cpu_ptr(tr->trace_buffer.data, cpu);
125
+ *data = per_cpu_ptr(tr->array_buffer.data, cpu);
125126 disabled = atomic_inc_return(&(*data)->disabled);
126127
127128 if (likely(disabled == 1))
....@@ -142,11 +143,14 @@
142143 struct trace_array *tr = irqsoff_trace;
143144 struct trace_array_cpu *data;
144145 unsigned long flags;
146
+ unsigned int trace_ctx;
145147
146148 if (!func_prolog_dec(tr, &data, &flags))
147149 return;
148150
149
- trace_function(tr, ip, parent_ip, flags, preempt_count());
151
+ trace_ctx = tracing_gen_ctx_flags(flags);
152
+
153
+ trace_function(tr, ip, parent_ip, trace_ctx);
150154
151155 atomic_dec(&data->disabled);
152156 }
....@@ -166,7 +170,7 @@
166170 per_cpu(tracing_cpu, cpu) = 0;
167171
168172 tr->max_latency = 0;
169
- tracing_reset_online_cpus(&irqsoff_trace->trace_buffer);
173
+ tracing_reset_online_cpus(&irqsoff_trace->array_buffer);
170174
171175 return start_irqsoff_tracer(irqsoff_trace, set);
172176 }
....@@ -176,8 +180,8 @@
176180 struct trace_array *tr = irqsoff_trace;
177181 struct trace_array_cpu *data;
178182 unsigned long flags;
183
+ unsigned int trace_ctx;
179184 int ret;
180
- int pc;
181185
182186 if (ftrace_graph_ignore_func(trace))
183187 return 0;
....@@ -194,8 +198,8 @@
194198 if (!func_prolog_dec(tr, &data, &flags))
195199 return 0;
196200
197
- pc = preempt_count();
198
- ret = __trace_graph_entry(tr, trace, flags, pc);
201
+ trace_ctx = tracing_gen_ctx_flags(flags);
202
+ ret = __trace_graph_entry(tr, trace, trace_ctx);
199203 atomic_dec(&data->disabled);
200204
201205 return ret;
....@@ -206,17 +210,22 @@
206210 struct trace_array *tr = irqsoff_trace;
207211 struct trace_array_cpu *data;
208212 unsigned long flags;
209
- int pc;
213
+ unsigned int trace_ctx;
210214
211215 ftrace_graph_addr_finish(trace);
212216
213217 if (!func_prolog_dec(tr, &data, &flags))
214218 return;
215219
216
- pc = preempt_count();
217
- __trace_graph_return(tr, trace, flags, pc);
220
+ trace_ctx = tracing_gen_ctx_flags(flags);
221
+ __trace_graph_return(tr, trace, trace_ctx);
218222 atomic_dec(&data->disabled);
219223 }
224
+
225
+static struct fgraph_ops fgraph_ops = {
226
+ .entryfunc = &irqsoff_graph_entry,
227
+ .retfunc = &irqsoff_graph_return,
228
+};
220229
221230 static void irqsoff_trace_open(struct trace_iterator *iter)
222231 {
....@@ -233,7 +242,7 @@
233242
234243 #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \
235244 TRACE_GRAPH_PRINT_PROC | \
236
- TRACE_GRAPH_PRINT_ABS_TIME | \
245
+ TRACE_GRAPH_PRINT_REL_TIME | \
237246 TRACE_GRAPH_PRINT_DURATION)
238247
239248 static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
....@@ -261,23 +270,16 @@
261270 static void
262271 __trace_function(struct trace_array *tr,
263272 unsigned long ip, unsigned long parent_ip,
264
- unsigned long flags, int pc)
273
+ unsigned int trace_ctx)
265274 {
266275 if (is_graph(tr))
267
- trace_graph_function(tr, ip, parent_ip, flags, pc);
276
+ trace_graph_function(tr, ip, parent_ip, trace_ctx);
268277 else
269
- trace_function(tr, ip, parent_ip, flags, pc);
278
+ trace_function(tr, ip, parent_ip, trace_ctx);
270279 }
271280
272281 #else
273282 #define __trace_function trace_function
274
-
275
-#ifdef CONFIG_FUNCTION_TRACER
276
-static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
277
-{
278
- return -1;
279
-}
280
-#endif
281283
282284 static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
283285 {
....@@ -288,7 +290,6 @@
288290 static void irqsoff_trace_close(struct trace_iterator *iter) { }
289291
290292 #ifdef CONFIG_FUNCTION_TRACER
291
-static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { }
292293 static void irqsoff_print_header(struct seq_file *s)
293294 {
294295 trace_default_header(s);
....@@ -324,15 +325,13 @@
324325 {
325326 u64 T0, T1, delta;
326327 unsigned long flags;
327
- int pc;
328
+ unsigned int trace_ctx;
328329
329330 T0 = data->preempt_timestamp;
330331 T1 = ftrace_now(cpu);
331332 delta = T1-T0;
332333
333
- local_save_flags(flags);
334
-
335
- pc = preempt_count();
334
+ trace_ctx = tracing_gen_ctx();
336335
337336 if (!report_latency(tr, delta))
338337 goto out;
....@@ -343,9 +342,9 @@
343342 if (!report_latency(tr, delta))
344343 goto out_unlock;
345344
346
- __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
345
+ __trace_function(tr, CALLER_ADDR0, parent_ip, trace_ctx);
347346 /* Skip 5 functions to get to the irq/preempt enable function */
348
- __trace_stack(tr, flags, 5, pc);
347
+ __trace_stack(tr, trace_ctx, 5);
349348
350349 if (data->critical_sequence != max_sequence)
351350 goto out_unlock;
....@@ -365,16 +364,15 @@
365364 out:
366365 data->critical_sequence = max_sequence;
367366 data->preempt_timestamp = ftrace_now(cpu);
368
- __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
367
+ __trace_function(tr, CALLER_ADDR0, parent_ip, trace_ctx);
369368 }
370369
371
-static inline void
372
-start_critical_timing(unsigned long ip, unsigned long parent_ip, int pc)
370
+static nokprobe_inline void
371
+start_critical_timing(unsigned long ip, unsigned long parent_ip)
373372 {
374373 int cpu;
375374 struct trace_array *tr = irqsoff_trace;
376375 struct trace_array_cpu *data;
377
- unsigned long flags;
378376
379377 if (!tracer_enabled || !tracing_is_enabled())
380378 return;
....@@ -384,7 +382,7 @@
384382 if (per_cpu(tracing_cpu, cpu))
385383 return;
386384
387
- data = per_cpu_ptr(tr->trace_buffer.data, cpu);
385
+ data = per_cpu_ptr(tr->array_buffer.data, cpu);
388386
389387 if (unlikely(!data) || atomic_read(&data->disabled))
390388 return;
....@@ -395,22 +393,20 @@
395393 data->preempt_timestamp = ftrace_now(cpu);
396394 data->critical_start = parent_ip ? : ip;
397395
398
- local_save_flags(flags);
399
-
400
- __trace_function(tr, ip, parent_ip, flags, pc);
396
+ __trace_function(tr, ip, parent_ip, tracing_gen_ctx());
401397
402398 per_cpu(tracing_cpu, cpu) = 1;
403399
404400 atomic_dec(&data->disabled);
405401 }
406402
407
-static inline void
408
-stop_critical_timing(unsigned long ip, unsigned long parent_ip, int pc)
403
+static nokprobe_inline void
404
+stop_critical_timing(unsigned long ip, unsigned long parent_ip)
409405 {
410406 int cpu;
411407 struct trace_array *tr = irqsoff_trace;
412408 struct trace_array_cpu *data;
413
- unsigned long flags;
409
+ unsigned int trace_ctx;
414410
415411 cpu = raw_smp_processor_id();
416412 /* Always clear the tracing cpu on stopping the trace */
....@@ -422,7 +418,7 @@
422418 if (!tracer_enabled || !tracing_is_enabled())
423419 return;
424420
425
- data = per_cpu_ptr(tr->trace_buffer.data, cpu);
421
+ data = per_cpu_ptr(tr->array_buffer.data, cpu);
426422
427423 if (unlikely(!data) ||
428424 !data->critical_start || atomic_read(&data->disabled))
....@@ -430,8 +426,8 @@
430426
431427 atomic_inc(&data->disabled);
432428
433
- local_save_flags(flags);
434
- __trace_function(tr, ip, parent_ip, flags, pc);
429
+ trace_ctx = tracing_gen_ctx();
430
+ __trace_function(tr, ip, parent_ip, trace_ctx);
435431 check_critical_timing(tr, data, parent_ip ? : ip, cpu);
436432 data->critical_start = 0;
437433 atomic_dec(&data->disabled);
....@@ -440,21 +436,19 @@
440436 /* start and stop critical timings used to for stoppage (in idle) */
441437 void start_critical_timings(void)
442438 {
443
- int pc = preempt_count();
444
-
445
- if (preempt_trace(pc) || irq_trace())
446
- start_critical_timing(CALLER_ADDR0, CALLER_ADDR1, pc);
439
+ if (preempt_trace(preempt_count()) || irq_trace())
440
+ start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
447441 }
448442 EXPORT_SYMBOL_GPL(start_critical_timings);
443
+NOKPROBE_SYMBOL(start_critical_timings);
449444
450445 void stop_critical_timings(void)
451446 {
452
- int pc = preempt_count();
453
-
454
- if (preempt_trace(pc) || irq_trace())
455
- stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1, pc);
447
+ if (preempt_trace(preempt_count()) || irq_trace())
448
+ stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
456449 }
457450 EXPORT_SYMBOL_GPL(stop_critical_timings);
451
+NOKPROBE_SYMBOL(stop_critical_timings);
458452
459453 #ifdef CONFIG_FUNCTION_TRACER
460454 static bool function_enabled;
....@@ -468,8 +462,7 @@
468462 return 0;
469463
470464 if (graph)
471
- ret = register_ftrace_graph(&irqsoff_graph_return,
472
- &irqsoff_graph_entry);
465
+ ret = register_ftrace_graph(&fgraph_ops);
473466 else
474467 ret = register_ftrace_function(tr->ops);
475468
....@@ -485,7 +478,7 @@
485478 return;
486479
487480 if (graph)
488
- unregister_ftrace_graph();
481
+ unregister_ftrace_graph(&fgraph_ops);
489482 else
490483 unregister_ftrace_function(tr->ops);
491484
....@@ -563,6 +556,8 @@
563556 /* non overwrite screws up the latency tracers */
564557 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
565558 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1);
559
+ /* without pause, we will produce garbage if another latency occurs */
560
+ set_tracer_flag(tr, TRACE_ITER_PAUSE_ON_TRACE, 1);
566561
567562 tr->max_latency = 0;
568563 irqsoff_trace = tr;
....@@ -584,11 +579,13 @@
584579 {
585580 int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
586581 int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;
582
+ int pause_flag = save_flags & TRACE_ITER_PAUSE_ON_TRACE;
587583
588584 stop_irqsoff_tracer(tr, is_graph(tr));
589585
590586 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
591587 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
588
+ set_tracer_flag(tr, TRACE_ITER_PAUSE_ON_TRACE, pause_flag);
592589 ftrace_reset_array_ops(tr);
593590
594591 irqsoff_busy = false;
....@@ -610,19 +607,17 @@
610607 */
611608 void tracer_hardirqs_on(unsigned long a0, unsigned long a1)
612609 {
613
- unsigned int pc = preempt_count();
614
-
615
- if (!preempt_trace(pc) && irq_trace())
616
- stop_critical_timing(a0, a1, pc);
610
+ if (!preempt_trace(preempt_count()) && irq_trace())
611
+ stop_critical_timing(a0, a1);
617612 }
613
+NOKPROBE_SYMBOL(tracer_hardirqs_on);
618614
619615 void tracer_hardirqs_off(unsigned long a0, unsigned long a1)
620616 {
621
- unsigned int pc = preempt_count();
622
-
623
- if (!preempt_trace(pc) && irq_trace())
624
- start_critical_timing(a0, a1, pc);
617
+ if (!preempt_trace(preempt_count()) && irq_trace())
618
+ start_critical_timing(a0, a1);
625619 }
620
+NOKPROBE_SYMBOL(tracer_hardirqs_off);
626621
627622 static int irqsoff_tracer_init(struct trace_array *tr)
628623 {
....@@ -660,18 +655,14 @@
660655 #ifdef CONFIG_PREEMPT_TRACER
661656 void tracer_preempt_on(unsigned long a0, unsigned long a1)
662657 {
663
- int pc = preempt_count();
664
-
665
- if (preempt_trace(pc) && !irq_trace())
666
- stop_critical_timing(a0, a1, pc);
658
+ if (preempt_trace(preempt_count()) && !irq_trace())
659
+ stop_critical_timing(a0, a1);
667660 }
668661
669662 void tracer_preempt_off(unsigned long a0, unsigned long a1)
670663 {
671
- int pc = preempt_count();
672
-
673
- if (preempt_trace(pc) && !irq_trace())
674
- start_critical_timing(a0, a1, pc);
664
+ if (preempt_trace(preempt_count()) && !irq_trace())
665
+ start_critical_timing(a0, a1);
675666 }
676667
677668 static int preemptoff_tracer_init(struct trace_array *tr)