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 <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "evsel.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 "record.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "util/mmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <perf/mmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #ifndef O_DIRECTORY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define O_DIRECTORY    00200000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #ifndef AT_FDCWD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define AT_FDCWD       -100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct record_opts opts = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		.target = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 			.uid = UINT_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			.uses_mmap = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		.no_buffering = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		.freq	      = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		.mmap_pages   = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		.raw_samples  = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	const char *filename = "/etc/passwd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int flags = O_RDONLY | O_DIRECTORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct evlist *evlist = evlist__new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int err = -1, i, nr_events = 0, nr_polls = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	char sbuf[STRERR_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (evlist == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		pr_debug("%s: perf_evlist__new\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		goto out;
^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) 	evsel = evsel__newtp("syscalls", "sys_enter_openat");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (IS_ERR(evsel)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		pr_debug("%s: evsel__newtp\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		goto out_delete_evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	evlist__add(evlist, evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	err = perf_evlist__create_maps(evlist, &opts.target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		pr_debug("%s: perf_evlist__create_maps\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		goto out_delete_evlist;
^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) 	evsel__config(evsel, &opts, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	perf_thread_map__set_pid(evlist->core.threads, 0, getpid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	err = evlist__open(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		pr_debug("perf_evlist__open: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			 str_error_r(errno, sbuf, sizeof(sbuf)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		goto out_delete_evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	err = evlist__mmap(evlist, UINT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		pr_debug("evlist__mmap: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			 str_error_r(errno, sbuf, sizeof(sbuf)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		goto out_delete_evlist;
^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) 	evlist__enable(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * Generate the event:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	openat(AT_FDCWD, filename, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		int before = nr_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		for (i = 0; i < evlist->core.nr_mmaps; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			union perf_event *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			struct mmap *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			md = &evlist->mmap[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			if (perf_mmap__read_init(&md->core) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			while ((event = perf_mmap__read_event(&md->core)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				const u32 type = event->header.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				int tp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				struct perf_sample sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				++nr_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				if (type != PERF_RECORD_SAMPLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 					perf_mmap__consume(&md->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				err = evsel__parse_sample(evsel, event, &sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 					pr_debug("Can't parse sample, err = %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 					goto out_delete_evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				tp_flags = evsel__intval(evsel, &sample, "flags");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				if (flags != tp_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 					pr_debug("%s: Expected flags=%#x, got %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 						 __func__, flags, tp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 					goto out_delete_evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				goto out_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			perf_mmap__read_done(&md->core);
^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) 		if (nr_events == before)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			evlist__poll(evlist, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (++nr_polls > 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			pr_debug("%s: no events!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			goto out_delete_evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) out_ok:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) out_delete_evlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	evlist__delete(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }