File Index
Files and directories
Sign in
FILE

mmcr2_l2l3_test.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr2_l2l3_test.c C
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Copyright 2022, Madhavan Srinivasan, IBM Corp.
 4 */
 5
 6#include <stdio.h>
 7#include <stdlib.h>
 8
 9#include "../event.h"
10#include "misc.h"
11#include "utils.h"
12
13/* All successful D-side store dispatches for this thread */
14#define EventCode 0x010000046080
15
16#define MALLOC_SIZE     (0x10000 * 10)  /* Ought to be enough .. */
17
18/*
19 * A perf sampling test for mmcr2
20 * fields : l2l3
21 */
22static int mmcr2_l2l3(void)
23{
24	struct event event;
25	u64 *intr_regs;
26	char *p;
27	int i;
28
29	/* Check for platform support for the test */
30	SKIP_IF(check_pvr_for_sampling_tests());
31	SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1));
32
33	/* Init the event for the sampling test */
34	event_init_sampling(&event, EventCode);
35	event.attr.sample_regs_intr = platform_extended_mask;
36	FAIL_IF(event_open(&event));
37	event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
38
39	FAIL_IF(event_enable(&event));
40
41	/* workload to make the event overflow */
42	p = malloc(MALLOC_SIZE);
43	FAIL_IF(!p);
44
45	for (i = 0; i < MALLOC_SIZE; i += 0x10000)
46		p[i] = i;
47
48	FAIL_IF(event_disable(&event));
49
50	/* Check for sample count */
51	FAIL_IF(!collect_samples(event.mmap_buffer));
52
53	intr_regs = get_intr_regs(&event, event.mmap_buffer);
54
55	/* Check for intr_regs */
56	FAIL_IF(!intr_regs);
57
58	/*
59	 * Verify that l2l3 field of MMCR2 match with
60	 * corresponding event code field
61	 */
62	FAIL_IF(EV_CODE_EXTRACT(event.attr.config, l2l3) !=
63		get_mmcr2_l2l3(get_reg_value(intr_regs, "MMCR2"), 4));
64
65	event_close(&event);
66	free(p);
67
68	return 0;
69}
70
71int main(void)
72{
73	return test_harness(mmcr2_l2l3, "mmcr2_l2l3");
74}
~/ Read-only file preview.