xref: /openbmc/linux/tools/perf/arch/x86/util/auxtrace.c (revision c4c3c32d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * auxtrace.c: AUX area tracing support
4  * Copyright (c) 2013-2014, Intel Corporation.
5  */
6 
7 #include <errno.h>
8 #include <stdbool.h>
9 
10 #include "../../../util/header.h"
11 #include "../../../util/debug.h"
12 #include "../../../util/pmu.h"
13 #include "../../../util/pmus.h"
14 #include "../../../util/auxtrace.h"
15 #include "../../../util/intel-pt.h"
16 #include "../../../util/intel-bts.h"
17 #include "../../../util/evlist.h"
18 
19 static
20 struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist,
21 						    int *err)
22 {
23 	struct perf_pmu *intel_pt_pmu;
24 	struct perf_pmu *intel_bts_pmu;
25 	struct evsel *evsel;
26 	bool found_pt = false;
27 	bool found_bts = false;
28 
29 	intel_pt_pmu = perf_pmus__find(INTEL_PT_PMU_NAME);
30 	intel_bts_pmu = perf_pmus__find(INTEL_BTS_PMU_NAME);
31 
32 	evlist__for_each_entry(evlist, evsel) {
33 		if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type)
34 			found_pt = true;
35 		if (intel_bts_pmu && evsel->core.attr.type == intel_bts_pmu->type)
36 			found_bts = true;
37 	}
38 
39 	if (found_pt && found_bts) {
40 		pr_err("intel_pt and intel_bts may not be used together\n");
41 		*err = -EINVAL;
42 		return NULL;
43 	}
44 
45 	if (found_pt)
46 		return intel_pt_recording_init(err);
47 
48 	if (found_bts)
49 		return intel_bts_recording_init(err);
50 
51 	return NULL;
52 }
53 
54 struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
55 					      int *err)
56 {
57 	char buffer[64];
58 	int ret;
59 
60 	*err = 0;
61 
62 	ret = get_cpuid(buffer, sizeof(buffer));
63 	if (ret) {
64 		*err = ret;
65 		return NULL;
66 	}
67 
68 	if (!strncmp(buffer, "GenuineIntel,", 13))
69 		return auxtrace_record__init_intel(evlist, err);
70 
71 	return NULL;
72 }
73