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) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <api/fs/tracing_path.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "thread_map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "util/counts.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int test__openat_syscall_event(struct test *test __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	int err = -1, fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	unsigned int nr_openat_calls = 111, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	struct perf_thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	char sbuf[STRERR_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	char errbuf[BUFSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	if (threads == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		pr_debug("thread_map__new\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	evsel = evsel__newtp("syscalls", "sys_enter_openat");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	if (IS_ERR(evsel)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 		tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		pr_debug("%s\n", errbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 		goto out_thread_map_delete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	if (evsel__open_per_thread(evsel, threads) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		pr_debug("failed to open counter: %s, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 			 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 			 str_error_r(errno, sbuf, sizeof(sbuf)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		goto out_evsel_delete;
^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) 	for (i = 0; i < nr_openat_calls; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		fd = openat(0, "/etc/passwd", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		close(fd);
^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) 	if (evsel__read_on_cpu(evsel, 0, 0) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		pr_debug("evsel__read_on_cpu\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		goto out_close_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		pr_debug("evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 			 nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		goto out_close_fd;
^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) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) out_close_fd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	perf_evsel__close_fd(&evsel->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) out_evsel_delete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	evsel__delete(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) out_thread_map_delete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	perf_thread_map__put(threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }