1/*
2 * Copyright 2014, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8
9#include "ebb.h"
10
11
12/*
13 * Basic test that counts user cycles and takes EBBs.
14 */
15int cycles(void)
16{
17	struct event event;
18
19	event_init_named(&event, 0x1001e, "cycles");
20	event_leader_ebb_init(&event);
21
22	event.attr.exclude_kernel = 1;
23	event.attr.exclude_hv = 1;
24	event.attr.exclude_idle = 1;
25
26	FAIL_IF(event_open(&event));
27
28	ebb_enable_pmc_counting(1);
29	setup_ebb_handler(standard_ebb_callee);
30	ebb_global_enable();
31	FAIL_IF(ebb_event_enable(&event));
32
33	mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
34
35	while (ebb_state.stats.ebb_count < 10) {
36		FAIL_IF(core_busy_loop());
37		FAIL_IF(ebb_check_mmcr0());
38	}
39
40	ebb_global_disable();
41	ebb_freeze_pmcs();
42
43	count_pmc(1, sample_period);
44
45	dump_ebb_state();
46
47	event_close(&event);
48
49	FAIL_IF(ebb_state.stats.ebb_count == 0);
50	FAIL_IF(!ebb_check_count(1, sample_period, 100));
51
52	return 0;
53}
54
55int main(void)
56{
57	return test_harness(cycles, "cycles");
58}
59