hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/tools/perf/tests/sample-parsing.c
....@@ -1,13 +1,18 @@
11 // SPDX-License-Identifier: GPL-2.0
22 #include <stdbool.h>
33 #include <inttypes.h>
4
+#include <stdlib.h>
5
+#include <string.h>
6
+#include <linux/bitops.h>
47 #include <linux/kernel.h>
58 #include <linux/types.h>
69
7
-#include "util.h"
10
+#include "map_symbol.h"
11
+#include "branch.h"
812 #include "event.h"
913 #include "evsel.h"
1014 #include "debug.h"
15
+#include "util/synthetic-events.h"
1116
1217 #include "tests.h"
1318
....@@ -94,6 +99,7 @@
9499
95100 if (type & PERF_SAMPLE_BRANCH_STACK) {
96101 COMP(branch_stack->nr);
102
+ COMP(branch_stack->hw_idx);
97103 for (i = 0; i < s1->branch_stack->nr; i++)
98104 MCOMP(branch_stack->entries[i]);
99105 }
....@@ -145,16 +151,30 @@
145151 if (type & PERF_SAMPLE_PHYS_ADDR)
146152 COMP(phys_addr);
147153
154
+ if (type & PERF_SAMPLE_CGROUP)
155
+ COMP(cgroup);
156
+
157
+ if (type & PERF_SAMPLE_AUX) {
158
+ COMP(aux_sample.size);
159
+ if (memcmp(s1->aux_sample.data, s2->aux_sample.data,
160
+ s1->aux_sample.size)) {
161
+ pr_debug("Samples differ at 'aux_sample'\n");
162
+ return false;
163
+ }
164
+ }
165
+
148166 return true;
149167 }
150168
151169 static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
152170 {
153
- struct perf_evsel evsel = {
171
+ struct evsel evsel = {
154172 .needs_swap = false,
155
- .attr = {
156
- .sample_type = sample_type,
157
- .read_format = read_format,
173
+ .core = {
174
+ . attr = {
175
+ .sample_type = sample_type,
176
+ .read_format = read_format,
177
+ },
158178 },
159179 };
160180 union perf_event *event;
....@@ -170,11 +190,12 @@
170190 u64 data[64];
171191 } branch_stack = {
172192 /* 1 branch_entry */
173
- .data = {1, 211, 212, 213},
193
+ .data = {1, -1ULL, 211, 212, 213},
174194 };
175195 u64 regs[64];
176196 const u32 raw_data[] = {0x12345678, 0x0a0b0c0d, 0x11020304, 0x05060708, 0 };
177197 const u64 data[] = {0x2211443366558877ULL, 0, 0xaabbccddeeff4321ULL};
198
+ const u64 aux_data[] = {0xa55a, 0, 0xeeddee, 0x0282028202820282};
178199 struct perf_sample sample = {
179200 .ip = 101,
180201 .pid = 102,
....@@ -191,6 +212,7 @@
191212 .transaction = 112,
192213 .raw_data = (void *)raw_data,
193214 .callchain = &callchain.callchain,
215
+ .no_hw_idx = false,
194216 .branch_stack = &branch_stack.branch_stack,
195217 .user_regs = {
196218 .abi = PERF_SAMPLE_REGS_ABI_64,
....@@ -211,6 +233,11 @@
211233 .regs = regs,
212234 },
213235 .phys_addr = 113,
236
+ .cgroup = 114,
237
+ .aux_sample = {
238
+ .size = sizeof(aux_data),
239
+ .data = (void *)aux_data,
240
+ },
214241 };
215242 struct sample_read_value values[] = {{1, 5}, {9, 3}, {2, 7}, {6, 4},};
216243 struct perf_sample sample_out;
....@@ -218,10 +245,13 @@
218245 int err, ret = -1;
219246
220247 if (sample_type & PERF_SAMPLE_REGS_USER)
221
- evsel.attr.sample_regs_user = sample_regs;
248
+ evsel.core.attr.sample_regs_user = sample_regs;
222249
223250 if (sample_type & PERF_SAMPLE_REGS_INTR)
224
- evsel.attr.sample_regs_intr = sample_regs;
251
+ evsel.core.attr.sample_regs_intr = sample_regs;
252
+
253
+ if (sample_type & PERF_SAMPLE_BRANCH_STACK)
254
+ evsel.core.attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
225255
226256 for (i = 0; i < sizeof(regs); i++)
227257 *(i + (u8 *)regs) = i & 0xfe;
....@@ -266,12 +296,12 @@
266296 goto out_free;
267297 }
268298
269
- evsel.sample_size = __perf_evsel__sample_size(sample_type);
299
+ evsel.sample_size = __evsel__sample_size(sample_type);
270300
271
- err = perf_evsel__parse_sample(&evsel, event, &sample_out);
301
+ err = evsel__parse_sample(&evsel, event, &sample_out);
272302 if (err) {
273303 pr_debug("%s failed for sample_type %#"PRIx64", error %d\n",
274
- "perf_evsel__parse_sample", sample_type, err);
304
+ "evsel__parse_sample", sample_type, err);
275305 goto out_free;
276306 }
277307
....@@ -310,7 +340,7 @@
310340 * were added. Please actually update the test rather than just change
311341 * the condition below.
312342 */
313
- if (PERF_SAMPLE_MAX > PERF_SAMPLE_PHYS_ADDR << 1) {
343
+ if (PERF_SAMPLE_MAX > PERF_SAMPLE_CGROUP << 1) {
314344 pr_debug("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n");
315345 return -1;
316346 }