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)  * kdb helper for dumping the ftrace buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010 Jason Wessel <jason.wessel@windriver.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * ftrace_dump_buf based on ftrace_dump:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kgdb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kdb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ftrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "trace_output.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct trace_iterator iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static struct ring_buffer_iter *buffer_iter[CONFIG_NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static void ftrace_dump_buf(int skip_entries, long cpu_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	unsigned int old_userobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int cnt = 0, cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	tr = iter.tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	old_userobj = tr->trace_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* don't look at user memory in panic mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	kdb_printf("Dumping ftrace buffer:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (skip_entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		kdb_printf("(skipping %d entries)\n", skip_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	trace_iterator_reset(&iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	iter.iter_flags |= TRACE_FILE_LAT_FMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (cpu_file == RING_BUFFER_ALL_CPUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		for_each_tracing_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			iter.buffer_iter[cpu] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			ring_buffer_read_prepare(iter.array_buffer->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 						 cpu, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			ring_buffer_read_start(iter.buffer_iter[cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			tracing_iter_reset(&iter, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		iter.cpu_file = cpu_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		iter.buffer_iter[cpu_file] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			ring_buffer_read_prepare(iter.array_buffer->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 						 cpu_file, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		ring_buffer_read_start(iter.buffer_iter[cpu_file]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		tracing_iter_reset(&iter, cpu_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	while (trace_find_next_entry_inc(&iter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		if (!cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			kdb_printf("---------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		if (!skip_entries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			print_trace_line(&iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			trace_printk_seq(&iter.seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			skip_entries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (KDB_FLAG(CMD_INTERRUPT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			goto out;
^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) 	if (!cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		kdb_printf("   (ftrace buffer empty)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		kdb_printf("---------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	tr->trace_flags = old_userobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	for_each_tracing_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (iter.buffer_iter[cpu]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			ring_buffer_read_finish(iter.buffer_iter[cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			iter.buffer_iter[cpu] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * kdb_ftdump - Dump the ftrace log buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static int kdb_ftdump(int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	int skip_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	long cpu_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	char *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (argc > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return KDB_ARGCOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (argc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		skip_entries = simple_strtol(argv[1], &cp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (*cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			skip_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (argc == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		cpu_file = simple_strtol(argv[2], &cp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		    !cpu_online(cpu_file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			return KDB_BADINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		cpu_file = RING_BUFFER_ALL_CPUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	kdb_trap_printk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	trace_init_global_iter(&iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	iter.buffer_iter = buffer_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	for_each_tracing_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* A negative skip_entries means skip all but the last entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (skip_entries < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (cpu_file == RING_BUFFER_ALL_CPUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			cnt = trace_total_entries(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			cnt = trace_total_entries_cpu(NULL, cpu_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		skip_entries = max(cnt + skip_entries, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ftrace_dump_buf(skip_entries, cpu_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	for_each_tracing_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	kdb_trap_printk--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static __init int kdb_ftrace_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	kdb_register_flags("ftdump", kdb_ftdump, "[skip_#entries] [cpu]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			    "Dump ftrace log; -skip dumps last #entries", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			    KDB_ENABLE_ALWAYS_SAFE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) late_initcall(kdb_ftrace_register);