From nobody Sun Apr 19 09:11:21 2026 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 91CA9CCA47F for ; Mon, 4 Jul 2022 08:12:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233405AbiGDIMF (ORCPT ); Mon, 4 Jul 2022 04:12:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232409AbiGDILz (ORCPT ); Mon, 4 Jul 2022 04:11:55 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69798AE57 for ; Mon, 4 Jul 2022 01:11:54 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id o4so12281746wrh.3 for ; Mon, 04 Jul 2022 01:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zojxnvZpFWkM41A8//tAsHc+Fw1PYbCZcokYl1kSYpo=; b=pcELbfqKsb/9A6ba2dU8TOvaU/2GPdBJs8ngahCUzcvmfXQxiouyZZ6hGLmLM3A2p1 DjH6LrIdkVWkoWFHLxoTxp8YFlqloWUJSYZA1aTjiCgclKfErG0OmdlWi9NDNIrNkFux NvqS5tFQbxQb9G5n5U1ISfFObevI1TD5P7g6odbGnqQP62pgMWigjUt0lepNZjurKDP9 ZFx+odRQvSpLd26CN0P4L1bgSfPEdXmhReRxmqhrJ6lkE0+3076AdQqFP5BEFxTIrfSc LKdpF6vPW81OsbwaVXjsM6odS0Gy6vdRk7cUz1fAyKS28KkD6N3IE2aIoiFh16+Bv7yn ItMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zojxnvZpFWkM41A8//tAsHc+Fw1PYbCZcokYl1kSYpo=; b=6ZN9ij8/4lYl4+FiXBLUZDXU0LCQCv52KM/vWIysv3hE40WBXvWK/ZmvgPVrWtFaLc uDyp65sPVrvXcRJjstuWHhVoIysKgR+ukRENDM14OiwsXV+3YpytATyJxAhvULi8ZI8E Oe0J+bhu53ScPdvhh/cfLA3kc62IDSrPovH8Diq18A3/pnndgG70brzZdkMg9A6vsGJU wQfELxV/4QjdIT2GI2GrHVJtYmI4SDc+ohyV/E2YaiasUhbJzAyyD4XK32UY0UTrYx1k 7FlSFgWmthNDFkngoGIBEyE2dpPwwEIAEdkFWCn2w/M7r2Cf1dG+rmJ1BtAX0dZYvQAK r7GA== X-Gm-Message-State: AJIora+yPxZuyY9tJ/RH9qw+1tfPMNaKKyxx7zdL8c89fgo8hYZpUKjK GSfEg9WMV+HCzJ/OGz5dhmUiAw== X-Google-Smtp-Source: AGRyM1u2JUjmiAZ362yt+wwuOtw7QOGrzyblpb6xqNWVGU9CMqwYC7qrqVFcuiv32mEHJsSE4MswoA== X-Received: by 2002:a05:6000:1b86:b0:21d:21d2:3e12 with SMTP id r6-20020a0560001b8600b0021d21d23e12mr26055596wru.515.1656922312928; Mon, 04 Jul 2022 01:11:52 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:52 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 01/13] coresight: trace-id: Add API to dynamically assign Trace ID values Date: Mon, 4 Jul 2022 09:11:37 +0100 Message-Id: <20220704081149.16797-2-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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 existing mechanism to assign Trace ID values to sources is limited and does not scale for larger multicore / multi trace source systems. The API introduces functions that reserve IDs based on availabilty represented by a coresight_trace_id_map structure. This records the used and free IDs in a bitmap. CPU bound sources such as ETMs use the coresight_trace_id_get_cpu_id / coresight_trace_id_put_cpu_id pair of functions. The API will record the ID associated with the CPU. This ensures that the same ID will be re-used while perf events are active on the CPU. The put_cpu_id function will pend release of the ID until all perf cs_etm sessions are complete. Non-cpu sources, such as the STM can use coresight_trace_id_get_system_id / coresight_trace_id_put_system_id. Signed-off-by: Mike Leach --- drivers/hwtracing/coresight/Makefile | 2 +- .../hwtracing/coresight/coresight-trace-id.c | 230 ++++++++++++++++++ .../hwtracing/coresight/coresight-trace-id.h | 65 +++++ 3 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 drivers/hwtracing/coresight/coresight-trace-id.c create mode 100644 drivers/hwtracing/coresight/coresight-trace-id.h diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/cores= ight/Makefile index b6c4a48140ec..329a0c704b87 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -6,7 +6,7 @@ obj-$(CONFIG_CORESIGHT) +=3D coresight.o coresight-y :=3D coresight-core.o coresight-etm-perf.o coresight-platform= .o \ coresight-sysfs.o coresight-syscfg.o coresight-config.o \ coresight-cfg-preload.o coresight-cfg-afdo.o \ - coresight-syscfg-configfs.o + coresight-syscfg-configfs.o coresight-trace-id.o obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) +=3D coresight-tmc.o coresight-tmc-y :=3D coresight-tmc-core.o coresight-tmc-etf.o \ coresight-tmc-etr.o diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwt= racing/coresight/coresight-trace-id.c new file mode 100644 index 000000000000..dac9c89ae00d --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -0,0 +1,230 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022, Linaro Limited, All rights reserved. + * Author: Mike Leach + */ +#include +#include +#include + +#include "coresight-trace-id.h" + +/* need to keep data on ids & association with cpus. */ +struct cpu_id_info { + int id; + bool pend_rel; +}; + +/* default trace ID map. Used for systems that do not require per sink map= pings */ +static struct coresight_trace_id_map id_map_default; + +/* maintain a record of the current mapping of cpu IDs */ +static DEFINE_PER_CPU(struct cpu_id_info, cpu_ids); + +/* perf session active flag */ +static int perf_cs_etm_session_active; + +/* lock to protect id_map and cpu data */ +static DEFINE_SPINLOCK(id_map_lock); + +/* ID 0 is reserved */ +#define CORESIGHT_TRACE_ID_RES_0 0 + +/* ID 0x70 onwards are reserved */ +#define CORESIGHT_TRACE_ID_RES_RANGE_LO 0x70 +#define CORESIGHT_TRACE_ID_RES_RANGE_HI 0x7F + +#define IS_VALID_ID(id) \ + ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_RANGE_LO= )) + +static void coresight_trace_id_set_inuse(int id, struct coresight_trace_id= _map *id_map) +{ + if (IS_VALID_ID(id)) + set_bit(id, id_map->avail_ids); +} + +static void coresight_trace_id_clear_inuse(int id, struct coresight_trace_= id_map *id_map) +{ + if (IS_VALID_ID(id)) + clear_bit(id, id_map->avail_ids); +} + +static void coresight_trace_id_set_pend_rel(int id, struct coresight_trace= _id_map *id_map) +{ + if (IS_VALID_ID(id)) + set_bit(id, id_map->pend_rel_ids); +} + +static void coresight_trace_id_clear_pend_rel(int id, struct coresight_tra= ce_id_map *id_map) +{ + if (IS_VALID_ID(id)) + clear_bit(id, id_map->pend_rel_ids); +} + +static int coresight_trace_id_find_new_id(struct coresight_trace_id_map *i= d_map) +{ + int id; + + id =3D find_first_zero_bit(id_map->avail_ids, CORESIGHT_TRACE_IDS_MAX); + if (id >=3D CORESIGHT_TRACE_IDS_MAX) + id =3D -EINVAL; + return id; +} + +/* release all pending IDs for all current maps & clear CPU associations */ +static void coresight_trace_id_release_all_pending(void) +{ + struct coresight_trace_id_map *id_map =3D &id_map_default; + int cpu, bit; + + for_each_set_bit(bit, id_map->pend_rel_ids, CORESIGHT_TRACE_IDS_MAX) { + clear_bit(bit, id_map->avail_ids); + clear_bit(bit, id_map->pend_rel_ids); + } + + for_each_possible_cpu(cpu) { + if (per_cpu(cpu_ids, cpu).pend_rel) { + per_cpu(cpu_ids, cpu).pend_rel =3D false; + per_cpu(cpu_ids, cpu).id =3D 0; + } + } +} + +static void coresight_trace_id_init_id_map(struct coresight_trace_id_map *= id_map) +{ + int bit; + + /* set all reserved bits as in-use */ + set_bit(CORESIGHT_TRACE_ID_RES_0, id_map->avail_ids); + for (bit =3D CORESIGHT_TRACE_ID_RES_RANGE_LO; + bit <=3D CORESIGHT_TRACE_ID_RES_RANGE_HI; bit++) + set_bit(bit, id_map->avail_ids); +} + +static int coresight_trace_id_map_get_cpu_id(int cpu, struct coresight_tra= ce_id_map *id_map) +{ + unsigned long flags; + int id; + + spin_lock_irqsave(&id_map_lock, flags); + + /* check for existing allocation for this CPU */ + id =3D per_cpu(cpu_ids, cpu).id; + if (id) + goto get_cpu_id_out; + + /* find a new ID */ + id =3D coresight_trace_id_find_new_id(id_map); + if (id < 0) + goto get_cpu_id_out; + + /* got a valid new ID - save details */ + per_cpu(cpu_ids, cpu).id =3D id; + per_cpu(cpu_ids, cpu).pend_rel =3D false; + coresight_trace_id_set_inuse(id, id_map); + coresight_trace_id_clear_pend_rel(id, id_map); + +get_cpu_id_out: + spin_unlock_irqrestore(&id_map_lock, flags); + return id; +} + +static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_tr= ace_id_map *id_map) +{ + unsigned long flags; + int id; + + spin_lock_irqsave(&id_map_lock, flags); + id =3D per_cpu(cpu_ids, cpu).id; + if (!id) + goto put_cpu_id_out; + + if (perf_cs_etm_session_active) { + /* set release at pending if perf still active */ + coresight_trace_id_set_pend_rel(id, id_map); + per_cpu(cpu_ids, cpu).pend_rel =3D true; + } else { + /* otherwise clear id */ + coresight_trace_id_clear_inuse(id, id_map); + per_cpu(cpu_ids, cpu).id =3D 0; + } + + put_cpu_id_out: + spin_unlock_irqrestore(&id_map_lock, flags); +} + +static int coresight_trace_id_map_get_system_id(struct coresight_trace_id_= map *id_map) +{ + unsigned long flags; + int id; + + spin_lock_irqsave(&id_map_lock, flags); + id =3D coresight_trace_id_find_new_id(id_map); + if (id > 0) + coresight_trace_id_set_inuse(id, id_map); + spin_unlock_irqrestore(&id_map_lock, flags); + + return id; +} + +static void coresight_trace_id_map_put_system_id(struct coresight_trace_id= _map *id_map, int id) +{ + unsigned long flags; + + spin_lock_irqsave(&id_map_lock, flags); + coresight_trace_id_clear_inuse(id, id_map); + spin_unlock_irqrestore(&id_map_lock, flags); +} + +/* API functions */ +int coresight_trace_id_get_cpu_id(int cpu) +{ + return coresight_trace_id_map_get_cpu_id(cpu, &id_map_default); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_get_cpu_id); + +void coresight_trace_id_put_cpu_id(int cpu) +{ + coresight_trace_id_map_put_cpu_id(cpu, &id_map_default); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id); + +int coresight_trace_id_get_system_id(void) +{ + return coresight_trace_id_map_get_system_id(&id_map_default); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_get_system_id); + +void coresight_trace_id_put_system_id(int id) +{ + coresight_trace_id_map_put_system_id(&id_map_default, id); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_put_system_id); + +void coresight_trace_id_perf_start(void) +{ + unsigned long flags; + + spin_lock_irqsave(&id_map_lock, flags); + perf_cs_etm_session_active++; + spin_unlock_irqrestore(&id_map_lock, flags); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_perf_start); + +void coresight_trace_id_perf_stop(void) +{ + unsigned long flags; + + spin_lock_irqsave(&id_map_lock, flags); + perf_cs_etm_session_active--; + if (!perf_cs_etm_session_active) + coresight_trace_id_release_all_pending(); + spin_unlock_irqrestore(&id_map_lock, flags); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_perf_stop); + +void coresight_trace_id_init_default_map(void) +{ + coresight_trace_id_init_id_map(&id_map_default); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_init_default_map); diff --git a/drivers/hwtracing/coresight/coresight-trace-id.h b/drivers/hwt= racing/coresight/coresight-trace-id.h new file mode 100644 index 000000000000..63950087edf6 --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-trace-id.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright(C) 2022 Linaro Limited. All rights reserved. + * Author: Mike Leach + */ + +#ifndef _CORESIGHT_TRACE_ID_H +#define _CORESIGHT_TRACE_ID_H + +/* + * Coresight trace ID allocation API + * + * With multi cpu systems, and more additional trace sources a scalable + * trace ID reservation system is required. + * + * The system will allocate Ids on a demand basis, and allow them to be + * released when done. + * + * In order to ensure that a consistent cpu / ID matching is maintained + * throughout a perf cs_etm event session - a session in progress flag will + * be maintained, and released IDs not cleared until the perf session is + * complete. This allows the same CPU to be re-allocated its prior ID. + * + * + * Trace ID maps will be created and initialised to prevent architecturally + * reserved IDs from being allocated. + * + * API permits multiple maps to be maintained - for large systems where + * different sets of cpus trace into different independent sinks. + */ + +#include +#include + + +/* architecturally we have 128 IDs some of which are reserved */ +#define CORESIGHT_TRACE_IDS_MAX 128 + +/** + * Trace ID map. + * + * @avail_ids: Bitmap to register available (bit =3D 0) and in use (bit = =3D 1) IDs. + * Initialised so that the reserved IDs are permanently marked as in use. + * @pend_rel_ids: CPU IDs that have been released by the trace source but = not yet marked + * as available, to allow re-allocation to the same CPU dur= ing a perf session. + */ +struct coresight_trace_id_map { + DECLARE_BITMAP(avail_ids, CORESIGHT_TRACE_IDS_MAX); + DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); +}; + +/* Allocate and release IDs for a single default trace ID map */ +int coresight_trace_id_get_cpu_id(int cpu); +int coresight_trace_id_get_system_id(void); +void coresight_trace_id_put_cpu_id(int cpu); +void coresight_trace_id_put_system_id(int id); + +/* notifiers for perf session start and stop */ +void coresight_trace_id_perf_start(void); +void coresight_trace_id_perf_stop(void); + +/* initialise the default ID map */ +void coresight_trace_id_init_default_map(void); + +#endif /* _CORESIGHT_TRACE_ID_H */ --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 1D70DC433EF for ; Mon, 4 Jul 2022 08:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233339AbiGDIMK (ORCPT ); Mon, 4 Jul 2022 04:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232950AbiGDIL4 (ORCPT ); Mon, 4 Jul 2022 04:11:56 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F681B1E7 for ; Mon, 4 Jul 2022 01:11:55 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id j7so4905629wmp.2 for ; Mon, 04 Jul 2022 01:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ENeqPY38I5RkKtR3x+NAjXJGNLiXjGEjs0/S3/8e+0g=; b=fZnGLarNI4qm9uYt1V8DlHg9SSr0ryyK0I7SFQetRoQLwyxzw36owZAEn5z4u1d2Lp JSLDUYGr5yB9Mgajwai3P3x5P3PsqKQOkR4Mh6CUb4ntoN+uwJD2wYKHIPo3wZ93JlN4 KfXKx6j6rpDL9w/rK5cNqGyHxRlMyIw55cSkgLdJWmFu9/7oxLTmqrgemdCtaVbT9RHC XKLqCM7kfKSNUNJP8AkZHgv0rW+oWtWwn05c1ofVlgIApjC5W+kjv03WxA3AcWgSo457 oE3hrB8XRdL//gWOkosCD5FSfgRJIhEW1uPm8EkddOyFsrtDmQd+HxxhqNGfAMgPE0AW lOqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ENeqPY38I5RkKtR3x+NAjXJGNLiXjGEjs0/S3/8e+0g=; b=JLnz51sACdwOsZIWG9i6zxSIJJCiojtylzoq29XC4QRGiz24pMkpNGJDK4WM7s7QzH GMFUCfU8qbkBbdEvjs7MkdpuoAy/1mHily3cO8QX/3sRPQiuokLU3ufKKypifGJPIsJe sUx+YTEnbknGCtL4RQvU/2coHd658ngucHJbsX3a4wwthjK40Yw3k7O5qVNBpo2N/e20 Pcm/PWhvzhMzj+O5zL3sqET0F89DwBDRo6sXktFVpjFflf9tyh7Qkr8FCQjCeyXB0u52 AXDvLtVKQogGMyTQ3Cd7MiNV/r5Mr77vIvUKipCvnJ5WNM3ak19IaPJH7ID4eYwhreaR IYRQ== X-Gm-Message-State: AJIora91/epSZ3qAmYnrnCr+1CGrlhoHY2WqyNozgmdzvPKgXh40IMgE eqVX/ZO/nIyULSF8rprGkdzyig== X-Google-Smtp-Source: AGRyM1tbg7T3RfKE51u/Ld3uOhZDTDvnB2ymDvYMNW9HAL27M8QNYUar9r7Hv5lpOk+aVOoUgxitRA== X-Received: by 2002:a05:600c:1d0e:b0:3a0:50bb:55e0 with SMTP id l14-20020a05600c1d0e00b003a050bb55e0mr30617774wms.89.1656922313887; Mon, 04 Jul 2022 01:11:53 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:53 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 02/13] coresight: trace-id: update CoreSight core to use Trace ID API Date: Mon, 4 Jul 2022 09:11:38 +0100 Message-Id: <20220704081149.16797-3-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" Initialises the default trace ID map. This will be used by all source drivers to be allocated their trace IDs. The checks for sources to have unique IDs has been removed - this is now guaranteed by the ID allocation mechanisms, and inappropriate where multiple ID maps are in use in larger systems Signed-off-by: Mike Leach --- drivers/hwtracing/coresight/coresight-core.c | 49 ++------------------ 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 1edfec1e9d18..be69e05fde1f 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -22,6 +22,7 @@ #include "coresight-etm-perf.h" #include "coresight-priv.h" #include "coresight-syscfg.h" +#include "coresight-trace-id.h" =20 static DEFINE_MUTEX(coresight_mutex); static DEFINE_PER_CPU(struct coresight_device *, csdev_sink); @@ -84,45 +85,6 @@ struct coresight_device *coresight_get_percpu_sink(int c= pu) } EXPORT_SYMBOL_GPL(coresight_get_percpu_sink); =20 -static int coresight_id_match(struct device *dev, void *data) -{ - int trace_id, i_trace_id; - struct coresight_device *csdev, *i_csdev; - - csdev =3D data; - i_csdev =3D to_coresight_device(dev); - - /* - * No need to care about oneself and components that are not - * sources or not enabled - */ - if (i_csdev =3D=3D csdev || !i_csdev->enable || - i_csdev->type !=3D CORESIGHT_DEV_TYPE_SOURCE) - return 0; - - /* Get the source ID for both components */ - trace_id =3D source_ops(csdev)->trace_id(csdev); - i_trace_id =3D source_ops(i_csdev)->trace_id(i_csdev); - - /* All you need is one */ - if (trace_id =3D=3D i_trace_id) - return 1; - - return 0; -} - -static int coresight_source_is_unique(struct coresight_device *csdev) -{ - int trace_id =3D source_ops(csdev)->trace_id(csdev); - - /* this shouldn't happen */ - if (trace_id < 0) - return 0; - - return !bus_for_each_dev(&coresight_bustype, NULL, - csdev, coresight_id_match); -} - static int coresight_find_link_inport(struct coresight_device *csdev, struct coresight_device *parent) { @@ -431,12 +393,6 @@ static int coresight_enable_source(struct coresight_de= vice *csdev, u32 mode) { int ret; =20 - if (!coresight_source_is_unique(csdev)) { - dev_warn(&csdev->dev, "traceID %d not unique\n", - source_ops(csdev)->trace_id(csdev)); - return -EINVAL; - } - if (!csdev->enable) { if (source_ops(csdev)->enable) { ret =3D coresight_control_assoc_ectdev(csdev, true); @@ -1775,6 +1731,9 @@ static int __init coresight_init(void) if (ret) goto exit_bus_unregister; =20 + /* initialise the default trace ID map */ + coresight_trace_id_init_default_map(); + /* initialise the coresight syscfg API */ ret =3D cscfg_init(); if (!ret) --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 42611CCA479 for ; Mon, 4 Jul 2022 08:12:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233455AbiGDIMO (ORCPT ); Mon, 4 Jul 2022 04:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233085AbiGDIL5 (ORCPT ); Mon, 4 Jul 2022 04:11:57 -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 39940AE51 for ; Mon, 4 Jul 2022 01:11:56 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id m6-20020a05600c3b0600b003a0489f412cso5818226wms.1 for ; Mon, 04 Jul 2022 01:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ChF7YhZJ5oK75QeSz9xjFEI1oMT1B8ivnJmEVxe44YU=; b=KHXoITi0VlpeFAc8mJ41i/+VC2MOXFq3PO13PX0hhyD6csdOI5JyfnQ0JCf45ShCfK yihaboRiHuf/MuarutvS7tkoTe7DbxKFNvlqmtJEIKEYdB0AbaS0CnR4ms8x7RLT0y7A Wqr17+DQNb3tbvrzs44QDCk3zGNpU7Ldwp81P7PQFUrsLUNX8Ka9scUWs6NPynzucj7V x20GHD5CtVmBbEHtc8nIGpwvz4hEeZ9tKvpEnuQimFK40Os5d4J3fq/ttkHbOv+h6398 IGMb7UiUqIi/SqXAUh3Rjx9+HyaahAlYcCydH3fp1gsriIpWdZTHYAS4H94insYDxPdL SB2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ChF7YhZJ5oK75QeSz9xjFEI1oMT1B8ivnJmEVxe44YU=; b=JRE1xKnxZf6okbV/FV/voSdfSsCGUjYw0tYh1IzYef/wo2M51kQAHNLV48kcWPdUoJ bmRfMBKZJr50DjOaRRNMVwHWqdoZJ9bn2prnAem8bz22D13xeE9VuM+OY+rYZg+zCpfn Wp1oFHNneGYJEgAGDB5UppEhCndzPu+6xKReIlwZnbqz60mENje4dNlp3nh5wMCe4/WK 73a6CXzx0f/0gIfKfzitt71aWU3+QLSF6H9iH1j8az8+AspI90MX+6lUnYSQPNRz4hJb HpdDENUq3VpayMKYgeQwwEGq04t+UIKN4brs9IuXcFFGj3Q+Nikyzw0JgIYGcYYu1mty 4/rQ== X-Gm-Message-State: AJIora8wuVAVMB5mIAySWxZ7+tpIRENfgbIhoc5IrWE/V+g3accJsZkm ldtbAIRo4EXyuX2sWGUvysnWZerafpE4EA== X-Google-Smtp-Source: AGRyM1u0JcpNIODBc3BhqBED6dntz8ygCUA0VYPXOsX8sMEhi3g5Lq7sdG+kcp3kb4yLdDgsAKYylA== X-Received: by 2002:a05:600c:3481:b0:3a1:918d:6719 with SMTP id a1-20020a05600c348100b003a1918d6719mr14506687wmq.35.1656922314833; Mon, 04 Jul 2022 01:11:54 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:54 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 03/13] coresight: stm: Update STM driver to use Trace ID API Date: Mon, 4 Jul 2022 09:11:39 +0100 Message-Id: <20220704081149.16797-4-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" Updates the STM driver to use the trace ID allocation API. This uses the _system_id calls to allocate an ID on device poll, and release on device remove. The sysfs access to the STMTRACEIDR register has been changed from RW to RO. Having this value as writable is not appropriate for the new Trace ID scheme - and had potential to cause errors in the previous scheme if values clashed with other sources. Signed-off-by: Mike Leach Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-stm.c | 41 +++++++-------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracin= g/coresight/coresight-stm.c index bb14a3a8a921..9ef3e923a930 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -31,6 +31,7 @@ #include =20 #include "coresight-priv.h" +#include "coresight-trace-id.h" =20 #define STMDMASTARTR 0xc04 #define STMDMASTOPR 0xc08 @@ -615,24 +616,7 @@ static ssize_t traceid_show(struct device *dev, val =3D drvdata->traceid; return sprintf(buf, "%#lx\n", val); } - -static ssize_t traceid_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - int ret; - unsigned long val; - struct stm_drvdata *drvdata =3D dev_get_drvdata(dev->parent); - - ret =3D kstrtoul(buf, 16, &val); - if (ret) - return ret; - - /* traceid field is 7bit wide on STM32 */ - drvdata->traceid =3D val & 0x7f; - return size; -} -static DEVICE_ATTR_RW(traceid); +static DEVICE_ATTR_RO(traceid); =20 #define coresight_stm_reg(name, offset) \ coresight_simple_reg32(struct stm_drvdata, name, offset) @@ -819,14 +803,6 @@ static void stm_init_default_data(struct stm_drvdata *= drvdata) */ drvdata->stmsper =3D ~0x0; =20 - /* - * The trace ID value for *ETM* tracers start at CPU_ID * 2 + 0x10 and - * anything equal to or higher than 0x70 is reserved. Since 0x00 is - * also reserved the STM trace ID needs to be higher than 0x00 and - * lowner than 0x10. - */ - drvdata->traceid =3D 0x1; - /* Set invariant transaction timing on all channels */ bitmap_clear(drvdata->chs.guaranteed, 0, drvdata->numsp); } @@ -854,7 +830,7 @@ static void stm_init_generic_data(struct stm_drvdata *d= rvdata, =20 static int stm_probe(struct amba_device *adev, const struct amba_id *id) { - int ret; + int ret, trace_id; void __iomem *base; struct device *dev =3D &adev->dev; struct coresight_platform_data *pdata =3D NULL; @@ -938,12 +914,22 @@ static int stm_probe(struct amba_device *adev, const = struct amba_id *id) goto stm_unregister; } =20 + trace_id =3D coresight_trace_id_get_system_id(); + if (trace_id < 0) { + ret =3D trace_id; + goto cs_unregister; + } + drvdata->traceid =3D (u8)trace_id; + pm_runtime_put(&adev->dev); =20 dev_info(&drvdata->csdev->dev, "%s initialized\n", (char *)coresight_get_uci_data(id)); return 0; =20 +cs_unregister: + coresight_unregister(drvdata->csdev); + stm_unregister: stm_unregister_device(&drvdata->stm); return ret; @@ -953,6 +939,7 @@ static void stm_remove(struct amba_device *adev) { struct stm_drvdata *drvdata =3D dev_get_drvdata(&adev->dev); =20 + coresight_trace_id_put_system_id(drvdata->traceid); coresight_unregister(drvdata->csdev); =20 stm_unregister_device(&drvdata->stm); --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 8D102C433EF for ; Mon, 4 Jul 2022 08:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233500AbiGDIMT (ORCPT ); Mon, 4 Jul 2022 04:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233289AbiGDIL7 (ORCPT ); Mon, 4 Jul 2022 04:11:59 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40BBCB1EC for ; Mon, 4 Jul 2022 01:11:57 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id k7so12244349wrc.12 for ; Mon, 04 Jul 2022 01:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Gldn9rvF6v1FgHyQMd21plWEViWV+KFAmS14f6XtzZ8=; b=xMxPTKOf1wg8vITKGGApEvdQ1jKdas7OPRBZRHS6Nx8gbSDEMgjC9n/DAhCB1njjPS s928TQ08Du9RvmKK3Kv40GhgqNaoBRbO9XBZR7QdTnlrxSwCxcr/7H5fl80yKELH82B/ r6VIAAm9qAs+pHCN02FHe+4CkXYxg8fqi8JZcS+q5R5QBl+QLGdRJgJKDJ7dcySZMVj6 ysxm3yA0TsdwKVQpEDIvb6yywQMl7AzKl9YkKIA+/MCfC1WaC9Cs5obSM68CltmuUDmB nJFrh3R9ms0CWQ8GPrWQDnuCw6R65nlKX5HFxINC9swTrH55Wxiuol3Jap0Exeq4JGOv KKTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Gldn9rvF6v1FgHyQMd21plWEViWV+KFAmS14f6XtzZ8=; b=uDl3I4j29Ye0iG1IfCa7s2393WB6Ev5D72zyL0LqLGBUTXFJ3hZ+4jL/bo68LDMckJ yPr/Ls04ReqKodPzDYjcuprhY2VoGFhfcC3uaazFcwhyfklE03zwrKynzvAAgBLWRBmZ XVMvAwbnogfKvJot6X+yHaJVErr0VmyPCJQjEqOlMlWSfX0RTrNlfs8s3O13nBT55SkN vOa9GAvxcYymSEPEdD8MoYEqD2oSPKCikotHb7gwdyg9RAQtfc7caPHBfHTqTp7MxB48 Qs60WZKfjnIsH1YWdtkvcfG6naIKsnDmTFtx24wEvsRdNB7Mc6x7trp3dCC+1RayI1aY se/A== X-Gm-Message-State: AJIora/tY/JCsWpWTvEw2rr2UHb9/QG4g1QZcRkWo2DzvMgjTKW6Urou gNZB2RPC8uvwdG4BG23Q7MRHrg== X-Google-Smtp-Source: AGRyM1sQedCuyj1o4tY5NnYeJ6qJzio2bvEnjJbR+u8HH+6e5GsxAfDR9qB6V8PNLxFmZLPxKU+yzQ== X-Received: by 2002:a5d:47c8:0:b0:21d:2295:6a05 with SMTP id o8-20020a5d47c8000000b0021d22956a05mr25526635wrc.302.1656922315828; Mon, 04 Jul 2022 01:11:55 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:55 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 04/13] coresight: etm4x: Update ETM4 driver to use Trace ID API Date: Mon, 4 Jul 2022 09:11:40 +0100 Message-Id: <20220704081149.16797-5-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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 trace ID API is now used to allocate trace IDs for ETM4.x / ETE devices. For perf sessions, these will be allocated on enable, and released on disable. For sysfs sessions, these will be allocated on enable, but only released on reset. This allows the sysfs session to interrogate the Trace ID used after the session is over - maintaining functional consistency with the previous allocation scheme. The trace ID will also be allocated on read of the mgmt/trctraceid file. This ensures that if perf or sysfs read this before enabling trace, the value will be the one used for the trace session. Trace ID initialisation is removed from the _probe() function. Signed-off-by: Mike Leach --- .../coresight/coresight-etm4x-core.c | 65 +++++++++++++++++-- .../coresight/coresight-etm4x-sysfs.c | 32 ++++++++- drivers/hwtracing/coresight/coresight-etm4x.h | 3 + 3 files changed, 91 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/h= wtracing/coresight/coresight-etm4x-core.c index 87299e99dabb..3f4f7ddd14ec 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -42,6 +42,7 @@ #include "coresight-etm4x-cfg.h" #include "coresight-self-hosted-trace.h" #include "coresight-syscfg.h" +#include "coresight-trace-id.h" =20 static int boot_enable; module_param(boot_enable, int, 0444); @@ -234,6 +235,38 @@ static int etm4_trace_id(struct coresight_device *csde= v) return drvdata->trcid; } =20 +int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata) +{ + int trace_id; + + /* + * This will allocate a trace ID to the cpu, + * or return the one currently allocated. + */ + spin_lock(&drvdata->spinlock); + trace_id =3D drvdata->trcid; + if (!trace_id) { + trace_id =3D coresight_trace_id_get_cpu_id(drvdata->cpu); + if (trace_id > 0) + drvdata->trcid =3D (u8)trace_id; + } + spin_unlock(&drvdata->spinlock); + + if (trace_id <=3D 0) + pr_err("Failed to allocate trace ID for %s on CPU%d\n", + dev_name(&drvdata->csdev->dev), drvdata->cpu); + + return trace_id; +} + +void etm4_release_trace_id(struct etmv4_drvdata *drvdata) +{ + spin_lock(&drvdata->spinlock); + coresight_trace_id_put_cpu_id(drvdata->cpu); + drvdata->trcid =3D 0; + spin_unlock(&drvdata->spinlock); +} + struct etm4_enable_arg { struct etmv4_drvdata *drvdata; int rc; @@ -715,9 +748,18 @@ static int etm4_enable_perf(struct coresight_device *c= sdev, ret =3D etm4_parse_event_config(csdev, event); if (ret) goto out; + + /* allocate a trace ID */ + ret =3D etm4_read_alloc_trace_id(drvdata); + if (ret < 0) + goto out; + /* And enable it */ ret =3D etm4_enable_hw(drvdata); =20 + /* failed to enable */ + if (ret) + etm4_release_trace_id(drvdata); out: return ret; } @@ -737,6 +779,11 @@ static int etm4_enable_sysfs(struct coresight_device *= csdev) return ret; } =20 + /* allocate a trace ID */ + ret =3D etm4_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + spin_lock(&drvdata->spinlock); =20 /* @@ -754,6 +801,8 @@ static int etm4_enable_sysfs(struct coresight_device *c= sdev) =20 if (!ret) dev_dbg(&csdev->dev, "ETM tracing enabled\n"); + else + etm4_release_trace_id(drvdata); return ret; } =20 @@ -881,6 +930,9 @@ static int etm4_disable_perf(struct coresight_device *c= sdev, /* TRCVICTLR::SSSTATUS, bit[9] */ filters->ssstatus =3D (control & BIT(9)); =20 + /* release trace ID - this may pend release if perf session is still acti= ve */ + etm4_release_trace_id(drvdata); + return 0; } =20 @@ -906,6 +958,13 @@ static void etm4_disable_sysfs(struct coresight_device= *csdev) spin_unlock(&drvdata->spinlock); cpus_read_unlock(); =20 + /* + * unlike for perf session - we only release trace IDs when resetting + * sysfs. This permits sysfs users to read the trace ID after the trace + * session has completed. This maintains operational behaviour with + * prior trace id allocation method + */ + dev_dbg(&csdev->dev, "ETM tracing disabled\n"); } =20 @@ -1548,11 +1607,6 @@ static int etm4_dying_cpu(unsigned int cpu) return 0; } =20 -static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) -{ - drvdata->trcid =3D coresight_get_trace_id(drvdata->cpu); -} - static int __etm4_cpu_save(struct etmv4_drvdata *drvdata) { int i, ret =3D 0; @@ -1957,7 +2011,6 @@ static int etm4_probe(struct device *dev, void __iome= m *base, u32 etm_pid) if (!desc.name) return -ENOMEM; =20 - etm4_init_trace_id(drvdata); etm4_set_default(&drvdata->config); =20 pdata =3D coresight_get_platform_data(dev); diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/= hwtracing/coresight/coresight-etm4x-sysfs.c index 6ea8181816fc..c7f896a020d9 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -266,10 +266,11 @@ static ssize_t reset_store(struct device *dev, config->vmid_mask0 =3D 0x0; config->vmid_mask1 =3D 0x0; =20 - drvdata->trcid =3D drvdata->cpu + 1; - spin_unlock(&drvdata->spinlock); =20 + /* for sysfs - only release trace id when resetting */ + etm4_release_trace_id(drvdata); + cscfg_csdev_reset_feats(to_coresight_device(dev)); =20 return size; @@ -2363,6 +2364,31 @@ static struct attribute *coresight_etmv4_attrs[] =3D= { NULL, }; =20 +/* + * Trace ID allocated dynamically on enable - but also allocate on read + * in case sysfs or perf read before enable to ensure consistent metadata + * information for trace decode + */ +static ssize_t trctraceid_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int trace_id; + struct etmv4_drvdata *drvdata =3D dev_get_drvdata(dev->parent); + + trace_id =3D etm4_read_alloc_trace_id(drvdata); + if (trace_id < 0) + return trace_id; + + return scnprintf(buf, PAGE_SIZE, "0x%x\n", trace_id); +} + +/* mgmt group uses extended attributes - no standard macro available */ +static struct dev_ext_attribute dev_attr_trctraceid =3D { + __ATTR(trctraceid, 0444, trctraceid_show, NULL), + (void *)(unsigned long)TRCTRACEIDR +}; + struct etmv4_reg { struct coresight_device *csdev; u32 offset; @@ -2499,7 +2525,7 @@ static struct attribute *coresight_etmv4_mgmt_attrs[]= =3D { coresight_etm4x_reg(trcpidr3, TRCPIDR3), coresight_etm4x_reg(trcoslsr, TRCOSLSR), coresight_etm4x_reg(trcconfig, TRCCONFIGR), - coresight_etm4x_reg(trctraceid, TRCTRACEIDR), + &dev_attr_trctraceid.attr.attr, coresight_etm4x_reg(trcdevarch, TRCDEVARCH), NULL, }; diff --git a/drivers/hwtracing/coresight/coresight-etm4x.h b/drivers/hwtrac= ing/coresight/coresight-etm4x.h index 33869c1d20c3..e0a9d334375d 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -1094,4 +1094,7 @@ static inline bool etm4x_is_ete(struct etmv4_drvdata = *drvdata) { return drvdata->arch >=3D ETM_ARCH_ETE; } + +int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata); +void etm4_release_trace_id(struct etmv4_drvdata *drvdata); #endif --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 E148DC43334 for ; Mon, 4 Jul 2022 08:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233472AbiGDIMQ (ORCPT ); Mon, 4 Jul 2022 04:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232526AbiGDIL6 (ORCPT ); Mon, 4 Jul 2022 04:11:58 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CFDFB1E1 for ; Mon, 4 Jul 2022 01:11:57 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id v14so12273543wra.5 for ; Mon, 04 Jul 2022 01:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U50rZuxIKcDyH6WCrUs5gy3BPn7+6cStMsPigtR0Cnw=; b=TlL5fN2u1hMHkBXyo0T9bg+w/2FnSGw3S7p+PUIrq2HVUIxhT2dJmfcX2iM6yUbOMo plIXQkVCtXfY+ozK6Vc6Z1YcCOnKpXNwp3SA1noaevLiB1hM8QX/ge4RjFJjU9EtARwU 3PH8aTWO4qDquViRqSiXLskWyQ2F6jH2Q1I0iCyJDJYrRSkiDmezA6jWgL6EZPuEYdmv 0Pi508ochtpDkcfjN11g6EY4yg/c13BgkKZrg2RpjEEQdYAaG40JtnGlPQXfGI9Wnt/a ZnYnuTHeNrQpUHk833AIJ2GvJ9olErY0g/+Yar8OwXGsyYHnm348igDNYRK7hTp4Oq+V q/eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=U50rZuxIKcDyH6WCrUs5gy3BPn7+6cStMsPigtR0Cnw=; b=tISyqqEniq2oZFkhzMa2L57JCriHaM5a97QiKZFfLS93mxszhejvuCK8k2qtomEfEs 21P2m4Xv7O3N5WmUgDj9xaJCRYvsFRu19fpjLUFgDopx4Is7DeTRuQn+V3+6qWn+I/7O x0T67WfMfzcnCO1qZo+Cjcm8p0WZN2t4MLo0ebAdiZJtku9G/WCxjqqIesSYvNXD+QRz Psj9Day5VEtecjrSmZ7vUoMjMDCw9hxMhEQcJv9FureARxc2ahA1k9Y9NPIrMjIXwFoH JS3p9fD6OelFDdelwsVwRDQhbh0lFK2WErTehOA9MsXlsf35TAOr2PBuzshVBVwr7PyZ wUTA== X-Gm-Message-State: AJIora8Oi78tX3GYk7Lk+xShyD6/CO5PtxtQ6R5iqzx6CSIMFzPQI6Nm 3F0FReI+7msYi/NSpRqa2qgZEA== X-Google-Smtp-Source: AGRyM1t5p/dQFBSowEC4EVhbXgaZYU7RsUiPNxLT/4u8FeYgwHiArbQ8m3Phklcl+B16EhJX3nA1OQ== X-Received: by 2002:a5d:62c4:0:b0:21b:c031:a94b with SMTP id o4-20020a5d62c4000000b0021bc031a94bmr25682399wrv.624.1656922316781; Mon, 04 Jul 2022 01:11:56 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:56 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 05/13] coresight: etm3x: Update ETM3 driver to use Trace ID API Date: Mon, 4 Jul 2022 09:11:41 +0100 Message-Id: <20220704081149.16797-6-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" Use the TraceID API to allocate ETM trace IDs dynamically. As with the etm4x we allocate on enable / disable for perf, allocate on enable / reset for sysfs. Additionally we allocate on sysfs file read as both perf and sysfs can read the ID before enabling the hardware. Remove sysfs option to write trace ID - which is inconsistent with both the dynamic allocation method and the fixed allocation method previously used. Signed-off-by: Mike Leach --- drivers/hwtracing/coresight/coresight-etm.h | 2 + .../coresight/coresight-etm3x-core.c | 68 +++++++++++++++++-- .../coresight/coresight-etm3x-sysfs.c | 28 +++----- 3 files changed, 71 insertions(+), 27 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm.h b/drivers/hwtracin= g/coresight/coresight-etm.h index f3ab96eaf44e..3667428d38b6 100644 --- a/drivers/hwtracing/coresight/coresight-etm.h +++ b/drivers/hwtracing/coresight/coresight-etm.h @@ -287,4 +287,6 @@ int etm_get_trace_id(struct etm_drvdata *drvdata); void etm_set_default(struct etm_config *config); void etm_config_trace_mode(struct etm_config *config); struct etm_config *get_etm_config(struct etm_drvdata *drvdata); +int etm_read_alloc_trace_id(struct etm_drvdata *drvdata); +void etm_release_trace_id(struct etm_drvdata *drvdata); #endif diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/h= wtracing/coresight/coresight-etm3x-core.c index d0ab9933472b..273f37be322b 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c @@ -32,6 +32,7 @@ =20 #include "coresight-etm.h" #include "coresight-etm-perf.h" +#include "coresight-trace-id.h" =20 /* * Not really modular but using module_param is the easiest way to @@ -490,18 +491,61 @@ static int etm_trace_id(struct coresight_device *csde= v) return etm_get_trace_id(drvdata); } =20 +int etm_read_alloc_trace_id(struct etm_drvdata *drvdata) +{ + int trace_id; + + /* + * This will allocate a trace ID to the cpu, + * or return the one currently allocated. + */ + spin_lock(&drvdata->spinlock); + trace_id =3D drvdata->traceid; + if (!trace_id) { + trace_id =3D coresight_trace_id_get_cpu_id(drvdata->cpu); + if (trace_id > 0) + drvdata->traceid =3D (u8)trace_id; + } + spin_unlock(&drvdata->spinlock); + + if (trace_id <=3D 0) + pr_err("Failed to allocate trace ID for %s on CPU%d\n", + dev_name(&drvdata->csdev->dev), drvdata->cpu); + + return trace_id; +} + +void etm_release_trace_id(struct etm_drvdata *drvdata) +{ + spin_lock(&drvdata->spinlock); + coresight_trace_id_put_cpu_id(drvdata->cpu); + drvdata->traceid =3D 0; + spin_unlock(&drvdata->spinlock); +} + static int etm_enable_perf(struct coresight_device *csdev, struct perf_event *event) { struct etm_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); + int ret; =20 if (WARN_ON_ONCE(drvdata->cpu !=3D smp_processor_id())) return -EINVAL; =20 /* Configure the tracer based on the session's specifics */ etm_parse_event_config(drvdata, event); + + /* allocate a trace ID */ + ret =3D etm_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + /* And enable it */ - return etm_enable_hw(drvdata); + ret =3D etm_enable_hw(drvdata); + + if (ret) + etm_release_trace_id(drvdata); + return ret; } =20 static int etm_enable_sysfs(struct coresight_device *csdev) @@ -510,6 +554,11 @@ static int etm_enable_sysfs(struct coresight_device *c= sdev) struct etm_enable_arg arg =3D { }; int ret; =20 + /* allocate a trace ID */ + ret =3D etm_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + spin_lock(&drvdata->spinlock); =20 /* @@ -532,6 +581,8 @@ static int etm_enable_sysfs(struct coresight_device *cs= dev) =20 if (!ret) dev_dbg(&csdev->dev, "ETM tracing enabled\n"); + else + etm_release_trace_id(drvdata); return ret; } =20 @@ -611,6 +662,8 @@ static void etm_disable_perf(struct coresight_device *c= sdev) coresight_disclaim_device_unlocked(csdev); =20 CS_LOCK(drvdata->base); + + etm_release_trace_id(drvdata); } =20 static void etm_disable_sysfs(struct coresight_device *csdev) @@ -635,6 +688,13 @@ static void etm_disable_sysfs(struct coresight_device = *csdev) spin_unlock(&drvdata->spinlock); cpus_read_unlock(); =20 + /* + * unlike for perf session - we only release trace IDs when resetting + * sysfs. This permits sysfs users to read the trace ID after the trace + * session has completed. This maintains operational behaviour with + * prior trace id allocation method + */ + dev_dbg(&csdev->dev, "ETM tracing disabled\n"); } =20 @@ -781,11 +841,6 @@ static void etm_init_arch_data(void *info) CS_LOCK(drvdata->base); } =20 -static void etm_init_trace_id(struct etm_drvdata *drvdata) -{ - drvdata->traceid =3D coresight_get_trace_id(drvdata->cpu); -} - static int __init etm_hp_setup(void) { int ret; @@ -871,7 +926,6 @@ static int etm_probe(struct amba_device *adev, const st= ruct amba_id *id) if (etm_arch_supported(drvdata->arch) =3D=3D false) return -EINVAL; =20 - etm_init_trace_id(drvdata); etm_set_default(&drvdata->config); =20 pdata =3D coresight_get_platform_data(dev); diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/= hwtracing/coresight/coresight-etm3x-sysfs.c index 68fcbf4ce7a8..962d6ac96d64 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c @@ -86,6 +86,8 @@ static ssize_t reset_store(struct device *dev, =20 etm_set_default(config); spin_unlock(&drvdata->spinlock); + /* release trace id outside the spinlock as this fn uses it */ + etm_release_trace_id(drvdata); } =20 return size; @@ -1189,30 +1191,16 @@ static DEVICE_ATTR_RO(cpu); static ssize_t traceid_show(struct device *dev, struct device_attribute *attr, char *buf) { - unsigned long val; - struct etm_drvdata *drvdata =3D dev_get_drvdata(dev->parent); - - val =3D etm_get_trace_id(drvdata); - - return sprintf(buf, "%#lx\n", val); -} - -static ssize_t traceid_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - int ret; - unsigned long val; + int trace_id; struct etm_drvdata *drvdata =3D dev_get_drvdata(dev->parent); =20 - ret =3D kstrtoul(buf, 16, &val); - if (ret) - return ret; + trace_id =3D etm_read_alloc_trace_id(drvdata); + if (trace_id < 0) + return trace_id; =20 - drvdata->traceid =3D val & ETM_TRACEID_MASK; - return size; + return sprintf(buf, "%#x\n", trace_id); } -static DEVICE_ATTR_RW(traceid); +static DEVICE_ATTR_RO(traceid); =20 static struct attribute *coresight_etm_attrs[] =3D { &dev_attr_nr_addr_cmp.attr, --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 451E5C43334 for ; Mon, 4 Jul 2022 08:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233514AbiGDIMY (ORCPT ); Mon, 4 Jul 2022 04:12:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbiGDIMA (ORCPT ); Mon, 4 Jul 2022 04:12:00 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B8FAE51 for ; Mon, 4 Jul 2022 01:11:59 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id z12so2665595wrq.7 for ; Mon, 04 Jul 2022 01:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s0X3OXDZ+bM8Kln7AQPu4r8yIcFwpLnAHC12SH0eaqM=; b=cQBoIeUcOlaE5MUPaV6tsoq5qOk1bRxeAte8eRBQfzXqDN+CvvTqVjYZ/oujx8eOfU c/aU1+iG3PXV7v5HLbi/vmjOuyiGX4UG/iKChrwttjkcvfYrlcLTLDDAuE8+WoDqtsNQ vI6PDB+Jn9rxkOO0K3rclzzb5E+Mi3+FHFcvIhHfOitpa0Acg2h0jtCE4JUxQ65moQmc jKx6HUNHf7IkcUQ4/pR9+XaHXx0/l0j8WBxZmdfzKAX6YgW5X1zkftZXfLspmVm7Mnd/ j9X3n5fOvDa54Cnafw+AkDXGySZpgzCePj2QyGVgjx/xrsZ9a4uo7PbKPwYEdKoxF1Wa PJqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s0X3OXDZ+bM8Kln7AQPu4r8yIcFwpLnAHC12SH0eaqM=; b=qk4CWszY+nAzOz9cROaE+8Ej5ns4oBHSh2Ty89G+Lywwxdct4dcxcTmU4i8s6B9LP6 L8AMjd++o17GHrErUMWPyOVogwIJFlq+2uCJx6ivl/yV7xFxPuu055A8ezUYtjbHLIHX +sv1fA36Qz3icaeKfGtOVlxyMCjZSd3kFvQ4yqlfU2KgXFF3adY3NF0nFyyDZsPosMUd sfaWUJXyfSFOJh9ON5VXq8QAyWwlhksCh8gUbwLnTdeeyIizKl3t32D+xHMDaNsV/T8v U7I1p7363zbpfylBiT/j0YzHTI7oEhr2ya5BBjOeTgIMnz3ecGW5ldEqLJVU89NfenB8 Nd9A== X-Gm-Message-State: AJIora9y4pi9VGK3mkIMMp1cLl9BBTRkeRSocax/8cfcSwTtNrQqrheT /LpEbwVC6KCJWdxDnV9FgNs+pw== X-Google-Smtp-Source: AGRyM1ufDDAiL8LUot5lrbQ4mVWUOvQySpn7LG7JMXUGrl7d+DrZ+eQscTgduO58gAToHllp4Ozqyg== X-Received: by 2002:a05:6000:1889:b0:21d:28e8:b6a with SMTP id a9-20020a056000188900b0021d28e80b6amr24864840wri.14.1656922317684; Mon, 04 Jul 2022 01:11:57 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:57 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 06/13] coresight: etmX.X: stm: Remove unused legacy source Trace ID ops Date: Mon, 4 Jul 2022 09:11:42 +0100 Message-Id: <20220704081149.16797-7-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" CoreSight sources provide a callback (.trace_id) in the standard source ops which returns the ID to the core code. This was used to check that sources all had a unique Trace ID. Uniqueness is now gauranteed by the Trace ID allocation system, and the check code has been removed from the core. This patch removes the unneeded and unused .trace_id source ops from the ops structure and implementations in etm3x, etm4x and stm. Signed-off-by: Mike Leach Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etm.h | 1 - .../coresight/coresight-etm3x-core.c | 37 ------------------- .../coresight/coresight-etm4x-core.c | 8 ---- drivers/hwtracing/coresight/coresight-stm.c | 8 ---- include/linux/coresight.h | 3 -- 5 files changed, 57 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm.h b/drivers/hwtracin= g/coresight/coresight-etm.h index 3667428d38b6..9a0d08b092ae 100644 --- a/drivers/hwtracing/coresight/coresight-etm.h +++ b/drivers/hwtracing/coresight/coresight-etm.h @@ -283,7 +283,6 @@ static inline unsigned int etm_readl(struct etm_drvdata= *drvdata, u32 off) } =20 extern const struct attribute_group *coresight_etm_groups[]; -int etm_get_trace_id(struct etm_drvdata *drvdata); void etm_set_default(struct etm_config *config); void etm_config_trace_mode(struct etm_config *config); struct etm_config *get_etm_config(struct etm_drvdata *drvdata); diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/h= wtracing/coresight/coresight-etm3x-core.c index 273f37be322b..911d961dd736 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c @@ -455,42 +455,6 @@ static int etm_cpu_id(struct coresight_device *csdev) return drvdata->cpu; } =20 -int etm_get_trace_id(struct etm_drvdata *drvdata) -{ - unsigned long flags; - int trace_id =3D -1; - struct device *etm_dev; - - if (!drvdata) - goto out; - - etm_dev =3D drvdata->csdev->dev.parent; - if (!local_read(&drvdata->mode)) - return drvdata->traceid; - - pm_runtime_get_sync(etm_dev); - - spin_lock_irqsave(&drvdata->spinlock, flags); - - CS_UNLOCK(drvdata->base); - trace_id =3D (etm_readl(drvdata, ETMTRACEIDR) & ETM_TRACEID_MASK); - CS_LOCK(drvdata->base); - - spin_unlock_irqrestore(&drvdata->spinlock, flags); - pm_runtime_put(etm_dev); - -out: - return trace_id; - -} - -static int etm_trace_id(struct coresight_device *csdev) -{ - struct etm_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); - - return etm_get_trace_id(drvdata); -} - int etm_read_alloc_trace_id(struct etm_drvdata *drvdata) { int trace_id; @@ -731,7 +695,6 @@ static void etm_disable(struct coresight_device *csdev, =20 static const struct coresight_ops_source etm_source_ops =3D { .cpu_id =3D etm_cpu_id, - .trace_id =3D etm_trace_id, .enable =3D etm_enable, .disable =3D etm_disable, }; diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/h= wtracing/coresight/coresight-etm4x-core.c index 3f4f7ddd14ec..b7c7980cc71c 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -228,13 +228,6 @@ static int etm4_cpu_id(struct coresight_device *csdev) return drvdata->cpu; } =20 -static int etm4_trace_id(struct coresight_device *csdev) -{ - struct etmv4_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); - - return drvdata->trcid; -} - int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata) { int trace_id; @@ -998,7 +991,6 @@ static void etm4_disable(struct coresight_device *csdev, =20 static const struct coresight_ops_source etm4_source_ops =3D { .cpu_id =3D etm4_cpu_id, - .trace_id =3D etm4_trace_id, .enable =3D etm4_enable, .disable =3D etm4_disable, }; diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracin= g/coresight/coresight-stm.c index 9ef3e923a930..f4b4232614b0 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -281,15 +281,7 @@ static void stm_disable(struct coresight_device *csdev, } } =20 -static int stm_trace_id(struct coresight_device *csdev) -{ - struct stm_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); - - return drvdata->traceid; -} - static const struct coresight_ops_source stm_source_ops =3D { - .trace_id =3D stm_trace_id, .enable =3D stm_enable, .disable =3D stm_disable, }; diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 9f445f09fcfe..247147c11231 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -314,14 +314,11 @@ struct coresight_ops_link { * Operations available for sources. * @cpu_id: returns the value of the CPU number this component * is associated to. - * @trace_id: returns the value of the component's trace ID as known - * to the HW. * @enable: enables tracing for a source. * @disable: disables tracing for a source. */ struct coresight_ops_source { int (*cpu_id)(struct coresight_device *csdev); - int (*trace_id)(struct coresight_device *csdev); int (*enable)(struct coresight_device *csdev, struct perf_event *event, u32 mode); void (*disable)(struct coresight_device *csdev, --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 AA760CCA47F for ; Mon, 4 Jul 2022 08:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbiGDIMa (ORCPT ); Mon, 4 Jul 2022 04:12:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbiGDIMD (ORCPT ); Mon, 4 Jul 2022 04:12:03 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA9B4B1FA for ; Mon, 4 Jul 2022 01:11:59 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id f2so6902803wrr.6 for ; Mon, 04 Jul 2022 01:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XdfZuCz31I3dZ9oZhErj8lvxSYGHlQH77vSFPPyQopc=; b=Ge1INB7cKd6HbqaH4ZXMeX/l3dO8/q5UGHnCGDbV+bcEPzZWk+k0IHWd3Z3kBG5MU0 Z7fR+3LRRwMTEMET3bg12K3bNHWwz6GkI9xvsDcQhOCi1j/AD18o7ZQHRVaOPJQKuL+q eeyS4+Bvc93d1Rn/mNy4wBGwdTwZzKGMVhaRwMZCGPtElDKdHttoh6zYhUn7WhGuR0Fq GaUVhRUHxfYAcjaXB4vo8ZeA7uA3/a7qlpCGkLFp3DOyrqxQy9V3eokzUHq1ojU/F/Yp N4ha7h1jp3Ku1cgimvDXbeA1TgxrP1FPNhn7j/62mJpKJbYfzcXygex429chSmifkc29 x7ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XdfZuCz31I3dZ9oZhErj8lvxSYGHlQH77vSFPPyQopc=; b=eAG/J7o8G9/v5S17TDfqPe/IcTNwewrFvZNGzhhv4EL+Dolocj7XM2KyFBcFUrmAve 9gltUVbhIsy3Y2ZlOgdvi403XiYp7tkacDa/04b4vbzrbPEyY576xddLRaoX8MBW84nS hLmc2jQ+XPZOySFpFJ3xvzMOwlS7EapIG9Z4I+FHdfaIaAu/GQFoajPLz9H0eSgtW0Y5 UUQOrXXhW1wNt89D9gwLWj93MxT2nsS92nmIxzFuPsZ8PXSnUOc75kx80nyc5ZPn/D2S qrNKDHU3H7OrI+p0Yz96CMPNYJuJeb/rDEzK70qA5xdfnN2SBcdQN/w9mq4l7gVybVGS vMKg== X-Gm-Message-State: AJIora88gxxkJuacR8/AyXmI14k9zo/GOuecGsXnNrVMT4VWbo88RZqZ IZfZWM4TGfdQO9+Ui64SQU96pA== X-Google-Smtp-Source: AGRyM1uHtXRF4rfVMvWkJuFgqxnQW29twRsyx5gVj0TcSf6ZxXjLvxDofjYD1B9qmSYGx/LI2JBs+w== X-Received: by 2002:a5d:52d0:0:b0:21d:3626:6cc3 with SMTP id r16-20020a5d52d0000000b0021d36266cc3mr21378760wrv.334.1656922318576; Mon, 04 Jul 2022 01:11:58 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:58 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 07/13] coresight: perf: traceid: Add perf notifiers for Trace ID Date: Mon, 4 Jul 2022 09:11:43 +0100 Message-Id: <20220704081149.16797-8-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" Adds in notifier calls to the trace ID allocator that perf events are starting and stopping. This ensures that Trace IDs associated with CPUs remain the same throughout the perf session, and are only released when all perf sessions are complete. Signed-off-by: Mike Leach --- drivers/hwtracing/coresight/coresight-etm-perf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index c039b6ae206f..ad3fdc07c60b 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -22,6 +22,7 @@ #include "coresight-etm-perf.h" #include "coresight-priv.h" #include "coresight-syscfg.h" +#include "coresight-trace-id.h" =20 static struct pmu etm_pmu; static bool etm_perf_up; @@ -228,6 +229,9 @@ static void free_event_data(struct work_struct *work) *ppath =3D NULL; } =20 + /* mark perf event as done for trace id allocator */ + coresight_trace_id_perf_stop(); + free_percpu(event_data->path); kfree(event_data); } @@ -314,6 +318,9 @@ static void *etm_setup_aux(struct perf_event *event, vo= id **pages, sink =3D user_sink =3D coresight_get_sink_by_id(id); } =20 + /* tell the trace ID allocator that a perf event is starting up */ + coresight_trace_id_perf_start(); + /* check if user wants a coresight configuration selected */ cfg_hash =3D (u32)((event->attr.config2 & GENMASK_ULL(63, 32)) >> 32); if (cfg_hash) { --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 9A144C433EF for ; Mon, 4 Jul 2022 08:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233546AbiGDIM2 (ORCPT ); Mon, 4 Jul 2022 04:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233319AbiGDIMC (ORCPT ); Mon, 4 Jul 2022 04:12:02 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E582CAE57 for ; Mon, 4 Jul 2022 01:12:00 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id b26so12301327wrc.2 for ; Mon, 04 Jul 2022 01:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RD0yzf+F/wW0874+yGj00tt1sAsOODbCCotfldJYXsg=; b=hcEcJ7ns/gDL/SPp/Q9o35fae7VnIMiUSrjHnnvnbdRHvCyC1Q5lL5UZ7a5yYfucD5 dNiPfF3xc1mhZhnrMP9+lJCag31oL+3s85nFsUn82h9i5sFOT3iLlnJ0SWSsQr8uA0aS BZRyFt1jK9VgYkMKyS6D4Nz+hEhsVgGUkPEOJY5ayb1EWcBFdVqELF/6D86PwPTA7FMp ynczGVyXKE/ptYSZkDtEB7Ef+JDowffpSJ1eQFuyq5uxppKfOZbVkl2T+Q1h08xperFx jSVLCZNbIk2JsdnzmQGw9a0Kh65h74eyTGE761E3w14LS1+VppAUog1BFhC6aeJl8rR9 rK7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RD0yzf+F/wW0874+yGj00tt1sAsOODbCCotfldJYXsg=; b=DQFJB91aMwEdWtQHL6PQa3JAdPmQz+1pEW44BlU/M1GQEb/Z+N2wQDn66jXHXKQl6I qh8mezh7VikYKCtmELXqR9AO1GuLfLDPEwCP9XN+hQzO75QIBrooRKY97Eoj65mlOKy6 KbT9EFPpOel47QBo0y4oyH49CpSlmlTZsqk2GFUDSYAR/nw7uRjdQ7ZRsJGnIyxKof2U ki2QNnRcjE+z7wF1XFXdUXJrocxJDPFkASnLR2ye8NCaq+uj75SfzCXEjx1pXbHsUNX/ eu9f9Yzt+oD/B3p5HbW9l5C3ACzjx4n3OhJ7Xo9snnZLXNiPMgWOLgZxXd3Pwm29ZfPv Yj4w== X-Gm-Message-State: AJIora82dLUQm/Sx5n2CdJx0Q2NMGls4jpD351+MXqHy2CmBx3tKMKUE gxqcUBnqV3H68mWy38O0cvICZQ== X-Google-Smtp-Source: AGRyM1v2EdBohgY7Hcu9Zs15xs8AkLH6u4h7mC1gnbQmE4uwovpy9Ig2GJdmRhweyx5rQeV2j6QoDQ== X-Received: by 2002:adf:dd0d:0:b0:21d:666b:298e with SMTP id a13-20020adfdd0d000000b0021d666b298emr6601500wrm.412.1656922319480; Mon, 04 Jul 2022 01:11:59 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:59 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 08/13] perf: cs-etm: Move mapping of Trace ID and cpu into helper function Date: Mon, 4 Jul 2022 09:11:44 +0100 Message-Id: <20220704081149.16797-9-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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 and setting the value in AUXINFO to an unused value. To prepare for this, we only map Trace ID and CPU data from AUXINFO if the header version and values are valid, and move the mapping into a helper function. Signed-off-by: Mike Leach --- tools/perf/util/cs-etm.c | 53 +++++++++++++++++++++++++++------------- tools/perf/util/cs-etm.h | 14 +++++++++-- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 8b95fb3c4d7b..df9d67901f8d 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) { @@ -2886,7 +2910,6 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, { 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; @@ -2898,6 +2921,7 @@ int cs_etm__process_auxtrace_info(union perf_event *e= vent, u64 *ptr, *hdr =3D NULL; u64 **metadata =3D NULL; u64 hdr_version; + u8 trace_chan_id; =20 /* * sizeof(auxtrace_info_event::type) + @@ -2991,25 +3015,20 @@ int cs_etm__process_auxtrace_info(union perf_event = *event, goto err_free_metadata; } =20 - /* 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. + * Associate a trace ID with metadata. + * Later versions of the drivers will make this association using a + * hardware ID packet in the data file, setting the value in AUXINFO to = an + * invalid trace ID value. Only map here if the value is valid. */ - if (inode->priv) { - err =3D -EINVAL; - goto err_free_metadata; + if (hdr_version < CS_AUX_HW_ID_VERSION_MIN) { + trace_chan_id =3D metadata[j][trcidr_idx]; + if (CS_IS_VALID_TRACE_ID(trace_chan_id)) { + err =3D cs_etm__map_trace_id(trace_chan_id, metadata[j]); + if (err) + goto err_free_metadata; + } } - /* All good, associate the traceID with the metadata pointer */ - inode->priv =3D metadata[j]; } =20 /* 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 From nobody Sun Apr 19 09:11:21 2026 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 556A2CCA479 for ; Mon, 4 Jul 2022 08:12:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233657AbiGDIMd (ORCPT ); Mon, 4 Jul 2022 04:12:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233340AbiGDIMD (ORCPT ); Mon, 4 Jul 2022 04:12:03 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9623B1FF for ; Mon, 4 Jul 2022 01:12:01 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id be14-20020a05600c1e8e00b003a04a458c54so5136360wmb.3 for ; Mon, 04 Jul 2022 01:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=O0T6iSxIoNn8Gu/FxWaC6WvogLfn9QCdL/z8tiUr0ks=; b=N2WHXyk2+zP/vYzR1T2MOhfZGFijkVFfzaRR82FrfOQGY/7ezaU7j94KlC1Z///RDR UFu6dTuPwMYttwKj1Nht5wSahuHlIIHV5VhsuUQE8qLT+pZNg88pzqnXVOQIQ75DwoxD c1aKGMXgzHh7g8kPCGAY8iNqbuoGicdN06m3BPmxiLlTVJ8na0slgJdSwpSVRHoQtZIm GuZobYP4jnz7keEPEhN2X3L+1ufXKg6dmI+c+yp64AvTKnYiWtglUIW8qGLkTtRuiTAW Z5VvYlU4Vos+eGePHzw1CFLKfrWkFq2T4C27sRuzweoYaHwiBuff5d+4T6kEyedfSn0j 2Jqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=O0T6iSxIoNn8Gu/FxWaC6WvogLfn9QCdL/z8tiUr0ks=; b=6oZ6LnL0/DQ90bRFtzKmpiEF1Jg6utOXeLVkfMzxQkZOw/0kZd48j1EKkTsOx2pUBM vLbHxqKoyASCodIRh+o8a26EoBgod2CyfljLwSQp/OrccaEox46A6u3tZbgxxfpSi2c1 roM1yn8rejQrOrJOcO+nlDaXs1jCee4ddCieMYYY3M21AEgtnAbsgIFDF6dQs7VTFgZz wwlIRFuGtAtNrCwXw6s3JslHSd6Pr3v6qOio/UdOFZUuKs4DoombOnyjJY26Dd/VqZBl Ngs9gOYt9WDQUMmNrkb5k2Os+5r1z+Nj3yOuJ0o/iDTO632iqtO47WCWd8XNcQ5vXqC7 fpRA== X-Gm-Message-State: AJIora/jGHi5ra55nLj6NCbzXuFO3NgWq/N7pHzuoSPXBXjRSWn5Kt37 kANWmReqKeP6MZsTY4ArMu+TSw== X-Google-Smtp-Source: AGRyM1vyZRYXOjBVB9DRfkXD+EUlfDYeLN4AeTBJSnU/FigvnmKIqmrXouU3ruaOFHQTpcPFSAOd1g== X-Received: by 2002:a05:600c:3d96:b0:3a1:8681:cc80 with SMTP id bi22-20020a05600c3d9600b003a18681cc80mr22311366wmb.192.1656922320417; Mon, 04 Jul 2022 01:12:00 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:59 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 09/13] perf: cs-etm: Update record event to use new Trace ID protocol Date: Mon, 4 Jul 2022 09:11:45 +0100 Message-Id: <20220704081149.16797-10-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" Trace IDs are now dynamically allocated. Previously used the static association algorithm that is no longer used. The 'cpu * 2 + seed' was outdated and broken for systems with high core counts (>46). as it did not scale and was broken for larger core counts. Trace ID is as unknown in AUXINFO record, and the ID / CPU association will now be sent in PERF_RECORD_AUX_OUTPUT_HW_ID record. Remove legacy Trace ID allocation algorithm. Signed-off-by: Mike Leach --- include/linux/coresight-pmu.h | 19 +++++++------------ tools/include/linux/coresight-pmu.h | 19 +++++++------------ tools/perf/arch/arm/util/cs-etm.c | 21 ++++++++++++--------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h index 4ac5c081af93..9f7ee380266b 100644 --- a/include/linux/coresight-pmu.h +++ b/include/linux/coresight-pmu.h @@ -8,7 +8,13 @@ #define _LINUX_CORESIGHT_PMU_H =20 #define CORESIGHT_ETM_PMU_NAME "cs_etm" -#define CORESIGHT_ETM_PMU_SEED 0x10 + +/* + * Metadata now contains an unused trace ID - IDs are transmitted using a + * PERF_RECORD_AUX_OUTPUT_HW_ID record. + * Value architecturally defined as reserved in CoreSight. + */ +#define CS_UNUSED_TRACE_ID 0x7F =20 /* * Below are the definition of bit offsets for perf option, and works as @@ -32,15 +38,4 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 =20 -static inline int coresight_get_trace_id(int cpu) -{ - /* - * A trace ID of value 0 is invalid, so let's start at some - * random value that fits in 7 bits and go from there. Since - * the common convention is to have data trace IDs be I(N) + 1, - * set instruction trace IDs as a function of the CPU number. - */ - return (CORESIGHT_ETM_PMU_SEED + (cpu * 2)); -} - #endif diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/core= sight-pmu.h index 6c2fd6cc5a98..31d007fab3a6 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -8,7 +8,13 @@ #define _LINUX_CORESIGHT_PMU_H =20 #define CORESIGHT_ETM_PMU_NAME "cs_etm" -#define CORESIGHT_ETM_PMU_SEED 0x10 + +/* + * Metadata now contains an unused trace ID - IDs are transmitted using a + * PERF_RECORD_AUX_OUTPUT_HW_ID record. + * Value architecturally defined as reserved in CoreSight. + */ +#define CS_UNUSED_TRACE_ID 0x7F =20 /* * Below are the definition of bit offsets for perf option, and works as @@ -34,15 +40,4 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 =20 -static inline int coresight_get_trace_id(int cpu) -{ - /* - * A trace ID of value 0 is invalid, so let's start at some - * random value that fits in 7 bits and go from there. Since - * the common convention is to have data trace IDs be I(N) + 1, - * set instruction trace IDs as a function of the CPU number. - */ - return (CORESIGHT_ETM_PMU_SEED + (cpu * 2)); -} - #endif diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index 1b54638d53b0..2d68e6a722ed 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -421,13 +421,16 @@ static int cs_etm_recording_options(struct auxtrace_r= ecord *itr, evlist__to_front(evlist, cs_etm_evsel); =20 /* - * In the case of per-cpu mmaps, we need the CPU on the - * AUX event. We also need the contextID in order to be notified + * get the CPU on the sample - need it to associate trace ID in the + * AUX_OUTPUT_HW_ID event, and the AUX event for per-cpu mmaps. + */ + evsel__set_sample_bit(cs_etm_evsel, CPU); + + /* + * Also the case of per-cpu mmaps, need the contextID in order to be noti= fied * when a context switch happened. */ if (!perf_cpu_map__empty(cpus)) { - evsel__set_sample_bit(cs_etm_evsel, CPU); - err =3D cs_etm_set_option(itr, cs_etm_evsel, BIT(ETM_OPT_CTXTID) | BIT(ETM_OPT_TS)); if (err) @@ -633,8 +636,9 @@ static void cs_etm_save_etmv4_header(__u64 data[], stru= ct auxtrace_record *itr, =20 /* Get trace configuration register */ data[CS_ETMV4_TRCCONFIGR] =3D cs_etmv4_get_config(itr); - /* Get traceID from the framework */ - data[CS_ETMV4_TRCTRACEIDR] =3D coresight_get_trace_id(cpu); + /* traceID set to unused */ + data[CS_ETMV4_TRCTRACEIDR] =3D CS_UNUSED_TRACE_ID; + /* Get read-only information from sysFS */ data[CS_ETMV4_TRCIDR0] =3D cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0]); @@ -681,9 +685,8 @@ static void cs_etm_get_metadata(int cpu, u32 *offset, magic =3D __perf_cs_etmv3_magic; /* Get configuration register */ info->priv[*offset + CS_ETM_ETMCR] =3D cs_etm_get_config(itr); - /* Get traceID from the framework */ - info->priv[*offset + CS_ETM_ETMTRACEIDR] =3D - coresight_get_trace_id(cpu); + /* traceID set to unused */ + info->priv[*offset + CS_ETM_ETMTRACEIDR] =3D CS_UNUSED_TRACE_ID; /* Get read-only information from sysFS */ info->priv[*offset + CS_ETM_ETMCCER] =3D cs_etm_get_ro(cs_etm_pmu, cpu, --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 DB60ACCA482 for ; Mon, 4 Jul 2022 08:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233527AbiGDIMf (ORCPT ); Mon, 4 Jul 2022 04:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233367AbiGDIME (ORCPT ); Mon, 4 Jul 2022 04:12:04 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7051B482 for ; Mon, 4 Jul 2022 01:12:02 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id r81-20020a1c4454000000b003a0297a61ddso7455880wma.2 for ; Mon, 04 Jul 2022 01:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=plqraaSJUkeNCDGA4aEvfb+pg8+kvKD5XTON2+h9YBA=; b=oz12zjWXxiKYvIUnwdtU+1cpeW4xquYSJyHG0bWhwcfdSFfsDSCYoHXHy/Qjx4VSYr e1HSsp3iLxlQcFkWH7+LF6cQbnVq5OXaY7LHK9Mq38WxdbjljKhOlshcZ6D/njgfaBox VtT22S1fk56slCsu6XCkh7X/9D9SlseAHIoDINGoJOciVy/zHWho1/3Umceqv+m9+cbk /eM90nNK03YRXH/JNdhcjJk2uLPehskE5wZOhv6SupGyyTV8xvlrWPAB5CmdUxEzjixm mqNPj5LFBraN09ulIJ3q4MHOhjzJEpCPpwFcl+QkltjicBJfpsn0PAwBlX4n2BRsQNPT rQAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=plqraaSJUkeNCDGA4aEvfb+pg8+kvKD5XTON2+h9YBA=; b=yBto/eDPAj5lDuAgVW3CVl3uDqcPvHtuWx9Wt4w0o755sfPsdFwhtk7NU8Fgnsd2o2 njRaFuv6O0VcPYbsDDb5MGLh1dVDjsiaUEYc80miXozYkqWiyHJqu98YFXFV1tknK4nd r6/kcm1z1LVkrCGYb1gjtZSx4ItEg8nTOmLmufOlu9F1ZsKMubJRZtZZ+rRf+DZiCBWA rZFsD0oGXN/rbStlnuFwFvtoTtpncvYZlu/x4jyUoYcDABmKcwSAj+6Dk//cyt4TjiYm 8PU5gWBiOxnpGoc+AugBtWJAXkZSYP5RalG6a0aYj4u/z1HMwDngEmmoANFpDETxIDC+ Y5Sg== X-Gm-Message-State: AJIora/THWzTmqgoWOxDq9RVmmSuRiZ5bH96L44VdP3neXnNa48Ni7ai /ntPxgGaI5X0MrmY198ULNTYjg== X-Google-Smtp-Source: AGRyM1vcBm9hrS+Gdaug34C9Dljbs673NhCTJGPPhK8Fnlnl/szz96TTGBkFZVXyU/g5yAKaKRYb6g== X-Received: by 2002:a05:600c:a08:b0:3a1:9319:ab78 with SMTP id z8-20020a05600c0a0800b003a19319ab78mr13105975wmp.158.1656922321341; Mon, 04 Jul 2022 01:12:01 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:12:00 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 10/13] kernel: events: Export perf_report_aux_output_id() Date: Mon, 4 Jul 2022 09:11:46 +0100 Message-Id: <20220704081149.16797-11-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" CoreSight trace being updated to use the perf_report_aux_output_id() in a similar way to intel-pt. This function in needs export visibility to allow it to be called from kernel loadable modules, which CoreSight may configured to be built as. Signed-off-by: Mike Leach Acked-by: Suzuki K Poulose --- kernel/events/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 80782cddb1da..f5835e5833cd 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9117,6 +9117,7 @@ void perf_report_aux_output_id(struct perf_event *eve= nt, u64 hw_id) =20 perf_output_end(&handle); } +EXPORT_SYMBOL_GPL(perf_report_aux_output_id); =20 static int __perf_event_account_interrupt(struct perf_event *event, int throttle) --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 977E5C433EF for ; Mon, 4 Jul 2022 08:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233554AbiGDIMi (ORCPT ); Mon, 4 Jul 2022 04:12:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233393AbiGDIMF (ORCPT ); Mon, 4 Jul 2022 04:12:05 -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 CF879B486 for ; Mon, 4 Jul 2022 01:12:03 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id o19-20020a05600c4fd300b003a0489f414cso5133284wmq.4 for ; Mon, 04 Jul 2022 01:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DPhuhsON6Dc/bAUa+COj6G0TCJ1Xh6/F1XbcAf+VvAE=; b=I0rQtX/S4jKILdle+AmJn+Adpkxf4W51sNK0FP3j+RtpmcRfimYjPzgMaKB6/6me21 gwIjG8R8dAdviBNYfCrvBKpujJWGCdAWEBW8lALFkpxPb0ZXTSafQhUdZih7jcEzAQ/L zJxsRu1cw9+TO6htblDXh7myga7RLZEYqBEaXoaTgP9B6mzRXCIGPjRGpXVvtWqV4OMm YJ1JmQEifhIKO5OGrz3bqRMuFk6V0XIopmxS5GgxUePAe+jo3Md/UuTQj0AZpMlJgYQK kx81esVxEsataRmOgVeoVVwfpkLh966QQPpoaLuGHu/Cq+wZ6eEyVWOQdce97KJfhqJd 08PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DPhuhsON6Dc/bAUa+COj6G0TCJ1Xh6/F1XbcAf+VvAE=; b=wbj9fvsZSpK05LZ+2drK6RRuGrcPqAIBg6RzX1HhMlW39MVboZw7iVTvK3nSN6+ngv 5RV1VCMAmccbVecW8SmTP6BEcfGE4FgkkoiI9aKjWEnYPATQTl+IN5htHSAxedCF3Z2F 5vAgQrHS8UAi5PTneSsVBCoZmoUQLB9ynGkwKvvvrDIxPqnkUwD799PW/lPfn7B6aoK0 mCd47WJKSTR/M3lV859Bz9x4yR+I+2Kudlq2MRsuF/QTi9wzCxj3YogMTXp5KovvhpJk Zzm8fVjhX33GriPr81dHwfDpBv4BQ+TEGeCktiufIjG4yZD8CBzdLx2YSBU8MALI5Ee6 6z2g== X-Gm-Message-State: AJIora/RmrHXtEVNh6TSM0/0/Nlifin24eHBevUYwj9dn+oqQJ3mz4rO 6mhHJvS2+lGGLXPlp7VmhIcroQ== X-Google-Smtp-Source: AGRyM1vpCyboJomqm1lHAvyOdGyxbADDBoKw20wKr4sDPikn7uhdRg7EOT5yvw9JuSvI7QrXDcLyvQ== X-Received: by 2002:a05:600c:4f05:b0:3a1:67df:a116 with SMTP id l5-20020a05600c4f0500b003a167dfa116mr30017057wmq.103.1656922322341; Mon, 04 Jul 2022 01:12:02 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:12:01 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 11/13] perf: cs-etm: Handle PERF_RECORD_AUX_OUTPUT_HW_ID packet Date: Mon, 4 Jul 2022 09:11:47 +0100 Message-Id: <20220704081149.16797-12-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" When using dynamically assigned CoreSight trace IDs the drivers can output the ID / CPU association as a PERF_RECORD_AUX_OUTPUT_HW_ID packet. Update cs-etm decoder to handle this packet by setting the CPU/Trace ID mapping. Signed-off-by: Mike Leach --- tools/include/linux/coresight-pmu.h | 14 ++ .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 9 + tools/perf/util/cs-etm.c | 167 +++++++++++++++++- 3 files changed, 185 insertions(+), 5 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/core= sight-pmu.h index 31d007fab3a6..4e8b3148f939 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -7,6 +7,8 @@ #ifndef _LINUX_CORESIGHT_PMU_H #define _LINUX_CORESIGHT_PMU_H =20 +#include + #define CORESIGHT_ETM_PMU_NAME "cs_etm" =20 /* @@ -40,4 +42,16 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 =20 +/* + * Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. + * Used to associate a CPU with the CoreSight Trace ID. + * [63:16] - unused SBZ + * [15:08] - Trace ID + * [07:00] - Version + */ +#define CS_AUX_HW_ID_VERSION_MASK GENMASK_ULL(7, 0) +#define CS_AUX_HW_ID_TRACE_ID_MASK GENMASK_ULL(15, 8) + +#define CS_AUX_HW_ID_CURR_VERSION 0 + #endif diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/u= til/cs-etm-decoder/cs-etm-decoder.c index 31fa3b45134a..d1dd73310707 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -611,6 +611,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_e= lem_printer( return resp; } =20 +#define CS_TRACE_ID_MASK GENMASK(6, 0) + static int cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, struct cs_etm_trace_params *t_params, @@ -625,6 +627,7 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decode= r_params *d_params, switch (t_params->protocol) { case CS_ETM_PROTO_ETMV3: case CS_ETM_PROTO_PTM: + csid =3D (t_params->etmv3.reg_idr & CS_TRACE_ID_MASK); cs_etm_decoder__gen_etmv3_config(t_params, &config_etmv3); decoder->decoder_name =3D (t_params->protocol =3D=3D CS_ETM_PROTO_ETMV3)= ? OCSD_BUILTIN_DCD_ETMV3 : @@ -632,11 +635,13 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_deco= der_params *d_params, trace_config =3D &config_etmv3; break; case CS_ETM_PROTO_ETMV4i: + csid =3D (t_params->etmv4.reg_traceidr & CS_TRACE_ID_MASK); cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4); decoder->decoder_name =3D OCSD_BUILTIN_DCD_ETMV4I; trace_config =3D &trace_config_etmv4; break; case CS_ETM_PROTO_ETE: + csid =3D (t_params->ete.reg_traceidr & CS_TRACE_ID_MASK); cs_etm_decoder__gen_ete_config(t_params, &trace_config_ete); decoder->decoder_name =3D OCSD_BUILTIN_DCD_ETE; trace_config =3D &trace_config_ete; @@ -645,6 +650,10 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decod= er_params *d_params, return -1; } =20 + /* if the CPU has no trace ID associated, no decoder needed */ + if (csid =3D=3D CS_UNUSED_TRACE_ID) + return 0; + if (d_params->operation =3D=3D CS_ETM_OPERATION_DECODE) { if (ocsd_dt_create_decoder(decoder->dcd_tree, decoder->decoder_name, diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index df9d67901f8d..ffce858f21fd 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -217,6 +217,139 @@ static int cs_etm__map_trace_id(u8 trace_chan_id, u64= *cpu_metadata) return 0; } =20 +static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metad= ata) +{ + u64 cs_etm_magic =3D cpu_metadata[CS_ETM_MAGIC]; + + switch (cs_etm_magic) { + case __perf_cs_etmv3_magic: + *trace_chan_id =3D cpu_metadata[CS_ETM_ETMTRACEIDR]; + break; + case __perf_cs_etmv4_magic: + case __perf_cs_ete_magic: + *trace_chan_id =3D cpu_metadata[CS_ETMV4_TRCTRACEIDR]; + break; + + default: + return -EINVAL; + } + return 0; +} + +static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metada= ta) +{ + u64 cs_etm_magic =3D cpu_metadata[CS_ETM_MAGIC]; + + switch (cs_etm_magic) { + case __perf_cs_etmv3_magic: + cpu_metadata[CS_ETM_ETMTRACEIDR] =3D trace_chan_id; + break; + case __perf_cs_etmv4_magic: + case __perf_cs_ete_magic: + cpu_metadata[CS_ETMV4_TRCTRACEIDR] =3D trace_chan_id; + break; + + default: + return -EINVAL; + } + return 0; +} + +/* + * FIELD_GET (linux/bitfield.h) not available outside kernel code, + * and the header contains too many dependencies to just copy over, + * so roll our own based on the original + */ +#define __bf_shf(x) (__builtin_ffsll(x) - 1) +#define FIELD_GET(_mask, _reg) \ + ({ \ + (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \ + }) + +/* + * Handle the PERF_RECORD_AUX_OUTPUT_HW_ID event. + * + * The payload associates the Trace ID and the CPU. + * The routine is tolerant of seeing multiple packets with the same associ= ation, + * but a CPU / Trace ID association changing during a session is an error. + */ +static int cs_etm__process_aux_output_hw_id(struct perf_session *session, + union perf_event *event) +{ + struct cs_etm_auxtrace *etm; + struct perf_sample sample; + struct int_node *inode; + struct evsel *evsel; + u64 *cpu_data; + u64 hw_id; + int cpu, version, err; + u8 trace_chan_id, curr_chan_id; + + /* extract and parse the HW ID */ + hw_id =3D event->aux_output_hw_id.hw_id; + version =3D FIELD_GET(CS_AUX_HW_ID_VERSION_MASK, hw_id); + trace_chan_id =3D FIELD_GET(CS_AUX_HW_ID_TRACE_ID_MASK, hw_id); + + /* check that we can handle this version */ + if (version > CS_AUX_HW_ID_CURR_VERSION) + return -EINVAL; + + /* get access to the etm metadata */ + etm =3D container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace); + if (!etm || !etm->metadata) + return -EINVAL; + + /* parse the sample to get the CPU */ + evsel =3D evlist__event2evsel(session->evlist, event); + if (!evsel) + return -EINVAL; + err =3D evsel__parse_sample(evsel, event, &sample); + if (err) + return err; + cpu =3D sample.cpu; + if (cpu =3D=3D -1) { + /* no CPU in the sample - possibly recorded with an old version of perf = */ + pr_err("CS_ETM: no CPU AUX_OUTPUT_HW_ID sample. Use compatible perf to r= ecord."); + return -EINVAL; + } + + /* + * look to see if the metadata contains a valid trace ID. + * if so we mapped it before and it must be the same as the ID in the pac= ket. + */ + cpu_data =3D etm->metadata[cpu]; + err =3D cs_etm__metadata_get_trace_id(&curr_chan_id, cpu_data); + if (err) + return err; + if (CS_IS_VALID_TRACE_ID(curr_chan_id) && (curr_chan_id !=3D trace_chan_i= d)) { + pr_err("CS_ETM: mismatch between CPU trace ID and HW_ID packet ID\n"); + return -EINVAL; + } + + /* next see if the ID is mapped to a CPU, and it matches the current CPU = */ + inode =3D intlist__find(traceid_list, trace_chan_id); + if (inode) { + cpu_data =3D inode->priv; + if ((int)cpu_data[CS_ETM_CPU] !=3D cpu) { + pr_err("CS_ETM: map mismatch between HW_ID packet CPU and Trace ID\n"); + return -EINVAL; + } + return 0; + } + + /* not one we've seen before - lets map it */ + err =3D cs_etm__map_trace_id(trace_chan_id, cpu_data); + if (err) + return err; + + /* + * if we are picking up the association from the packet, need to plug + * the correct trace ID into the metadata for setting up decoders later. + */ + err =3D cs_etm__metadata_set_trace_id(trace_chan_id, cpu_data); + return err; +} + void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, u8 trace_chan_id) { @@ -2433,6 +2566,8 @@ static int cs_etm__process_event(struct perf_session = *session, return cs_etm__process_itrace_start(etm, event); else if (event->header.type =3D=3D PERF_RECORD_SWITCH_CPU_WIDE) return cs_etm__process_switch_cpu_wide(etm, event); + else if (event->header.type =3D=3D PERF_RECORD_AUX_OUTPUT_HW_ID) + return cs_etm__process_aux_output_hw_id(session, event); =20 if (!etm->timeless_decoding && event->header.type =3D=3D PERF_RECORD_AUX)= { /* @@ -2662,7 +2797,7 @@ static void cs_etm__print_auxtrace_info(__u64 *val, i= nt num) 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) + else if (version =3D=3D 1 || version =3D=3D 2) err =3D cs_etm__print_cpu_metadata_v1(val, &i); if (err) return; @@ -2774,11 +2909,16 @@ static int cs_etm__queue_aux_fragment(struct perf_s= ession *session, off_t file_o } =20 /* - * In per-thread mode, CPU is set to -1, but TID will be set instead. See - * auxtrace_mmap_params__set_idx(). Return 'not found' if neither CPU nor= TID match. + * In per-thread mode, auxtrace CPU is set to -1, but TID will be set ins= tead. See + * auxtrace_mmap_params__set_idx(). However, the sample AUX event will co= ntain a + * CPU as we set this always for the AUX_OUTPUT_HW_ID event. + * So now compare only TIDs if auxtrace CPU is -1, and CPUs if auxtrace C= PU is not -1. + * Return 'not found' if mismatch. */ - if ((auxtrace_event->cpu =3D=3D (__u32) -1 && auxtrace_event->tid !=3D sa= mple->tid) || - auxtrace_event->cpu !=3D sample->cpu) + if (auxtrace_event->cpu =3D=3D (__u32) -1) { + if (auxtrace_event->tid !=3D sample->tid) + return 1; + } else if (auxtrace_event->cpu !=3D sample->cpu) return 1; =20 if (aux_event->flags & PERF_AUX_FLAG_OVERWRITE) { @@ -2827,6 +2967,15 @@ static int cs_etm__queue_aux_fragment(struct perf_se= ssion *session, off_t file_o return 1; } =20 +static int cs_etm__process_aux_hw_id_cb(struct perf_session *session, unio= n perf_event *event, + u64 offset __maybe_unused, void *data __maybe_unused) +{ + /* look to handle PERF_RECORD_AUX_OUTPUT_HW_ID early to ensure decoders c= an be set up */ + if (event->header.type =3D=3D PERF_RECORD_AUX_OUTPUT_HW_ID) + return cs_etm__process_aux_output_hw_id(session, event); + return 0; +} + static int cs_etm__queue_aux_records_cb(struct perf_session *session, unio= n perf_event *event, u64 offset __maybe_unused, void *data __maybe_unused) { @@ -3109,6 +3258,14 @@ int cs_etm__process_auxtrace_info(union perf_event *= event, if (err) goto err_delete_thread; =20 + /* scan for AUX_OUTPUT_HW_ID records */ + if (hdr_version >=3D CS_AUX_HW_ID_VERSION_MIN) { + err =3D perf_session__peek_events(session, session->header.data_offset, + session->header.data_size, + cs_etm__process_aux_hw_id_cb, NULL); + if (err) + goto err_delete_thread; + } err =3D cs_etm__queue_aux_records(session); if (err) goto err_delete_thread; --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 7C851C43334 for ; Mon, 4 Jul 2022 08:12:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233668AbiGDIMk (ORCPT ); Mon, 4 Jul 2022 04:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232950AbiGDIML (ORCPT ); Mon, 4 Jul 2022 04:12:11 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA651B48D for ; Mon, 4 Jul 2022 01:12:04 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id be14-20020a05600c1e8e00b003a04a458c54so5136451wmb.3 for ; Mon, 04 Jul 2022 01:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jVURNUygCeW21dF6Em3WQRHaxEsapZQYIGA6mQ8Wh5Q=; b=xtC6GuwCyAlyb/Zr988UgFE2vSgoZVJSqHHdAbdoCn2zXTTQ95bcxpfeRtuATBDlcR ugx4TMAyenDTPaFmGks19eHk2LlsMtEcga5TUTWYvyhDU2Dvo9P5JtDTEt34gXFV9o0d aQctUj7kAgLvyXixRFaCHlTUAQVingSCGnKW/5fNUHOGJQUWvGIz0AVwODty3IPI8JkG wEX8ibacACiG1/J5ABwyFx4tDjFtnrNVkSDJ4sSwUyGGEKiGsS/RnSHEJnXPmblXHWWO 3TbhXgvCiKMkwKNBTPRzkZt2hi503wi+9uD0dAWkczQ74VGxLRLAUkn/KD6QLW5AJ4iO cYzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jVURNUygCeW21dF6Em3WQRHaxEsapZQYIGA6mQ8Wh5Q=; b=w2xSrcFFYjcdrVHM5ChEmrDjUea9Qt8flOizxi4rZ89+Y4f0eRmuEK6DrTa1XgxjEn A1NohBlreCWwaBUSEjA2A71EBsxczhugXwqJGSylb7TRWWLb0Gy2ivD7cLlra9Nenim2 9ty9EfM2l0/byKz1lbxodVzhOJy2CoGJmyBAv14EDxOEbC9012gFBhGJDx1H8pBcaRQX 0T6IzFas/ZCZ2kpiGX3PSUlb8HjCCiOLF7Le66pDpJa9sbbXhICfTglgRwaRyXcrr2E8 91L0llTHPF86YdQIkjw+C8fDSfa9WX5NUAjp8DeaL/y/fKRFmKY9PVTLMZwNEKa6Z3fO 5zow== X-Gm-Message-State: AJIora8lh4LtKjmmS7Fis/E55H23f9YOW1cmdJIkkRPQCDxH7hCVXt+2 k10boMp9frQbuML6PWmFLd8Nf6isCYp95A== X-Google-Smtp-Source: AGRyM1vdQ5X/T4qTaulT8bVJRKWtoOJXrVUMmSl2XW9gC5Pqms/iIBwspD7l1h7ZCr/tZDOy9g/NTw== X-Received: by 2002:a05:600c:4e49:b0:3a0:4c17:c67f with SMTP id e9-20020a05600c4e4900b003a04c17c67fmr32310009wmq.1.1656922323276; Mon, 04 Jul 2022 01:12:03 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:12:02 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 12/13] coresight: events: PERF_RECORD_AUX_OUTPUT_HW_ID used for Trace ID Date: Mon, 4 Jul 2022 09:11:48 +0100 Message-Id: <20220704081149.16797-13-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" Use the perf_report_aux_output_id() call to output the CoreSight trace ID and associated CPU as a PERF_RECORD_AUX_OUTPUT_HW_ID record in the perf.data file. Signed-off-by: Mike Leach --- drivers/hwtracing/coresight/coresight-etm-perf.c | 10 ++++++++++ include/linux/coresight-pmu.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index ad3fdc07c60b..531f5d42272b 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -4,6 +4,7 @@ * Author: Mathieu Poirier */ =20 +#include #include #include #include @@ -437,6 +438,7 @@ static void etm_event_start(struct perf_event *event, i= nt flags) struct perf_output_handle *handle =3D &ctxt->handle; struct coresight_device *sink, *csdev =3D per_cpu(csdev_src, cpu); struct list_head *path; + u64 hw_id; =20 if (!csdev) goto fail; @@ -482,6 +484,11 @@ static void etm_event_start(struct perf_event *event, = int flags) if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF)) goto fail_disable_path; =20 + /* output cpu / trace ID in perf record */ + hw_id =3D FIELD_PREP(CS_AUX_HW_ID_VERSION_MASK, CS_AUX_HW_ID_CURR_VERSION= ) | + FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, coresight_trace_id_get_cpu_id(cpu= )); + perf_report_aux_output_id(event, hw_id); + out: /* Tell the perf core the event is alive */ event->hw.state =3D 0; @@ -600,6 +607,9 @@ static void etm_event_stop(struct perf_event *event, in= t mode) =20 /* Disabling the path make its elements available to other sessions */ coresight_disable_path(path); + + /* release the trace ID we read on event start */ + coresight_trace_id_put_cpu_id(cpu); } =20 static int etm_event_add(struct perf_event *event, int mode) diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h index 9f7ee380266b..5572d0e10822 100644 --- a/include/linux/coresight-pmu.h +++ b/include/linux/coresight-pmu.h @@ -7,6 +7,8 @@ #ifndef _LINUX_CORESIGHT_PMU_H #define _LINUX_CORESIGHT_PMU_H =20 +#include + #define CORESIGHT_ETM_PMU_NAME "cs_etm" =20 /* @@ -38,4 +40,16 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 =20 +/* + * Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. + * Used to associate a CPU with the CoreSight Trace ID. + * [63:16] - unused SBZ + * [15:08] - Trace ID + * [07:00] - Version + */ +#define CS_AUX_HW_ID_VERSION_MASK GENMASK_ULL(7, 0) +#define CS_AUX_HW_ID_TRACE_ID_MASK GENMASK_ULL(15, 8) + +#define CS_AUX_HW_ID_CURR_VERSION 0 + #endif --=20 2.17.1 From nobody Sun Apr 19 09:11:21 2026 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 60D95C433EF for ; Mon, 4 Jul 2022 08:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233674AbiGDIMm (ORCPT ); Mon, 4 Jul 2022 04:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233435AbiGDIMM (ORCPT ); Mon, 4 Jul 2022 04:12:12 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ED7BB493 for ; Mon, 4 Jul 2022 01:12:05 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id g39-20020a05600c4ca700b003a03ac7d540so7441813wmp.3 for ; Mon, 04 Jul 2022 01:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PTooRwbsdLD3OOIuzOYJzIkCxcUPBK7VZILGtwDxgv8=; b=PQ4bNkRRVNU2cYS7j7W1mfEhb+fKztLHPOlexnGD/LLD5abRR2eteBvUPs0dD8PpxK njYPHJncc7vU7yD8ODW5mtlpu6LExnSOvJxyJ4zuavRr7KMPVE1gLRwzzPBpacjopt3c rQ7Q1SQfFk7rTHU4MVAN5u62VHSuEpmSXQQiHuGNom8Q88Y9QJcAQz8CWHUNcga5Ogxk QkovaD/tjndCQHIZ1crG9I/i7IEWel3qBQzL9/bCO3J8n97eah+qDBJbyxybJMPeeuE3 6lNP2niosAGtY/8yYGxmt9MhxMFYofi164Y6r3s4mnQbMQKzt5qgGZeIZQ1gK/sVjj2e IBeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PTooRwbsdLD3OOIuzOYJzIkCxcUPBK7VZILGtwDxgv8=; b=1k0/N+4EEmk1hlv6c46QK4E6iWhIf71hfYOgtYG0WDZ8udjmu3OsJ/IyTE83Jhp5R6 2NjHZdxrfKs+28oiHKXaDPVUzX0+024HvnYO+1YGzGaoCNcnsWCfR+U8szqTkuu07InW UjVx/Ld/bgcmsqRCoUxIfzkLTGdMRgmycyl1E+r7+8Jc5BtGQLe0T9O5dcAzYGfUQdJv vFBvTguYvNldrsXaUmbFuu2EZ1xhyfCuh+hn2tbdFVUOJzCZGJa5xa/LfWxosZ7J+Fzu CKkwIwh/fl3Z6mG4ajq9CONEF1K+u6I4skFsgn6oDQY6fXr0j0y6phJt+yQl37uLumBy ZVaA== X-Gm-Message-State: AJIora98GTkIZF5+7KV3Q8p90MpiGVMs/lPCzFIojL1YdVIDptJUlcCP HRRaSuVKILcvrRp4xMPZn8FYBw== X-Google-Smtp-Source: AGRyM1tjEn71qrKmNMS7wp3T3S+d/t0dVPqKJQezpaQfm5B9v8Y+F+k95yPYU5LV/RIbsvx/NRnIZQ== X-Received: by 2002:a05:600c:1c21:b0:3a1:9608:1ffb with SMTP id j33-20020a05600c1c2100b003a196081ffbmr11837879wms.163.1656922324210; Mon, 04 Jul 2022 01:12:04 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:c4c4:4ed1:ae43:27f2]) by smtp.gmail.com with ESMTPSA id u3-20020adfdd43000000b0021d650e4df4sm4388276wrm.87.2022.07.04.01.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:12:03 -0700 (PDT) From: Mike Leach To: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, 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 v2 13/13] coresight: trace-id: Add debug & test macros to Trace ID allocation Date: Mon, 4 Jul 2022 09:11:49 +0100 Message-Id: <20220704081149.16797-14-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704081149.16797-1-mike.leach@linaro.org> References: <20220704081149.16797-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" Adds in a number of pr_debug macros to allow the debugging and test of the trace ID allocation system. Signed-off-by: Mike Leach --- .../hwtracing/coresight/coresight-trace-id.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwt= racing/coresight/coresight-trace-id.c index dac9c89ae00d..841307e0d899 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.c +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -71,6 +71,27 @@ static int coresight_trace_id_find_new_id(struct coresig= ht_trace_id_map *id_map) return id; } =20 +/* #define TRACE_ID_DEBUG 1 */ +#ifdef TRACE_ID_DEBUG +static void coresight_trace_id_dump_table(struct coresight_trace_id_map *i= d_map, + const char *func_name) +{ + /* currently 2 u64s are sufficient to hold all the ids */ + pr_debug("%s id_map::\n", func_name); + pr_debug("Avial=3D 0x%016lx%016lx\n", id_map->avail_ids[1], id_map->avail= _ids[0]); + pr_debug("Pend =3D 0x%016lx%016lx\n", id_map->pend_rel_ids[1], id_map->pe= nd_rel_ids[0]); +} +#define DUMP_ID_MAP(map) coresight_trace_id_dump_table(map, __func__) +#define DUMP_ID_CPU(cpu, id) pr_debug("%s called; cpu=3D%d, id=3D%d\n", _= _func__, cpu, id) +#define DUMP_ID(id) pr_debug("%s called; id=3D%d\n", __func__, id) +#define PERF_SESSION(n) pr_debug("%s perf count %d\n", __func__, n) +#else +#define DUMP_ID_MAP(map) +#define DUMP_ID(id) +#define DUMP_ID_CPU(cpu, id) +#define PERF_SESSION(n) +#endif + /* release all pending IDs for all current maps & clear CPU associations */ static void coresight_trace_id_release_all_pending(void) { @@ -81,6 +102,7 @@ static void coresight_trace_id_release_all_pending(void) clear_bit(bit, id_map->avail_ids); clear_bit(bit, id_map->pend_rel_ids); } + DUMP_ID_MAP(id_map); =20 for_each_possible_cpu(cpu) { if (per_cpu(cpu_ids, cpu).pend_rel) { @@ -126,6 +148,8 @@ static int coresight_trace_id_map_get_cpu_id(int cpu, s= truct coresight_trace_id_ =20 get_cpu_id_out: spin_unlock_irqrestore(&id_map_lock, flags); + DUMP_ID_CPU(cpu, id); + DUMP_ID_MAP(id_map); return id; } =20 @@ -151,6 +175,8 @@ static void coresight_trace_id_map_put_cpu_id(int cpu, = struct coresight_trace_id =20 put_cpu_id_out: spin_unlock_irqrestore(&id_map_lock, flags); + DUMP_ID_CPU(cpu, id); + DUMP_ID_MAP(id_map); } =20 static int coresight_trace_id_map_get_system_id(struct coresight_trace_id_= map *id_map) @@ -164,6 +190,8 @@ static int coresight_trace_id_map_get_system_id(struct = coresight_trace_id_map *i coresight_trace_id_set_inuse(id, id_map); spin_unlock_irqrestore(&id_map_lock, flags); =20 + DUMP_ID(id); + DUMP_ID_MAP(id_map); return id; } =20 @@ -174,6 +202,9 @@ static void coresight_trace_id_map_put_system_id(struct= coresight_trace_id_map * spin_lock_irqsave(&id_map_lock, flags); coresight_trace_id_clear_inuse(id, id_map); spin_unlock_irqrestore(&id_map_lock, flags); + + DUMP_ID(id); + DUMP_ID_MAP(id_map); } =20 /* API functions */ @@ -207,6 +238,7 @@ void coresight_trace_id_perf_start(void) =20 spin_lock_irqsave(&id_map_lock, flags); perf_cs_etm_session_active++; + PERF_SESSION(perf_cs_etm_session_active); spin_unlock_irqrestore(&id_map_lock, flags); } EXPORT_SYMBOL_GPL(coresight_trace_id_perf_start); @@ -217,6 +249,7 @@ void coresight_trace_id_perf_stop(void) =20 spin_lock_irqsave(&id_map_lock, flags); perf_cs_etm_session_active--; + PERF_SESSION(perf_cs_etm_session_active); if (!perf_cs_etm_session_active) coresight_trace_id_release_all_pending(); spin_unlock_irqrestore(&id_map_lock, flags); --=20 2.17.1