aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/powerpc/pmu/event_code_tests/hw_cache_event_type_test.c
blob: a45b1da5b56806daa1b84966d4ef141dde159dd0 (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
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2022, Kajol Jain, IBM Corp.
 */

#include <stdio.h>
#include <stdlib.h>

#include "../event.h"
#include "utils.h"
#include "../sampling_tests/misc.h"

/*
 * Load Missed L1, for power9 its pointing to PM_LD_MISS_L1_FIN (0x2c04e) and
 * for power10 its pointing to PM_LD_MISS_L1 (0x3e054)
 *
 * Hardware cache level : PERF_COUNT_HW_CACHE_L1D
 * Hardware cache event operation type : PERF_COUNT_HW_CACHE_OP_READ
 * Hardware cache event result type : PERF_COUNT_HW_CACHE_RESULT_MISS
 */
#define EventCode_1 0x10000
/*
 * Hardware cache level : PERF_COUNT_HW_CACHE_L1D
 * Hardware cache event operation type : PERF_COUNT_HW_CACHE_OP_WRITE
 * Hardware cache event result type : PERF_COUNT_HW_CACHE_RESULT_ACCESS
 */
#define EventCode_2 0x0100
/*
 * Hardware cache level : PERF_COUNT_HW_CACHE_DTLB
 * Hardware cache event operation type : PERF_COUNT_HW_CACHE_OP_WRITE
 * Hardware cache event result type : PERF_COUNT_HW_CACHE_RESULT_ACCESS
 */
#define EventCode_3 0x0103
/*
 * Hardware cache level : PERF_COUNT_HW_CACHE_L1D
 * Hardware cache event operation type : PERF_COUNT_HW_CACHE_OP_READ
 * Hardware cache event result type : Invalid ( > PERF_COUNT_HW_CACHE_RESULT_MAX)
 */
#define EventCode_4 0x030000

/*
 * A perf test to check valid hardware cache events.
 */
static int hw_cache_event_type_test(void)
{
	struct event event;

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

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

	/* Init the event to test hardware cache event */
	event_init_opts(&event, EventCode_1, PERF_TYPE_HW_CACHE, "event");

	/* Expected to success as its pointing to L1 load miss */
	FAIL_IF(event_open(&event));
	event_close(&event);

	/* Init the event to test hardware cache event */
	event_init_opts(&event, EventCode_2, PERF_TYPE_HW_CACHE, "event");

	/* Expected to fail as the corresponding cache event entry have 0 in that index */
	FAIL_IF(!event_open(&event));
	event_close(&event);

	/* Init the event to test hardware cache event */
	event_init_opts(&event, EventCode_3, PERF_TYPE_HW_CACHE, "event");

	/* Expected to fail as the corresponding cache event entry have -1 in that index */
	FAIL_IF(!event_open(&event));
	event_close(&event);

	/* Init the event to test hardware cache event */
	event_init_opts(&event, EventCode_4, PERF_TYPE_HW_CACHE, "event");

	/* Expected to fail as hardware cache event result type is Invalid */
	FAIL_IF(!event_open(&event));
	event_close(&event);

	return 0;
}

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