From nobody Thu Sep 18 02:40:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AC2AC10F1D for ; Mon, 12 Dec 2022 15:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbiLLPzq (ORCPT ); Mon, 12 Dec 2022 10:55:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbiLLPzn (ORCPT ); Mon, 12 Dec 2022 10:55:43 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CC5064FA; Mon, 12 Dec 2022 07:55:43 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4D77B2F4; Mon, 12 Dec 2022 07:56:23 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4BBAA3F71E; Mon, 12 Dec 2022 07:55:40 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 1/5] perf: cs-etm: Print unknown header version as an error Date: Mon, 12 Dec 2022 15:55:09 +0000 Message-Id: <20221212155513.2259623-2-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is an error rather than just for the raw trace dump so always print it as an error. Also remove the duplicate header version check. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 16db965ac995..aeb1e30888db 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2623,14 +2623,7 @@ static void cs_etm__print_auxtrace_info(__u64 *val, = int num) { int i, cpu =3D 0, version, err; =20 - /* bail out early on bad header version */ version =3D val[0]; - if (version > CS_HEADER_CURRENT_VERSION) { - /* failure.. return */ - fprintf(stdout, " Unknown Header Version =3D %x, ", version); - fprintf(stdout, "Version supported <=3D %x\n", CS_HEADER_CURRENT_VERSION= ); - return; - } =20 for (i =3D 0; i < CS_HEADER_VERSION_MAX; i++) fprintf(stdout, cs_etm_global_header_fmts[i], val[i]); @@ -2916,9 +2909,8 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, /* Look for version of the header */ hdr_version =3D ptr[0]; if (hdr_version > CS_HEADER_CURRENT_VERSION) { - /* print routine will print an error on bad version */ - if (dump_trace) - cs_etm__print_auxtrace_info(auxtrace_info->priv, 0); + pr_err("\nCS ETM Trace: Unknown Header Version =3D %#" PRIx64, hdr_versi= on); + pr_err(", version supported <=3D %x\n", CS_HEADER_CURRENT_VERSION); return -EINVAL; } =20 --=20 2.25.1 From nobody Thu Sep 18 02:40:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 889C2C4332F for ; Mon, 12 Dec 2022 15:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232632AbiLLPzx (ORCPT ); Mon, 12 Dec 2022 10:55:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232628AbiLLPzr (ORCPT ); Mon, 12 Dec 2022 10:55:47 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7476364FA; Mon, 12 Dec 2022 07:55:46 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B75FF15BF; Mon, 12 Dec 2022 07:56:26 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B20343F71E; Mon, 12 Dec 2022 07:55:43 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 2/5] perf: cs-etm: Remove unused stub methods Date: Mon, 12 Dec 2022 15:55:10 +0000 Message-Id: <20221212155513.2259623-3-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These aren't used outside of cs-etm so don't need stubs. Leave cs_etm__process_auxtrace_info() which is used externally, and add an error message so that it's obvious to users why it causes errors. Signed-off-by: James Clark --- tools/perf/util/cs-etm.h | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 90c83f932d9a..401f74be98d6 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -7,6 +7,7 @@ #ifndef INCLUDE__UTIL_PERF_CS_ETM_H__ #define INCLUDE__UTIL_PERF_CS_ETM_H__ =20 +#include "debug.h" #include "util/event.h" #include =20 @@ -218,40 +219,9 @@ static inline int cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, struct perf_session *session __maybe_unused) { + pr_err("\nCS ETM Trace: OpenCSD is not linked in, please recompile with C= ORESIGHT=3D1\n"); return -1; } - -static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, - int *cpu __maybe_unused) -{ - return -1; -} - -static inline int cs_etm__etmq_set_tid( - struct cs_etm_queue *etmq __maybe_unused, - pid_t tid __maybe_unused, - u8 trace_chan_id __maybe_unused) -{ - return -1; -} - -static inline bool cs_etm__etmq_is_timeless( - struct cs_etm_queue *etmq __maybe_unused) -{ - /* What else to return? */ - return true; -} - -static inline void cs_etm__etmq_set_traceid_queue_timestamp( - struct cs_etm_queue *etmq __maybe_unused, - u8 trace_chan_id __maybe_unused) {} - -static inline struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue( - struct cs_etm_queue *etmq __maybe_unused, - u8 trace_chan_id __maybe_unused) -{ - return NULL; -} #endif =20 #endif --=20 2.25.1 From nobody Thu Sep 18 02:40:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBBCEC4167B for ; Mon, 12 Dec 2022 15:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232685AbiLLP4B (ORCPT ); Mon, 12 Dec 2022 10:56:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232642AbiLLPzv (ORCPT ); Mon, 12 Dec 2022 10:55:51 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0006465B5; Mon, 12 Dec 2022 07:55:49 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D5CE15DB; Mon, 12 Dec 2022 07:56:30 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2BCE03F71E; Mon, 12 Dec 2022 07:55:47 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 3/5] perf: cs-etm: Tidy up auxtrace info header printing Date: Mon, 12 Dec 2022 15:55:11 +0000 Message-Id: <20221212155513.2259623-4-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" cs_etm__print_auxtrace_info() is called twice in case there is an error somewhere in cs_etm__process_auxtrace_info(), but all the info is already available at the beginning so just print it there instead. Also use u64 and the already cast ptr variable to make it more consistent with the rest of the etm code. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index aeb1e30888db..bf8fbcec2d69 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2541,14 +2541,14 @@ static const char * const cs_etmv4_priv_fmts[] =3D { }; =20 static const char * const param_unk_fmt =3D - " Unknown parameter [%d] %llx\n"; + " Unknown parameter [%d] %"PRIx64"\n"; static const char * const magic_unk_fmt =3D - " Magic number Unknown %llx\n"; + " Magic number Unknown %"PRIx64"\n"; =20 -static int cs_etm__print_cpu_metadata_v0(__u64 *val, int *offset) +static int cs_etm__print_cpu_metadata_v0(u64 *val, int *offset) { int i =3D *offset, j, nr_params =3D 0, fmt_offset; - __u64 magic; + u64 magic; =20 /* check magic value */ magic =3D val[i + CS_ETM_MAGIC]; @@ -2580,10 +2580,10 @@ static int cs_etm__print_cpu_metadata_v0(__u64 *val= , int *offset) return 0; } =20 -static int cs_etm__print_cpu_metadata_v1(__u64 *val, int *offset) +static int cs_etm__print_cpu_metadata_v1(u64 *val, int *offset) { int i =3D *offset, j, total_params =3D 0; - __u64 magic; + u64 magic; =20 magic =3D val[i + CS_ETM_MAGIC]; /* total params to print is NR_PARAMS + common block size for v1 */ @@ -2619,7 +2619,7 @@ static int cs_etm__print_cpu_metadata_v1(__u64 *val, = int *offset) return 0; } =20 -static void cs_etm__print_auxtrace_info(__u64 *val, int num) +static void cs_etm__print_auxtrace_info(u64 *val, int num) { int i, cpu =3D 0, version, err; =20 @@ -2925,6 +2925,9 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, pmu_type =3D (unsigned int) ((hdr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); =20 + if (dump_trace) + cs_etm__print_auxtrace_info(ptr, num_cpu); + /* * Create an RB tree for traceID-metadata tuple. Since the conversion * has to be made for each packet that gets decoded, optimizing access @@ -3074,10 +3077,6 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, goto err_delete_thread; } =20 - if (dump_trace) { - cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu); - } - err =3D cs_etm__synth_events(etm, session); if (err) goto err_delete_thread; @@ -3113,12 +3112,5 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, intlist__delete(traceid_list); err_free_hdr: zfree(&hdr); - /* - * At this point, as a minimum we have valid header. Dump the rest of - * the info section - the print routines will error out on structural - * issues. - */ - if (dump_trace) - cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu); return err; } --=20 2.25.1 From nobody Thu Sep 18 02:40:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 681E6C4332F for ; Mon, 12 Dec 2022 15:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232695AbiLLP4E (ORCPT ); Mon, 12 Dec 2022 10:56:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232636AbiLLPz5 (ORCPT ); Mon, 12 Dec 2022 10:55:57 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52ED812AE6; Mon, 12 Dec 2022 07:55:53 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 963411FB; Mon, 12 Dec 2022 07:56:33 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 949133F71E; Mon, 12 Dec 2022 07:55:50 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 4/5] perf: cs-etm: Cleanup cs_etm__process_auxtrace_info() Date: Mon, 12 Dec 2022 15:55:12 +0000 Message-Id: <20221212155513.2259623-5-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" hdr is a copy of 3 values of ptr and doesn't need to be long lived. So just use ptr instead which means the malloc and the extra error path can be removed to simplify things. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index bf8fbcec2d69..ab30591a6c6a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2888,7 +2888,7 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, int num_cpu, trcidr_idx; int err =3D 0; int i, j; - u64 *ptr, *hdr =3D NULL; + u64 *ptr =3D NULL; u64 **metadata =3D NULL; u64 hdr_version; =20 @@ -2914,15 +2914,8 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, return -EINVAL; } =20 - hdr =3D zalloc(sizeof(*hdr) * CS_HEADER_VERSION_MAX); - if (!hdr) - return -ENOMEM; - - /* Extract header information - see cs-etm.h for format */ - for (i =3D 0; i < CS_HEADER_VERSION_MAX; i++) - hdr[i] =3D ptr[i]; - num_cpu =3D hdr[CS_PMU_TYPE_CPUS] & 0xffffffff; - pmu_type =3D (unsigned int) ((hdr[CS_PMU_TYPE_CPUS] >> 32) & + num_cpu =3D ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; + pmu_type =3D (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); =20 if (dump_trace) @@ -2934,10 +2927,8 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, * in anything other than a sequential array is worth doing. */ traceid_list =3D intlist__new(NULL); - if (!traceid_list) { - err =3D -ENOMEM; - goto err_free_hdr; - } + if (!traceid_list) + return -ENOMEM; =20 metadata =3D zalloc(sizeof(*metadata) * num_cpu); if (!metadata) { @@ -2945,6 +2936,9 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, goto err_free_traceid_list; } =20 + /* Start parsing after the common part of the header */ + i =3D CS_HEADER_VERSION_MAX; + /* * The metadata is stored in the auxtrace_info section and encodes * the configuration of the ARM embedded trace macrocell which is @@ -3043,7 +3037,7 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, =20 etm->num_cpu =3D num_cpu; etm->pmu_type =3D pmu_type; - etm->snapshot_mode =3D (hdr[CS_ETM_SNAPSHOT] !=3D 0); + etm->snapshot_mode =3D (ptr[CS_ETM_SNAPSHOT] !=3D 0); etm->metadata =3D metadata; etm->auxtrace_type =3D auxtrace_info->type; etm->timeless_decoding =3D cs_etm__is_timeless_decoding(etm); @@ -3110,7 +3104,5 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, zfree(&metadata); err_free_traceid_list: intlist__delete(traceid_list); -err_free_hdr: - zfree(&hdr); return err; } --=20 2.25.1 From nobody Thu Sep 18 02:40:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE369C4332F for ; Mon, 12 Dec 2022 15:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232355AbiLLP4X (ORCPT ); Mon, 12 Dec 2022 10:56:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232649AbiLLP4C (ORCPT ); Mon, 12 Dec 2022 10:56:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1116213EB1; Mon, 12 Dec 2022 07:55:56 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 407CE15BF; Mon, 12 Dec 2022 07:56:37 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1A1C93F71E; Mon, 12 Dec 2022 07:55:53 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 5/5] perf: cs-etm: Print auxtrace info even if OpenCSD isn't linked Date: Mon, 12 Dec 2022 15:55:13 +0000 Message-Id: <20221212155513.2259623-6-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Printing the info doesn't have any dependency on OpenCSD, and neither does recording Coresight data. Because it's sometimes useful to look at the info for debugging, it makes sense to be able to see it on the same platform that the recording was made on. So pull the auxtrace info printing parts into a new file that is always compiled into Perf. Signed-off-by: James Clark --- tools/perf/util/Build | 1 + tools/perf/util/cs-etm-base.c | 174 ++++++++++++++++++++++++++++++++++ tools/perf/util/cs-etm.c | 170 ++------------------------------- tools/perf/util/cs-etm.h | 12 ++- 4 files changed, 191 insertions(+), 166 deletions(-) create mode 100644 tools/perf/util/cs-etm-base.c diff --git a/tools/perf/util/Build b/tools/perf/util/Build index ab37f588ee8b..1193b207ef7d 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -125,6 +125,7 @@ ifdef CONFIG_LIBOPENCSD perf-$(CONFIG_AUXTRACE) +=3D cs-etm.o perf-$(CONFIG_AUXTRACE) +=3D cs-etm-decoder/ endif +perf-$(CONFIG_AUXTRACE) +=3D cs-etm-base.o =20 perf-y +=3D parse-branch-options.o perf-y +=3D dump-insn.o diff --git a/tools/perf/util/cs-etm-base.c b/tools/perf/util/cs-etm-base.c new file mode 100644 index 000000000000..597542410854 --- /dev/null +++ b/tools/perf/util/cs-etm-base.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * File for any parts of the Coresight decoding that don't require + * OpenCSD. + */ + +#include +#include + +#include "cs-etm.h" + +static const char * const cs_etm_global_header_fmts[] =3D { + [CS_HEADER_VERSION] =3D " Header version %llx\n", + [CS_PMU_TYPE_CPUS] =3D " PMU type/num cpus %llx\n", + [CS_ETM_SNAPSHOT] =3D " Snapshot %llx\n", +}; + +static const char * const cs_etm_priv_fmts[] =3D { + [CS_ETM_MAGIC] =3D " Magic number %llx\n", + [CS_ETM_CPU] =3D " CPU %lld\n", + [CS_ETM_NR_TRC_PARAMS] =3D " NR_TRC_PARAMS %llx\n", + [CS_ETM_ETMCR] =3D " ETMCR %llx\n", + [CS_ETM_ETMTRACEIDR] =3D " ETMTRACEIDR %llx\n", + [CS_ETM_ETMCCER] =3D " ETMCCER %llx\n", + [CS_ETM_ETMIDR] =3D " ETMIDR %llx\n", +}; + +static const char * const cs_etmv4_priv_fmts[] =3D { + [CS_ETM_MAGIC] =3D " Magic number %llx\n", + [CS_ETM_CPU] =3D " CPU %lld\n", + [CS_ETM_NR_TRC_PARAMS] =3D " NR_TRC_PARAMS %llx\n", + [CS_ETMV4_TRCCONFIGR] =3D " TRCCONFIGR %llx\n", + [CS_ETMV4_TRCTRACEIDR] =3D " TRCTRACEIDR %llx\n", + [CS_ETMV4_TRCIDR0] =3D " TRCIDR0 %llx\n", + [CS_ETMV4_TRCIDR1] =3D " TRCIDR1 %llx\n", + [CS_ETMV4_TRCIDR2] =3D " TRCIDR2 %llx\n", + [CS_ETMV4_TRCIDR8] =3D " TRCIDR8 %llx\n", + [CS_ETMV4_TRCAUTHSTATUS] =3D " TRCAUTHSTATUS %llx\n", + [CS_ETE_TRCDEVARCH] =3D " TRCDEVARCH %llx\n" +}; + +static const char * const param_unk_fmt =3D + " Unknown parameter [%d] %"PRIx64"\n"; +static const char * const magic_unk_fmt =3D + " Magic number Unknown %"PRIx64"\n"; + +static int cs_etm__print_cpu_metadata_v0(u64 *val, int *offset) +{ + int i =3D *offset, j, nr_params =3D 0, fmt_offset; + u64 magic; + + /* check magic value */ + magic =3D val[i + CS_ETM_MAGIC]; + if ((magic !=3D __perf_cs_etmv3_magic) && + (magic !=3D __perf_cs_etmv4_magic)) { + /* failure - note bad magic value */ + fprintf(stdout, magic_unk_fmt, magic); + return -EINVAL; + } + + /* print common header block */ + fprintf(stdout, cs_etm_priv_fmts[CS_ETM_MAGIC], val[i++]); + fprintf(stdout, cs_etm_priv_fmts[CS_ETM_CPU], val[i++]); + + if (magic =3D=3D __perf_cs_etmv3_magic) { + nr_params =3D CS_ETM_NR_TRC_PARAMS_V0; + fmt_offset =3D CS_ETM_ETMCR; + /* after common block, offset format index past NR_PARAMS */ + for (j =3D fmt_offset; j < nr_params + fmt_offset; j++, i++) + fprintf(stdout, cs_etm_priv_fmts[j], val[i]); + } else if (magic =3D=3D __perf_cs_etmv4_magic) { + nr_params =3D CS_ETMV4_NR_TRC_PARAMS_V0; + fmt_offset =3D CS_ETMV4_TRCCONFIGR; + /* after common block, offset format index past NR_PARAMS */ + for (j =3D fmt_offset; j < nr_params + fmt_offset; j++, i++) + fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); + } + *offset =3D i; + return 0; +} + +static int cs_etm__print_cpu_metadata_v1(u64 *val, int *offset) +{ + int i =3D *offset, j, total_params =3D 0; + u64 magic; + + magic =3D val[i + CS_ETM_MAGIC]; + /* total params to print is NR_PARAMS + common block size for v1 */ + total_params =3D val[i + CS_ETM_NR_TRC_PARAMS] + CS_ETM_COMMON_BLK_MAX_V1; + + if (magic =3D=3D __perf_cs_etmv3_magic) { + for (j =3D 0; j < total_params; j++, i++) { + /* if newer record - could be excess params */ + if (j >=3D CS_ETM_PRIV_MAX) + fprintf(stdout, param_unk_fmt, j, val[i]); + else + fprintf(stdout, cs_etm_priv_fmts[j], val[i]); + } + } else if (magic =3D=3D __perf_cs_etmv4_magic || magic =3D=3D __perf_cs_e= te_magic) { + /* + * ETE and ETMv4 can be printed in the same block because the number of = parameters + * is saved and they share the list of parameter names. ETE is also only= supported + * in V1 files. + */ + for (j =3D 0; j < total_params; j++, i++) { + /* if newer record - could be excess params */ + if (j >=3D CS_ETE_PRIV_MAX) + fprintf(stdout, param_unk_fmt, j, val[i]); + else + fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); + } + } else { + /* failure - note bad magic value and error out */ + fprintf(stdout, magic_unk_fmt, magic); + return -EINVAL; + } + *offset =3D i; + return 0; +} + +static void cs_etm__print_auxtrace_info(u64 *val, int num) +{ + int i, cpu =3D 0, version, err; + + version =3D val[0]; + + for (i =3D 0; i < CS_HEADER_VERSION_MAX; i++) + fprintf(stdout, cs_etm_global_header_fmts[i], val[i]); + + for (i =3D CS_HEADER_VERSION_MAX; cpu < num; cpu++) { + if (version =3D=3D 0) + err =3D cs_etm__print_cpu_metadata_v0(val, &i); + else if (version =3D=3D 1) + err =3D cs_etm__print_cpu_metadata_v1(val, &i); + if (err) + return; + } +} + +/* + * Do some basic checks and print the auxtrace info header before calling + * into cs_etm__process_auxtrace_info_full() which requires OpenCSD to be + * linked in. This allows some basic debugging if OpenCSD is missing. + */ +int cs_etm__process_auxtrace_info(union perf_event *event, + struct perf_session *session) +{ + struct perf_record_auxtrace_info *auxtrace_info =3D &event->auxtrace_info; + int event_header_size =3D sizeof(struct perf_event_header); + int num_cpu; + u64 *ptr =3D NULL; + u64 hdr_version; + + if (auxtrace_info->header.size < (event_header_size + INFO_HEADER_SIZE)) + return -EINVAL; + + /* First the global part */ + ptr =3D (u64 *) auxtrace_info->priv; + + /* Look for version of the header */ + hdr_version =3D ptr[0]; + if (hdr_version > CS_HEADER_CURRENT_VERSION) { + pr_err("\nCS ETM Trace: Unknown Header Version =3D %#" PRIx64, hdr_versi= on); + pr_err(", version supported <=3D %x\n", CS_HEADER_CURRENT_VERSION); + return -EINVAL; + } + + if (dump_trace) { + num_cpu =3D ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; + cs_etm__print_auxtrace_info(ptr, num_cpu); + } + + return cs_etm__process_auxtrace_info_full(event, session); +} diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index ab30591a6c6a..33303d03c2fa 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2510,134 +2510,6 @@ static bool cs_etm__is_timeless_decoding(struct cs_= etm_auxtrace *etm) return timeless_decoding; } =20 -static const char * const cs_etm_global_header_fmts[] =3D { - [CS_HEADER_VERSION] =3D " Header version %llx\n", - [CS_PMU_TYPE_CPUS] =3D " PMU type/num cpus %llx\n", - [CS_ETM_SNAPSHOT] =3D " Snapshot %llx\n", -}; - -static const char * const cs_etm_priv_fmts[] =3D { - [CS_ETM_MAGIC] =3D " Magic number %llx\n", - [CS_ETM_CPU] =3D " CPU %lld\n", - [CS_ETM_NR_TRC_PARAMS] =3D " NR_TRC_PARAMS %llx\n", - [CS_ETM_ETMCR] =3D " ETMCR %llx\n", - [CS_ETM_ETMTRACEIDR] =3D " ETMTRACEIDR %llx\n", - [CS_ETM_ETMCCER] =3D " ETMCCER %llx\n", - [CS_ETM_ETMIDR] =3D " ETMIDR %llx\n", -}; - -static const char * const cs_etmv4_priv_fmts[] =3D { - [CS_ETM_MAGIC] =3D " Magic number %llx\n", - [CS_ETM_CPU] =3D " CPU %lld\n", - [CS_ETM_NR_TRC_PARAMS] =3D " NR_TRC_PARAMS %llx\n", - [CS_ETMV4_TRCCONFIGR] =3D " TRCCONFIGR %llx\n", - [CS_ETMV4_TRCTRACEIDR] =3D " TRCTRACEIDR %llx\n", - [CS_ETMV4_TRCIDR0] =3D " TRCIDR0 %llx\n", - [CS_ETMV4_TRCIDR1] =3D " TRCIDR1 %llx\n", - [CS_ETMV4_TRCIDR2] =3D " TRCIDR2 %llx\n", - [CS_ETMV4_TRCIDR8] =3D " TRCIDR8 %llx\n", - [CS_ETMV4_TRCAUTHSTATUS] =3D " TRCAUTHSTATUS %llx\n", - [CS_ETE_TRCDEVARCH] =3D " TRCDEVARCH %llx\n" -}; - -static const char * const param_unk_fmt =3D - " Unknown parameter [%d] %"PRIx64"\n"; -static const char * const magic_unk_fmt =3D - " Magic number Unknown %"PRIx64"\n"; - -static int cs_etm__print_cpu_metadata_v0(u64 *val, int *offset) -{ - int i =3D *offset, j, nr_params =3D 0, fmt_offset; - u64 magic; - - /* check magic value */ - magic =3D val[i + CS_ETM_MAGIC]; - if ((magic !=3D __perf_cs_etmv3_magic) && - (magic !=3D __perf_cs_etmv4_magic)) { - /* failure - note bad magic value */ - fprintf(stdout, magic_unk_fmt, magic); - return -EINVAL; - } - - /* print common header block */ - fprintf(stdout, cs_etm_priv_fmts[CS_ETM_MAGIC], val[i++]); - fprintf(stdout, cs_etm_priv_fmts[CS_ETM_CPU], val[i++]); - - if (magic =3D=3D __perf_cs_etmv3_magic) { - nr_params =3D CS_ETM_NR_TRC_PARAMS_V0; - fmt_offset =3D CS_ETM_ETMCR; - /* after common block, offset format index past NR_PARAMS */ - for (j =3D fmt_offset; j < nr_params + fmt_offset; j++, i++) - fprintf(stdout, cs_etm_priv_fmts[j], val[i]); - } else if (magic =3D=3D __perf_cs_etmv4_magic) { - nr_params =3D CS_ETMV4_NR_TRC_PARAMS_V0; - fmt_offset =3D CS_ETMV4_TRCCONFIGR; - /* after common block, offset format index past NR_PARAMS */ - for (j =3D fmt_offset; j < nr_params + fmt_offset; j++, i++) - fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); - } - *offset =3D i; - return 0; -} - -static int cs_etm__print_cpu_metadata_v1(u64 *val, int *offset) -{ - int i =3D *offset, j, total_params =3D 0; - u64 magic; - - magic =3D val[i + CS_ETM_MAGIC]; - /* total params to print is NR_PARAMS + common block size for v1 */ - total_params =3D val[i + CS_ETM_NR_TRC_PARAMS] + CS_ETM_COMMON_BLK_MAX_V1; - - if (magic =3D=3D __perf_cs_etmv3_magic) { - for (j =3D 0; j < total_params; j++, i++) { - /* if newer record - could be excess params */ - if (j >=3D CS_ETM_PRIV_MAX) - fprintf(stdout, param_unk_fmt, j, val[i]); - else - fprintf(stdout, cs_etm_priv_fmts[j], val[i]); - } - } else if (magic =3D=3D __perf_cs_etmv4_magic || magic =3D=3D __perf_cs_e= te_magic) { - /* - * ETE and ETMv4 can be printed in the same block because the number of = parameters - * is saved and they share the list of parameter names. ETE is also only= supported - * in V1 files. - */ - for (j =3D 0; j < total_params; j++, i++) { - /* if newer record - could be excess params */ - if (j >=3D CS_ETE_PRIV_MAX) - fprintf(stdout, param_unk_fmt, j, val[i]); - else - fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); - } - } else { - /* failure - note bad magic value and error out */ - fprintf(stdout, magic_unk_fmt, magic); - return -EINVAL; - } - *offset =3D i; - return 0; -} - -static void cs_etm__print_auxtrace_info(u64 *val, int num) -{ - int i, cpu =3D 0, version, err; - - version =3D val[0]; - - for (i =3D 0; i < CS_HEADER_VERSION_MAX; i++) - fprintf(stdout, cs_etm_global_header_fmts[i], val[i]); - - for (i =3D CS_HEADER_VERSION_MAX; cpu < num; cpu++) { - if (version =3D=3D 0) - err =3D cs_etm__print_cpu_metadata_v0(val, &i); - else if (version =3D=3D 1) - err =3D cs_etm__print_cpu_metadata_v1(val, &i); - if (err) - return; - } -} - /* * Read a single cpu parameter block from the auxtrace_info priv block. * @@ -2874,15 +2746,13 @@ static int cs_etm__queue_aux_records(struct perf_se= ssion *session) return 0; } =20 -int cs_etm__process_auxtrace_info(union perf_event *event, - struct perf_session *session) +int cs_etm__process_auxtrace_info_full(union perf_event *event, + struct perf_session *session) { struct perf_record_auxtrace_info *auxtrace_info =3D &event->auxtrace_info; struct cs_etm_auxtrace *etm =3D NULL; struct int_node *inode; - unsigned int pmu_type; int event_header_size =3D sizeof(struct perf_event_header); - int info_header_size; int total_size =3D auxtrace_info->header.size; int priv_size =3D 0; int num_cpu, trcidr_idx; @@ -2890,36 +2760,6 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, int i, j; u64 *ptr =3D NULL; u64 **metadata =3D NULL; - u64 hdr_version; - - /* - * sizeof(auxtrace_info_event::type) + - * sizeof(auxtrace_info_event::reserved) =3D=3D 8 - */ - info_header_size =3D 8; - - if (total_size < (event_header_size + info_header_size)) - return -EINVAL; - - priv_size =3D total_size - event_header_size - info_header_size; - - /* First the global part */ - ptr =3D (u64 *) auxtrace_info->priv; - - /* Look for version of the header */ - hdr_version =3D ptr[0]; - if (hdr_version > CS_HEADER_CURRENT_VERSION) { - pr_err("\nCS ETM Trace: Unknown Header Version =3D %#" PRIx64, hdr_versi= on); - pr_err(", version supported <=3D %x\n", CS_HEADER_CURRENT_VERSION); - return -EINVAL; - } - - num_cpu =3D ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; - pmu_type =3D (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & - 0xffffffff); - - if (dump_trace) - cs_etm__print_auxtrace_info(ptr, num_cpu); =20 /* * Create an RB tree for traceID-metadata tuple. Since the conversion @@ -2930,6 +2770,9 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, if (!traceid_list) return -ENOMEM; =20 + /* First the global part */ + ptr =3D (u64 *) auxtrace_info->priv; + num_cpu =3D ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; metadata =3D zalloc(sizeof(*metadata) * num_cpu); if (!metadata) { err =3D -ENOMEM; @@ -3008,6 +2851,7 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, * The following tests if the correct number of double words was * present in the auxtrace info section. */ + priv_size =3D total_size - event_header_size - INFO_HEADER_SIZE; if (i * 8 !=3D priv_size) { err =3D -EINVAL; goto err_free_metadata; @@ -3036,7 +2880,7 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, etm->machine =3D &session->machines.host; =20 etm->num_cpu =3D num_cpu; - etm->pmu_type =3D pmu_type; + etm->pmu_type =3D (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xfffff= fff); etm->snapshot_mode =3D (ptr[CS_ETM_SNAPSHOT] !=3D 0); etm->metadata =3D metadata; etm->auxtrace_type =3D auxtrace_info->type; diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 401f74be98d6..5da50d5dae6b 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -202,9 +202,13 @@ struct cs_etm_packet_queue { #define CS_ETMV4_PRIV_SIZE (CS_ETMV4_PRIV_MAX * sizeof(u64)) #define CS_ETE_PRIV_SIZE (CS_ETE_PRIV_MAX * sizeof(u64)) =20 -#ifdef HAVE_CSTRACE_SUPPORT +#define INFO_HEADER_SIZE (sizeof(((struct perf_record_auxtrace_info *)0)->= type) + \ + sizeof(((struct perf_record_auxtrace_info *)0)->reserved__)) + int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); + +#ifdef HAVE_CSTRACE_SUPPORT int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt); int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq, @@ -214,10 +218,12 @@ void cs_etm__etmq_set_traceid_queue_timestamp(struct = cs_etm_queue *etmq, u8 trace_chan_id); struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id= ); +int cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unu= sed, + struct perf_session *session __maybe_unused); #else static inline int -cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, - struct perf_session *session __maybe_unused) +cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused, + struct perf_session *session __maybe_unused) { pr_err("\nCS ETM Trace: OpenCSD is not linked in, please recompile with C= ORESIGHT=3D1\n"); return -1; --=20 2.25.1