From patchwork Mon Jul 4 08:11:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904832 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AED4C43334 for ; Mon, 4 Jul 2022 08:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=C2jKso9mpxP1kBFmjhsmOQLReqGLC74LzrxL3+vB8gE=; b=Pncr5GlhbCAz1c 0LoOPI3Y5kBs+EGeO4sRJ7ryOLRwNiZ90DUFlAmXw4kWRQebvm0nGEm+/hHQlS70i9qS8PKdWdiDl S2hy/j6SG23KTIrxmh8fw3yr96a4FKjhcZZUj4Pamo0lZ5LEBO8hI1tmIh6Jt6btIushYjbJVD0+2 AgcWG5wbXvG4KtQ/cHo4Nifm78nzzH0yfyVfPl0OlksjlZLdvPL9B40kjY+6j0Lo7EbHINHQjYu6f 4HWqdjNFdd+a2riYwAb/6Dk+7bgoNi0qZSw5kegHo9SZphaAvMhbtLA1hL5CQljgH0MFvnVOM/P55 2zAFD/eNcN2+Y5zRtJiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HC9-005y6x-Am; Mon, 04 Jul 2022 08:12:37 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBW-005xke-Vv for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:04 +0000 Received: by mail-wr1-x429.google.com with SMTP id r14so6482191wrg.1 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=e0z5QkS94n4oCSlYcqmXqjq22bCKA2zuvT4wF3tPQgrI2khl3l7slnHNrvcky+kp6+ 5ZNDP1Ew5T/I2FUQSTHRzMEwluwPqldiwVRjqqvKnA5x8b7Ds8u0rVgsr+4Wyco+UVr0 cKG18yjzXjEV94BHAG/sV+D4SCmVyxVSfYrrKAS0F746Ikuw12e/HKchLwuOs61QNgoi gG13msD0SzwKWTpUlI3Y+TBwMjfWP1eRo3WnymWYNfcSNEW9xp8iUPtCgIjzWFbq/6ba Es3BpuZawGxozsd3snUWcLVQE0/u/SJmS8OviBkNSFEj7NfN1V3u8yDveAJq/bpUMO73 qv1w== X-Gm-Message-State: AJIora+O0Jy1NGP9/UgDVCeoxTIvgRDS4nWoXZMQ+hbu42boVNiRP5TQ dD8uUTNsuun5pEz8xTrYOlCuCw== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011159_109891_33B10703 X-CRM114-Status: GOOD ( 32.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/coresight/Makefile index b6c4a48140ec..329a0c704b87 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -6,7 +6,7 @@ obj-$(CONFIG_CORESIGHT) += coresight.o coresight-y := 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) += coresight-tmc.o coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \ coresight-tmc-etr.o diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwtracing/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 mappings */ +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_trace_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 *id_map) +{ + int id; + + id = find_first_zero_bit(id_map->avail_ids, CORESIGHT_TRACE_IDS_MAX); + if (id >= CORESIGHT_TRACE_IDS_MAX) + id = -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 = &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 = false; + per_cpu(cpu_ids, cpu).id = 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 = CORESIGHT_TRACE_ID_RES_RANGE_LO; + bit <= 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_trace_id_map *id_map) +{ + unsigned long flags; + int id; + + spin_lock_irqsave(&id_map_lock, flags); + + /* check for existing allocation for this CPU */ + id = per_cpu(cpu_ids, cpu).id; + if (id) + goto get_cpu_id_out; + + /* find a new ID */ + id = 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 = id; + per_cpu(cpu_ids, cpu).pend_rel = 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_trace_id_map *id_map) +{ + unsigned long flags; + int id; + + spin_lock_irqsave(&id_map_lock, flags); + id = 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 = true; + } else { + /* otherwise clear id */ + coresight_trace_id_clear_inuse(id, id_map); + per_cpu(cpu_ids, cpu).id = 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 = 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/hwtracing/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 = 0) and in use (bit = 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 during 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 */ From patchwork Mon Jul 4 08:11:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904830 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0DAC5C433EF for ; Mon, 4 Jul 2022 08:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4hyvrlxyUBhM8SsHOtHm8Kva3lE/aQkqXdv9tbxnugs=; b=43GR3bbc4oDsYN f+LrmkqwhziFWJM/NWxGEEjFXJqnO8U558zYmAGbgXD+EoAvUkW0RTM0u1kOjiZxwWUQQHmpMhaPi 5MrIX2U8MwM+B+NmSL5WO3b6t7AD6t4QaDxTyS32RWOi7MJVVwT67oyz8Fp+Nj7rb4zC68ocdsAOk K4nK3ATWbpO7cH7hCAWEO8UfkR5qvl+PbLvyJ3yp9ybrUCIloHOGzl395WUmOv6j8yJcs9OhXMaKM yUWPwuu57OvCJqBmiNcfQA7OAXGQouCP5Y1iKGm5qTqf89AnAjYZK3W28pzlHadL+avKl5L7ycwt7 UZ5FVrQFuvWargkrWYwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBo-005xyD-Oe; Mon, 04 Jul 2022 08:12:16 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBW-005xlN-Vm for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:02 +0000 Received: by mail-wm1-x333.google.com with SMTP id n185so4890191wmn.4 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=NOhLRQ+8Ob47sctE5X2Isyc8j5R5T2c/0gFtGZT5rxbCxtRLYsgFC/SKf/4VSdGqpa ubxQK1Sj19xhi6Ajs0+7rc26dEVLpt1y4rWIXS4e0d9GBQduzmu+0Gb0asYJtAwgAqw5 t4o7ufvRfY6paNbOWgmLAxs4GKJkC/3NN22JAWsZFJngzaMRA9xqJPuDbYyN7rZD0FmY OLGA4vzdsZPQh3RCgmqcCXh3+JvH3xTT8ya07snDmxAwVF0pEguyF+e+mbob+jGWOU6/ bBeRy0jNEC7lwh4yxPqiwi1nIhfNi93V86wFAkLjiJVORhkhYVDpj1ZRxJBYewZlkTBe dFpQ== X-Gm-Message-State: AJIora9oQ7qIRs/xneHusfOwCJdViqhvf5ssU1LQDFppYOO9wuZmD1kw ZcwwuJ+hOHwZr9l+pmS/n1/VYg== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011159_104789_7EC6CCC5 X-CRM114-Status: GOOD ( 18.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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" 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 cpu) } EXPORT_SYMBOL_GPL(coresight_get_percpu_sink); -static int coresight_id_match(struct device *dev, void *data) -{ - int trace_id, i_trace_id; - struct coresight_device *csdev, *i_csdev; - - csdev = data; - i_csdev = to_coresight_device(dev); - - /* - * No need to care about oneself and components that are not - * sources or not enabled - */ - if (i_csdev == csdev || !i_csdev->enable || - i_csdev->type != CORESIGHT_DEV_TYPE_SOURCE) - return 0; - - /* Get the source ID for both components */ - trace_id = source_ops(csdev)->trace_id(csdev); - i_trace_id = source_ops(i_csdev)->trace_id(i_csdev); - - /* All you need is one */ - if (trace_id == i_trace_id) - return 1; - - return 0; -} - -static int coresight_source_is_unique(struct coresight_device *csdev) -{ - int trace_id = 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_device *csdev, u32 mode) { int ret; - 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 = coresight_control_assoc_ectdev(csdev, true); @@ -1775,6 +1731,9 @@ static int __init coresight_init(void) if (ret) goto exit_bus_unregister; + /* initialise the default trace ID map */ + coresight_trace_id_init_default_map(); + /* initialise the coresight syscfg API */ ret = cscfg_init(); if (!ret) From patchwork Mon Jul 4 08:11:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904833 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6FFEDC433EF for ; Mon, 4 Jul 2022 08:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mdrVHsDdvtMoEMpLbnKEHFsrnVT08x0HR99vG947BAE=; b=fLHSlzpnuu7c+T rw4d7JIhXi8user5xi02zuVfvGe03gbFcT9cpMEdb3cywrLVGdcLDGeL1O2hTPjUNPOuvZBecllS1 z737LydeKT7RDrM2eonKYM88yBOTqJME6qKTs+xdYPZzzRr+IcProh8LamVVTIzOaI9he3XUJmHHt wkduezW0U+o3WMegpJjA+QD3FFZ4KhS0w9Fg7lD7f2/ltMj8Jyw38mH7ycq1Ld8n9nHNWzgXyl6QD +ajLNTtGKDiIngrPdIYNZc5CpzdLQAUTRW5XmfOJ3150cSE8XzXjCIGJl8s+OB+UIPlOeIqqPh/rL IErQf8MFfOx/6EY9znMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HCO-005yDi-HR; Mon, 04 Jul 2022 08:12:53 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBY-005xld-0g for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:04 +0000 Received: by mail-wm1-x32f.google.com with SMTP id l68so4897239wml.3 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=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=aSn7TNe0og9BepURjPcBqFsnFKpEXVq+4jkbFt+R6RdN7vOyaf3StNZPxk7KwR3krH MiFIqlfd1jTrGLr5CuJdw9bnj4D+ABFsTORnNO0vic5q/NQTkTLdBxoAfdX4Yv6SMWvu Q6+C5trI28k4Z7rPGonRgkQgQmGS6HRC7gV7ctK9+TaFFwENBpz70rhVhv/CnF/2QeGv HSPtF82L7PG7UaRKt+L/d+F2cp/KpiUp63gDgtCGkGfyHuv38TZIw550bUVNiE5/6XPR Zy5/2JmQd/c8ZBdgXnb1WXqEnuWgo5uwBZh2GdqecUIcyQI4QZlLIfNtq0btO2mpZdqy NFIA== X-Gm-Message-State: AJIora+fPdF/Qw5W5574tMwnUPdqhfqHNFPBS4zjGzb48vb+ikEGJUKX 0WrZq075syhk7U/cvvoOT1M9qw== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011200_112137_6FB5B7B7 X-CRM114-Status: GOOD ( 21.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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 #include "coresight-priv.h" +#include "coresight-trace-id.h" #define STMDMASTARTR 0xc04 #define STMDMASTOPR 0xc08 @@ -615,24 +616,7 @@ static ssize_t traceid_show(struct device *dev, val = 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 = dev_get_drvdata(dev->parent); - - ret = kstrtoul(buf, 16, &val); - if (ret) - return ret; - - /* traceid field is 7bit wide on STM32 */ - drvdata->traceid = val & 0x7f; - return size; -} -static DEVICE_ATTR_RW(traceid); +static DEVICE_ATTR_RO(traceid); #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 = ~0x0; - /* - * 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 = 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 *drvdata, 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 = &adev->dev; struct coresight_platform_data *pdata = NULL; @@ -938,12 +914,22 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id) goto stm_unregister; } + trace_id = coresight_trace_id_get_system_id(); + if (trace_id < 0) { + ret = trace_id; + goto cs_unregister; + } + drvdata->traceid = (u8)trace_id; + pm_runtime_put(&adev->dev); dev_info(&drvdata->csdev->dev, "%s initialized\n", (char *)coresight_get_uci_data(id)); return 0; +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 = dev_get_drvdata(&adev->dev); + coresight_trace_id_put_system_id(drvdata->traceid); coresight_unregister(drvdata->csdev); stm_unregister_device(&drvdata->stm); From patchwork Mon Jul 4 08:11:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904834 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B574C43334 for ; Mon, 4 Jul 2022 08:14:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eRdm1vvFWa7CxiUrgvkp77kavi+KiPPbetsHk8/wVlg=; b=UrhR/nY5m6fPJR 4KWSflCp+WAjrVN4ooJ/2/gkgdeU01Pk7QVurCevb5FSX2rXnpsZFA1o8zaCP6+lGI/JdIm30bWVb BWasIWZcdaRUi7xDg9kd/RqyY5daZ4FbTdXVAqT9s5Fb7A6CNQ5XhrLBg9jwmVdt5+KBVp5wTqzVg 64dcI7l07aNMO5U9P9Yaau7fqBfg2wzLuNsROnhYFYWp3tYUAkHrWl8d8bmGNwUR+ycDeLRhuFCKe Jzu8vA+dlJMyAL1tby9qxmjN5c1mLQdb7Emqm3FxxUGZm4jWIKIEJihIHO3fsqRFAfVK+8R1lYJdj doAEuwKZ3UfUXTstyQmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HCj-005yP2-Qk; Mon, 04 Jul 2022 08:13:14 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBZ-005xly-1h for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:06 +0000 Received: by mail-wr1-x430.google.com with SMTP id o4so12281930wrh.3 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=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=RdhzOWwDcRfO+ByJrkBF4rm8itXtw1CNs6YFIRx2ishZE4GADySFOk1r5SQg+xDNJE GnpHG69+9jG3h9GkjpE3fV9Is6Qm3B0w0KdK3swb6YXUkdFLCg40+cBbRHtoAO1rK8dS f6A4xPAbCPZjSgckjNE4BISzfToDtm8IYdhszieENK2NVkZ7lRNqIwL/i+DOyssJsTsN GTWSQhT6Z+7i+8Bk8EJZ/Eq398Uqz2+q7XR1+hq+Bj4BKKiQhMmn1sBv40gryaIDdnnJ SjwoiTCikpD/ZhtyrN7XhpcJx/54PHOLcsNtwQCrMkpRp6bZrJgK4Lb85Y7uug5vTd1T jyQg== X-Gm-Message-State: AJIora9CXbkYl/gFoFe809QgJX+g8i1PAI3wIMPKUQu4L7QCUuEi3JK8 eRvgXwav4AtQo3L62vznwVMIhQ== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011201_182049_EEF86170 X-CRM114-Status: GOOD ( 26.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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" static int boot_enable; module_param(boot_enable, int, 0444); @@ -234,6 +235,38 @@ static int etm4_trace_id(struct coresight_device *csdev) return drvdata->trcid; } +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 = drvdata->trcid; + if (!trace_id) { + trace_id = coresight_trace_id_get_cpu_id(drvdata->cpu); + if (trace_id > 0) + drvdata->trcid = (u8)trace_id; + } + spin_unlock(&drvdata->spinlock); + + if (trace_id <= 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 = 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 *csdev, ret = etm4_parse_event_config(csdev, event); if (ret) goto out; + + /* allocate a trace ID */ + ret = etm4_read_alloc_trace_id(drvdata); + if (ret < 0) + goto out; + /* And enable it */ ret = etm4_enable_hw(drvdata); + /* 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; } + /* allocate a trace ID */ + ret = etm4_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + spin_lock(&drvdata->spinlock); /* @@ -754,6 +801,8 @@ static int etm4_enable_sysfs(struct coresight_device *csdev) if (!ret) dev_dbg(&csdev->dev, "ETM tracing enabled\n"); + else + etm4_release_trace_id(drvdata); return ret; } @@ -881,6 +930,9 @@ static int etm4_disable_perf(struct coresight_device *csdev, /* TRCVICTLR::SSSTATUS, bit[9] */ filters->ssstatus = (control & BIT(9)); + /* release trace ID - this may pend release if perf session is still active */ + etm4_release_trace_id(drvdata); + return 0; } @@ -906,6 +958,13 @@ static void etm4_disable_sysfs(struct coresight_device *csdev) spin_unlock(&drvdata->spinlock); cpus_read_unlock(); + /* + * 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"); } @@ -1548,11 +1607,6 @@ static int etm4_dying_cpu(unsigned int cpu) return 0; } -static void etm4_init_trace_id(struct etmv4_drvdata *drvdata) -{ - drvdata->trcid = coresight_get_trace_id(drvdata->cpu); -} - static int __etm4_cpu_save(struct etmv4_drvdata *drvdata) { int i, ret = 0; @@ -1957,7 +2011,6 @@ static int etm4_probe(struct device *dev, void __iomem *base, u32 etm_pid) if (!desc.name) return -ENOMEM; - etm4_init_trace_id(drvdata); etm4_set_default(&drvdata->config); pdata = 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 = 0x0; config->vmid_mask1 = 0x0; - drvdata->trcid = drvdata->cpu + 1; - spin_unlock(&drvdata->spinlock); + /* for sysfs - only release trace id when resetting */ + etm4_release_trace_id(drvdata); + cscfg_csdev_reset_feats(to_coresight_device(dev)); return size; @@ -2363,6 +2364,31 @@ static struct attribute *coresight_etmv4_attrs[] = { NULL, }; +/* + * 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 = dev_get_drvdata(dev->parent); + + trace_id = 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 = { + __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[] = { 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/hwtracing/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 >= ETM_ARCH_ETE; } + +int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata); +void etm4_release_trace_id(struct etmv4_drvdata *drvdata); #endif From patchwork Mon Jul 4 08:11:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904835 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26DD0C433EF for ; Mon, 4 Jul 2022 08:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F/QML/Knt7J+vXacYK70nlL0mLkAJDOdis+TqGpwuGc=; b=2ySc6NZIDx5PNm /ATaA2Nr/7AzHyCfUY4RRLLg2q6nk/Fgvv3LVWnNV6KiT7LagMhlDxEc2J8fdJLE9xCzJ8u5bBUC/ qsShbDTTBQCsJQHL+LcK/+6WmKbdNN4E/GQtmDLZw541mLG+XwUH2d2jFKYUk9D9EpCuLXq5KwmfZ aLbxpLs+b2KSc6wkZObbpTueQ1FkMVrPNEvrKROy+mKyyN8EooeLHO6XJfIdc9ejslH2mCAUzodMx +nBNh01b4oIjNHrZ7WDSVJNYOmbPUmr7Wy+bOv7B5nixX+Llj6bIuh0FNEDiPQLUTcgMNjaq1aKoy wLmnoog/rMmfA3BON5gQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HD7-005ya0-Ux; Mon, 04 Jul 2022 08:13:38 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBZ-005xmQ-1G for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:07 +0000 Received: by mail-wr1-x435.google.com with SMTP id s1so12257711wra.9 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=q/Gpsdnq6NMeOrRtqYEpDz3kvjzz72td+04fYsnDnMxnOMoMTBaHBHSd4m0gT32P8+ 32EgacT40rtynfs8+4/Utdmej31cqrdGo2AgkjqAY4YKPmikSUcajBjLqh/llvoHz/Z4 gfq+gDc7zcz2bieAIinEKXCwktaqiV7YwIQ8/SubrKZrnflQNhgy4Fu+y234Nm0zmEJ0 RxUJUMVTlxIeoJp+TMwDBLfw7unscBrmchoozSsUbFI7AdHdegWE0c37FNjDW/MK2T+l IbJiJ09cV8SJEBl9uLphf7Wf9RjTXWQtOoV8p6P2Uu+JfOVfX1jgw/94SUL5LSGeKEEs 2yXw== X-Gm-Message-State: AJIora/2cd9WiTXYYT9K26jNDe6gpF927z/S2dMiCyIy2x4WsJ4TxQZ1 52OLOFwZx4hmtSx2a+s41cxtZQ== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011201_182504_CF0B835F X-CRM114-Status: GOOD ( 22.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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/hwtracing/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 @@ #include "coresight-etm.h" #include "coresight-etm-perf.h" +#include "coresight-trace-id.h" /* * Not really modular but using module_param is the easiest way to @@ -490,18 +491,61 @@ static int etm_trace_id(struct coresight_device *csdev) return etm_get_trace_id(drvdata); } +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 = drvdata->traceid; + if (!trace_id) { + trace_id = coresight_trace_id_get_cpu_id(drvdata->cpu); + if (trace_id > 0) + drvdata->traceid = (u8)trace_id; + } + spin_unlock(&drvdata->spinlock); + + if (trace_id <= 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 = 0; + spin_unlock(&drvdata->spinlock); +} + static int etm_enable_perf(struct coresight_device *csdev, struct perf_event *event) { struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + int ret; if (WARN_ON_ONCE(drvdata->cpu != smp_processor_id())) return -EINVAL; /* Configure the tracer based on the session's specifics */ etm_parse_event_config(drvdata, event); + + /* allocate a trace ID */ + ret = etm_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + /* And enable it */ - return etm_enable_hw(drvdata); + ret = etm_enable_hw(drvdata); + + if (ret) + etm_release_trace_id(drvdata); + return ret; } static int etm_enable_sysfs(struct coresight_device *csdev) @@ -510,6 +554,11 @@ static int etm_enable_sysfs(struct coresight_device *csdev) struct etm_enable_arg arg = { }; int ret; + /* allocate a trace ID */ + ret = etm_read_alloc_trace_id(drvdata); + if (ret < 0) + return ret; + spin_lock(&drvdata->spinlock); /* @@ -532,6 +581,8 @@ static int etm_enable_sysfs(struct coresight_device *csdev) if (!ret) dev_dbg(&csdev->dev, "ETM tracing enabled\n"); + else + etm_release_trace_id(drvdata); return ret; } @@ -611,6 +662,8 @@ static void etm_disable_perf(struct coresight_device *csdev) coresight_disclaim_device_unlocked(csdev); CS_LOCK(drvdata->base); + + etm_release_trace_id(drvdata); } 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(); + /* + * 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"); } @@ -781,11 +841,6 @@ static void etm_init_arch_data(void *info) CS_LOCK(drvdata->base); } -static void etm_init_trace_id(struct etm_drvdata *drvdata) -{ - drvdata->traceid = 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 struct amba_id *id) if (etm_arch_supported(drvdata->arch) == false) return -EINVAL; - etm_init_trace_id(drvdata); etm_set_default(&drvdata->config); pdata = 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, etm_set_default(config); spin_unlock(&drvdata->spinlock); + /* release trace id outside the spinlock as this fn uses it */ + etm_release_trace_id(drvdata); } 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 = dev_get_drvdata(dev->parent); - - val = 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 = dev_get_drvdata(dev->parent); - ret = kstrtoul(buf, 16, &val); - if (ret) - return ret; + trace_id = etm_read_alloc_trace_id(drvdata); + if (trace_id < 0) + return trace_id; - drvdata->traceid = val & ETM_TRACEID_MASK; - return size; + return sprintf(buf, "%#x\n", trace_id); } -static DEVICE_ATTR_RW(traceid); +static DEVICE_ATTR_RO(traceid); static struct attribute *coresight_etm_attrs[] = { &dev_attr_nr_addr_cmp.attr, From patchwork Mon Jul 4 08:11:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904831 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 493B3C43334 for ; Mon, 4 Jul 2022 08:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A6cHN7pAurpk9v3blYAkq0BKrKgmkSL9xGFlDRvwyA0=; b=Ws5pzrr2mlnayY UTah9CwrwOUcbujGjfcMyCSCGNrrRk4XeckzuKg1kp8RsLOswKxtFHiOuN+pIp5wry9rathhNBfDv QyoxTFDmIOqQ2ciAruUiFBWLsunIxV2kMHdlK5aYphQm1ddwcQnSUtyaNn7Wc8WZcKtglrxghdTfq g+3QfOu1BCAqA16VYcIdCLYumdrz4a6y0MSDyib1LhhMTWO2IoOhdEQN0cXbH8bKfJgFpQCN+tUuk akbDAuFEsXeJbXm363E0OBbDm/Gmh0CPOlHjvHCVFY2gODvIFFAc1dg6BtP4j+s59JjrlDIcC1ghy Z6i0EI8Hhih3rfqYiFOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBx-005y1Z-SM; Mon, 04 Jul 2022 08:12:26 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBW-005xmq-RX for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:03 +0000 Received: by mail-wr1-x433.google.com with SMTP id o4so12282025wrh.3 for ; Mon, 04 Jul 2022 01:11:58 -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=Qq/Oe4bRi6pzYduem6fzi5BSgGNAtgdVw8QvxxyOuPN3+ZP4T6DQWv0JeV74CQlyon 8FWUBqBaEwfXcK7ZPL89WKW2ACXkuUnAzonM4V4pA/6ss4WBjQG2whj4GA/WxWHeRDtg ov4YL+BPpkkzK/N6NMsCihgGFP7WZATcPHSkwb1DWY7594/SBePPMME8//5fQrPgn0bR SEZM65a3c/8VgUPbY1k3zx4urLWmrO/xqlZ55eTm7gqz6i2EP9WGUpSDhCYYx1e7vijq ZOn+WlVbtzeqqddW63wPavHQN6+jFdJg1yrtxzHM1ezgSU41vs+uY/EPcyqG1JGYDy7i 6ZEg== X-Gm-Message-State: AJIora9hHbsUwsxwKtXM5N41LRB/Ydde6W1VMcI9tQKdaJLzrEeGofLX YTk6Ap5qFPj09RRbQjUikibqRQ== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011158_954293_8FDBCDC3 X-CRM114-Status: GOOD ( 18.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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) } 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/hwtracing/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; } -int etm_get_trace_id(struct etm_drvdata *drvdata) -{ - unsigned long flags; - int trace_id = -1; - struct device *etm_dev; - - if (!drvdata) - goto out; - - etm_dev = 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 = (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 = 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, static const struct coresight_ops_source etm_source_ops = { .cpu_id = etm_cpu_id, - .trace_id = etm_trace_id, .enable = etm_enable, .disable = etm_disable, }; diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/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; } -static int etm4_trace_id(struct coresight_device *csdev) -{ - struct etmv4_drvdata *drvdata = 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, static const struct coresight_ops_source etm4_source_ops = { .cpu_id = etm4_cpu_id, - .trace_id = etm4_trace_id, .enable = etm4_enable, .disable = etm4_disable, }; diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/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, } } -static int stm_trace_id(struct coresight_device *csdev) -{ - struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); - - return drvdata->traceid; -} - static const struct coresight_ops_source stm_source_ops = { - .trace_id = stm_trace_id, .enable = stm_enable, .disable = 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, From patchwork Mon Jul 4 08:11:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904836 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6005BC433EF for ; Mon, 4 Jul 2022 08:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OvGhFAKygxKpg8/moO7bTwBDZj0rtC5m7kja6u2fRCY=; b=pEtCvb3ZkP/L56 GDza3OxNlFjufGjsv95V4SmFH82VRSBHVSE7R4unWg2vqg7LTYOIdC6PzLliUok5lA5iQldhEmNn2 pWqeOWz68of8ryMYfE6DK0D5QKzDDjkgf6vy9s2xIphwVuaekydBWkGlhj13aPoTbowU8R2fI/Q8C t0+/M64NNOzAp+m7pDLFAGrkF+yaAevTcz+8boR1lkuo9FMqmssHpKDqgF4l6GsYF05RR7NMOYbc4 pInf2Bv5a7v9RTjM4PhojdaOFkgjgo2PDfjjI5yIKUTpLP7IIiBiTyzKRswLZVHc2m9R6ARkpYKk6 ocEwrF2w/JJKnefgtcxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HDf-005yqL-8I; Mon, 04 Jul 2022 08:14:12 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBa-005xnr-6F for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:07 +0000 Received: by mail-wr1-x42c.google.com with SMTP id q9so12264964wrd.8 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=fU084lV36Lz1dopsFZDv/XnAn6drCatiJATQGDJVY9fPK4Jv/hde8Q0spnZ43ijN0w 5/o5QUxNuAi/9IFrOO407lZDeKnqSi5z4ayWeUJFPsiccawx+vZ6nbo+wjFh2a19NHu0 zsp55Mwh/AoqBqWxmmavc4ie44N7h+g33kmJJ6p27McKYcHMdqCulhkBbc61gcxrAlzU fXwJ+kcdXliZj7nCunfMPzna0jB2O+TakPuMzVmfMuxOyg6ZUUicIGDxOB3BK9yU3T+C 0YTuXCvoI0qx139OqM/OAbWl8UZXPFyasvnhiPC5FepmCnRp5B8jbNl+Re8oi51uVGSo sWTw== X-Gm-Message-State: AJIora+N+XRmCR02VrNneNRuSkUpe45OPL0n8rtaxliQ7YeiYSiY1rRR 1iDyCClHfRwj9zNms6rmDKui7Q== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011202_283713_792258B4 X-CRM114-Status: GOOD ( 14.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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" static struct pmu etm_pmu; static bool etm_perf_up; @@ -228,6 +229,9 @@ static void free_event_data(struct work_struct *work) *ppath = NULL; } + /* 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, void **pages, sink = user_sink = coresight_get_sink_by_id(id); } + /* 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 = (u32)((event->attr.config2 & GENMASK_ULL(63, 32)) >> 32); if (cfg_hash) { From patchwork Mon Jul 4 08:11:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904837 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E472FC433EF for ; Mon, 4 Jul 2022 08:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4gTA1tD6hFeMXLzJxvYpFdFl9mj+RhOWVtM41ctG0yo=; b=s3J7t684xcb7BX L3fInmf4LqdMmHBPkzT5+AgkCIj/3ycGxuhm436lZmWdM5alp2d4+s+eOrOSq8Ry0iSqJX9S8Kjj3 iIp1wCOi1h1/0/VY4PcR35A0yfBFDsSfLqnDuKy/rxg41xNDmsFnc2861k73paZzZrPNYV1omgYNv hgTeJI2+3wag2ylkSoLc34gvBEb1bpC5MA8B5YrbZNvjAkiWxiUlpyRVAG0fhxGh2LpVLedZHLZUY wU6mmtvLRT+NWsLaUBU133MNJXqkiau/gKz4l0ny0J35cAxZBDAuSpvS2UdgVfpRCvD8a936uoXGe c3Dtl4DYhBnLGADiVaGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HEM-005zDP-3j; Mon, 04 Jul 2022 08:14:54 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBb-005xou-0R for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:09 +0000 Received: by mail-wr1-x42f.google.com with SMTP id k7so12244587wrc.12 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=JZDREDQtCAP8FI1nurmjVQECe78Jltc6peGTzNx1923iydsNqVPnmJsJUsa74r/MYG pR7u1IM3lMSjaexCN8e/n5BD9sleyHRzyiKy1XRwxwG8APHtGGnpuWKfuX1n9KThsw+0 pvSSuXq7kA+006zwdvk8gFsQHTHA+OONeJzbAbP1bC59mD5Smsui7+Hv0by2cGzpDm+h LNA3EqkZZeb87P4sBzkV8C8crGylnux/bJ8uia0a8HPGzUmLYj/zYO8iK1BSAi7tM2sN yX78EiNnhiHRdY2ns0/QRbYWNHIPUbIfAtwBgdQVVpwu+6FMwBm1RPE6kfB8UV/i+xrA UtYw== X-Gm-Message-State: AJIora8UEZA3K0tpau5U6dDFYvIvsZBlO3x9nsy2CYPccCjp1F8NAM1B GsLoGVneMEAwsQZlE5ysTtoPcw== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011203_087061_439AA952 X-CRM114-Status: GOOD ( 24.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; } +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 = 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 = 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 *event, { struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; struct cs_etm_auxtrace *etm = NULL; - struct int_node *inode; unsigned int pmu_type; int event_header_size = sizeof(struct perf_event_header); int info_header_size; @@ -2898,6 +2921,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, u64 *ptr, *hdr = NULL; u64 **metadata = NULL; u64 hdr_version; + u8 trace_chan_id; /* * sizeof(auxtrace_info_event::type) + @@ -2991,25 +3015,20 @@ int cs_etm__process_auxtrace_info(union perf_event *event, goto err_free_metadata; } - /* Get an RB node for this CPU */ - inode = intlist__findnew(traceid_list, metadata[j][trcidr_idx]); - - /* Something went wrong, no need to continue */ - if (!inode) { - err = -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 = -EINVAL; - goto err_free_metadata; + if (hdr_version < CS_AUX_HW_ID_VERSION_MIN) { + trace_chan_id = metadata[j][trcidr_idx]; + if (CS_IS_VALID_TRACE_ID(trace_chan_id)) { + err = 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 = metadata[j]; } /* 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 /* Beginning of header common to both ETMv3 and V4 */ enum { @@ -85,6 +89,12 @@ enum { CS_ETE_PRIV_MAX }; +/* + * Check for valid CoreSight trace ID. If an invalid value is present in the 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) From patchwork Mon Jul 4 08:11:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904838 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F00B4C43334 for ; Mon, 4 Jul 2022 08:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CrxdL0DqVKDPLzH9VvjvYqcXqU2dGnFIcWe9hSDtH6o=; b=gKnU0u4hH1W/4T brJ/LLKF23+wcx+jeiNwikdfTkUT7K0nTpETuZXY5oMR0OmS/WWIjzW57dY+jmPotGVU3aAj4O5TU s7GYlFg92XcN0xbx7CgjoBaRN+US07NJGs2AcP4jKHwQq8RFdNONTpxNuoV2Lqlwv+y2rWPqEMZBl gGeyL17Pvo4NB/DqsLFx86rmXeGsj3qwACAUNq7mYW9BsMTeiltu91j6PEW3t+ieYu9J8QB9Dmuy6 fC3RiD+MERRQ+Ou2MF/0JnAhYgRUFYKNFUgkZIBH4pdmLhfXr0XI4Mo3X/HkYvzy89AthELrfdIq7 6yr3U3ZsM4nNniXxdSmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HEr-005zSG-30; Mon, 04 Jul 2022 08:15:25 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBc-005xpu-21 for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:09 +0000 Received: by mail-wm1-x336.google.com with SMTP id 205-20020a1c02d6000000b003a03567d5e9so7021263wmc.1 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=p8kkIfATqwWyuKSTcEDKQbnPl7Vd6z4nzxlS2wQaBKNnCJaj/P4szLoTTdL7i9bMP9 1DRkGVJ6Tc0yp1XgjGU8dSzeeOAybH4okiRqsbQssRwMVoRUUBI5gNhEZHKylSk7h7IF iew0mViogZKv0dXRGEUdxIm7uw2UAyzWjhyMosmCvlBOuogEsDrQJYvC4VHJ/9chCvT0 tP9UMQvM57CNXNFPxDMNnLW5fPazmLI0XqCybzlQS5o/nsEaQQ0JSblCSQBJDPDGWCLH Q7Vq0677eM61ZeJAyoBlRnWPfGwYbAaZ/zI0wK2PkRHXTce/zAI6qZJNHdS6q/FlXF31 XS6g== X-Gm-Message-State: AJIora8Pf+jvzIr+Dq6GqBWN82zz7tI0LmvMPNOEGuDXDRzoLJRE0z1E TIri8XqboFiyaKCrxfILY+hxyA== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011204_180806_D48D456A X-CRM114-Status: GOOD ( 21.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 #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 /* * 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 -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/coresight-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 #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 /* * 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 -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/cs-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_record *itr, evlist__to_front(evlist, cs_etm_evsel); /* - * 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 notified * when a context switch happened. */ if (!perf_cpu_map__empty(cpus)) { - evsel__set_sample_bit(cs_etm_evsel, CPU); - err = 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[], struct auxtrace_record *itr, /* Get trace configuration register */ data[CS_ETMV4_TRCCONFIGR] = cs_etmv4_get_config(itr); - /* Get traceID from the framework */ - data[CS_ETMV4_TRCTRACEIDR] = coresight_get_trace_id(cpu); + /* traceID set to unused */ + data[CS_ETMV4_TRCTRACEIDR] = CS_UNUSED_TRACE_ID; + /* Get read-only information from sysFS */ data[CS_ETMV4_TRCIDR0] = 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 = __perf_cs_etmv3_magic; /* Get configuration register */ info->priv[*offset + CS_ETM_ETMCR] = cs_etm_get_config(itr); - /* Get traceID from the framework */ - info->priv[*offset + CS_ETM_ETMTRACEIDR] = - coresight_get_trace_id(cpu); + /* traceID set to unused */ + info->priv[*offset + CS_ETM_ETMTRACEIDR] = CS_UNUSED_TRACE_ID; /* Get read-only information from sysFS */ info->priv[*offset + CS_ETM_ETMCCER] = cs_etm_get_ro(cs_etm_pmu, cpu, From patchwork Mon Jul 4 08:11:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904872 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 94D71C43334 for ; Mon, 4 Jul 2022 09:00:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mc8TYnNa7JlbRahk6ChN4Ny2yQPbLTAcaCEcjuJpEA8=; b=nGcNzGRJGd9OUw usUS97e/hQLD0FsWPUJcABFlYjZxJQ8s0nGQMIOxRJ5awycbmozOkTJqFe6Ea3J0mtmegpo11s8lh 91viEti+uK6Jr+lao1x048t4h9qVdDvUj717+OFoMFRSVwveQZ+uYBIfTo6t0+r4wLzAU8w3KeE7/ g3Q0MiF9dABE4fKaSyY00Q165GnPJXdnhHKoYuRG1pxr9DX7avTzahIbdhEbosz0YuiQHvKsQZAFc 9Zgwc8xh2KgTJs86I/ypEIIsJNl6Tong5hZiQ01hdo8q9CoQ2Y4l/lwqR/68pegm3EMAXsFXRVeky OCxJdXjlIV0iptwZ2/zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Hvb-006E5a-3A; Mon, 04 Jul 2022 08:59:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HvY-006Dv2-WC for linux-arm-kernel@bombadil.infradead.org; Mon, 04 Jul 2022 08:59:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=plqraaSJUkeNCDGA4aEvfb+pg8+kvKD5XTON2+h9YBA=; b=DPlGqNasWs4I478VEC0QU2T2gC 8uXcshexpFQhUQlw46FpOfL8osBq6ik+1895LHXMcABU2bhHyckGQE5Ev3Zr/4HXCZEdyCVPk19lf Ibu+LjHQKqz7cmwv4kvbLPcMTyuczQvGwG270H72vj00XcptqRhBuUE4xn3iQGtJgHzssL7EBUb1L ATKvGgHXNwFi+9TCObP7tSPPxlvCd36jg+AaJ/eXzTVJvUbXyZ/2jOfyAPKHe0TBMCAtjse/i1/A1 hzk7k+tkwawNturI9F7YxWjnO6xs/4toPflqsQN8nrv8oAcey/tv/leMY9T5Ukfv8EYyuVjUqo/QC ddKoltFQ==; Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBp-00H2qG-Dy for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:34 +0000 Received: by mail-wm1-x335.google.com with SMTP id t17-20020a1c7711000000b003a0434b0af7so5173440wmi.0 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=sGqOHAfV16P21ChCGlCT9+jYa1l9DOHwYthfSkDxXbon/J+B4jAO7JXQtmDQ7dwjfO 9b3Az5JFxAO0UUpvZl94G8zXKr+jBq01KXSjIUdxjZZKyfB8q3uv2+DMjcQd7/c6NiQC ldGUbeXJ/wg5N8/SIOtdf5dBrEbDvXQVAzy3b0byo0bAkfcOcHff5/cIuCXhu+yd64/H k3KqZOPcFr8Mclpp/9mwxAozBML7q+AZg7f2ms8EzZH7rb43DQonaygZvogMQ5PE28xU oeNmP3p0YKzj2JDX0UxdwU1jUEp9Zpi697RGoZOVKzABPUf+IXH47c+c9xkJQggXElMk wMkw== X-Gm-Message-State: AJIora+OBxjKjgGnqIaM2WN/59x+xnGhQ6cgDKj/m0HIw9Y6a85uOeLl KucCGmI+hILTxn4WaM/C1AtpYA== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_091219_948593_21874C3F X-CRM114-Status: GOOD ( 11.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *event, u64 hw_id) perf_output_end(&handle); } +EXPORT_SYMBOL_GPL(perf_report_aux_output_id); static int __perf_event_account_interrupt(struct perf_event *event, int throttle) From patchwork Mon Jul 4 08:11:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904873 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43E06C43334 for ; Mon, 4 Jul 2022 09:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8WtZ9qflPElymM+lKDxPdskhSZSiyveDB44ttcpOUyI=; b=KS6EuqW4sccmO2 IrmZ6aOVvJ/A+atehVjpawJRWsyC6JFn3pZGmfhDxYaa7/UTe0ffl8GGNftpQte78oYJk0/9U9sXM 770hZs0Yxu0ce+dqA7fQjc4D89aDngRHfOpZBxr+XWFQngkYlkwlOjETvu3+NKjkaQ0EsE9csgYZk N4otLHCTiBHpUFHPNmeFhZruSZnu3jY1JQaByjH9kRAm9+3O09D090VxF7zFyzh3LoPja+ZwapE+U h+P3bo76TwpmafS+8RNTzWLeQmvG94DHVDj27MwfWFB2vsQZ4sYEpwnfpiry4mpc+K1VWEhvXpwHT +UVYjpvtXIBfaIaE6vrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Hvk-006EA6-AZ; Mon, 04 Jul 2022 08:59:44 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Hvb-006Dv2-87 for linux-arm-kernel@bombadil.infradead.org; Mon, 04 Jul 2022 08:59:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=DPhuhsON6Dc/bAUa+COj6G0TCJ1Xh6/F1XbcAf+VvAE=; b=NtcMqYlKC7Y/a9cbH1Ga/kLA+Y rV2xXQLflOFCsjVOLxAIlEhybFgwIkqFa+DcIthrk4Y6vmKT+Hg+qHnUNJaYQtM2noijrnQyrRzHv jtSjQ2BYP0YXqQvcJIPO/yucC6MBUOsRvvs5VB3r3MsPCQOHz93BkOdPecOItdxiwqr2Ih5Q6ZR36 P1dOa0l+BizNUrkpAKRD+CbbgbXV9vTjb+DR6F1sJWrgPVqLb3YxDyd/4lj79QkBPBrroMhpPmvJS rRHwLdj0zq69wspM6gj7RMIHX//szPamPS8P6wu2sqptpVzsKPku8nkveOmOvkzsvKLP5xLjFayYj C+hnnt8w==; Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBo-00H2qK-Gg for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:23 +0000 Received: by mail-wm1-x329.google.com with SMTP id bi22-20020a05600c3d9600b003a04de22ab6so5155876wmb.1 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=4naTXO4hP0Cym+DhV6My32dol4Hfr46Sgq6Vy01nLo90SRnZDzKm0/49olRbmPTN4k P/ft9legGYOsT6ezpttchYhQSRR4EQ2EaXxaVrY0z6mGMi86aRL0JVfudyB28o3zZIIH BkwCYLXc2Ob5/uczoVvaxPgrPWXF2BeUS3R7XVBv48fFcoaFQMGtFYStfLma6KsmiRVi k+ffJEmWQPbMSwhF1cfmhV0P3jgbSuoefzaLeUIk2AOIYxhgNZaVWA8H6HDYsU8TYEoR aqwjRwwUXYal3PysdDWRmDeEhGTjVOpLC8p2mvXhrnYBKGsLpr4omWY0gakt2Zy9CL8T e+FQ== X-Gm-Message-State: AJIora9uAsbUVweFOzgndAX/HAVA0wL/TEEaVOF33ccdKRtldpmj1sJF vyydEHqzLr4FqP+9hyDqGl/htFluBfBU+w== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_091219_809130_ED2F7500 X-CRM114-Status: GOOD ( 31.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/coresight-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 +#include + #define CORESIGHT_ETM_PMU_NAME "cs_etm" /* @@ -40,4 +42,16 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 +/* + * Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. + * Used to associate a CPU with the CoreSight Trace ID. + * [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/util/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_elem_printer( return resp; } +#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_decoder_params *d_params, switch (t_params->protocol) { case CS_ETM_PROTO_ETMV3: case CS_ETM_PROTO_PTM: + csid = (t_params->etmv3.reg_idr & CS_TRACE_ID_MASK); cs_etm_decoder__gen_etmv3_config(t_params, &config_etmv3); decoder->decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ? OCSD_BUILTIN_DCD_ETMV3 : @@ -632,11 +635,13 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, trace_config = &config_etmv3; break; case CS_ETM_PROTO_ETMV4i: + csid = (t_params->etmv4.reg_traceidr & CS_TRACE_ID_MASK); cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4); decoder->decoder_name = OCSD_BUILTIN_DCD_ETMV4I; trace_config = &trace_config_etmv4; break; case CS_ETM_PROTO_ETE: + csid = (t_params->ete.reg_traceidr & CS_TRACE_ID_MASK); cs_etm_decoder__gen_ete_config(t_params, &trace_config_ete); decoder->decoder_name = OCSD_BUILTIN_DCD_ETE; trace_config = &trace_config_ete; @@ -645,6 +650,10 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, return -1; } + /* if the CPU has no trace ID associated, no decoder needed */ + if (csid == CS_UNUSED_TRACE_ID) + return 0; + if (d_params->operation == 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; } +static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metadata) +{ + u64 cs_etm_magic = cpu_metadata[CS_ETM_MAGIC]; + + switch (cs_etm_magic) { + case __perf_cs_etmv3_magic: + *trace_chan_id = cpu_metadata[CS_ETM_ETMTRACEIDR]; + break; + case __perf_cs_etmv4_magic: + case __perf_cs_ete_magic: + *trace_chan_id = 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_metadata) +{ + u64 cs_etm_magic = cpu_metadata[CS_ETM_MAGIC]; + + switch (cs_etm_magic) { + case __perf_cs_etmv3_magic: + cpu_metadata[CS_ETM_ETMTRACEIDR] = trace_chan_id; + break; + case __perf_cs_etmv4_magic: + case __perf_cs_ete_magic: + cpu_metadata[CS_ETMV4_TRCTRACEIDR] = 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 association, + * 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 = event->aux_output_hw_id.hw_id; + version = FIELD_GET(CS_AUX_HW_ID_VERSION_MASK, hw_id); + trace_chan_id = 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 = container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace); + if (!etm || !etm->metadata) + return -EINVAL; + + /* parse the sample to get the CPU */ + evsel = evlist__event2evsel(session->evlist, event); + if (!evsel) + return -EINVAL; + err = evsel__parse_sample(evsel, event, &sample); + if (err) + return err; + cpu = sample.cpu; + if (cpu == -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 record."); + 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 packet. + */ + cpu_data = etm->metadata[cpu]; + err = 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 != trace_chan_id)) { + 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 = intlist__find(traceid_list, trace_chan_id); + if (inode) { + cpu_data = inode->priv; + if ((int)cpu_data[CS_ETM_CPU] != 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 = 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 = 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 == PERF_RECORD_SWITCH_CPU_WIDE) return cs_etm__process_switch_cpu_wide(etm, event); + else if (event->header.type == PERF_RECORD_AUX_OUTPUT_HW_ID) + return cs_etm__process_aux_output_hw_id(session, event); if (!etm->timeless_decoding && event->header.type == PERF_RECORD_AUX) { /* @@ -2662,7 +2797,7 @@ static void cs_etm__print_auxtrace_info(__u64 *val, int num) for (i = CS_HEADER_VERSION_MAX; cpu < num; cpu++) { if (version == 0) err = cs_etm__print_cpu_metadata_v0(val, &i); - else if (version == 1) + else if (version == 1 || version == 2) err = cs_etm__print_cpu_metadata_v1(val, &i); if (err) return; @@ -2774,11 +2909,16 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o } /* - * 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 instead. See + * auxtrace_mmap_params__set_idx(). However, the sample AUX event will contain 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 CPU is not -1. + * Return 'not found' if mismatch. */ - if ((auxtrace_event->cpu == (__u32) -1 && auxtrace_event->tid != sample->tid) || - auxtrace_event->cpu != sample->cpu) + if (auxtrace_event->cpu == (__u32) -1) { + if (auxtrace_event->tid != sample->tid) + return 1; + } else if (auxtrace_event->cpu != sample->cpu) return 1; if (aux_event->flags & PERF_AUX_FLAG_OVERWRITE) { @@ -2827,6 +2967,15 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o return 1; } +static int cs_etm__process_aux_hw_id_cb(struct perf_session *session, union perf_event *event, + u64 offset __maybe_unused, void *data __maybe_unused) +{ + /* look to handle PERF_RECORD_AUX_OUTPUT_HW_ID early to ensure decoders can be set up */ + if (event->header.type == 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, union 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; + /* scan for AUX_OUTPUT_HW_ID records */ + if (hdr_version >= CS_AUX_HW_ID_VERSION_MIN) { + err = 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 = cs_etm__queue_aux_records(session); if (err) goto err_delete_thread; From patchwork Mon Jul 4 08:11:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904875 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 634E3C43334 for ; Mon, 4 Jul 2022 09:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Qshkz5ODQOrw7dVdBXWKDCwvgEc67exP4B+lIbTOiLo=; b=bGO+N/vNz/cUlM qrcBP6IwT/hK1EsEfJU0M7TyMlmVGrUcdea2EKTRuEMktujmugJdErfZQXjqMZyiGaB8D6mSxCh2l CxOccoQInOEq6N8FNRi2f5Dn8K0JpQxKpBDxt8gY+nLhnfLh7r0uh7YpG+z+vSg+gWiQCoBoS/5n/ FjoF9YAwlGYv7aPZmefGMt92PPhln9WCLrLZ4d0zfywsve3Qz0qAXp2I6sc8fT9sYpSiSo8TRCzYe 6W2pqWfCizChObN752a4lQ+5R4ZiS1omRdqAPFVmjFBRrseUavXBadr2dxjheyGmwxUCeI4QtQQlx IHmqKSfhjc6NWByQDY2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Hw3-006EJP-JO; Mon, 04 Jul 2022 09:00:03 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Hvc-006Dv2-SV for linux-arm-kernel@bombadil.infradead.org; Mon, 04 Jul 2022 08:59:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jVURNUygCeW21dF6Em3WQRHaxEsapZQYIGA6mQ8Wh5Q=; b=kXZpETMqr43isrtk40D4/ifamT BaaJkhN1JECVSr9GCU4q9y4wiTICCGppl/Rl0KCXqJSOh3Qa+8+0dKmnGE+hfL/4hNzbR9nurTxq/ z94y68fi9NS6DQSFrR3awsvA2h5J7FYxX4yx6Qb5Ox9W7yF6GyRBYcIki6fbXqAYLL71+D6ABzPr5 OPPlUS9ZBxj+pLC5T3qsEtH9kMnfS+ec7zd0Sj7U99I8J6uv9NYuPkTGPS8agdTJ4xxABT6npd464 eklUMhtXLVQWLHEAiSGSJakN+XSE9CR09J/uqO56qNOAF4aBprGErRSRWJ233xk2cRcqtlbnFKwgi 1Y2QTXYg==; Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBn-00H2qN-0E for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:21 +0000 Received: by mail-wm1-x32e.google.com with SMTP id c131-20020a1c3589000000b003a19b2bce36so1863644wma.4 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=2PBJOBr6tZHQVMXRiG5oilPdmjANxGtjNA6E7JCTCR7+Qm8FGv57Iv30yJz+cbMohA cRRk6sA4oJv7UZ0KmVizQlICjKX60R9kapSg8XNXh/H6yG2NedwzmdgxIgdgm2eMdGbI ZKHcYjWDmak3B+e3+XfiQJqt32I1SKPPwJJOrTWPsS0SXqvpSDikCXlIIFXj1u85Rrxo fyvzLEi6r0g6d/rv6r2POMJvpbS83KLBfpv/5dCMcw5x6d35M52St74sSf5AAOjUlNTW QEtAGSoQYd/SdupKd3/CY5aptq9fyzDtLiDIsyamHxDkgzufG6q17O8q7xGI/iBUTvi2 U+tw== X-Gm-Message-State: AJIora8EIsAEEkyYdf29Qo+Ut5VPUPztXamkNnwLBUqjv6xAB+eYMivD PXfVIehsdbAT5IawmjsqhFrTIw== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_091219_385640_1BDA1BF2 X-CRM114-Status: GOOD ( 16.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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 */ +#include #include #include #include @@ -437,6 +438,7 @@ static void etm_event_start(struct perf_event *event, int flags) struct perf_output_handle *handle = &ctxt->handle; struct coresight_device *sink, *csdev = per_cpu(csdev_src, cpu); struct list_head *path; + u64 hw_id; 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; + /* output cpu / trace ID in perf record */ + hw_id = 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 = 0; @@ -600,6 +607,9 @@ static void etm_event_stop(struct perf_event *event, int mode) /* 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); } 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 +#include + #define CORESIGHT_ETM_PMU_NAME "cs_etm" /* @@ -38,4 +40,16 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 +/* + * Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. + * Used to associate a CPU with the CoreSight Trace ID. + * [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 From patchwork Mon Jul 4 08:11:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904874 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 478E4C43334 for ; Mon, 4 Jul 2022 09:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=O/78d7rQFEmmzxDi4RXhaVxf1EWSS2ocsKbBGldewUI=; b=RwAc5Zb0SHMccY q4gNXt7iRHLwjosp/x6+JxO5TQ27J6KbAY24mBvUWyiTDA0dSm4jtst1AYSRm+qTpANUj4hqf6MCc 5j9/KdlVX8LXLtIQMoBh6L7p6jpJdPr0DtdTffPexJkxsg5qhnDvl4qu9qjjgBFEXQiL4hP5490q0 raqRm+WIFYbkGlbwk1EGNWCVTNfnMVswJfJIEPUu+rgq/bdmdl21YA6dmh6D/gKjd90j6tf/vzGIz Iuy56vDMjSi/STBhK6+w7weHpCDRnwmeH4964jFQHn/Z6V3WnQ/z59oGNlvRE/LZnOYTJ87VSn8d8 1FDxoet4IrCrrI89q4Eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Hvu-006EFB-5B; Mon, 04 Jul 2022 08:59:54 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Hvb-006Dv2-VU for linux-arm-kernel@bombadil.infradead.org; Mon, 04 Jul 2022 08:59:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=PTooRwbsdLD3OOIuzOYJzIkCxcUPBK7VZILGtwDxgv8=; b=WzYupgQgS7RMOYnFOT70LPLdOE UWJ1uNWQNcMulT9aCf75JVmhd3QKfZNxh2hq2pJjRrETEWqOYaMFgp/PMjAv6L9HSZhk8I0Xb2NmS 9ZDMk0AYkklU9RhROHUfZKsVRKKHo+RE6VruD6WR8b3gWbul0O/64jrTQuNevjanHU/tZEKniTNdU K6RqoG8NOB35JyNoZ+AqF0q2t8ylao21uJHqdIAOoWeYK80RyhCWPLFoP4Nmjeiz3ywVcdAsA94lb kusfZmhZA3ol5gGNC0RQwwoxWHxbO2Fkr6v1m98gyYVbim6yEM3zEYIk0Tywklik3FBBf+vbS8YMs iLOG2hkQ==; Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBn-00H2qR-M5 for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:12:21 +0000 Received: by mail-wm1-x32c.google.com with SMTP id bi22-20020a05600c3d9600b003a04de22ab6so5155934wmb.1 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=HhaoE/TUbZwFH9owv2htnObAZH30HyPMuo8URiODXa8Ga10GiYSFnewVAEMUAc6fdd LQ38DKrrZG9LgqS87urf3aFmFWSkZxhPmW+dn0al7h26WbiLioEM4j/HqAvkEEpYO4fT Cwow/S1xbQNII/ocf6XHUDCPLrbWSxXPnrdE1nVC227XLlKhyKBWdQZB3ENcCRO2yB9I /9UXEEm1PcUgwUzuQH92Q3LRscYOJZhFDvPYUHnKm2kY2uk3BjLBTMhdRRQfkvWM4TRz 6oWM/3CwgAW0zT9sGI+hknKFRqIQlKhm5FxleOUcp8fbgzXDInt3HIC6ROypU1QbjMSm TVzQ== X-Gm-Message-State: AJIora/bdTBP0d9WXUSj7nhOnrqQ4kHjcVdLoohjPqLLfoAfoMPIKtDC oQ6wO5d3lqeB8pvJKMk9Yl4Xgw== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_091219_806422_2C930C1C X-CRM114-Status: GOOD ( 12.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/hwtracing/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 coresight_trace_id_map *id_map) return id; } +/* #define TRACE_ID_DEBUG 1 */ +#ifdef TRACE_ID_DEBUG +static void coresight_trace_id_dump_table(struct coresight_trace_id_map *id_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= 0x%016lx%016lx\n", id_map->avail_ids[1], id_map->avail_ids[0]); + pr_debug("Pend = 0x%016lx%016lx\n", id_map->pend_rel_ids[1], id_map->pend_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=%d, id=%d\n", __func__, cpu, id) +#define DUMP_ID(id) pr_debug("%s called; id=%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); 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, struct coresight_trace_id_ get_cpu_id_out: spin_unlock_irqrestore(&id_map_lock, flags); + DUMP_ID_CPU(cpu, id); + DUMP_ID_MAP(id_map); return id; } @@ -151,6 +175,8 @@ static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_trace_id put_cpu_id_out: spin_unlock_irqrestore(&id_map_lock, flags); + DUMP_ID_CPU(cpu, id); + DUMP_ID_MAP(id_map); } 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); + DUMP_ID(id); + DUMP_ID_MAP(id_map); return id; } @@ -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); } /* API functions */ @@ -207,6 +238,7 @@ void coresight_trace_id_perf_start(void) 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) 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);