Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * trace irqs off critical timings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * From code in the latency_tracer, that is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Copyright (C) 2004-2006 Ingo Molnar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  Copyright (C) 2004 Nadia Yvette Chambers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/ftrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <trace/events/preemptirq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #if defined(CONFIG_IRQSOFF_TRACER) || defined(CONFIG_PREEMPT_TRACER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static struct trace_array		*irqsoff_trace __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static int				tracer_enabled __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static DEFINE_PER_CPU(int, tracing_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static DEFINE_RAW_SPINLOCK(max_trace_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	TRACER_IRQS_OFF		= (1 << 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	TRACER_PREEMPT_OFF	= (1 << 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int trace_type __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int save_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static void stop_irqsoff_tracer(struct trace_array *tr, int graph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static int start_irqsoff_tracer(struct trace_array *tr, int graph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #ifdef CONFIG_PREEMPT_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) preempt_trace(int pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return ((trace_type & TRACER_PREEMPT_OFF) && pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) # define preempt_trace(pc) (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #ifdef CONFIG_IRQSOFF_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) irq_trace(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return ((trace_type & TRACER_IRQS_OFF) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		irqs_disabled());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) # define irq_trace() (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #ifdef CONFIG_FUNCTION_GRAPH_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int irqsoff_display_graph(struct trace_array *tr, int set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) # define is_graph(tr) ((tr)->trace_flags & TRACE_ITER_DISPLAY_GRAPH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static inline int irqsoff_display_graph(struct trace_array *tr, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) # define is_graph(tr) false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * Sequence count - we record it when starting a measurement and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * skip the latency if the sequence has changed - some other section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * did a maximum and could disturb our measurement with serial console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * printouts, etc. Truly coinciding maximum latencies should be rare
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * and what happens together happens separately as well, so this doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * decrease the validity of the maximum found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static __cacheline_aligned_in_smp	unsigned long max_sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #ifdef CONFIG_FUNCTION_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * Prologue for the preempt and irqs off function tracers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * Returns 1 if it is OK to continue, and data->disabled is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *            incremented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  *         0 if the trace is to be ignored, and data->disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *            is kept the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * Note, this function is also used outside this ifdef but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *  inside the #ifdef of the function graph tracer below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *  This is OK, since the function graph tracer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *  dependent on the function tracer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static int func_prolog_dec(struct trace_array *tr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			   struct trace_array_cpu **data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			   unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	long disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 * Does not matter if we preempt. We test the flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * afterward, to see if irqs are disabled or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 * If we preempt and get a false positive, the flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	 * test will fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (likely(!per_cpu(tracing_cpu, cpu)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	local_save_flags(*flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 * Slight chance to get a false positive on tracing_cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 * although I'm starting to think there isn't a chance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * Leave this for now just to be paranoid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (!irqs_disabled_flags(*flags) && !preempt_count())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	*data = per_cpu_ptr(tr->array_buffer.data, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	disabled = atomic_inc_return(&(*data)->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (likely(disabled == 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	atomic_dec(&(*data)->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * irqsoff uses its own tracer function to keep the overhead down:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		    struct ftrace_ops *op, struct pt_regs *pt_regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct trace_array *tr = irqsoff_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct trace_array_cpu *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (!func_prolog_dec(tr, &data, &flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	trace_function(tr, ip, parent_ip, flags, preempt_count());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	atomic_dec(&data->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #endif /* CONFIG_FUNCTION_TRACER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #ifdef CONFIG_FUNCTION_GRAPH_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int irqsoff_display_graph(struct trace_array *tr, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (!(is_graph(tr) ^ set))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	stop_irqsoff_tracer(irqsoff_trace, !set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	for_each_possible_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		per_cpu(tracing_cpu, cpu) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	tr->max_latency = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	tracing_reset_online_cpus(&irqsoff_trace->array_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return start_irqsoff_tracer(irqsoff_trace, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct trace_array *tr = irqsoff_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct trace_array_cpu *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (ftrace_graph_ignore_func(trace))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * Do not trace a function if it's filtered by set_graph_notrace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * Make the index of ret stack negative to indicate that it should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * ignore further functions.  But it needs its own ret stack entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 * to recover the original index in order to continue tracing after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 * returning from the function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (ftrace_graph_notrace_addr(trace->func))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (!func_prolog_dec(tr, &data, &flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	ret = __trace_graph_entry(tr, trace, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	atomic_dec(&data->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct trace_array *tr = irqsoff_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct trace_array_cpu *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	ftrace_graph_addr_finish(trace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (!func_prolog_dec(tr, &data, &flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	__trace_graph_return(tr, trace, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	atomic_dec(&data->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static struct fgraph_ops fgraph_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.entryfunc		= &irqsoff_graph_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.retfunc		= &irqsoff_graph_return,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static void irqsoff_trace_open(struct trace_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (is_graph(iter->tr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		graph_trace_open(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static void irqsoff_trace_close(struct trace_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (iter->private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		graph_trace_close(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			    TRACE_GRAPH_PRINT_PROC | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			    TRACE_GRAPH_PRINT_REL_TIME | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			    TRACE_GRAPH_PRINT_DURATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * In graph mode call the graph tracer output function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * otherwise go with the TRACE_FN event handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (is_graph(iter->tr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return TRACE_TYPE_UNHANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static void irqsoff_print_header(struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct trace_array *tr = irqsoff_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (is_graph(tr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		trace_default_header(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) __trace_function(struct trace_array *tr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		 unsigned long ip, unsigned long parent_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		 unsigned long flags, int pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (is_graph(tr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		trace_graph_function(tr, ip, parent_ip, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		trace_function(tr, ip, parent_ip, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define __trace_function trace_function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	return TRACE_TYPE_UNHANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static void irqsoff_trace_open(struct trace_iterator *iter) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static void irqsoff_trace_close(struct trace_iterator *iter) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #ifdef CONFIG_FUNCTION_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static void irqsoff_print_header(struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	trace_default_header(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static void irqsoff_print_header(struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	trace_latency_header(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #endif /* CONFIG_FUNCTION_TRACER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * Should this new latency be reported/recorded?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static bool report_latency(struct trace_array *tr, u64 delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (tracing_thresh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		if (delta < tracing_thresh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		if (delta <= tr->max_latency)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) check_critical_timing(struct trace_array *tr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		      struct trace_array_cpu *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		      unsigned long parent_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		      int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	u64 T0, T1, delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	int pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	T0 = data->preempt_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	T1 = ftrace_now(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	delta = T1-T0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	local_save_flags(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (!report_latency(tr, delta))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	raw_spin_lock_irqsave(&max_trace_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	/* check if we are still the max latency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (!report_latency(tr, delta))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	__trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/* Skip 5 functions to get to the irq/preempt enable function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	__trace_stack(tr, flags, 5, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (data->critical_sequence != max_sequence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	data->critical_end = parent_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (likely(!is_tracing_stopped())) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		tr->max_latency = delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		update_max_tr_single(tr, current, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	max_sequence++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	raw_spin_unlock_irqrestore(&max_trace_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	data->critical_sequence = max_sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	data->preempt_timestamp = ftrace_now(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	__trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static nokprobe_inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) start_critical_timing(unsigned long ip, unsigned long parent_ip, int pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	struct trace_array *tr = irqsoff_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	struct trace_array_cpu *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (!tracer_enabled || !tracing_is_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (per_cpu(tracing_cpu, cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	data = per_cpu_ptr(tr->array_buffer.data, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (unlikely(!data) || atomic_read(&data->disabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	atomic_inc(&data->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	data->critical_sequence = max_sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	data->preempt_timestamp = ftrace_now(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	data->critical_start = parent_ip ? : ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	local_save_flags(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	__trace_function(tr, ip, parent_ip, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	per_cpu(tracing_cpu, cpu) = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	atomic_dec(&data->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static nokprobe_inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) stop_critical_timing(unsigned long ip, unsigned long parent_ip, int pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct trace_array *tr = irqsoff_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct trace_array_cpu *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	/* Always clear the tracing cpu on stopping the trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (unlikely(per_cpu(tracing_cpu, cpu)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		per_cpu(tracing_cpu, cpu) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (!tracer_enabled || !tracing_is_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	data = per_cpu_ptr(tr->array_buffer.data, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (unlikely(!data) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	    !data->critical_start || atomic_read(&data->disabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	atomic_inc(&data->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	local_save_flags(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	__trace_function(tr, ip, parent_ip, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	check_critical_timing(tr, data, parent_ip ? : ip, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	data->critical_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	atomic_dec(&data->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /* start and stop critical timings used to for stoppage (in idle) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) void start_critical_timings(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	int pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (preempt_trace(pc) || irq_trace())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		start_critical_timing(CALLER_ADDR0, CALLER_ADDR1, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) EXPORT_SYMBOL_GPL(start_critical_timings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) NOKPROBE_SYMBOL(start_critical_timings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) void stop_critical_timings(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	int pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (preempt_trace(pc) || irq_trace())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) EXPORT_SYMBOL_GPL(stop_critical_timings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) NOKPROBE_SYMBOL(stop_critical_timings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #ifdef CONFIG_FUNCTION_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static bool function_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	/* 'set' is set if TRACE_ITER_FUNCTION is about to be set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER_FUNCTION)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	if (graph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		ret = register_ftrace_graph(&fgraph_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		ret = register_ftrace_function(tr->ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		function_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static void unregister_irqsoff_function(struct trace_array *tr, int graph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	if (!function_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (graph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		unregister_ftrace_graph(&fgraph_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		unregister_ftrace_function(tr->ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	function_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (!(mask & TRACE_ITER_FUNCTION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	if (set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		register_irqsoff_function(tr, is_graph(tr), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		unregister_irqsoff_function(tr, is_graph(tr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static void unregister_irqsoff_function(struct trace_array *tr, int graph) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static inline int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) #endif /* CONFIG_FUNCTION_TRACER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static int irqsoff_flag_changed(struct trace_array *tr, u32 mask, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	struct tracer *tracer = tr->current_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	if (irqsoff_function_set(tr, mask, set))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) #ifdef CONFIG_FUNCTION_GRAPH_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	if (mask & TRACE_ITER_DISPLAY_GRAPH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		return irqsoff_display_graph(tr, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	return trace_keep_overwrite(tracer, mask, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static int start_irqsoff_tracer(struct trace_array *tr, int graph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	ret = register_irqsoff_function(tr, graph, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (!ret && tracing_is_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		tracer_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		tracer_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static void stop_irqsoff_tracer(struct trace_array *tr, int graph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	tracer_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	unregister_irqsoff_function(tr, graph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static bool irqsoff_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static int __irqsoff_tracer_init(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	if (irqsoff_busy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	save_flags = tr->trace_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	/* non overwrite screws up the latency tracers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	/* without pause, we will produce garbage if another latency occurs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	set_tracer_flag(tr, TRACE_ITER_PAUSE_ON_TRACE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	tr->max_latency = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	irqsoff_trace = tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	/* make sure that the tracer is visible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	ftrace_init_array_ops(tr, irqsoff_tracer_call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	/* Only toplevel instance supports graph tracing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 				      is_graph(tr))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		printk(KERN_ERR "failed to start irqsoff tracer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	irqsoff_busy = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) static void __irqsoff_tracer_reset(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	int pause_flag = save_flags & TRACE_ITER_PAUSE_ON_TRACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	stop_irqsoff_tracer(tr, is_graph(tr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	set_tracer_flag(tr, TRACE_ITER_PAUSE_ON_TRACE, pause_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	ftrace_reset_array_ops(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	irqsoff_busy = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) static void irqsoff_tracer_start(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	tracer_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static void irqsoff_tracer_stop(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	tracer_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) #ifdef CONFIG_IRQSOFF_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)  * We are only interested in hardirq on/off events:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) void tracer_hardirqs_on(unsigned long a0, unsigned long a1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	unsigned int pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	if (!preempt_trace(pc) && irq_trace())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		stop_critical_timing(a0, a1, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) NOKPROBE_SYMBOL(tracer_hardirqs_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) void tracer_hardirqs_off(unsigned long a0, unsigned long a1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	unsigned int pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	if (!preempt_trace(pc) && irq_trace())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		start_critical_timing(a0, a1, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) NOKPROBE_SYMBOL(tracer_hardirqs_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) static int irqsoff_tracer_init(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	trace_type = TRACER_IRQS_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	return __irqsoff_tracer_init(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) static void irqsoff_tracer_reset(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	__irqsoff_tracer_reset(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static struct tracer irqsoff_tracer __read_mostly =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	.name		= "irqsoff",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	.init		= irqsoff_tracer_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	.reset		= irqsoff_tracer_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	.start		= irqsoff_tracer_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	.stop		= irqsoff_tracer_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	.print_max	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	.print_header   = irqsoff_print_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	.print_line     = irqsoff_print_line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	.flag_changed	= irqsoff_flag_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) #ifdef CONFIG_FTRACE_SELFTEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	.selftest    = trace_selftest_startup_irqsoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	.open           = irqsoff_trace_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	.close          = irqsoff_trace_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	.allow_instances = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	.use_max_tr	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) #endif /*  CONFIG_IRQSOFF_TRACER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) #ifdef CONFIG_PREEMPT_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) void tracer_preempt_on(unsigned long a0, unsigned long a1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	int pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	if (preempt_trace(pc) && !irq_trace())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		stop_critical_timing(a0, a1, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) void tracer_preempt_off(unsigned long a0, unsigned long a1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	int pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	if (preempt_trace(pc) && !irq_trace())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		start_critical_timing(a0, a1, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static int preemptoff_tracer_init(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	trace_type = TRACER_PREEMPT_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	return __irqsoff_tracer_init(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) static void preemptoff_tracer_reset(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	__irqsoff_tracer_reset(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) static struct tracer preemptoff_tracer __read_mostly =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	.name		= "preemptoff",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	.init		= preemptoff_tracer_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	.reset		= preemptoff_tracer_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	.start		= irqsoff_tracer_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	.stop		= irqsoff_tracer_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	.print_max	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	.print_header   = irqsoff_print_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	.print_line     = irqsoff_print_line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	.flag_changed	= irqsoff_flag_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) #ifdef CONFIG_FTRACE_SELFTEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	.selftest    = trace_selftest_startup_preemptoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	.open		= irqsoff_trace_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	.close		= irqsoff_trace_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	.allow_instances = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	.use_max_tr	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) #endif /* CONFIG_PREEMPT_TRACER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) static int preemptirqsoff_tracer_init(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	return __irqsoff_tracer_init(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) static void preemptirqsoff_tracer_reset(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	__irqsoff_tracer_reset(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) static struct tracer preemptirqsoff_tracer __read_mostly =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	.name		= "preemptirqsoff",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	.init		= preemptirqsoff_tracer_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	.reset		= preemptirqsoff_tracer_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	.start		= irqsoff_tracer_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	.stop		= irqsoff_tracer_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	.print_max	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	.print_header   = irqsoff_print_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	.print_line     = irqsoff_print_line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	.flag_changed	= irqsoff_flag_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) #ifdef CONFIG_FTRACE_SELFTEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	.selftest    = trace_selftest_startup_preemptirqsoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	.open		= irqsoff_trace_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	.close		= irqsoff_trace_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	.allow_instances = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	.use_max_tr	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) __init static int init_irqsoff_tracer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) #ifdef CONFIG_IRQSOFF_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	register_tracer(&irqsoff_tracer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) #ifdef CONFIG_PREEMPT_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	register_tracer(&preemptoff_tracer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	register_tracer(&preemptirqsoff_tracer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) core_initcall(init_irqsoff_tracer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) #endif /* IRQSOFF_TRACER || PREEMPTOFF_TRACER */