1 #include "tests/tests.h"
7 #include "arch-tests.h"
15 static pid_t spawn(void)
29 * Create an event group that contains both a sampled hardware
30 * (cpu-cycles) and software (intel_cqm/llc_occupancy/) event. We then
31 * wait for the hardware perf counter to overflow and generate a PMI,
32 * which triggers an event read for both of the events in the group.
34 * Since reading Intel CQM event counters requires sending SMP IPIs, the
35 * CQM pmu needs to handle the above situation gracefully, and return
36 * the last read counter value to avoid triggering a WARN_ON_ONCE() in
37 * smp_call_function_many() caused by sending IPIs from NMI context.
39 int test__intel_cqm_count_nmi_context(struct test *test __maybe_unused, int subtest __maybe_unused)
41 struct perf_evlist *evlist = NULL;
42 struct perf_evsel *evsel = NULL;
43 struct perf_event_attr pe;
44 int i, fd[2], flag, ret;
50 flag = perf_event_open_cloexec_flag();
52 evlist = perf_evlist__new();
54 pr_debug("perf_evlist__new failed\n");
58 ret = parse_events(evlist, "intel_cqm/llc_occupancy/", NULL);
60 pr_debug("parse_events failed, is \"intel_cqm/llc_occupancy/\" available?\n");
65 evsel = perf_evlist__first(evlist);
67 pr_debug("perf_evlist__first failed\n");
71 memset(&pe, 0, sizeof(pe));
74 pe.type = PERF_TYPE_HARDWARE;
75 pe.config = PERF_COUNT_HW_CPU_CYCLES;
76 pe.read_format = PERF_FORMAT_GROUP;
78 pe.sample_period = 128;
79 pe.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_READ;
83 fd[0] = sys_perf_event_open(&pe, pid, -1, -1, flag);
85 pr_debug("failed to open event\n");
89 memset(&pe, 0, sizeof(pe));
92 pe.type = evsel->attr.type;
93 pe.config = evsel->attr.config;
95 fd[1] = sys_perf_event_open(&pe, pid, -1, fd[0], flag);
97 pr_debug("failed to open event\n");
102 * Pick a power-of-two number of pages + 1 for the meta-data
103 * page (struct perf_event_mmap_page). See tools/perf/design.txt.
105 mmap_len = page_size * 65;
107 event = mmap(NULL, mmap_len, PROT_READ, MAP_SHARED, fd[0], 0);
108 if (event == (void *)(-1)) {
109 pr_debug("failed to mmap %d\n", errno);
117 munmap(event, mmap_len);
119 for (i = 0; i < 2; i++)
125 perf_evlist__delete(evlist);