2018-04-18 16:05:18 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-09-16 09:50:00 -06:00
|
|
|
/*
|
|
|
|
* Copyright(C) 2015 Linaro Limited. All rights reserved.
|
|
|
|
* Author: Mathieu Poirier <mathieu.poirier@linaro.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <linux/coresight-pmu.h>
|
2019-07-04 11:32:27 -03:00
|
|
|
#include <linux/zalloc.h>
|
2016-09-16 09:50:00 -06:00
|
|
|
|
|
|
|
#include "../../util/auxtrace.h"
|
2019-08-29 15:56:40 -03:00
|
|
|
#include "../../util/debug.h"
|
2016-09-16 09:50:00 -06:00
|
|
|
#include "../../util/evlist.h"
|
|
|
|
#include "../../util/pmu.h"
|
|
|
|
#include "cs-etm.h"
|
2018-01-14 13:28:50 -06:00
|
|
|
#include "arm-spe.h"
|
|
|
|
|
|
|
|
static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)
|
|
|
|
{
|
|
|
|
struct perf_pmu **arm_spe_pmus = NULL;
|
|
|
|
int ret, i, nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
|
|
|
|
/* arm_spe_xxxxxxxxx\0 */
|
|
|
|
char arm_spe_pmu_name[sizeof(ARM_SPE_PMU_NAME) + 10];
|
|
|
|
|
|
|
|
arm_spe_pmus = zalloc(sizeof(struct perf_pmu *) * nr_cpus);
|
|
|
|
if (!arm_spe_pmus) {
|
|
|
|
pr_err("spes alloc failed\n");
|
|
|
|
*err = -ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nr_cpus; i++) {
|
|
|
|
ret = sprintf(arm_spe_pmu_name, "%s%d", ARM_SPE_PMU_NAME, i);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_err("sprintf failed\n");
|
|
|
|
*err = -ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
arm_spe_pmus[*nr_spes] = perf_pmu__find(arm_spe_pmu_name);
|
|
|
|
if (arm_spe_pmus[*nr_spes]) {
|
|
|
|
pr_debug2("%s %d: arm_spe_pmu %d type %d name %s\n",
|
|
|
|
__func__, __LINE__, *nr_spes,
|
|
|
|
arm_spe_pmus[*nr_spes]->type,
|
|
|
|
arm_spe_pmus[*nr_spes]->name);
|
|
|
|
(*nr_spes)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return arm_spe_pmus;
|
|
|
|
}
|
2016-09-16 09:50:00 -06:00
|
|
|
|
|
|
|
struct auxtrace_record
|
2019-07-21 13:23:52 +02:00
|
|
|
*auxtrace_record__init(struct evlist *evlist, int *err)
|
2016-09-16 09:50:00 -06:00
|
|
|
{
|
|
|
|
struct perf_pmu *cs_etm_pmu;
|
2019-07-21 13:23:51 +02:00
|
|
|
struct evsel *evsel;
|
2016-09-16 09:50:00 -06:00
|
|
|
bool found_etm = false;
|
perf tools: Fix record failure when mixed with ARM SPE event
When recording with cache-misses and arm_spe_x event, I found that it
will just fail without showing any error info if i put cache-misses
after 'arm_spe_x' event.
[root@localhost 0620]# perf record -e cache-misses \
-e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.067 MB perf.data ]
[root@localhost 0620]#
[root@localhost 0620]# perf record -e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ \
-e cache-misses sleep 1
[root@localhost 0620]#
The current code can only work if the only event to be traced is an
'arm_spe_x', or if it is the last event to be specified. Otherwise the
last event type will be checked against all the arm_spe_pmus[i]->types,
none will match and an out of bound 'i' index will be used in
arm_spe_recording_init().
We don't support concurrent multiple arm_spe_x events currently, that
is checked in arm_spe_recording_options(), and it will show the relevant
info. So add the check and record of the first found 'arm_spe_pmu' to
fix this issue here.
Fixes: ffd3d18c20b8 ("perf tools: Add ARM Statistical Profiling Extensions (SPE) support")
Signed-off-by: Wei Li <liwei391@huawei.com>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Tested-by-by: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lore.kernel.org/lkml/20200724071111.35593-2-liwei391@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-07-24 15:11:10 +08:00
|
|
|
struct perf_pmu *found_spe = NULL;
|
2020-07-24 15:11:11 +08:00
|
|
|
struct perf_pmu **arm_spe_pmus = NULL;
|
|
|
|
int nr_spes = 0;
|
2018-02-12 13:32:37 -07:00
|
|
|
int i = 0;
|
2018-01-14 13:28:50 -06:00
|
|
|
|
|
|
|
if (!evlist)
|
|
|
|
return NULL;
|
2016-09-16 09:50:00 -06:00
|
|
|
|
|
|
|
cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME);
|
2020-07-24 15:11:11 +08:00
|
|
|
arm_spe_pmus = find_all_arm_spe_pmus(&nr_spes, err);
|
2018-01-14 13:28:50 -06:00
|
|
|
|
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
|
|
|
if (cs_etm_pmu &&
|
2019-07-21 13:24:29 +02:00
|
|
|
evsel->core.attr.type == cs_etm_pmu->type)
|
2018-01-14 13:28:50 -06:00
|
|
|
found_etm = true;
|
|
|
|
|
perf tools: Fix record failure when mixed with ARM SPE event
When recording with cache-misses and arm_spe_x event, I found that it
will just fail without showing any error info if i put cache-misses
after 'arm_spe_x' event.
[root@localhost 0620]# perf record -e cache-misses \
-e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.067 MB perf.data ]
[root@localhost 0620]#
[root@localhost 0620]# perf record -e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ \
-e cache-misses sleep 1
[root@localhost 0620]#
The current code can only work if the only event to be traced is an
'arm_spe_x', or if it is the last event to be specified. Otherwise the
last event type will be checked against all the arm_spe_pmus[i]->types,
none will match and an out of bound 'i' index will be used in
arm_spe_recording_init().
We don't support concurrent multiple arm_spe_x events currently, that
is checked in arm_spe_recording_options(), and it will show the relevant
info. So add the check and record of the first found 'arm_spe_pmu' to
fix this issue here.
Fixes: ffd3d18c20b8 ("perf tools: Add ARM Statistical Profiling Extensions (SPE) support")
Signed-off-by: Wei Li <liwei391@huawei.com>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Tested-by-by: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lore.kernel.org/lkml/20200724071111.35593-2-liwei391@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-07-24 15:11:10 +08:00
|
|
|
if (!nr_spes || found_spe)
|
2018-01-14 13:28:50 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_spes; i++) {
|
2019-07-21 13:24:29 +02:00
|
|
|
if (evsel->core.attr.type == arm_spe_pmus[i]->type) {
|
perf tools: Fix record failure when mixed with ARM SPE event
When recording with cache-misses and arm_spe_x event, I found that it
will just fail without showing any error info if i put cache-misses
after 'arm_spe_x' event.
[root@localhost 0620]# perf record -e cache-misses \
-e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.067 MB perf.data ]
[root@localhost 0620]#
[root@localhost 0620]# perf record -e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ \
-e cache-misses sleep 1
[root@localhost 0620]#
The current code can only work if the only event to be traced is an
'arm_spe_x', or if it is the last event to be specified. Otherwise the
last event type will be checked against all the arm_spe_pmus[i]->types,
none will match and an out of bound 'i' index will be used in
arm_spe_recording_init().
We don't support concurrent multiple arm_spe_x events currently, that
is checked in arm_spe_recording_options(), and it will show the relevant
info. So add the check and record of the first found 'arm_spe_pmu' to
fix this issue here.
Fixes: ffd3d18c20b8 ("perf tools: Add ARM Statistical Profiling Extensions (SPE) support")
Signed-off-by: Wei Li <liwei391@huawei.com>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Tested-by-by: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lore.kernel.org/lkml/20200724071111.35593-2-liwei391@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-07-24 15:11:10 +08:00
|
|
|
found_spe = arm_spe_pmus[i];
|
2018-01-14 13:28:50 -06:00
|
|
|
break;
|
|
|
|
}
|
2016-09-16 09:50:00 -06:00
|
|
|
}
|
|
|
|
}
|
2020-07-24 15:11:11 +08:00
|
|
|
free(arm_spe_pmus);
|
2016-09-16 09:50:00 -06:00
|
|
|
|
2018-01-14 13:28:50 -06:00
|
|
|
if (found_etm && found_spe) {
|
|
|
|
pr_err("Concurrent ARM Coresight ETM and SPE operation not currently supported\n");
|
|
|
|
*err = -EOPNOTSUPP;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-16 09:50:00 -06:00
|
|
|
if (found_etm)
|
|
|
|
return cs_etm_record_init(err);
|
|
|
|
|
2018-01-14 13:28:50 -06:00
|
|
|
#if defined(__aarch64__)
|
|
|
|
if (found_spe)
|
perf tools: Fix record failure when mixed with ARM SPE event
When recording with cache-misses and arm_spe_x event, I found that it
will just fail without showing any error info if i put cache-misses
after 'arm_spe_x' event.
[root@localhost 0620]# perf record -e cache-misses \
-e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.067 MB perf.data ]
[root@localhost 0620]#
[root@localhost 0620]# perf record -e arm_spe_0/ts_enable=1,pct_enable=1,pa_enable=1,load_filter=1,jitter=1,store_filter=1,min_latency=0/ \
-e cache-misses sleep 1
[root@localhost 0620]#
The current code can only work if the only event to be traced is an
'arm_spe_x', or if it is the last event to be specified. Otherwise the
last event type will be checked against all the arm_spe_pmus[i]->types,
none will match and an out of bound 'i' index will be used in
arm_spe_recording_init().
We don't support concurrent multiple arm_spe_x events currently, that
is checked in arm_spe_recording_options(), and it will show the relevant
info. So add the check and record of the first found 'arm_spe_pmu' to
fix this issue here.
Fixes: ffd3d18c20b8 ("perf tools: Add ARM Statistical Profiling Extensions (SPE) support")
Signed-off-by: Wei Li <liwei391@huawei.com>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Tested-by-by: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lore.kernel.org/lkml/20200724071111.35593-2-liwei391@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-07-24 15:11:10 +08:00
|
|
|
return arm_spe_recording_init(err, found_spe);
|
2018-01-14 13:28:50 -06:00
|
|
|
#endif
|
|
|
|
|
2016-09-16 09:50:00 -06:00
|
|
|
/*
|
2018-01-14 13:28:50 -06:00
|
|
|
* Clear 'err' even if we haven't found an event - that way perf
|
2016-09-16 09:50:00 -06:00
|
|
|
* record can still be used even if tracers aren't present. The NULL
|
|
|
|
* return value will take care of telling the infrastructure HW tracing
|
|
|
|
* isn't available.
|
|
|
|
*/
|
|
|
|
*err = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|