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 <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "map_symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "branch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "util/synthetic-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define COMP(m) do {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (s1->m != s2->m) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		pr_debug("Samples differ at '"#m"'\n");	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		return false;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	}						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define MCOMP(m) do {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	if (memcmp(&s1->m, &s2->m, sizeof(s1->m))) {	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		pr_debug("Samples differ at '"#m"'\n");	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		return false;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	}						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static bool samples_same(const struct perf_sample *s1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			 const struct perf_sample *s2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			 u64 type, u64 read_format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (type & PERF_SAMPLE_IDENTIFIER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		COMP(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (type & PERF_SAMPLE_IP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		COMP(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (type & PERF_SAMPLE_TID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		COMP(pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		COMP(tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (type & PERF_SAMPLE_TIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		COMP(time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (type & PERF_SAMPLE_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		COMP(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (type & PERF_SAMPLE_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		COMP(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (type & PERF_SAMPLE_STREAM_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		COMP(stream_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (type & PERF_SAMPLE_CPU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		COMP(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (type & PERF_SAMPLE_PERIOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		COMP(period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (type & PERF_SAMPLE_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		if (read_format & PERF_FORMAT_GROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			COMP(read.group.nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			COMP(read.one.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			COMP(read.time_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			COMP(read.time_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		/* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		if (read_format & PERF_FORMAT_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			for (i = 0; i < s1->read.group.nr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				MCOMP(read.group.values[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			COMP(read.one.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (type & PERF_SAMPLE_CALLCHAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		COMP(callchain->nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		for (i = 0; i < s1->callchain->nr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			COMP(callchain->ips[i]);
^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) 	if (type & PERF_SAMPLE_RAW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		COMP(raw_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (memcmp(s1->raw_data, s2->raw_data, s1->raw_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			pr_debug("Samples differ at 'raw_data'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			return false;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (type & PERF_SAMPLE_BRANCH_STACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		COMP(branch_stack->nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		COMP(branch_stack->hw_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		for (i = 0; i < s1->branch_stack->nr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			MCOMP(branch_stack->entries[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (type & PERF_SAMPLE_REGS_USER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		size_t sz = hweight_long(s1->user_regs.mask) * sizeof(u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		COMP(user_regs.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		COMP(user_regs.abi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (s1->user_regs.abi &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		    (!s1->user_regs.regs || !s2->user_regs.regs ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		     memcmp(s1->user_regs.regs, s2->user_regs.regs, sz))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			pr_debug("Samples differ at 'user_regs'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			return false;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (type & PERF_SAMPLE_STACK_USER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		COMP(user_stack.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (memcmp(s1->user_stack.data, s2->user_stack.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			   s1->user_stack.size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			pr_debug("Samples differ at 'user_stack'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			return false;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (type & PERF_SAMPLE_WEIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		COMP(weight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (type & PERF_SAMPLE_DATA_SRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		COMP(data_src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (type & PERF_SAMPLE_TRANSACTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		COMP(transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (type & PERF_SAMPLE_REGS_INTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		size_t sz = hweight_long(s1->intr_regs.mask) * sizeof(u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		COMP(intr_regs.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		COMP(intr_regs.abi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (s1->intr_regs.abi &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		    (!s1->intr_regs.regs || !s2->intr_regs.regs ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		     memcmp(s1->intr_regs.regs, s2->intr_regs.regs, sz))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			pr_debug("Samples differ at 'intr_regs'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			return false;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (type & PERF_SAMPLE_PHYS_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		COMP(phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (type & PERF_SAMPLE_CGROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		COMP(cgroup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (type & PERF_SAMPLE_AUX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		COMP(aux_sample.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		if (memcmp(s1->aux_sample.data, s2->aux_sample.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			   s1->aux_sample.size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			pr_debug("Samples differ at 'aux_sample'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		}
^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) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct evsel evsel = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		.needs_swap = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		.core = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			. attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				.sample_type = sample_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				.read_format = read_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	union perf_event *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		struct ip_callchain callchain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		u64 data[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	} callchain = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		/* 3 ips */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		.data = {3, 201, 202, 203},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		struct branch_stack branch_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		u64 data[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	} branch_stack = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		/* 1 branch_entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		.data = {1, -1ULL, 211, 212, 213},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	u64 regs[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	const u32 raw_data[] = {0x12345678, 0x0a0b0c0d, 0x11020304, 0x05060708, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	const u64 data[] = {0x2211443366558877ULL, 0, 0xaabbccddeeff4321ULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	const u64 aux_data[] = {0xa55a, 0, 0xeeddee, 0x0282028202820282};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct perf_sample sample = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		.ip		= 101,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		.pid		= 102,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		.tid		= 103,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		.time		= 104,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		.addr		= 105,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		.id		= 106,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		.stream_id	= 107,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		.period		= 108,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		.weight		= 109,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		.cpu		= 110,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		.raw_size	= sizeof(raw_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		.data_src	= 111,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		.transaction	= 112,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		.raw_data	= (void *)raw_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		.callchain	= &callchain.callchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		.no_hw_idx      = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		.branch_stack	= &branch_stack.branch_stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		.user_regs	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			.abi	= PERF_SAMPLE_REGS_ABI_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			.mask	= sample_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			.regs	= regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		.user_stack	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			.size	= sizeof(data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			.data	= (void *)data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		.read		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			.time_enabled = 0x030a59d664fca7deULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			.time_running = 0x011b6ae553eb98edULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		.intr_regs	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			.abi	= PERF_SAMPLE_REGS_ABI_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			.mask	= sample_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			.regs	= regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		.phys_addr	= 113,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		.cgroup		= 114,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		.aux_sample	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			.size	= sizeof(aux_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			.data	= (void *)aux_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct sample_read_value values[] = {{1, 5}, {9, 3}, {2, 7}, {6, 4},};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct perf_sample sample_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	size_t i, sz, bufsz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	int err, ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (sample_type & PERF_SAMPLE_REGS_USER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		evsel.core.attr.sample_regs_user = sample_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (sample_type & PERF_SAMPLE_REGS_INTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		evsel.core.attr.sample_regs_intr = sample_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (sample_type & PERF_SAMPLE_BRANCH_STACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		evsel.core.attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	for (i = 0; i < sizeof(regs); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		*(i + (u8 *)regs) = i & 0xfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (read_format & PERF_FORMAT_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		sample.read.group.nr     = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		sample.read.group.values = values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		sample.read.one.value = 0x08789faeb786aa87ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		sample.read.one.id    = 99;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	sz = perf_event__sample_event_size(&sample, sample_type, read_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	bufsz = sz + 4096; /* Add a bit for overrun checking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	event = malloc(bufsz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		pr_debug("malloc failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	memset(event, 0xff, bufsz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	event->header.type = PERF_RECORD_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	event->header.misc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	event->header.size = sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	err = perf_event__synthesize_sample(event, sample_type, read_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 					    &sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		pr_debug("%s failed for sample_type %#"PRIx64", error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			 "perf_event__synthesize_sample", sample_type, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/* The data does not contain 0xff so we use that to check the size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	for (i = bufsz; i > 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		if (*(i - 1 + (u8 *)event) != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (i != sz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		pr_debug("Event size mismatch: actual %zu vs expected %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			 i, sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	evsel.sample_size = __evsel__sample_size(sample_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	err = evsel__parse_sample(&evsel, event, &sample_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		pr_debug("%s failed for sample_type %#"PRIx64", error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			 "evsel__parse_sample", sample_type, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (!samples_same(&sample, &sample_out, sample_type, read_format)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		pr_debug("parsing failed for sample_type %#"PRIx64"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			 sample_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	free(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (ret && read_format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		pr_debug("read_format %#"PRIx64"\n", read_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * test__sample_parsing - test sample parsing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * This function implements a test that synthesizes a sample event, parses it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * and then checks that the parsed sample matches the original sample.  The test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * checks sample format bits separately and together.  If the test passes %0 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  * returned, otherwise %-1 is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) int test__sample_parsing(struct test *test __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	const u64 rf[] = {4, 5, 6, 7, 12, 13, 14, 15};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	u64 sample_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	u64 sample_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	 * Fail the test if it has not been updated when new sample format bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	 * were added.  Please actually update the test rather than just change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	 * the condition below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (PERF_SAMPLE_MAX > PERF_SAMPLE_CGROUP << 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		pr_debug("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* Test each sample format bit separately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	for (sample_type = 1; sample_type != PERF_SAMPLE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	     sample_type <<= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		/* Test read_format variations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		if (sample_type == PERF_SAMPLE_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			for (i = 0; i < ARRAY_SIZE(rf); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				err = do_test(sample_type, 0, rf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 				if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 					return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		sample_regs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		if (sample_type == PERF_SAMPLE_REGS_USER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			sample_regs = 0x3fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		if (sample_type == PERF_SAMPLE_REGS_INTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			sample_regs = 0xff0fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		err = do_test(sample_type, sample_regs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			return err;
^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) 	/* Test all sample format bits together */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	sample_type = PERF_SAMPLE_MAX - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	sample_regs = 0x3fff; /* shared yb intr and user regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	for (i = 0; i < ARRAY_SIZE(rf); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		err = do_test(sample_type, sample_regs, rf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }