blob: 7a7805583e3fe4f40bba1b3435d9c149ea3adebd [file] [log] [blame]
Adrian Hunter5efb1d52015-07-17 19:33:42 +03001/*
2 * auxtrace.c: AUX area tracing support
3 * Copyright (c) 2013-2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
Adrian Hunterd0170af2015-07-17 19:33:43 +030016#include <stdbool.h>
17
Adrian Hunter5efb1d52015-07-17 19:33:42 +030018#include "../../util/header.h"
Adrian Hunterd0170af2015-07-17 19:33:43 +030019#include "../../util/debug.h"
20#include "../../util/pmu.h"
Adrian Hunter5efb1d52015-07-17 19:33:42 +030021#include "../../util/auxtrace.h"
22#include "../../util/intel-pt.h"
Adrian Hunterd0170af2015-07-17 19:33:43 +030023#include "../../util/intel-bts.h"
24#include "../../util/evlist.h"
Adrian Hunter5efb1d52015-07-17 19:33:42 +030025
Adrian Hunterd0170af2015-07-17 19:33:43 +030026static
27struct auxtrace_record *auxtrace_record__init_intel(struct perf_evlist *evlist,
28 int *err)
29{
30 struct perf_pmu *intel_pt_pmu;
31 struct perf_pmu *intel_bts_pmu;
32 struct perf_evsel *evsel;
33 bool found_pt = false;
34 bool found_bts = false;
35
36 intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
37 intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
38
39 if (evlist) {
40 evlist__for_each(evlist, evsel) {
41 if (intel_pt_pmu &&
42 evsel->attr.type == intel_pt_pmu->type)
43 found_pt = true;
44 if (intel_bts_pmu &&
45 evsel->attr.type == intel_bts_pmu->type)
46 found_bts = true;
47 }
48 }
49
50 if (found_pt && found_bts) {
51 pr_err("intel_pt and intel_bts may not be used together\n");
52 *err = -EINVAL;
53 return NULL;
54 }
55
56 if (found_pt)
57 return intel_pt_recording_init(err);
58
59 if (found_bts)
60 return intel_bts_recording_init(err);
61
62 return NULL;
63}
64
65struct auxtrace_record *auxtrace_record__init(struct perf_evlist *evlist,
Adrian Hunter5efb1d52015-07-17 19:33:42 +030066 int *err)
67{
68 char buffer[64];
69 int ret;
70
71 *err = 0;
72
73 ret = get_cpuid(buffer, sizeof(buffer));
74 if (ret) {
75 *err = ret;
76 return NULL;
77 }
78
79 if (!strncmp(buffer, "GenuineIntel,", 13))
Adrian Hunterd0170af2015-07-17 19:33:43 +030080 return auxtrace_record__init_intel(evlist, err);
Adrian Hunter5efb1d52015-07-17 19:33:42 +030081
82 return NULL;
83}