From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 4CD6F231A41 for ; Thu, 20 Nov 2025 11:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763639619; cv=none; b=iXd21JFPY73mVpF8deg0PklpV/61udvVrjlrlWDu9N4BnmhEPb32CM1K9VluDKkZyM0x1GU1y51nG12p3vMd3YuECrKz+RRcM5xFUKsykD9xz8h44E53UvyMBDpCjRIoWPNxJ8F6uu1UAn1e1vXdJP8Du/xmoaMo+gp2BqK5j74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763639619; c=relaxed/simple; bh=XEYRAOgPzU7WPp+njMSNI6lst5cQE4m5vt5S4LH5rcs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RluO2Aabe1aj1jy8QcuhjBfqv74rwROeFPnDGg4M+TG9NwnExULRHaORG+qs67jFwu/MTDLEgrtKA/vrdFJWRG8dY10rbznj0tHSAnqD2AmnBqpxtXYdfQKFY54aa3oA9Ldsd3hZP7mtfNeLc+30SRQDSUiuKTNU1wftCcJSoOA= 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=zkywA0Lo; arc=none smtp.client-ip=209.85.221.54 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="zkywA0Lo" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-42b2dc17965so743746f8f.3 for ; Thu, 20 Nov 2025 03:53:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1763639616; x=1764244416; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=FlqEVS0+MiGt+zpPjfFggE/AaavkPH2p4yD9Xw0jlrs=; b=zkywA0LobjO3dXEOYMRRwvVQfrA6qJqWaedHI6BwWRtlxFVZMSphb5wjXEvIfK8T+V 5+P8VgEtjxCMH7TGKSzMUfyn3oyUmc86VWLmakSqbTqqdb4hMB3bhUJuuW3/0Wcd9vJN 6y4VYYdDflFB3ErOoXbOIxt9tLJaCMqzm3ASLtSXvf7SQrJT9khh/Gmugzom/Im4uhoV W3lRtUfAjZ2j+CymTas8OsrWJNAPI16lxOhf+VhVnb7Tw1FBtLyYBq3nRl47HbiZ4czF frx/aYcM5BwlQqOuRQnt1TdwLfmcTS8B6VrLNBQWSZi2CcrQoEd2IrLUR7mooG2UmJlZ Azbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763639616; x=1764244416; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FlqEVS0+MiGt+zpPjfFggE/AaavkPH2p4yD9Xw0jlrs=; b=fKA7rk9bde5WUxtaj/Ucdg19N2OLtNPMg5OK7fl2dCm2mCykYGtSuHgnDOHwH3UuAs uJaGTAp5icbfy2tHiM9S8kXXxFp/Qsjxxijz06q+GT+jpGDtY12Gpb6S5coE0KlEKfHA qJJqf/GdroKEOv0Yv124mzGqTCdOgXBDFQWzRly+1Jugn4dsV7qD8oG7pRoUatBEQ/cc 5B4HEyfXeSvhlmO/GOXkhCMHChOUiJYDckAPzpTLiyPa6AwDeiG1NZRFlpbBdTrsJWl4 /acPl2XqM9c8A6psk+KJab65Kgz84XbuVTOG/6t3d+gGMzRtavXDLxMB/XH0XyF5uzUU OSVg== X-Forwarded-Encrypted: i=1; AJvYcCWRwj+QwT2UYqbobk0mBbraa8FsdmsRx6M3HU3eDRd8FWRC5SqdQbFhXChbAMkkH6mfXElh3hPlDGSThro=@vger.kernel.org X-Gm-Message-State: AOJu0YzM0nRi40oD/3dUihOsf6/M/oWNfcyg5D9gaZv2uQMhu80mhlSZ 5P1SydOwyJD93N+HkKkB3C5sH9BzqMJ5M6lwZjdZeI6Js4NiKxnpS8+UvfQETBknnIo= X-Gm-Gg: ASbGnctgkHAv7+glb4zyuaubz7BZoMOLBSVRIZNJNJE+hLo9Wrc5gcRxIzSq46AeVIV HdcZBKIyJC+pgFZFpR3RirkpVM78LhJ26AugmmzH3slJwKYEVl5ZOnNqsJuTGK9v85jCKik+I6a PvuS2GwYpWqsp/MTsukmimB8u/Gpeng3gq5FNrP0frWRstmLl7VjJXvDmnp4NcW7jB2AEvU/rW3 Y9hY0QydcvdldJYa+PkrO0e5hmMLe4oGnV58ygDhjDP71ehqKDgTHZU17YXIYiFcr1ybV3KmRSf Shzbg8SZR2qgb3Al28lsVTo1HGCKS7qHl/kujEiuDVR5PWcWT4H3Y99NgwAke+eFqwTyTTlHwmM 751TOe5b4b1VXiMikK5tAWBvs13Dcq7O1SqzAeWZrxPgTBLt4Y1r9wWkXNeniEn350e2BzVjsiC wtDpvQd6wOM5FPDc2lQrbp8JwZ/BQ= X-Google-Smtp-Source: AGHT+IH/clyUgV+SR1sU4PGc3WAKh6W0Xyw9krHbVPssxtnUzEeWpWW7mdUCix2QdK09ZVqc5ly6bA== X-Received: by 2002:a05:6000:288a:b0:42b:3746:3b85 with SMTP id ffacd0b85a97d-42cb9a5c1c9mr2098192f8f.45.1763639615574; Thu, 20 Nov 2025 03:53:35 -0800 (PST) Received: from [192.168.1.3] ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7f34ff3sm5584315f8f.16.2025.11.20.03.53.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Nov 2025 03:53:35 -0800 (PST) Message-ID: <5f4a848b-af1f-4c5f-bd82-5e3ebe1e9dd9@linaro.org> Date: Thu, 20 Nov 2025 11:53:34 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 10/13] coresight: Remove misleading definitions To: Mike Leach Cc: Suzuki K Poulose , Alexander Shishkin , Jonathan Corbet , Leo Yan , Randy Dunlap , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org References: <20251118-james-cs-syncfreq-v5-0-82efd7b1a751@linaro.org> <20251118-james-cs-syncfreq-v5-10-82efd7b1a751@linaro.org> Content-Language: en-US From: James Clark In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 20/11/2025 11:21 am, Mike Leach wrote: > On Tue, 18 Nov 2025 at 16:28, James Clark wrote: >> >> ETM_OPT_* definitions duplicate the PMU format attributes that have >> always been published in sysfs. Hardcoding them here makes it misleading >> as to what the 'real' PMU API is and prevents attributes from being >> rearranged in the future. >> >> ETM4_CFG_BIT_* definitions just define what the Arm Architecture is >> which is not the responsibility of the kernel to do and doesn't scale to >> other registers or versions of ETM. It's not an actual software ABI/API >> and these definitions here mislead that it is. >> >> Any tools using the first ones would be broken anyway as they won't work >> when attributes are moved, so removing them is the right thing to do and >> will prompt a fix. Tools using the second ones can trivially redefine >> them locally. >> >> Perf also has its own copy of the headers so both of these things can be >> fixed up at a later date. >> > > The perf version is used to reconstruct the control registers for etm3 > / etm4 to put into the trace metadata headers in the perf.data file > for the decoder to be intitialised correctly. > > perf_event_attr::config uses the ETM_OPT_* values, used directly for > etm3 since they match the bit pattern in the etm3/ptm config register, > and remapped for etm4 from ETM_OPT_* to equivalent ETM4_CFG_BIT* for > the etm4 config register. That was one of the parts that confused me. Just because the format bit positions happened to match the register config for ETM3, didn't mean that it had to avoid reading the positions from sysfs. And it wasn't consistent between ETM3 and ETM4 either. That's decoupled now anyway, so although they still match there's no reason it can't change in the future. > > The reason we do this re-construction - rather than read registers as > we do for the other metadata - is that the register value is not set > at the point we are recording the metadata - it does not actually get > set until the etm is enabled, later in the perf process. > > On this basis it would seem that any changing of the attribute bit > ordering has potential to break perf decode. Probably safe to remove Yes so we should keep the positions the same until enough time has passed after the Perf fixes go in. Although other than the timestamp one I can't see any of the format bits needing to be moved. The timestamp bit now won't be passed correctly to OpenCSD until Perf is fixed, but I saw it wasn't used for decode anyway, so that should be fine? > from this version of the file though, but overall, changing bit > meanings in the underlying variable may possibly need a fix in perf > and potentially a breaking change for earlier versions of the tools. > > That said, for this particular version of the header, since it appears > to no longer need the values due to earlier changes. > The reconstruction of the registers will remain in Perf, so nothing will change there apart from not hard coding the format bit positions. I plan to define the register bits in Perf in cs-etm.c in the same style as we do in the kernel. ETM_OPT_* and ETM4_CFG_* weren't searchable because the the bits are already defined in the kernel in a different style. So I'll define them to match like this: +/* ETMv4 CONFIGR register bits */ +#define TRCCONFIGR_BB BIT(3) +#define TRCCONFIGR_CCI BIT(4) +#define TRCCONFIGR_CID BIT(6) +#define TRCCONFIGR_VMID BIT(7) +#define TRCCONFIGR_TS BIT(11) +#define TRCCONFIGR_RS BIT(12) +#define TRCCONFIGR_VMIDOPT BIT(15) + +/* ETMv3 ETMCR register bits */ +#define ETMCR_CYC_ACC BIT(12) +#define ETMCR_TIMESTAMP_EN BIT(28) +#define ETMCR_RETURN_STACK BIT(29) + Then use the format strings to check which ones are set: if (!evsel__get_config_val(cs_etm_pmu, evsel, "cycacc", &val) && val) trcconfigr |= TRCCONFIGR_CCI; if (!evsel__get_config_val(cs_etm_pmu, evsel, "contextid1", &val) && val) trcconfigr |= TRCCONFIGR_CID; if (!evsel__get_config_val(cs_etm_pmu, evsel, "timestamp", &val) && val) trcconfigr |= TRCCONFIGR_TS; if (!evsel__get_config_val(cs_etm_pmu, evsel, "retstack", &val) && val) trcconfigr |= TRCCONFIGR_RS; if (!evsel__get_config_val(cs_etm_pmu, evsel, "contextid2", &val) && val) trcconfigr |= TRCCONFIGR_VMID | TRCCONFIGR_VMIDOPT; if (!evsel__get_config_val(cs_etm_pmu, evsel, "branch_broadcast", &val) && val) trcconfigr |= TRCCONFIGR_BB; This also highlighted another Perf bug that evsel__set_config_if_unset() only operates on config and not config1, config2 etc. That's also used for setting up the event so I'll fix that too. Seems like the API goes through a lot of effort to publish the bit positions in sysfs, but we've selectively not used them which wasn't quite right. > Reviewed-by: Mike Leach > >> Reviewed-by: Leo Yan >> Signed-off-by: James Clark >> --- >> include/linux/coresight-pmu.h | 24 ------------------------ >> 1 file changed, 24 deletions(-) >> >> diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h >> index 89b0ac0014b0..2e179abe472a 100644 >> --- a/include/linux/coresight-pmu.h >> +++ b/include/linux/coresight-pmu.h >> @@ -21,30 +21,6 @@ >> */ >> #define CORESIGHT_LEGACY_CPU_TRACE_ID(cpu) (0x10 + (cpu * 2)) >> >> -/* >> - * Below are the definition of bit offsets for perf option, and works as >> - * arbitrary values for all ETM versions. >> - * >> - * Most of them are orignally from ETMv3.5/PTM's ETMCR config, therefore, >> - * ETMv3.5/PTM doesn't define ETMCR config bits with prefix "ETM3_" and >> - * directly use below macros as config bits. >> - */ >> -#define ETM_OPT_BRANCH_BROADCAST 8 >> -#define ETM_OPT_CYCACC 12 >> -#define ETM_OPT_CTXTID 14 >> -#define ETM_OPT_CTXTID2 15 >> -#define ETM_OPT_TS 28 >> -#define ETM_OPT_RETSTK 29 >> - >> -/* ETMv4 CONFIGR programming bits for the ETM OPTs */ >> -#define ETM4_CFG_BIT_BB 3 >> -#define ETM4_CFG_BIT_CYCACC 4 >> -#define ETM4_CFG_BIT_CTXTID 6 >> -#define ETM4_CFG_BIT_VMID 7 >> -#define ETM4_CFG_BIT_TS 11 >> -#define ETM4_CFG_BIT_RETSTK 12 >> -#define ETM4_CFG_BIT_VMID_OPT 15 >> - >> /* >> * Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. >> * Used to associate a CPU with the CoreSight Trace ID. >> >> -- >> 2.34.1 >> > > > -- > Mike Leach > Principal Engineer, ARM Ltd. > Manchester Design Centre. UK