From nobody Sun Dec 14 06:15:23 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 AC5C4C48BEA for ; Tue, 23 Aug 2022 10:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356625AbiHWKva (ORCPT ); Tue, 23 Aug 2022 06:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244071AbiHWKmz (ORCPT ); Tue, 23 Aug 2022 06:42:55 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0565E868AD for ; Tue, 23 Aug 2022 02:10:22 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id k6-20020a05600c1c8600b003a54ecc62f6so7359325wms.5 for ; Tue, 23 Aug 2022 02:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc; bh=2CopkiLxI1R0tSg7DGbdQZ70GVhUg4ue9hUONhcw/TU=; b=LtuY01DvtZ5cSQ3H8jy3Yhu0NImyfg7h7KwOyM37fRH523B6yAP6gYIw8tV3eQ+tFY 4f8buVVZtv+5Izv37bwp5rOMRbXUvQDdQL/oc5IxVW7Xc4l2wc4C11FGAPrOJRc7lt40 EYzKox4wlk2oF+tln2NVytoIOgVeuCq+zuq8NfehzxzNV7I30lpJL2kdQC/7X2i2hb9c NyY1xLNLgPQw4VzyQfVohyxfHzZ+4a+M+psjdlHgSptvBy7KSYGIy+el3oEOlNGht53v 9jK80nw3xKCgzrMYqaPh8Xst++uq7D2m8JaWDW/3Z3D+Y/pIR5/bQrBLaThhKSBP547D ueUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc; bh=2CopkiLxI1R0tSg7DGbdQZ70GVhUg4ue9hUONhcw/TU=; b=vEhH4/5JkaOodrYNG8PKxif5LtcakKzQWABwxbnlOahjYngOHcmZD/gSF6ulHTnvZz pfoIA9mvkQWzqYFn884O/K7j3OAdI7buYQyTTGHSPg0zm9fTzDHMYMoYGFXYYfsO/rxG mzhqdh6v6jzpmGNbPvjw4mk8+NJ9HWC1xZiriJtXqoA+M1/KgDM+0VHAY2ngm5BbticS WHd89GE69yUzf8iv7TZ/c6FIuH3+6suWNWvS9Nj64M88rBntLEfwLm7c/9Ue8SXiJOS9 JNy1XZauu4LV9XanNbtHOXQUxdP3PrefCiJ33VjxyqBosyH7fGivF2O+6aS1aCMUPsD8 qf9Q== X-Gm-Message-State: ACgBeo2K7qD0bZZE1bX4wB6KlWcEvi4bNlA5tp32jF4ao0aDgX7e6AiO 0Hu+A6ML/ID1rTjPhMi4QflHAA== X-Google-Smtp-Source: AA6agR7Nf+qUc7NouF1+HmMkUg2xhEAOnM34Hu1dSqc2LQIcEELzvdogbwp9xkbzoqT4D9rMLAFZBw== X-Received: by 2002:a7b:ca58:0:b0:3a5:3c1c:6d71 with SMTP id m24-20020a7bca58000000b003a53c1c6d71mr1532836wml.118.1661245822355; Tue, 23 Aug 2022 02:10:22 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:4553:cf11:6cff:b293]) by smtp.gmail.com with ESMTPSA id w6-20020adfde86000000b002253d162491sm10760721wrl.52.2022.08.23.02.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 02:10:21 -0700 (PDT) From: Mike Leach To: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, linux-perf-users@vger.kernel.org, leo.yan@linaro.org, quic_jinlmao@quicinc.com, Mike Leach Subject: [PATCH v4 08/13] perf: cs-etm: Move mapping of Trace ID and cpu into helper function Date: Tue, 23 Aug 2022 10:10:04 +0100 Message-Id: <20220823091009.14121-9-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220823091009.14121-1-mike.leach@linaro.org> References: <20220823091009.14121-1-mike.leach@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The information to associate Trace ID and CPU will be changing. Drivers will start outputting this as a hardware ID packet in the data file which if present will be used in preference to the AUXINFO values. To prepare for this we provide a helper functions to do the individual ID mapping, and one to extract the IDs from the completed metadata blocks. Signed-off-by: Mike Leach Reviewed-by: James Clark --- tools/include/linux/coresight-pmu.h | 5 ++ tools/perf/util/cs-etm.c | 92 +++++++++++++++++++---------- tools/perf/util/cs-etm.h | 14 ++++- 3 files changed, 77 insertions(+), 34 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/core= sight-pmu.h index 6c2fd6cc5a98..db9c7c0abb6a 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -7,9 +7,14 @@ #ifndef _LINUX_CORESIGHT_PMU_H #define _LINUX_CORESIGHT_PMU_H =20 +#include + #define CORESIGHT_ETM_PMU_NAME "cs_etm" #define CORESIGHT_ETM_PMU_SEED 0x10 =20 +/* CoreSight trace ID is currently the bottom 7 bits of the value */ +#define CORESIGHT_TRACE_ID_VAL_MASK GENMASK(6, 0) + /* * Below are the definition of bit offsets for perf option, and works as * arbitrary values for all ETM versions. diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 8b95fb3c4d7b..48aaa2843ee2 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -193,6 +193,30 @@ int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt) return 0; } =20 +static int cs_etm__map_trace_id(u8 trace_chan_id, u64 *cpu_metadata) +{ + struct int_node *inode; + + /* Get an RB node for this CPU */ + inode =3D intlist__findnew(traceid_list, trace_chan_id); + + /* Something went wrong, no need to continue */ + if (!inode) + return -ENOMEM; + + /* + * The node for that CPU should not be taken. + * Back out if that's the case. + */ + if (inode->priv) + return -EINVAL; + + /* All good, associate the traceID with the metadata pointer */ + inode->priv =3D cpu_metadata; + + return 0; +} + void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, u8 trace_chan_id) { @@ -2881,18 +2905,47 @@ static int cs_etm__queue_aux_records(struct perf_se= ssion *session) return 0; } =20 +/* map trace ids to correct metadata block, from information in metadata */ +static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) +{ + u64 cs_etm_magic; + u8 trace_chan_id; + int i, err; + + for (i =3D 0; i < num_cpu; i++) { + cs_etm_magic =3D metadata[i][CS_ETM_MAGIC]; + switch (cs_etm_magic) { + case __perf_cs_etmv3_magic: + trace_chan_id =3D (u8)((metadata[i][CS_ETM_ETMTRACEIDR]) & + CORESIGHT_TRACE_ID_VAL_MASK); + break; + case __perf_cs_etmv4_magic: + case __perf_cs_ete_magic: + trace_chan_id =3D (u8)((metadata[i][CS_ETMV4_TRCTRACEIDR]) & + CORESIGHT_TRACE_ID_VAL_MASK); + break; + default: + /* unknown magic number */ + return -EINVAL; + } + err =3D cs_etm__map_trace_id(trace_chan_id, metadata[i]); + if (err) + return err; + } + return 0; +} + 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; 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; + int num_cpu; int err =3D 0; int i, j; u64 *ptr, *hdr =3D NULL; @@ -2962,23 +3015,13 @@ int cs_etm__process_auxtrace_info(union perf_event = *event, cs_etm__create_meta_blk(ptr, &i, CS_ETM_PRIV_MAX, CS_ETM_NR_TRC_PARAMS_V0); - - /* The traceID is our handle */ - trcidr_idx =3D CS_ETM_ETMTRACEIDR; - } else if (ptr[i] =3D=3D __perf_cs_etmv4_magic) { metadata[j] =3D cs_etm__create_meta_blk(ptr, &i, CS_ETMV4_PRIV_MAX, CS_ETMV4_NR_TRC_PARAMS_V0); - - /* The traceID is our handle */ - trcidr_idx =3D CS_ETMV4_TRCTRACEIDR; } else if (ptr[i] =3D=3D __perf_cs_ete_magic) { metadata[j] =3D cs_etm__create_meta_blk(ptr, &i, CS_ETE_PRIV_MAX, -1); - - /* ETE shares first part of metadata with ETMv4 */ - trcidr_idx =3D CS_ETMV4_TRCTRACEIDR; } else { ui__error("CS ETM Trace: Unrecognised magic number %#"PRIx64". File cou= ld be from a newer version of perf.\n", ptr[i]); @@ -2990,26 +3033,6 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, err =3D -ENOMEM; goto err_free_metadata; } - - /* Get an RB node for this CPU */ - inode =3D intlist__findnew(traceid_list, metadata[j][trcidr_idx]); - - /* Something went wrong, no need to continue */ - if (!inode) { - err =3D -ENOMEM; - goto err_free_metadata; - } - - /* - * The node for that CPU should not be taken. - * Back out if that's the case. - */ - if (inode->priv) { - err =3D -EINVAL; - goto err_free_metadata; - } - /* All good, associate the traceID with the metadata pointer */ - inode->priv =3D metadata[j]; } =20 /* @@ -3090,6 +3113,11 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, if (err) goto err_delete_thread; =20 + /* before aux records are queued, need to map metadata to trace IDs */ + err =3D cs_etm__map_trace_ids_metadata(num_cpu, metadata); + if (err) + goto err_delete_thread; + err =3D cs_etm__queue_aux_records(session); if (err) goto err_delete_thread; diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 90c83f932d9a..712a6f855f0e 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -28,13 +28,17 @@ enum { /* * Update the version for new format. * - * New version 1 format adds a param count to the per cpu metadata. + * Version 1: format adds a param count to the per cpu metadata. * This allows easy adding of new metadata parameters. * Requires that new params always added after current ones. * Also allows client reader to handle file versions that are different by * checking the number of params in the file vs the number expected. + * + * Version 2: Drivers will use PERF_RECORD_AUX_OUTPUT_HW_ID to output + * CoreSight Trace ID. ...TRACEIDR metadata will be set to unused ID. */ -#define CS_HEADER_CURRENT_VERSION 1 +#define CS_HEADER_CURRENT_VERSION 2 +#define CS_AUX_HW_ID_VERSION_MIN 2 =20 /* Beginning of header common to both ETMv3 and V4 */ enum { @@ -85,6 +89,12 @@ enum { CS_ETE_PRIV_MAX }; =20 +/* + * Check for valid CoreSight trace ID. If an invalid value is present in t= he metadata, + * then IDs are present in the hardware ID packet in the data file. + */ +#define CS_IS_VALID_TRACE_ID(id) ((id > 0) && (id < 0x70)) + /* * ETMv3 exception encoding number: * See Embedded Trace Macrocell specification (ARM IHI 0014Q) --=20 2.17.1