2 * Copyright(C) 2015 Linaro Limited. All rights reserved.
3 * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that 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
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <linux/coresight-pmu.h>
21 #include "../../util/auxtrace.h"
22 #include "../../util/evlist.h"
23 #include "../../util/pmu.h"
27 static struct perf_pmu
**find_all_arm_spe_pmus(int *nr_spes
, int *err
)
29 struct perf_pmu
**arm_spe_pmus
= NULL
;
30 int ret
, i
, nr_cpus
= sysconf(_SC_NPROCESSORS_CONF
);
31 /* arm_spe_xxxxxxxxx\0 */
32 char arm_spe_pmu_name
[sizeof(ARM_SPE_PMU_NAME
) + 10];
34 arm_spe_pmus
= zalloc(sizeof(struct perf_pmu
*) * nr_cpus
);
36 pr_err("spes alloc failed\n");
41 for (i
= 0; i
< nr_cpus
; i
++) {
42 ret
= sprintf(arm_spe_pmu_name
, "%s%d", ARM_SPE_PMU_NAME
, i
);
44 pr_err("sprintf failed\n");
49 arm_spe_pmus
[*nr_spes
] = perf_pmu__find(arm_spe_pmu_name
);
50 if (arm_spe_pmus
[*nr_spes
]) {
51 pr_debug2("%s %d: arm_spe_pmu %d type %d name %s\n",
52 __func__
, __LINE__
, *nr_spes
,
53 arm_spe_pmus
[*nr_spes
]->type
,
54 arm_spe_pmus
[*nr_spes
]->name
);
62 struct auxtrace_record
63 *auxtrace_record__init(struct perf_evlist
*evlist
, int *err
)
65 struct perf_pmu
*cs_etm_pmu
;
66 struct perf_evsel
*evsel
;
67 bool found_etm
= false;
68 bool found_spe
= false;
69 static struct perf_pmu
**arm_spe_pmus
= NULL
;
70 static int nr_spes
= 0;
76 cs_etm_pmu
= perf_pmu__find(CORESIGHT_ETM_PMU_NAME
);
79 arm_spe_pmus
= find_all_arm_spe_pmus(&nr_spes
, err
);
81 evlist__for_each_entry(evlist
, evsel
) {
83 evsel
->attr
.type
== cs_etm_pmu
->type
)
89 for (i
= 0; i
< nr_spes
; i
++) {
90 if (evsel
->attr
.type
== arm_spe_pmus
[i
]->type
) {
97 if (found_etm
&& found_spe
) {
98 pr_err("Concurrent ARM Coresight ETM and SPE operation not currently supported\n");
104 return cs_etm_record_init(err
);
106 #if defined(__aarch64__)
108 return arm_spe_recording_init(err
, arm_spe_pmus
[i
]);
112 * Clear 'err' even if we haven't found an event - that way perf
113 * record can still be used even if tracers aren't present. The NULL
114 * return value will take care of telling the infrastructure HW tracing