aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/powerpc/pmu/event_code_tests/event_alternatives_tests_p9.c
blob: f7dcf0e0447cad5bcc88e62a64bc30928d8dff46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2022, Athira Rajeev, IBM Corp.
 */

#include <stdio.h>
#include "../event.h"
#include "../sampling_tests/misc.h"

#define PM_RUN_CYC_ALT 0x200f4
#define PM_INST_DISP 0x200f2
#define PM_BR_2PATH 0x20036
#define PM_LD_MISS_L1 0x3e054
#define PM_RUN_INST_CMPL_ALT 0x400fa

#define EventCode_1 0x200fa
#define EventCode_2 0x200fc
#define EventCode_3 0x300fc
#define EventCode_4 0x400fc

/*
 * Check for event alternatives.
 */

static int event_alternatives_tests_p9(void)
{
	struct event event, leader;

	/* Check for platform support for the test */
	SKIP_IF(platform_check_for_tests());

	/*
	 * PVR check is used here since PMU specific data like
	 * alternative events is handled by respective PMU driver
	 * code and using PVR will work correctly for all cases
	 * including generic compat mode.
	 */
	SKIP_IF(PVR_VER(mfspr(SPRN_PVR)) != POWER9);

	/* Skip for generic compat PMU */
	SKIP_IF(check_for_generic_compat_pmu());

	/* Init the event for PM_RUN_CYC_ALT */
	event_init(&leader, PM_RUN_CYC_ALT);
	FAIL_IF(event_open(&leader));

	event_init(&event, EventCode_1);

	/*
	 * Expected to pass since PM_RUN_CYC_ALT in PMC2 has alternative event
	 * 0x600f4. So it can go in with EventCode_1 which is using PMC2
	 */
	FAIL_IF(event_open_with_group(&event, leader.fd));

	event_close(&leader);
	event_close(&event);

	event_init(&leader, PM_INST_DISP);
	FAIL_IF(event_open(&leader));

	event_init(&event, EventCode_2);
	/*
	 * Expected to pass since PM_INST_DISP in PMC2 has alternative event
	 * 0x300f2 in PMC3. So it can go in with EventCode_2 which is using PMC2
	 */
	FAIL_IF(event_open_with_group(&event, leader.fd));

	event_close(&leader);
	event_close(&event);

	event_init(&leader, PM_BR_2PATH);
	FAIL_IF(event_open(&leader));

	event_init(&event, EventCode_2);
	/*
	 * Expected to pass since PM_BR_2PATH in PMC2 has alternative event
	 * 0x40036 in PMC4. So it can go in with EventCode_2 which is using PMC2
	 */
	FAIL_IF(event_open_with_group(&event, leader.fd));

	event_close(&leader);
	event_close(&event);

	event_init(&leader, PM_LD_MISS_L1);
	FAIL_IF(event_open(&leader));

	event_init(&event, EventCode_3);
	/*
	 * Expected to pass since PM_LD_MISS_L1 in PMC3 has alternative event
	 * 0x400f0 in PMC4. So it can go in with EventCode_3 which is using PMC3
	 */
	FAIL_IF(event_open_with_group(&event, leader.fd));

	event_close(&leader);
	event_close(&event);

	event_init(&leader, PM_RUN_INST_CMPL_ALT);
	FAIL_IF(event_open(&leader));

	event_init(&event, EventCode_4);
	/*
	 * Expected to pass since PM_RUN_INST_CMPL_ALT in PMC4 has alternative event
	 * 0x500fa in PMC5. So it can go in with EventCode_4 which is using PMC4
	 */
	FAIL_IF(event_open_with_group(&event, leader.fd));

	event_close(&leader);
	event_close(&event);

	return 0;
}

int main(void)
{
	return test_harness(event_alternatives_tests_p9, "event_alternatives_tests_p9");
}