From nobody Mon Feb 9 17:57:32 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 EDACA3A1D05 for ; Wed, 14 Jan 2026 15:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768406283; cv=none; b=YKhEu8CuamOKot3Ek7P8mPACyt5QCA7FdjMrZzz8bPqEXjlaWUx27PuEz6e04RwiVnU7XwDWXOq2LxJkrDk44OnnjRw+HqMQm/B/0bUooQObQdqAQVXMKNn6RDi6MZzHLM2xnOLPHyWJBBH/xTVJNevYpB33YrokJI8eSKiLhew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768406283; c=relaxed/simple; bh=IlGWCJT2qBGC3XXCJRsXxYfQz51Y104FxCfSOx1WSLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KTtluRdiMXpJa+IA8ut1kJiAVhHiyamK3fUDcnqGOC/hz4qcZrOON+RYeKW/AKYZDeGSUC90+Ai63WgYf1ZdXXmaqahgHnE4Uo/hYZaQqoqz3GyyXhCjtG5hv5t0I/GugxahomCoqIcaRo/eU89xH4kuV5VlMrDqVmCR8w2vDmw= 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=YaJezoi+; arc=none smtp.client-ip=209.85.128.51 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="YaJezoi+" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-47d493a9b96so51040045e9.1 for ; Wed, 14 Jan 2026 07:57:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1768406271; x=1769011071; 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=eIFLeU/rZDWgQfxqeduMgDTr6BnNNm0nr5ZzvbheRLg=; b=YaJezoi+mYDGJT4Jjlh3we/6zaOCxjJteM5f28YqUA65x8UARrqND6BHh7zBWM/Jdd TfAOkrYHk3sFCsCVJfr554K7Or0WzTxb5mYNjSSRSzsprX6swNMC0IVWePf9vuxO4ek7 NBtiHQc92Y3E4WGeuGJUhL+MCEDV6dzzUEq3agNMMl8CB2zCtP99X9YxIC6IBSDgvYQm L4GO1bjxTuJS+aUOb+sqvAeU3w4I2Nb4bVQ/l27uqd05NKCLgbxhsKBvFbpyorYFn1WV VUziWSE/q2b1cyQi/cFzPSQ8XbXUKE6lx2h7xcFlTdy7Mt7azEPAgmgDB5/HLwWNFSEi YXXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768406271; x=1769011071; 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=eIFLeU/rZDWgQfxqeduMgDTr6BnNNm0nr5ZzvbheRLg=; b=KHni4SyPtfgJyn9KUolcTiReUKSlccOX0aWAphl6X55podxh/kgOpj3HNmLdDcxiVK UZ6kW9vXijN/Y4RIDHjXK6NZoxcB8VNUMQD33zgFbKcGE8y5gz+ye7cw+qBSsGcPh8ks lma68MzJ105yrKzlmaBrqXx2NhjpHixobztILM2WIzdpnA/aEXVw3/B+IT4Zqt7LBude z81VaFJVOgFzVEYq5r1xiySD70bpq819CIc4BZIt1bKJtsE/Bk9nA37y6/LT2M46+vSU rSgbfpnjujzTNWP7Y370Z+XYiT3KmL29utaFWgAwnZjSiN9dIU8aRQ+OmIfpbummP40T CH5g== X-Forwarded-Encrypted: i=1; AJvYcCUqyKPEgLT/ho+utiAAvu4XhIF4H1jLE2kkeF4GBVHbTxqKEqYTZZNpbL+KBRZ+2XCjcF+Z3SKi8t0q9rs=@vger.kernel.org X-Gm-Message-State: AOJu0YwNdal2SOL054Cf0KJuIHQmU1/DXpvCnU1o5oBp3czKoeBGIjEW XfYBUHQZzYPZxSno+k8F6NJWrUF7MjJ4CIO0jS9jIAHJ9IOwPASmKj1eS4AnHwc4B6Y= X-Gm-Gg: AY/fxX7/71i7lkF8Z6lkfownkuu1fkR+X7rN1xVV/XHGi/C9QtfJcPVNvVvRLgD64YV aYjr1o8U1kxZS1EdwbA++SPySj7miBybOY4E6VYatjLkGhVu6KjYRvEdM58kOsiadRr5881aS58 GZvjoN+6huQYZRzgEu6ZaEg7d0Qj+Xc91k0VJyQNoJ3GvIGWGUOdazOquCLudmqTErI0//b9dHc DmYno/WPGFy5o/YSJtbhbWM/SIyOYGBX6q1h6TdOh9tWAd0EfYJG+q7dbA/pF2ewbiDfZf4SXl4 WEOBWiFGoGxILxzBZbSyHOQuxdrEcyLqM3qu27AuWNzzZzcSG5sQNX/fnkJW+qRzqcVyJL+PteG EsQYbwVazXgDp6NPmkD54jPVt6+eYpTuRwZ/Xz+b0NNWoK8KUwwQ3d6NtKCga85stqdNTVGju9d ibKo0XovRW5p1kHjSRHDLn X-Received: by 2002:a05:600c:35c6:b0:477:5897:a0c4 with SMTP id 5b1f17b1804b1-47ee3323ccbmr41291455e9.4.1768406271314; Wed, 14 Jan 2026 07:57:51 -0800 (PST) Received: from ho-tower-lan.lan ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47ee85e8807sm7426475e9.16.2026.01.14.07.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 07:57:50 -0800 (PST) From: James Clark Date: Wed, 14 Jan 2026 15:57:23 +0000 Subject: [PATCH v5 11/14] 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: <20260114-james-perf-config-bits-v5-11-0ef97aaf1ac0@linaro.org> References: <20260114-james-perf-config-bits-v5-0-0ef97aaf1ac0@linaro.org> In-Reply-To: <20260114-james-perf-config-bits-v5-0-0ef97aaf1ac0@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.0 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/ Reviewed-by: Ian Rogers 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 a49753f0d20f..f535027ce862 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); @@ -484,6 +490,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(evsel, "cycacc", &val) && val) + etmcr |=3D ETMCR_CYC_ACC; + if (!evsel__get_config_val(evsel, "timestamp", &val) && val) + etmcr |=3D ETMCR_TIMESTAMP_EN; + if (!evsel__get_config_val(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 @@ -743,7 +776,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