From nobody Tue Jun 23 08:14:51 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 800DCC433F5 for ; Tue, 8 Mar 2022 20:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350298AbiCHUvL (ORCPT ); Tue, 8 Mar 2022 15:51:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350271AbiCHUvF (ORCPT ); Tue, 8 Mar 2022 15:51:05 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77A9F329BD for ; Tue, 8 Mar 2022 12:50:07 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id q20so208770wmq.1 for ; Tue, 08 Mar 2022 12:50:07 -0800 (PST) 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=tkKeTpGeVj1TsD7lgtJxbN6dJOpPm7ZIDu/PMW+d2/s=; b=R3oKdAIGROO1nl4fOdOTEC6Y6ElvV4vaUf0h9EF5Q1a6tdeoQKHA8CkWpHSUNVsgEs ZHznJ5jZZ8GKxjZ2ELfs3+r37otMN+c95llQLujM9jvz2mWWNN2pYDq0a2pE34b/CxXU 6rJFepurHMqRcBEnqRRx4L7DMjnMYHb+gxHaG91CjEneKyPl0cfaHM8gXCa5B9ZK7ICh egqDwxIBpkTXEdtb1JGKu9HQ/Y3zMikdRGOraiJHtf7PgkdeHjcOZI+qpwCGMzN1yDcF 5rupO50giyNJukaFq0ErZUZsGL/9E/7x2tcURZfwEppmaS22VfYyL1tYw8tsPhurAzxB auiw== 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=tkKeTpGeVj1TsD7lgtJxbN6dJOpPm7ZIDu/PMW+d2/s=; b=CbAfa/X3hIkVuyZAmcJHZALml7PNmzVdrU3Emsa0vnnMZopFCqiaIjUudob14sxA2E IrShzDr0RckQgbev1y4kgzkn16crYuVJbR2HNHIYtuyAhqqUIXBM1vaBa6Ec8MqAmzat oxrZ+dkLorjKO7DUhm2BkTdG4fDfKhjEvtZY3i+kFmBaKnK++/fcGJQ/DWDK3X6mbobk /NOjIqhiGzX6B7o3k3F46NjbQxS8mwMmhzS+iq8XAhBbGDCFMJYtbAcDaKTdzIVQZkDJ oshEM14BjJOUgpeQohVO0uqbta7lJoJnetkvdRVGE/j1Sov+L/qBZ8ZNXmYp0EqXRnVK M7PQ== X-Gm-Message-State: AOAM531NsJmz9+dr0fXz9x+D1b15wigFhfyDmb+MebWwodHrwIJ9kBbQ eTUtJdth9yLpHMX+AKZhxYgwrLFZQv3Gfw== X-Google-Smtp-Source: ABdhPJw8VChYAWgMdUZF0BnRoSIIHmH8w2IlzDcL5mxMB0asBtDYymYVai84TCVfRZXFdq+sUBYuGQ== X-Received: by 2002:a1c:4b0e:0:b0:389:bf16:d8fb with SMTP id y14-20020a1c4b0e000000b00389bf16d8fbmr5094074wma.103.1646772605960; Tue, 08 Mar 2022 12:50:05 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:05 -0800 (PST) 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, Mike Leach Subject: [PATCH 01/10] coresight: trace-id: Add API to dynamically assign trace ID values Date: Tue, 8 Mar 2022 20:49:51 +0000 Message-Id: <20220308205000.27646-2-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 | 222 ++++++++++++++++++ .../hwtracing/coresight/coresight-trace-id.h | 69 ++++++ 3 files changed, 292 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..ce6c7d7b55d6 --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -0,0 +1,222 @@ +// 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; +}; + +/* maintain a record of the current mapping of cpu IDs */ +static DEFINE_PER_CPU(struct cpu_id_info, cpu_ids); + +/* a list of currently used id_maps */ +static LIST_HEAD(id_map_list); + +/* perf session active flag */ +static int perf_cs_etm_session_active; + +/* lock to protect id_map list 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; + int cpu, bit; + + list_for_each_entry(id_map, &id_map_list, node) { + 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; + } + } +} + +int coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_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) { + id =3D coresight_trace_id_find_new_id(id_map); + if (id < 0) + goto get_cpu_id_out; + } + + 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; +} +EXPORT_SYMBOL_GPL(coresight_trace_id_get_cpu_id); + +void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_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); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id); + +int coresight_trace_id_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; +} +EXPORT_SYMBOL_GPL(coresight_trace_id_get_system_id); + +void coresight_trace_id_put_system_id(struct coresight_trace_id_map *id_ma= p, 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); +} +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_id_map(struct coresight_trace_id_map *id_map) +{ + unsigned long flags; + 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); + + spin_lock_irqsave(&id_map_lock, flags); + + /* add id_map to the list */ + list_add(&id_map->node, &id_map_list); + + spin_unlock_irqrestore(&id_map_lock, flags); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_init_id_map); + +void coresight_trace_id_release_id_map(struct coresight_trace_id_map *id_m= ap) +{ + unsigned long flags; + + spin_lock_irqsave(&id_map_lock, flags); + + /* remove id_map from list */ + list_del(&id_map->node); + + spin_unlock_irqrestore(&id_map_lock, flags); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_release_id_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..01db2441cee6 --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-trace-id.h @@ -0,0 +1,69 @@ +/* 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. + * @node: List entry to add to list of managed trace id maps. + */ +struct coresight_trace_id_map { + DECLARE_BITMAP(avail_ids, CORESIGHT_TRACE_IDS_MAX); + DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); + struct list_head node; +}; + +/* Allocate and release IDs */ +int coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map *= id_map); +int coresight_trace_id_get_system_id(struct coresight_trace_id_map *id_map= ); +void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_map = *id_map); +void coresight_trace_id_put_system_id(struct coresight_trace_id_map *id_ma= p, int id); + +/* initialise ID map - block reserved IDs, add to list of ID maps */ +void coresight_trace_id_init_id_map(struct coresight_trace_id_map *id_map); +/* remove ID maps from list of maps */ +void coresight_trace_id_release_id_map(struct coresight_trace_id_map *id_m= ap); + +/* notifiers for perf session start and stop */ +void coresight_trace_id_perf_start(void); +void coresight_trace_id_perf_stop(void); + +#endif /* _CORESIGHT_TRACE_ID_H */ --=20 2.17.1 From nobody Tue Jun 23 08:14:51 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 45198C433EF for ; Tue, 8 Mar 2022 20:50:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350293AbiCHUvK (ORCPT ); Tue, 8 Mar 2022 15:51:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350274AbiCHUvF (ORCPT ); Tue, 8 Mar 2022 15:51:05 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3182432ED1 for ; Tue, 8 Mar 2022 12:50:08 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id k24so20957191wrd.7 for ; Tue, 08 Mar 2022 12:50:08 -0800 (PST) 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=LSx46Zr8CS5+IFp2YS6e6Ha2KieIvZZnjZpzZmpCaRc=; b=DKd1skywiEYI0uWSl4whWGPs1qJaVU0tgUMdx/rl+nePouWjVVzDg3uy8EiRce3+f+ 7yzBz83zfqUX6YHUi9tOyPa1k9jxBXjn5qdhTxnUXLKPzIDHMreRdzemfgV4vxrO7AXC y6yJRLCAS4dkGGN0MBvuyJZXoMGhsEBzX19izVvjuQdxxvyStOxHAXS1pcJgcZj9x/Ag 1nQDCprNuNnyFdvqveKnxpokO3qHKZhFv/vJq/zGp01AdAE4mS0pVHdK182R0sFKGOYC H3wQfvVWvIzSd1mM7styL1ujDtLC1sKnkNDRxZr8kV/ZlCayP/OAQFhEWytjhLfj7vR2 as2w== 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=LSx46Zr8CS5+IFp2YS6e6Ha2KieIvZZnjZpzZmpCaRc=; b=r2k8d7TV98nIEKePtzzYiHZLdjwdixlpM498bZvjAeHxU5l9E4ByRfgBPm0x2Sxqoq oukW1AN2KyyaUHriwl06vE1T8YL4I8n14E1g4nLs1XvDu9+UO1KvMktQEhS9eXtnewLR 2UdxLaxjPkOkEGL1iSBTJlyQqAvHJ9mlLvz14j5zwRPzRD3I4tSmQ8t0E7aVb+/dWGCo 0UT5fTWvWy7TtSR+xUKARz2nnpnOkOB09riFRCbfFR1RZX/zlyOGqYCQZSiv0GtA4qdu jD27EW3HhHuifIEwRIIJRzeNk9OfvjcfkBUUuYqr+ewU2BkK2wchf8+XfTFnqxjgzDJ8 3ZlA== X-Gm-Message-State: AOAM531T3VUFC3h8hp7xhTrOAS7uH0x+R2jZS5b6e76rGjT1Jgix4Vvw 7WZh8AVnn0ctZG2wWliDfR7Mkg== X-Google-Smtp-Source: ABdhPJyd7vwDkz1rPuDSK+nJGsWP1TastawOkho5vhwKTYa01x9JG6lgrXm0BwOOCtJ+IJesykYW0w== X-Received: by 2002:a5d:4811:0:b0:1f1:d736:4862 with SMTP id l17-20020a5d4811000000b001f1d7364862mr13771648wrq.147.1646772606714; Tue, 08 Mar 2022 12:50:06 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:06 -0800 (PST) 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, Mike Leach Subject: [PATCH 02/10] coresight: trace-id: Set up source trace ID map for system Date: Tue, 8 Mar 2022 20:49:52 +0000 Message-Id: <20220308205000.27646-3-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 CoreSight trace ID map for the entire system. 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 | 64 ++++++-------------- drivers/hwtracing/coresight/coresight-priv.h | 1 + 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index af00dca8d1ac..bbf415c252f9 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); @@ -50,6 +51,19 @@ static DEFINE_PER_CPU(struct list_head *, tracer_path); */ static struct list_head *stm_path; =20 +/* + * Set up a global trace ID map. + * We may need a per sink ID map in future for larger / multi sink systems. + */ +static struct coresight_trace_id_map trace_id_map; + +/* Allow drivers to reference ID map when getting trace IDs */ +struct coresight_trace_id_map *coresight_get_trace_id_map(void) +{ + return &trace_id_map; +} +EXPORT_SYMBOL_GPL(coresight_get_trace_id_map); + /* * When losing synchronisation a new barrier packet needs to be inserted a= t the * beginning of the data collected in a buffer. That way the decoder know= s that @@ -84,45 +98,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 +406,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); @@ -1763,11 +1732,15 @@ static int __init coresight_init(void) if (ret) goto exit_bus_unregister; =20 + /* initialise the trace ID map */ + coresight_trace_id_init_id_map(coresight_get_trace_id_map()); + /* initialise the coresight syscfg API */ ret =3D cscfg_init(); if (!ret) return 0; =20 + coresight_trace_id_release_id_map(coresight_get_trace_id_map()); etm_perf_exit(); exit_bus_unregister: bus_unregister(&coresight_bustype); @@ -1776,6 +1749,7 @@ static int __init coresight_init(void) =20 static void __exit coresight_exit(void) { + coresight_trace_id_release_id_map(coresight_get_trace_id_map()); cscfg_exit(); etm_perf_exit(); bus_unregister(&coresight_bustype); diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtraci= ng/coresight/coresight-priv.h index ff1dd2092ac5..d3032ac545c1 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -166,6 +166,7 @@ int coresight_make_links(struct coresight_device *orig, struct coresight_device *target); void coresight_remove_links(struct coresight_device *orig, struct coresight_connection *conn); +struct coresight_trace_id_map *coresight_get_trace_id_map(void); =20 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X) extern int etm_readl_cp14(u32 off, unsigned int *val); --=20 2.17.1 From nobody Tue Jun 23 08:14:51 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 A363DC433EF for ; Tue, 8 Mar 2022 20:50:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350304AbiCHUvO (ORCPT ); Tue, 8 Mar 2022 15:51:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350277AbiCHUvG (ORCPT ); Tue, 8 Mar 2022 15:51:06 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D50B333891 for ; Tue, 8 Mar 2022 12:50:08 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id r10so5143wrp.3 for ; Tue, 08 Mar 2022 12:50:08 -0800 (PST) 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=oYqW9DzD5vwTM1HoTzl1M8XZ0WUdjZwmOMUBLoaQedw=; b=kwI9hOE21xzvlIG6kdrnHeuEPF6g66blY3CFHrAc2UD8TeLvKhI54dUHCtSErqPWlE 5w1WxnMEH4u+uohEKCsPAAUqDzUdksImLm/W/JBEgRJmbrnlOLdk5jh5/+zlOfoxndrx 65dV41IyvoBzSlGLjXT7yKpFHl+E7YkVy1oa2YYMabq6+tYyCe2LeA4zxeRwG+HafaxU nvng3fPDRjKUzxZlKe0qQwmYcvLo+UWJLv2cZcRP7VM1nckq9rLT2Tp/sLrToNM7Xy9Y v6WBC47e65Yp72Py5aI/LefiN2/wqEnj+6E6gjl/AILmt2SchXe3uUycBx4hwKvnNEvz t20A== 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=oYqW9DzD5vwTM1HoTzl1M8XZ0WUdjZwmOMUBLoaQedw=; b=c5/vHYCK/KxzRiMf2BDyqiHu16ekMr6Oqt8sKAMm9Z+4zXD8DDrPGHmV7oOyR5ANJ0 A/RvsZLRGfGOTrmccCMUlXiz7B6qTJzO36ZM26hyh6z0oe/4cat3EfwLb1lh1+Xbpo1s Mk7izbubl+Y7y1aUDfTv3hMpwGg8yBnwTXD7pxjL/88u4DI8aiF5hc42z/ATEx01Yiza U3NKOw3K2xtYi+TMHrNR8mGAhdugCM2AcpFFA4vPTh31C+j/gXfE1qr/fO7ZRF8cyiHr LkUlOCb+STnDFleern+W5XdcMyajCm5QpoSk+FN8XHSqRSsCX0pBu747pBOTAUbmh7Ye muqg== X-Gm-Message-State: AOAM533KDKEIH+QKy5OD7fGAHyYZeC0b+bPJXQq9F2LFJ27kj63wQ+x7 XQGpMdbEtW7UiE1EZsobwRTqYw== X-Google-Smtp-Source: ABdhPJzKg0st+pjq2d0t8XXWYDVKnWlRHCW0ZEWuOCuqNDzl8hjHvkNfLUxdT3Aupg7aNHVRMe8zHA== X-Received: by 2002:a5d:68c3:0:b0:1f0:4b40:90f with SMTP id p3-20020a5d68c3000000b001f04b40090fmr13434737wrw.443.1646772607455; Tue, 08 Mar 2022 12:50:07 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:07 -0800 (PST) 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, Mike Leach Subject: [PATCH 03/10] coresight: stm: Update STM driver to use Trace ID api Date: Tue, 8 Mar 2022 20:49:53 +0000 Message-Id: <20220308205000.27646-4-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 --- 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..6c2c29ae99fe 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(coresight_get_trace_id_map(= )); + 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(coresight_get_trace_id_map(), drvdata->t= raceid); coresight_unregister(drvdata->csdev); =20 stm_unregister_device(&drvdata->stm); --=20 2.17.1 From nobody Tue Jun 23 08:14:51 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 80F81C433F5 for ; Tue, 8 Mar 2022 20:50:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350310AbiCHUvQ (ORCPT ); Tue, 8 Mar 2022 15:51:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350282AbiCHUvH (ORCPT ); Tue, 8 Mar 2022 15:51:07 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D07831528 for ; Tue, 8 Mar 2022 12:50:09 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id o18-20020a05600c4fd200b003826701f847so2146412wmq.4 for ; Tue, 08 Mar 2022 12:50:09 -0800 (PST) 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=PHSx/CGWMYUlu4wfKzSTY+tbrWqGA6GP82ZeBxk1Lzk=; b=FFxv76yzgplTv6GmbwjqP2KTAP0fO1pv6j9vKEfaNA7rjuHxVYNoqcO/hv3Kd38I6N 8V6f5WCHhE4xVDac3cAJ09smoBshtV2NA7Dz8jS2aWwm1e5QX0dUlN8+T5Ob4pYgidUr C8MyOlY/Cd4PJOJCUeX5DkcXPcH0ClvPqxvSP+3pa8+uUmtpTz6QcoG8NaD6ZGaCYP3y h3SHHWfn965L0dc8bFOzdsoQoWOVzrq0ONOxyMJQreSQCnvOWbVvbztEYimxmhDBkamn NKSmAuSRzMXLgDmTGtNaVcVpdZZWEUTkv37rC9BKeR1aKvf+aPnpbCmMGi/EhkRSAQp4 tpzA== 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=PHSx/CGWMYUlu4wfKzSTY+tbrWqGA6GP82ZeBxk1Lzk=; b=4WbdRPhjiCbu5czfq3O2zQS/a8LuZL1nHfcqOzziJPfBMPhhZbxeaEnq2bEYYqBDJC li3iOGp8Rq5Y7jab7wayP2PQIh7zufShB5JWiVeU2Z79TObqcC+Tj2lm1GwNn1Tz/J3C aui4q5eEaGa+Lcr2lpe2QhnSJWhM4Ddtr3eDWKjpSB2zcWTZ0K1JJ2Wk+9F64AZbJF2S XIRO+FtSF3P00GVemni8aXLZpcSwGi7P9RMBT0mntNZP0BXZHFFT/Bh2e6rGVN+TZI8i rYV81aoA4oYk4GE8kztSBNt6sHMczJLoaJuUVRqFwt/UXZJj7pBFyabAp5AgANrc50qD oLXg== X-Gm-Message-State: AOAM5308BP9iPoKQcrF8lPWLRjmY1BeDwqeb642miEKqC3/paJ2+SwMb uC60xClbk5haz+cu70WolzL1gA== X-Google-Smtp-Source: ABdhPJxuIeR2m4zNxfUyYASFYOKIh8/CDI0v7ZJC7WkpdaLt1APzLOJJGd+g+c1MY0JYa5bD9EkHBQ== X-Received: by 2002:a1c:7c0a:0:b0:389:8d53:260e with SMTP id x10-20020a1c7c0a000000b003898d53260emr857663wmc.69.1646772608200; Tue, 08 Mar 2022 12:50:08 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:07 -0800 (PST) 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, Mike Leach Subject: [PATCH 04/10] coresight: etm4x: Use trace ID API to dynamically allocate trace ID Date: Tue, 8 Mar 2022 20:49:54 +0000 Message-Id: <20220308205000.27646-5-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 | 63 +++++++++++++++++-- .../coresight/coresight-etm4x-sysfs.c | 32 +++++++++- drivers/hwtracing/coresight/coresight-etm4x.h | 3 + 3 files changed, 89 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/h= wtracing/coresight/coresight-etm4x-core.c index 7f416a12000e..aa7ea5ad8b06 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,36 @@ 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. + */ + trace_id =3D coresight_trace_id_get_cpu_id(drvdata->cpu, + coresight_get_trace_id_map()); + if (trace_id > 0) { + spin_lock(&drvdata->spinlock); + drvdata->trcid =3D (u8)trace_id; + spin_unlock(&drvdata->spinlock); + } else { + 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) +{ + coresight_trace_id_put_cpu_id(drvdata->cpu, + coresight_get_trace_id_map()); + spin_lock(&drvdata->spinlock); + drvdata->trcid =3D 0; + spin_unlock(&drvdata->spinlock); +} + struct etm4_enable_arg { struct etmv4_drvdata *drvdata; int rc; @@ -717,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; } @@ -739,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 /* @@ -756,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 @@ -883,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 @@ -908,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 @@ -1596,11 +1653,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; @@ -2005,7 +2057,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 21687cc1e4e2..bb69a203b833 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; @@ -2355,6 +2356,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; @@ -2491,7 +2517,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 3c4d69b096ca..64976a00c839 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -1010,4 +1010,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 Tue Jun 23 08:14:51 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 B19C6C433F5 for ; Tue, 8 Mar 2022 20:50:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344590AbiCHUvY (ORCPT ); Tue, 8 Mar 2022 15:51:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350287AbiCHUvH (ORCPT ); Tue, 8 Mar 2022 15:51:07 -0500 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 5F7CE3207D for ; Tue, 8 Mar 2022 12:50:10 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id n33-20020a05600c3ba100b003832caf7f3aso2004429wms.0 for ; Tue, 08 Mar 2022 12:50:10 -0800 (PST) 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=3UYsDt0yevSXQ6U7sc5n3heP9iPsGQbfHAheP1SRQC0=; b=auI060en4E3ZPAf8X25iTbQJE8jh5ycpsEJ5Q8k7glIQpTu8k3NDu6+Qv7ksLDRFxi 7tOUzoOCvNJDXLw42STAF1r+vkHThpNcFIEe7bOQ9/f89XwPXxexWwaew2CGGsRHF3eq qgjwsx72XgAmSrIs9mDQImHczWZSxZPsAcUfmAVM+ZosIfrxVQ4B+Rx/d+iEv5NBN+e4 xqnHbdf/ICU1VMl1Dp3NKNQUUrRqBGlQPxYsEKAtGNi0E5DJdZTBEwt2TG4p4Qx5NsaG RLTNPpCPB0ijF0HN4rX3O1RMFjP2iWHfmqjfnIT3LbAKzSpP3hcZZYLZOzH/bxtFE1wg a6JQ== 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=3UYsDt0yevSXQ6U7sc5n3heP9iPsGQbfHAheP1SRQC0=; b=yEkK8r0kuaAEKf760CS3j6VNyeJWMZ4fesYDiNSaVkjIfoMD7VaUh6kw4fLBTIs/nj 2N7Ba7rQuX7BLTbcA0T8ePymXnqhcjwMa4Sc7dPqbft5MMq1drT6STmOlflKLg4dSQk2 HEtNi+KrT7oHsFr+o/JF67GvlKr/OBAoA/TeYgiOVhJQ0BrEpqexSQT5ko/k1eWe/QrA VjuYh1GExpRXKv7BZsArjMKGoPRHl0Mq9+6AkxniNIS05CRqcWIRy0vZ/4VVqivxkGWQ PbuHu4p0I40WLXuplzmgwwhuvhzHByMY/GCJUEvGRuw1GFBAtMVRQkUH+3qavjyzvE/V sFGA== X-Gm-Message-State: AOAM532sHSlK5AZtozy/li7bOb2yEBklY+68peYyX0ol7YrtFtHe0Z09 Y62JspNZwH05vblK7JRlgzu3fg== X-Google-Smtp-Source: ABdhPJy4EpWC1e2s5DMrlTr7d8Uw23sh3sZffOhSADmfSzqqHMRWiAp9osQRbbcU/vCgll2yOS2sNg== X-Received: by 2002:a05:600c:b4d:b0:382:ab98:f470 with SMTP id k13-20020a05600c0b4d00b00382ab98f470mr890047wmr.8.1646772608956; Tue, 08 Mar 2022 12:50:08 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:08 -0800 (PST) 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, Mike Leach Subject: [PATCH 05/10] coresight: etm3x: Use trace ID API to allocate IDs Date: Tue, 8 Mar 2022 20:49:55 +0000 Message-Id: <20220308205000.27646-6-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 | 72 ++++++++++++++++--- .../coresight/coresight-etm3x-sysfs.c | 28 +++----- 3 files changed, 71 insertions(+), 31 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 7d413ba8b823..98213503bd09 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,57 @@ 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. + */ + trace_id =3D coresight_trace_id_get_cpu_id(drvdata->cpu, + coresight_get_trace_id_map()); + if (trace_id > 0) { + spin_lock(&drvdata->spinlock); + drvdata->traceid =3D (u8)trace_id; + spin_unlock(&drvdata->spinlock); + } else { + 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) +{ + coresight_trace_id_put_cpu_id(drvdata->cpu, + coresight_get_trace_id_map()); + spin_lock(&drvdata->spinlock); + 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 + ret =3D etm_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + /* Configure the tracer based on the session's specifics */ etm_parse_event_config(drvdata, event); /* 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 +550,10 @@ static int etm_enable_sysfs(struct coresight_device *c= sdev) struct etm_enable_arg arg =3D { }; int ret; =20 + ret =3D etm_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + spin_lock(&drvdata->spinlock); =20 /* @@ -532,6 +576,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 +657,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) @@ -781,11 +829,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 +914,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); @@ -891,10 +933,12 @@ static int etm_probe(struct amba_device *adev, const = struct amba_id *id) return PTR_ERR(drvdata->csdev); =20 ret =3D etm_perf_symlink(drvdata->csdev, true); - if (ret) { - coresight_unregister(drvdata->csdev); - return ret; - } + if (ret) + goto cs_unregister; + + ret =3D etm_read_alloc_trace_id(drvdata); + if (ret < 0) + goto cs_unregister; =20 etmdrvdata[drvdata->cpu] =3D drvdata; =20 @@ -907,6 +951,10 @@ static int etm_probe(struct amba_device *adev, const s= truct amba_id *id) } =20 return 0; + +cs_unregister: + coresight_unregister(drvdata->csdev); + return ret; } =20 static void clear_etmdrvdata(void *info) @@ -922,6 +970,8 @@ static void etm_remove(struct amba_device *adev) =20 etm_perf_symlink(drvdata->csdev, false); =20 + etm_release_trace_id(drvdata); + /* * Taking hotplug lock here to avoid racing between etm_remove and * CPU hotplug call backs. diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/= hwtracing/coresight/coresight-etm3x-sysfs.c index e8c7649f123e..3ee70b174240 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 Tue Jun 23 08:14:51 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 7D13CC433EF for ; Tue, 8 Mar 2022 20:50:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344101AbiCHUv2 (ORCPT ); Tue, 8 Mar 2022 15:51:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350283AbiCHUvI (ORCPT ); Tue, 8 Mar 2022 15:51:08 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4167231528 for ; Tue, 8 Mar 2022 12:50:11 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id j26so16591wrb.1 for ; Tue, 08 Mar 2022 12:50:11 -0800 (PST) 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=dJy0pQDaSOg6ATnrDsu3nm+8IQXiwbkO3KaKWIh49Fg=; b=wvuMmLT+F1MWoxrCIV8vR3igpSzRRRGPxcd7SkROFQl2o4JeVO/3Bjq+ZMX6lNEnOi 0axIxIE2KuvY2zmfWOcfb/Go4f1evSnclofHZOYBoykBb1aFg67AhOh7b5ESx2QfoMSl wfYT4qdM3UOr9kgOFMzZ5dV6TdWVLzy2vsDPLWv7X0rMAeyn+lbxbvpUH3JajCRiQ45K Lg3RzEv5FMje6+YSStoY8lDgkvIVv7yzkOqh47Np87VWnkJw3m5tlmuTinUr6I4hUxOY 8ac9y+Y7YXLXRcE8c4FK+hgh27i3Ioz62BiquIOoIxgT8SQ1ZbcSjXUp4lAVv24u9/vc n4xA== 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=dJy0pQDaSOg6ATnrDsu3nm+8IQXiwbkO3KaKWIh49Fg=; b=vHvIQJf/PXLisarc4fK873XB7/fIJcHvyBJaF7PD3CXaboa1NgBszeKZ9IW9VF5L7w CMeBSa5oN4hNEpLtm6kLJUOdeJX9zCg7lE+8iWouKJa2WTwbkNiSoeN3cGrqFvzTLk+7 PFkK2VrgbOq1hmYu39Egl14G2DqCQf7SjrOaUlCCuAJHnuNvBLwcPCGiVgX0GKaex3hb rlKq7PxIr9tebAWll5IOav2ah+uyR4sssqtvIRBQnB2PWNOqHgA14ruT3nh/tzEWhkzS zmjCA9UIyLKm0IOzGoTWBVfnxOU0HV7s1cYTjBqRfbE8chaBWmfZoxrZ2jNbLmTvx8hK ylpg== X-Gm-Message-State: AOAM532omcf3qVlkAzUKe5UXGlc0Q56pulV6pUYNg8kphPqSuPSV5Hr3 1VONcDAgoCAv9JMLEFrCtK1pWQ== X-Google-Smtp-Source: ABdhPJwrdYIm6NC2LtonrqL5iaAbZgZ0elUfWZnw8rLwjTiE05M4nIE0BpoE0G1LHn5PCawBIn3IxA== X-Received: by 2002:a5d:5850:0:b0:1f0:2d5b:dc35 with SMTP id i16-20020a5d5850000000b001f02d5bdc35mr13445051wrf.344.1646772609794; Tue, 08 Mar 2022 12:50:09 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:09 -0800 (PST) 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, Mike Leach Subject: [PATCH 06/10] coresight: perf: traceid: Add perf notifiers for trace ID Date: Tue, 8 Mar 2022 20:49:56 +0000 Message-Id: <20220308205000.27646-7-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 release when all perf sessions are complete. Signed-off-by: Mike Leach --- drivers/hwtracing/coresight/coresight-etm-perf.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index c039b6ae206f..008f9dac429d 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; @@ -223,11 +224,21 @@ static void free_event_data(struct work_struct *work) struct list_head **ppath; =20 ppath =3D etm_event_cpu_path_ptr(event_data, cpu); - if (!(IS_ERR_OR_NULL(*ppath))) + if (!(IS_ERR_OR_NULL(*ppath))) { coresight_release_path(*ppath); + /* + * perf may have read a trace id for a cpu, but never actually + * executed code on that cpu - which means the trace id would + * not release on disable. Re-release here to be sure. + */ + coresight_trace_id_put_cpu_id(cpu, coresight_get_trace_id_map()); + } *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 +325,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 Tue Jun 23 08:14:51 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 506BDC433F5 for ; Tue, 8 Mar 2022 20:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350347AbiCHUvi (ORCPT ); Tue, 8 Mar 2022 15:51:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243954AbiCHUvT (ORCPT ); Tue, 8 Mar 2022 15:51:19 -0500 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 F216133883 for ; Tue, 8 Mar 2022 12:50:11 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id u10so28802495wra.9 for ; Tue, 08 Mar 2022 12:50:11 -0800 (PST) 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=VVamIeahV8l6/c1hyhhpxgfx+OG8gkG+rm525YIuvz0=; b=FPhmT64PsgT9wEUvw9reJ1VNjnbBYXzxz89rDSMxHj2pErqkE+vZ5sLTVpe+Y0dC2A EDUC9kCJ4iirUpVLewKhc67YodUQY6ISeX49DeGg+2zOTKN6S2+0lH5MdVeTHSWwn5x/ ZvrwBWj121Y+mKNfHRoqLBeuE27YFyiCF5+vJ3MvGwT92k4dcWhs5NGVoKy5DYHvce/j 59ywsaaN7HIaCI4gbMvp72/Gc9WYWbC7toBET/d1J/AYVn6YsYe/vU1aMY31vAkxWJH9 8xJWWvJWpJUW8X6iqXsqxzfpMqqqdXWV5qdGBPGH8GgydqC89m4nmonMxDoEqsdVH6Yj FQvA== 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=VVamIeahV8l6/c1hyhhpxgfx+OG8gkG+rm525YIuvz0=; b=lO7oXiNovDPnOYJ8joUSNnAjuQdVzg5XUsWo1n2v/KgNtyGjhc7FPBz7vjPTVaTXCK 93ubmcbEeWOU+AdQlxRYwh+TO6zoLs5YWng3kgQmSCKnWzBPJEoI6+09gr1dJZEvvngp BEnmORYzvjdkpffUNDkUDQwAY6wZtFOhOOULtj5ZQtGs+pnjOtm0Q1mUL1/A/20hQXZ1 xbuceEeFxENs9fwV8Ctc1/yxE/3Hhcm72m26VVZClsuTdLQ3/am2mCZA4c8IMFsIncF4 3iTVN6DBExtXaMZ1VnbL5P84neRTxqwsd3NjwyCTkDa7VaNs2XL+bs9kFartGrumgJuX ENCg== X-Gm-Message-State: AOAM530hzoyEtJld9B5fEqrdm0Q4mF4ym7/j5O9qKIjcjGkEmOT+p8JE QVG3i1KcCNrifpnfdV5xUdCO8w== X-Google-Smtp-Source: ABdhPJyc0DjjNk0UnsK59psw4hHmQCTr0W+xIIc2VbXZ+sHbsFh0hrk8Z3A8GkXu5hVknJGx971TRw== X-Received: by 2002:adf:d1a8:0:b0:1f0:59c5:5e18 with SMTP id w8-20020adfd1a8000000b001f059c55e18mr13807188wrc.585.1646772610571; Tue, 08 Mar 2022 12:50:10 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:10 -0800 (PST) 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, Mike Leach Subject: [PATCH 07/10] perf: cs-etm: Update event to read trace ID from sysfs Date: Tue, 8 Mar 2022 20:49:57 +0000 Message-Id: <20220308205000.27646-8-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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" Read the current trace ID values associated with a CPU from sysfs. Previously used the static association algorithm that is no longer used as it did not scale and was broken for larger core counts. Signed-off-by: Mike Leach --- tools/perf/arch/arm/util/cs-etm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index 2e8b2c4365a0..f48087d07bcb 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -43,11 +43,13 @@ struct cs_etm_recording { }; =20 static const char *metadata_etmv3_ro[CS_ETM_PRIV_MAX] =3D { + [CS_ETM_ETMTRACEIDR] =3D "traceid", [CS_ETM_ETMCCER] =3D "mgmt/etmccer", [CS_ETM_ETMIDR] =3D "mgmt/etmidr", }; =20 static const char * const metadata_etmv4_ro[] =3D { + [CS_ETMV4_TRCTRACEIDR] =3D "mgmt/trctraceid", [CS_ETMV4_TRCIDR0] =3D "trcidr/trcidr0", [CS_ETMV4_TRCIDR1] =3D "trcidr/trcidr1", [CS_ETMV4_TRCIDR2] =3D "trcidr/trcidr2", @@ -629,8 +631,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); + /* Get traceID from the sysfs */ + data[CS_ETMV4_TRCTRACEIDR] =3D cs_etm_get_ro(cs_etm_pmu, cpu, + metadata_etmv4_ro[CS_ETMV4_TRCTRACEIDR]); /* 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]); @@ -677,9 +680,10 @@ 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 */ + /* Get traceID from sysfs */ info->priv[*offset + CS_ETM_ETMTRACEIDR] =3D - coresight_get_trace_id(cpu); + cs_etm_get_ro(cs_etm_pmu, cpu, + metadata_etmv3_ro[CS_ETM_ETMTRACEIDR]); /* 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 Tue Jun 23 08:14:51 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 D5AD6C433F5 for ; Tue, 8 Mar 2022 20:50:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350312AbiCHUvc (ORCPT ); Tue, 8 Mar 2022 15:51:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350121AbiCHUvU (ORCPT ); Tue, 8 Mar 2022 15:51:20 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA8CD33E01 for ; Tue, 8 Mar 2022 12:50:12 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id h15so6077304wrc.6 for ; Tue, 08 Mar 2022 12:50:12 -0800 (PST) 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=Sw4xwZRTTjBJM4wcsTZt554bc360dKae0Yk+cjG+3LM=; b=VovctRatE/Hh/GbXDnfGoZ7kGZelTUslgwp4Sr6q2UrJWHkCaO6RSfDfl4AMzv13JX tpRiLWLlhDDJ4PRVMp5J3dj/yvSuyaHxdzAoEX9qHPlVAyQsGnltVOxnjroBs91k9Y0H SfZgQm5YTJVvrJfij2goljk0j4JVm+BpUKq+d8VTuCd4ZDdPVqJ/0RIWJSATf29tKmAC bfSy+KN0am/pKhXgICoe9gGBanbaSd6Y3WlQGFslO7tCwEm/sU79DQiV6c9l9hWd9RmO FE4CRw57GkoAn2UysKML38x61E22SMbG2iUVlXa5jnNTyTRoUYgByjQxVIemEEa6c9MK sSGA== 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=Sw4xwZRTTjBJM4wcsTZt554bc360dKae0Yk+cjG+3LM=; b=NkLrW2KBV3PNJjZdn7sFc5LbHxMtxK4x7iWztiymNeS26WKQAGXnepIEI/Klkry4Hn HQlE91go1pRNiaG5gSG5fr3vZYGWZC4gHiMJiI0Fl+uTrdsy8w9EUjXOnNgTTEiX4zPw unX1JAUuKF/xsuvVpZCaNh31fRti5D3LZz1uQ5U5uRe4HAHT4nlziQ8MvVvYQ2M0FkPy KlRxaGXP2HGSbepFqfd69KNsC/dS4SnAFwGLsfWaZeR+8OmVN87HZrFgeZvddgPlPeuU TPcx2zRS6mKBRzbEkBH6jvVHdudh71qlYMFfnSl6u0Gw0db90YeOdnlyAAsluFHZxNm+ a+WQ== X-Gm-Message-State: AOAM5302zFFyM1odBi9dquqFoHQKkOCKFbY1PJ563NzcH/06qGhY0yh4 x55RSZnAbM2iq1WlhCeCuWu2gQ== X-Google-Smtp-Source: ABdhPJxXSIbBxcT9dt3sJvdZKh8iPGJdFd/p52e4WRJecsc9Nrorp/W6kWWMjyBtM1B3Y6peeKsZgg== X-Received: by 2002:a5d:4892:0:b0:1ed:beaa:778a with SMTP id g18-20020a5d4892000000b001edbeaa778amr13409236wrq.35.1646772611303; Tue, 08 Mar 2022 12:50:11 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:11 -0800 (PST) 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, Mike Leach Subject: [PATCH 08/10] coresight: Remove legacy Trace ID allocation mechanism Date: Tue, 8 Mar 2022 20:49:58 +0000 Message-Id: <20220308205000.27646-9-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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" This static 'cpu * 2 + seed' was outdated and broken for systems with high core counts (>46). This has been replaced by a dynamic allocation system. Signed-off-by: Mike Leach --- include/linux/coresight-pmu.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h index 4ac5c081af93..bb4eb4de3c77 100644 --- a/include/linux/coresight-pmu.h +++ b/include/linux/coresight-pmu.h @@ -8,7 +8,6 @@ #define _LINUX_CORESIGHT_PMU_H =20 #define CORESIGHT_ETM_PMU_NAME "cs_etm" -#define CORESIGHT_ETM_PMU_SEED 0x10 =20 /* * Below are the definition of bit offsets for perf option, and works as @@ -32,15 +31,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 --=20 2.17.1 From nobody Tue Jun 23 08:14:51 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 58C63C433EF for ; Tue, 8 Mar 2022 20:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350374AbiCHUvq (ORCPT ); Tue, 8 Mar 2022 15:51:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350317AbiCHUvU (ORCPT ); Tue, 8 Mar 2022 15:51:20 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D60136E37 for ; Tue, 8 Mar 2022 12:50:13 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id l1-20020a05600c4f0100b00389645443d2so296116wmq.2 for ; Tue, 08 Mar 2022 12:50:13 -0800 (PST) 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=MM4EmkpbqCFdFxxd9GgbYGC5CZg14rKLljTmThXZPjg=; b=sR2qDcSTn/QrrRvC7tDPq3cB3qglIulDBC4pwgEW6YgF+zTEPRRMsvD/qAkX27iW4G t019Neq/9RrAIlHrw3dmUqJuh7L5/K46d01FZXPASJiSwMPJFqLImoD7Mu59Pe/C4mLC aoFVcfi3ZDRixHISwKhYkgTD64xfyDCCf1rh5Uv6qzvtVjI0t2gKR/7Mve1mdfen22gm pM4di5EsTmJPwqAiAoT6VO43/v1P113xqJIYoRgWbTR3xJs5YtAkLQqa2gZd1IExO/k7 6IZlsv2Qh1gTg8GXdFgkgeVhE+rqG9Z2PDFT2edl5VKN1h4Wvt92ZNiFmYtDwyhrr3Bg Qt+w== 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=MM4EmkpbqCFdFxxd9GgbYGC5CZg14rKLljTmThXZPjg=; b=qWNn3SNoEKmq7Rn20Xs9/IgMmtdY9DvzgoWgGjPx6op8P2tWPxaU/0ehdmNaRMJbwZ VcRSZycBzJJKJFFJSL4NuyLZ3AWMhEuAZ4BMmmIYq3I0WA1elq5EG396s01AtpcfAATC D+VfMbQsQZeNkz4jDsABgdCco9E93RQAnau1ec/LSZG3NuywGFwoeQbjkpTlkDbY5jCn HehiJw0tVujGCvZXwhdhpcHFuhY9llYDr4p3B0iQXS8yzSLawek4XD4SDmmFx3p+H1Q2 CSPZF9xiK86q04Meubka9fNq+V9s0UpuWO+sgME0oy6xCsLc3FxnHH9amg06kG5ZR1fs +C1A== X-Gm-Message-State: AOAM533Nv4IssvDDFPm5VRLRYUiG0LzWDMzgFkvhMg5PMFnfJRMOjrmu rOp8OKx32EColyDXIhzjTEYxGg== X-Google-Smtp-Source: ABdhPJzGFhXp/2CodsJvLCxofK1VbSGwJL/tOn4J0/ZvBH8o4nrDRRmiNjEJ3mSythvPL0q2EYQ1Gw== X-Received: by 2002:a1c:7302:0:b0:381:1f9a:a22b with SMTP id d2-20020a1c7302000000b003811f9aa22bmr884036wmb.78.1646772612033; Tue, 08 Mar 2022 12:50:12 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:11 -0800 (PST) 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, Mike Leach Subject: [PATCH 09/10] coresight: etmX.X: stm: Remove unused legacy source trace ID ops Date: Tue, 8 Mar 2022 20:49:59 +0000 Message-Id: <20220308205000.27646-10-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 --- 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 98213503bd09..4cfb8ed699df 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; @@ -719,7 +683,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 aa7ea5ad8b06..565947de702a 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 6c2c29ae99fe..6aa6eb9e4090 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 Tue Jun 23 08:14:51 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 EDDB6C433EF for ; Tue, 8 Mar 2022 20:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350357AbiCHUvw (ORCPT ); Tue, 8 Mar 2022 15:51:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350318AbiCHUvU (ORCPT ); Tue, 8 Mar 2022 15:51:20 -0500 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 451A539808 for ; Tue, 8 Mar 2022 12:50:14 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id v2-20020a7bcb42000000b0037b9d960079so2185020wmj.0 for ; Tue, 08 Mar 2022 12:50:14 -0800 (PST) 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=Xe7R99xlGwoKuAS3wrEqyXZp3yI8XEYJM9lw/vO8NYg=; b=tYKOgv1979h8LZb91Na6znYmERgLvMDR7BoDXLdax/BqQ5weQ/1uUEHgSLUszHDlD7 jpvArASGGFcjWsazR23WkbFIGp+xXkEte8YuhAToaW5OLSP8xUQVzqBWShV7CYRFC17I iotPeM9M2Jfz4jVPc19tYkhb9putbA5hNz75MLVcwyGZNVpKrWPFGP83qWNa+2M3hOKX XYneBkZHPwRMyIH6fDSG6Eg/noA3nnO3qgQU9KZM9ItcnNb0kKp/+C28SKCP1sV3sGF4 y2EFsy1+PuyjUcr/V99Sygk36cNEsxI12lislEK8hOhFdYc8LaEukpEzATYfuyL3IRNn MwUg== 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=Xe7R99xlGwoKuAS3wrEqyXZp3yI8XEYJM9lw/vO8NYg=; b=DXFIO0nHIbyh9UExfkIzenbDvOFtcrzxqKto5wUQFp9nVGLFqKlPSyrwN6sBQqno4i +umlPXLbvsksmucMmOerbmtFapQjFZ3vaCOdoUAM4/+U+DQsxByWVVtDOOOpCSJabKbd pGX7sj0RdwdbrNKoVm4Ef49vl5BqpRRUJJjGi3niZRqxMs+WMqiy/XVRhY4I/wlqe1Cx aH7nMhmQT9rMFfVzpMFbrd7D2u4QBC4uw5+eq7E56hVrhXWO0uVssghHaoz2IaTPSQGg 7elHE9BuM7YTteyToBuPTokF6TzboOO+wA/wm18xaRbMKSXLoRoRbobxuEd3DkW4lE3z rcsA== X-Gm-Message-State: AOAM532PjxN5dz60slgy+n4WzudxNIGMmmIVIirL3Wm43GjK/G4QBG49 rhgJ4MZy33P8Gy5KxlFqwjnf2A== X-Google-Smtp-Source: ABdhPJxCHJnxJZE/r6ZL7nJ0y7w9OoRJ4o+m2KyamsuT/8NnTRDXGrRnqDN1KOnJRNiJide62pdVkA== X-Received: by 2002:a05:600c:3ac3:b0:389:adb4:e7a1 with SMTP id d3-20020a05600c3ac300b00389adb4e7a1mr852701wms.136.1646772612778; Tue, 08 Mar 2022 12:50:12 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id p26-20020a1c741a000000b00389ab9a53c8sm3245758wmc.36.2022.03.08.12.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 12:50:12 -0800 (PST) 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, Mike Leach Subject: [PATCH 10/10] coresight: trace-id: Add debug & test macros to trace id allocation Date: Tue, 8 Mar 2022 20:50:00 +0000 Message-Id: <20220308205000.27646-11-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308205000.27646-1-mike.leach@linaro.org> References: <20220308205000.27646-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 ce6c7d7b55d6..8dcb698b8899 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) { @@ -82,6 +103,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) { @@ -112,6 +134,8 @@ int coresight_trace_id_get_cpu_id(int cpu, struct cores= ight_trace_id_map *id_map =20 get_cpu_id_out: spin_unlock_irqrestore(&id_map_lock, flags); + DUMP_ID_CPU(cpu, id); + DUMP_ID_MAP(id_map); return id; } EXPORT_SYMBOL_GPL(coresight_trace_id_get_cpu_id); @@ -138,6 +162,8 @@ void coresight_trace_id_put_cpu_id(int cpu, struct core= sight_trace_id_map *id_ma =20 put_cpu_id_out: spin_unlock_irqrestore(&id_map_lock, flags); + DUMP_ID_CPU(cpu, id); + DUMP_ID_MAP(id_map); } EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id); =20 @@ -152,6 +178,8 @@ int coresight_trace_id_get_system_id(struct coresight_t= race_id_map *id_map) 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; } EXPORT_SYMBOL_GPL(coresight_trace_id_get_system_id); @@ -163,6 +191,9 @@ void coresight_trace_id_put_system_id(struct coresight_= trace_id_map *id_map, int 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); } EXPORT_SYMBOL_GPL(coresight_trace_id_put_system_id); =20 @@ -172,6 +203,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); @@ -182,6 +214,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