xref: /openbmc/linux/tools/perf/arch/x86/util/auxtrace.c (revision 724ba675)
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 	intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
30 
31 	evlist__for_each_entry(evlist, evsel) {
32 		if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type)
33 			found_pt = true;
34 		if (intel_bts_pmu && evsel->core.attr.type == intel_bts_pmu->type)
35 			found_bts = true;
36 	}
37 
38 	if (found_pt && found_bts) {
39 		pr_err("intel_pt and intel_bts may not be used together\n");
40 		*err = -EINVAL;
41 		return NULL;
42 	}
43 
44 	if (found_pt)
45 		return intel_pt_recording_init(err);
46 
47 	if (found_bts)
48 		return intel_bts_recording_init(err);
49 
50 	return NULL;
51 }
52 
53 struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
54 					      int *err)
55 {
56 	char buffer[64];
57 	int ret;
58 
59 	*err = 0;
60 
61 	ret = get_cpuid(buffer, sizeof(buffer));
62 	if (ret) {
63 		*err = ret;
64 		return NULL;
65 	}
66 
67 	if (!strncmp(buffer, "GenuineIntel,", 13))
68 		return auxtrace_record__init_intel(evlist, err);
69 
70 	return NULL;
71 }
72