xref: /openbmc/linux/tools/perf/arch/x86/util/auxtrace.c (revision 37b9c7bb)
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/auxtrace.h"
14 #include "../../../util/intel-pt.h"
15 #include "../../../util/intel-bts.h"
16 #include "../../../util/evlist.h"
17 
18 static
19 struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist,
20 						    int *err)
21 {
22 	struct perf_pmu *intel_pt_pmu;
23 	struct perf_pmu *intel_bts_pmu;
24 	struct evsel *evsel;
25 	bool found_pt = false;
26 	bool found_bts = false;
27 
28 	intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
29 	if (intel_pt_pmu)
30 		intel_pt_pmu->auxtrace = true;
31 	intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
32 	if (intel_bts_pmu)
33 		intel_bts_pmu->auxtrace = true;
34 
35 	evlist__for_each_entry(evlist, evsel) {
36 		if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type)
37 			found_pt = true;
38 		if (intel_bts_pmu && evsel->core.attr.type == intel_bts_pmu->type)
39 			found_bts = true;
40 	}
41 
42 	if (found_pt && found_bts) {
43 		pr_err("intel_pt and intel_bts may not be used together\n");
44 		*err = -EINVAL;
45 		return NULL;
46 	}
47 
48 	if (found_pt)
49 		return intel_pt_recording_init(err);
50 
51 	if (found_bts)
52 		return intel_bts_recording_init(err);
53 
54 	return NULL;
55 }
56 
57 struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
58 					      int *err)
59 {
60 	char buffer[64];
61 	int ret;
62 
63 	*err = 0;
64 
65 	ret = get_cpuid(buffer, sizeof(buffer));
66 	if (ret) {
67 		*err = ret;
68 		return NULL;
69 	}
70 
71 	if (!strncmp(buffer, "GenuineIntel,", 13))
72 		return auxtrace_record__init_intel(evlist, err);
73 
74 	return NULL;
75 }
76