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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <dirent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <sys/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <sys/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "trace-event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int input_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static ssize_t trace_data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static bool repipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int __do_read(int fd, void *buf, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int rsize = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	while (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		int ret = read(fd, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		if (repipe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			int retw = write(STDOUT_FILENO, buf, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			if (retw <= 0 || retw != ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 				pr_debug("repiping input file");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		size -= ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		buf += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return rsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static int do_read(void *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	r = __do_read(input_fd, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (r <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		pr_debug("reading input file (size expected=%d received=%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			 size, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	trace_data_size += r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /* If it fails, the next read will report it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static void skip(int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	char buf[BUFSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	while (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		r = size > BUFSIZ ? BUFSIZ : size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		do_read(buf, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		size -= r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static unsigned int read4(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	unsigned int data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (do_read(&data, 4) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return tep_read_number(pevent, &data, 4);
^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) static unsigned long long read8(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned long long data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (do_read(&data, 8) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return tep_read_number(pevent, &data, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static char *read_string(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	char buf[BUFSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	char *str = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	off_t r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		r = read(input_fd, &c, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			pr_debug("reading input file");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		if (!r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			pr_debug("no data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		if (repipe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			int retw = write(STDOUT_FILENO, &c, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			if (retw <= 0 || retw != r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				pr_debug("repiping input file string");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		buf[size++] = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (!c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	trace_data_size += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	str = malloc(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		memcpy(str, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int read_proc_kallsyms(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	size = read4(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * Just skip it, now that we configure libtraceevent to use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * tools/perf/ symbol resolver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * We need to skip it so that we can continue parsing old perf.data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 * files, that contains this /proc/kallsyms payload.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 * Newer perf.data files will have just the 4-bytes zeros "kallsyms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * payload", so that older tools can continue reading it and interpret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * it as "no kallsyms payload is present".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	lseek(input_fd, size, SEEK_CUR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	trace_data_size += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int read_ftrace_printk(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* it can have 0 size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	size = read4(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	buf = malloc(size + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (do_read(buf, size) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	buf[size] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	parse_ftrace_printk(pevent, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int read_header_files(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	unsigned long long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	char *header_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	char buf[BUFSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (do_read(buf, 12) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (memcmp(buf, "header_page", 12) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		pr_debug("did not read header page");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	size = read8(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	header_page = malloc(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (header_page == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (do_read(header_page, size) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		pr_debug("did not read header page");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		free(header_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (!tep_parse_header_page(pevent, header_page, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				   tep_get_long_size(pevent))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		 * The commit field in the page is of type long,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		 * use that instead, since it represents the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		tep_set_long_size(pevent, tep_get_header_page_size(pevent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	free(header_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (do_read(buf, 13) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (memcmp(buf, "header_event", 13) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		pr_debug("did not read header event");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	size = read8(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	skip(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int read_ftrace_file(struct tep_handle *pevent, unsigned long long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	buf = malloc(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (buf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		pr_debug("memory allocation failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	ret = do_read(buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		pr_debug("error reading ftrace file.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	ret = parse_ftrace_file(pevent, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		pr_debug("error parsing ftrace file.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int read_event_file(struct tep_handle *pevent, char *sys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			   unsigned long long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	buf = malloc(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (buf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		pr_debug("memory allocation failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	ret = do_read(buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	ret = parse_event_file(pevent, buf, size, sys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		pr_debug("error parsing event file.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static int read_ftrace_files(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	unsigned long long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	count = read4(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		size = read8(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		ret = read_ftrace_file(pevent, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static int read_event_files(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	unsigned long long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	char *sys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	int systems;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	int i,x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	systems = read4(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	for (i = 0; i < systems; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		sys = read_string();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (sys == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		count = read4(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		for (x=0; x < count; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			size = read8(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			ret = read_event_file(pevent, sys, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				free(sys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		free(sys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static int read_saved_cmdline(struct tep_handle *pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	unsigned long long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* it can have 0 size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	size = read8(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	buf = malloc(size + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (buf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		pr_debug("memory allocation failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	ret = do_read(buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		pr_debug("error reading saved cmdlines\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	buf[ret] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	parse_saved_cmdline(pevent, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	char buf[BUFSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	char test[] = { 23, 8, 68 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	char *version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	int show_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	int show_funcs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	int show_printk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	ssize_t size = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	int file_bigendian;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	int host_bigendian;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	int file_long_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	int file_page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct tep_handle *pevent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	repipe = __repipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	input_fd = fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (do_read(buf, 3) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (memcmp(buf, test, 3) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		pr_debug("no trace data in the file");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (do_read(buf, 7) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	if (memcmp(buf, "tracing", 7) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		pr_debug("not a trace file (missing 'tracing' tag)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	version = read_string();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (version == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (show_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		printf("version = %s\n", version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (do_read(buf, 1) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		free(version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	file_bigendian = buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	host_bigendian = bigendian();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (trace_event__init(tevent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		pr_debug("trace_event__init failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	pevent = tevent->pevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	tep_set_flag(pevent, TEP_NSEC_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	tep_set_file_bigendian(pevent, file_bigendian);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	tep_set_local_bigendian(pevent, host_bigendian);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (do_read(buf, 1) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	file_long_size = buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	file_page_size = read4(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (!file_page_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	tep_set_long_size(pevent, file_long_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	tep_set_page_size(pevent, file_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	err = read_header_files(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	err = read_ftrace_files(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	err = read_event_files(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	err = read_proc_kallsyms(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	err = read_ftrace_printk(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (atof(version) >= 0.6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		err = read_saved_cmdline(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	size = trace_data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	repipe = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (show_funcs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		tep_print_funcs(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	} else if (show_printk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		tep_print_printk(pevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	pevent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (pevent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		trace_event__cleanup(tevent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	free(version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }