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) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "event.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 "header.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) static int process_event(struct evlist **pevlist, union perf_event *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	struct perf_sample sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	if (event->header.type == PERF_RECORD_HEADER_ATTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 		if (perf_event__process_attr(NULL, event, pevlist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 			pr_debug("perf_event__process_attr failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	if (!*pevlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (perf_evlist__parse_sample(*pevlist, event, &sample)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		pr_debug("perf_evlist__parse_sample failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int process_events(union perf_event **events, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct evlist *evlist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	for (i = 0; i < count && !err; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		err = process_event(&evlist, events[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	evlist__delete(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return err;
^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) struct test_attr_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct perf_event_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct perf_event_attr	 attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u64 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * This function tests parsing data produced on kernel's that do not support the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * sample_id_all bit.  Without the sample_id_all bit, non-sample events (such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * mmap events) do not have an id sample appended, and consequently logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * designed to determine the id will not work.  That case happens when there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * more than one selected event, so this test processes three events: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * attributes representing the selected events and one mmap event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * Return: %0 on success, %-1 if the test fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) int test__parse_no_sample_id_all(struct test *test __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct test_attr_event event1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		.header = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			.type = PERF_RECORD_HEADER_ATTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			.size = sizeof(struct test_attr_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct test_attr_event event2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		.header = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			.type = PERF_RECORD_HEADER_ATTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			.size = sizeof(struct test_attr_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		.id = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct perf_record_mmap event3 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		.header = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			.type = PERF_RECORD_MMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			.size = sizeof(struct perf_record_mmap),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	union perf_event *events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		(union perf_event *)&event1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		(union perf_event *)&event2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		(union perf_event *)&event3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	err = process_events(events, ARRAY_SIZE(events));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }