Message ID | 20230827133557.112494-2-leo.yan@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | perf cs-etm: Improve timestamp tracing | expand |
On 27/08/2023 14:35, Leo Yan wrote: > So far, it's impossible to validate timestamp trace in Arm CoreSight when > the perf is in the per-thread mode. E.g. for the command: > > perf record -e cs_etm/timestamp/ --per-thread -- ls > > The command enables config 'timestamp' for 'cs_etm' event in the > per-thread mode. In this case, the function cs_etm_validate_config() > directly bails out and skips validation. > > Given profiled process can be scheduled on any CPUs in the per-thread > mode, this patch validates timestamp tracing for all CPUs when detect > the CPU map is empty. There is an edge case where the profiled process is known by the user to be pinned to a specific CPU, rather than possibly running on all CPUs, so this isn't always true. But I think that can be worked around by changing it to a per-cpu session to get around the new error. Given that this validation was only supposed to be best effort information and not get in the way you could say to not make it more restrictive. But it's quite a small edge case so either way: Reviewed-by: James Clark <james.clark@arm.com> > > Signed-off-by: Leo Yan <leo.yan@linaro.org> > --- > tools/perf/arch/arm/util/cs-etm.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c > index b8d6a953fd74..cf9ef9ba800b 100644 > --- a/tools/perf/arch/arm/util/cs-etm.c > +++ b/tools/perf/arch/arm/util/cs-etm.c > @@ -205,8 +205,17 @@ static int cs_etm_validate_config(struct auxtrace_record *itr, > for (i = 0; i < cpu__max_cpu().cpu; i++) { > struct perf_cpu cpu = { .cpu = i, }; > > - if (!perf_cpu_map__has(event_cpus, cpu) || > - !perf_cpu_map__has(online_cpus, cpu)) > + /* > + * In per-cpu case, do the validation for CPUs to work with. > + * In per-thread case, the CPU map is empty. Since the traced > + * program can run on any CPUs in this case, thus don't skip > + * validation. > + */ > + if (!perf_cpu_map__empty(event_cpus) && > + !perf_cpu_map__has(event_cpus, cpu)) > + continue; > + > + if (!perf_cpu_map__has(online_cpus, cpu)) > continue; > > err = cs_etm_validate_context_id(itr, evsel, i);
On Mon, Sep 04, 2023 at 04:23:43PM +0100, James Clark wrote: > > On 27/08/2023 14:35, Leo Yan wrote: > > So far, it's impossible to validate timestamp trace in Arm CoreSight when > > the perf is in the per-thread mode. E.g. for the command: > > > > perf record -e cs_etm/timestamp/ --per-thread -- ls > > > > The command enables config 'timestamp' for 'cs_etm' event in the > > per-thread mode. In this case, the function cs_etm_validate_config() > > directly bails out and skips validation. > > > > Given profiled process can be scheduled on any CPUs in the per-thread > > mode, this patch validates timestamp tracing for all CPUs when detect > > the CPU map is empty. > > There is an edge case where the profiled process is known by the user to > be pinned to a specific CPU, rather than possibly running on all CPUs, > so this isn't always true. Good point. However, when a process is pinned to specific CPUs, we still can dynamically change the scheduling affinity to any other CPUs by using taskset command or calling sched_setaffinity(). From a perf session's pespective, it is sane to validate timestamp tracing for all online CPUs for per-thread mode. > But I think that can be worked around by changing it to a per-cpu > session to get around the new error. Given that this validation was only > supposed to be best effort information and not get in the way you could > say to not make it more restrictive. > > But it's quite a small edge case so either way: > > Reviewed-by: James Clark <james.clark@arm.com> Thanks for review! Leo
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index b8d6a953fd74..cf9ef9ba800b 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -205,8 +205,17 @@ static int cs_etm_validate_config(struct auxtrace_record *itr, for (i = 0; i < cpu__max_cpu().cpu; i++) { struct perf_cpu cpu = { .cpu = i, }; - if (!perf_cpu_map__has(event_cpus, cpu) || - !perf_cpu_map__has(online_cpus, cpu)) + /* + * In per-cpu case, do the validation for CPUs to work with. + * In per-thread case, the CPU map is empty. Since the traced + * program can run on any CPUs in this case, thus don't skip + * validation. + */ + if (!perf_cpu_map__empty(event_cpus) && + !perf_cpu_map__has(event_cpus, cpu)) + continue; + + if (!perf_cpu_map__has(online_cpus, cpu)) continue; err = cs_etm_validate_context_id(itr, evsel, i);
So far, it's impossible to validate timestamp trace in Arm CoreSight when the perf is in the per-thread mode. E.g. for the command: perf record -e cs_etm/timestamp/ --per-thread -- ls The command enables config 'timestamp' for 'cs_etm' event in the per-thread mode. In this case, the function cs_etm_validate_config() directly bails out and skips validation. Given profiled process can be scheduled on any CPUs in the per-thread mode, this patch validates timestamp tracing for all CPUs when detect the CPU map is empty. Signed-off-by: Leo Yan <leo.yan@linaro.org> --- tools/perf/arch/arm/util/cs-etm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)