aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/perf/arch/x86/tests/amd-ibs-via-core-pmu.c
blob: 78b1902f6f59d8ce5629a711f420747ede014d08 (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
// SPDX-License-Identifier: GPL-2.0
#include "arch-tests.h"
#include "linux/perf_event.h"
#include "tests/tests.h"
#include "pmu.h"
#include "pmus.h"
#include "../perf-sys.h"
#include "debug.h"

#define NR_SUB_TESTS 5

static struct sub_tests {
	int type;
	unsigned long config;
	bool valid;
} sub_tests[NR_SUB_TESTS] = {
	{ PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, true },
	{ PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, false },
	{ PERF_TYPE_RAW, 0x076, true },
	{ PERF_TYPE_RAW, 0x0C1, true },
	{ PERF_TYPE_RAW, 0x012, false },
};

static int event_open(int type, unsigned long config)
{
	struct perf_event_attr attr;

	memset(&attr, 0, sizeof(struct perf_event_attr));
	attr.type = type;
	attr.size = sizeof(struct perf_event_attr);
	attr.config = config;
	attr.disabled = 1;
	attr.precise_ip = 1;
	attr.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
	attr.sample_period = 100000;

	return sys_perf_event_open(&attr, -1, 0, -1, 0);
}

int test__amd_ibs_via_core_pmu(struct test_suite *test __maybe_unused,
			       int subtest __maybe_unused)
{
	struct perf_pmu *ibs_pmu;
	int ret = TEST_OK;
	int fd, i;

	ibs_pmu = perf_pmus__find("ibs_op");
	if (!ibs_pmu)
		return TEST_SKIP;

	for (i = 0; i < NR_SUB_TESTS; i++) {
		fd = event_open(sub_tests[i].type, sub_tests[i].config);
		pr_debug("type: 0x%x, config: 0x%lx, fd: %d  -  ", sub_tests[i].type,
			 sub_tests[i].config, fd);
		if ((sub_tests[i].valid && fd == -1) ||
		    (!sub_tests[i].valid && fd > 0)) {
			pr_debug("Fail\n");
			ret = TEST_FAIL;
		} else {
			pr_debug("Pass\n");
		}

		if (fd > 0)
			close(fd);
	}

	return ret;
}