From nobody Sun Dec 14 11:59:44 2025 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 388EB31BC95 for ; Fri, 12 Dec 2025 15:33:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765553584; cv=none; b=eYUdXwILoT+54s2MVZTfQgIuOD1JtbtGQLDST/uKoiD2nYsyntdmk/HQGqdL7UWaJFYvLQsC/Pri6KrZmToqgYmcmD3R6oS4vq5aV1r5aj3DZP+b8ej3bkLevrGTqusEsssLssREuzKAOoJrR/v56RVSPk4Ycxrv/NNjsLQCHh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765553584; c=relaxed/simple; bh=2fTL8UEB9CZOHe2mxY7U8rV3O2XcV9Rl69OFhNOOOs4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oS6qf/ZZrSrDMp4wwuVj/xA4cwKlXiMFJYC3ST58cT8nfir+XsZJju+O9AXW4wBEdmgjEPfrzwS+BxjcEJzjOnb/g5Ve4oLXDDrM+dQs9MmHJCiOHAllU8IYdy6Z4dAS05k6aaoSbJIgED5huuyp5t0fWh7daKGg96BnEIRqwnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ua8WsznG; arc=none smtp.client-ip=209.85.208.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ua8WsznG" Received: by mail-ed1-f68.google.com with SMTP id 4fb4d7f45d1cf-6495e5265c9so2078182a12.0 for ; Fri, 12 Dec 2025 07:33:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765553580; x=1766158380; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Pzt6Jr/+wkfmociJhlECu3e99FFKHyiFhWTKLOnLQI0=; b=ua8WsznGsxFEBawqlauw/cL92YaKPZvSDKmI1pMQQ9CIkFn0CJhDDGJ8+lqGMMJMp3 OEYVUMyHDWCgQziA7mex+4av6dLQmA15JZh5HUnQk0umEc1N6Fylfa5X7L+b2sn5jIRv mrx7x3SiojFqH2APwtW2+FRXVRjByGTYxwW+VvTWPjQBot4QoophzROU6qGARmYLP9Tj u77q16qA1czu6WqVvHnjoMxvgkuyAkSws5zDStxH2G6SUYvIDiL6OoVI9PHqKQaW1Ub/ V0UHv6v0hC95225HyEmcAJLIoUVsKQFpIv8U8J3XlWbe6kuN2INbumrWgtuVpdClrh3u Nhmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765553580; x=1766158380; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Pzt6Jr/+wkfmociJhlECu3e99FFKHyiFhWTKLOnLQI0=; b=B9tM600GtEfzyrS5ZCBsJq4NOltbze1wxHV8QhPdZakDGKyy+H5if7T54sV7R7ZPXJ H8vjtgCf0Pt6JtD6epFWOckFr5wu97coSsplr2oZLD1lErbOG9ATlrTOs6+iiTbDaRIu OFfR0HhRffrEJW/ZnAlA2w1CX0Fwl5ad601e3XQQRieHLxS3O1UWy4SQwQCxuTc3m0Oh 0jsu9d1e1IzKV5R2bPznL+JyfUp5EMeuYdVzzacy87DXwDcFqDUP9gzYomM0xvERQOHi /T7nxMz6rnzIA6eh4Nm8r2xoQXmy+3+bRKJhKcr1UMVUGs2zKdYhnfST1NJrBHiKXEtA HZQQ== X-Forwarded-Encrypted: i=1; AJvYcCVx0/kbv4l/Srq2inHU2QKRdqteEegX/P2hXpci0DR6N6XZ087w9iyAzhdpjj6pkspSJaP2bdvqyr74wfg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+SHYD4Tj7r5Zy80pBgSGdH0ahbm7QNQhr9xdXfMTy9lwf8IoB ra3qoSd/a9TaVssWF6OGHt+evt81BV80RmCtsPatX1Ksl9P7BGU97QYMNQMh60zjzns= X-Gm-Gg: AY/fxX6ZOA95XIVp9DKcUAfYHmnr0FNpcwr+lNToXjuoLvP0l5bvRNnZ53ACRSVgkb0 BLvAZ1srkfoFDQMAHbYK9tHmNObuhn4nxqvDfUtQX8yTGvqNTKXC0LFPpDuoEqHRBE3WkoNZPd2 bcMiHmUa/yfJf5NBPeZr19mAPGWc+AvpMUAHOt5gEQAQtOofVPoQGq3xzHBjDy0njy9tT9OmCmN 4fhxFAslFssCCChKbO8L1CwzyJjZbiMe3RHnhDhKJhV8MqGZiATzo62b4efrcmLwNFu+HR9zzAK 37OnNNdDdp1Nt7xx0DWeMrSG7zdaqr5WF807plpJum3FUhop6pVuIFad2YCoAIZR43VSrNHV1o0 qQzS8uWbVbEh/JWDFdBZ3aYWx3HIjXX1WMEMWkkev4+TAqk6v6esEX5vna0/LSATPeJYmqdkRNU 6ZfK/LQNhC9nRQlCi6N7qh X-Google-Smtp-Source: AGHT+IHuJrYzbGSy3G76dO6PcCNRHA+ZNmNldDx24ULUjiT5Wo9EMki68zi3Oygn9G+PH2eBroytyA== X-Received: by 2002:a05:6402:35ca:b0:640:9993:3cb8 with SMTP id 4fb4d7f45d1cf-6499b16e779mr2529095a12.5.1765553580465; Fri, 12 Dec 2025 07:33:00 -0800 (PST) Received: from e133063.arm.com ([130.185.218.160]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6498210ed32sm5433234a12.29.2025.12.12.07.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 07:33:00 -0800 (PST) From: James Clark Date: Fri, 12 Dec 2025 17:32:26 +0200 Subject: [PATCH v3 09/12] perf cs-etm: Don't use hard coded config bits when setting up ETMCR Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251212-james-perf-config-bits-v3-9-aa36a4846776@linaro.org> References: <20251212-james-perf-config-bits-v3-0-aa36a4846776@linaro.org> In-Reply-To: <20251212-james-perf-config-bits-v3-0-aa36a4846776@linaro.org> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, James Clark X-Mailer: b4 0.14.2 Perf only looks at attr.config when determining what was programmed into ETMCR. These bits could theoretically be in any of the config fields. Add a generic helper to find the value of any named format field in any config field and then use it to get the attributes relevant to ETMCR. The kernel will also stop publishing the ETMCR register bits in a header [1] so preempt that by defining them here. Move field_prep() to util.h so we can define it along side field_get(). Unfortunately FIELD_PREP() and FIELD_GET() from the kernel can't be used as they require the mask to be a compile time constant. [1]: https://lore.kernel.org/linux-arm-kernel/20251128-james-cs-syncfreq-v8= -10-4d319764cc58@linaro.org/ Signed-off-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index 22c6272e8c367e5671809771b841c5babe2d5282..a5135b743e6f18789026323ea75= b2a78d6495d73 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -68,6 +68,12 @@ static const char * const metadata_ete_ro[] =3D { =20 enum cs_etm_version { CS_NOT_PRESENT, CS_ETMV3, CS_ETMV4, CS_ETE }; =20 + +/* ETMv3 ETMCR register bits */ +#define ETMCR_CYC_ACC BIT(12) +#define ETMCR_TIMESTAMP_EN BIT(28) +#define ETMCR_RETURN_STACK BIT(29) + static bool cs_etm_is_ete(struct perf_pmu *cs_etm_pmu, struct perf_cpu cpu= ); static int cs_etm_get_ro(struct perf_pmu *pmu, struct perf_cpu cpu, const = char *path, __u64 *val); static bool cs_etm_pmu_path_exists(struct perf_pmu *pmu, struct perf_cpu c= pu, const char *path); @@ -487,6 +493,33 @@ static int cs_etm_recording_options(struct auxtrace_re= cord *itr, return err; } =20 +static u64 cs_etm_synth_etmcr(struct auxtrace_record *itr) +{ + struct cs_etm_recording *ptr =3D + container_of(itr, struct cs_etm_recording, itr); + struct perf_pmu *cs_etm_pmu =3D ptr->cs_etm_pmu; + struct evsel *evsel =3D cs_etm_get_evsel(ptr->evlist, cs_etm_pmu); + u64 etmcr =3D 0; + u64 val; + + if (!evsel) + return 0; + + /* + * Synthesize what the kernel programmed into ETMCR based on + * what options the event was opened with. This doesn't have to be + * complete or 100% accurate, not all bits used by OpenCSD anyway. + */ + if (!evsel__get_config_val(cs_etm_pmu, evsel, "cycacc", &val) && val) + etmcr |=3D ETMCR_CYC_ACC; + if (!evsel__get_config_val(cs_etm_pmu, evsel, "timestamp", &val) && val) + etmcr |=3D ETMCR_TIMESTAMP_EN; + if (!evsel__get_config_val(cs_etm_pmu, evsel, "retstack", &val) && val) + etmcr |=3D ETMCR_RETURN_STACK; + + return etmcr; +} + static u64 cs_etm_get_config(struct auxtrace_record *itr) { struct cs_etm_recording *ptr =3D @@ -746,7 +779,7 @@ static void cs_etm_get_metadata(struct perf_cpu cpu, u3= 2 *offset, case CS_ETMV3: magic =3D __perf_cs_etmv3_magic; /* Get configuration register */ - info->priv[*offset + CS_ETM_ETMCR] =3D cs_etm_get_config(itr); + info->priv[*offset + CS_ETM_ETMCR] =3D cs_etm_synth_etmcr(itr); /* traceID set to legacy value in case new perf running on old system */ info->priv[*offset + CS_ETM_ETMTRACEIDR] =3D cs_etm_get_legacy_trace_id(= cpu); /* Get read-only information from sysFS */ --=20 2.34.1