From patchwork Mon Jul 4 08:11:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12904829 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 84577C433EF for ; Mon, 4 Jul 2022 08:13: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: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:In-Reply-To:References: List-Owner; bh=ZoRYbAPeygIx8eY+3GQLmt41xKXVEGOWNlBgpd/W9jc=; b=4MzINsy8BwB4ao /p+3WRCiUGARAI6SCD2aOeU9OFCWTdrMX6HRno7bmcIQVQzgUfa6bAgNWfxH0k8aaVvcwYQjHnTDd enHcfv/mtNDO4/mkqJjcbDSZvTNdPMz7PK+KsdAXvfuTgIjKA9up5OfJIVp0ROgbdLOawgu52xf9C JLQLTRcIZ2kffiKwBQblU5CfkAa+a36Ji2m5tci/d7pLlr/m9UI6rCeIkCKeH5TN0Gbj4ejkXRpZo /2VVz2MAUdADhyQLabwkJZaDPwbbKqV0K+ok+cFbVMTjEvdFp1yhL43plHnim02a7hTgENiO/LsuA XAxa5ofJONJCyZsh5ZCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8HBa-005xpa-71; Mon, 04 Jul 2022 08:12:02 +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 1o8HBV-005xkP-48 for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 08:11:58 +0000 Received: by mail-wr1-x433.google.com with SMTP id o4so12281698wrh.3 for ; Mon, 04 Jul 2022 01:11:53 -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; bh=AUqFD9KYdiQpL3NUshToL5IaGhlRIXojEKi2n0eKo4A=; b=dB8izlzIQitU7ejWk9cue1Pu3HXTjLn0Md5bmX/ho2giI2ydA3svpBRa2RG47MNicb OHWa/daLcHdVR71nh/tj8UzDqcIM4LiVf0jxtQXx5v46JhwIof04UIXBFmc37BXn/3ik SgDaRbV3C/r1oZIqe2j458hBF+kY3FdWkFM8Mr6L2qccWAR8B0F+/YP0M05NbqUNROgt IfpC5s4YoX5UTW6Dh27gSKPqI008T4FfuEKSeckjTSI236HMrXGJW2VWMXt+AMW8jFZ/ IyXipe6RuG4ICqHS3dlhub+iJ+kdDcnUpkJTvUfcwW9ojwrlSPTiPqVJGoEd/8tlx43+ b0MA== 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; bh=AUqFD9KYdiQpL3NUshToL5IaGhlRIXojEKi2n0eKo4A=; b=ies2ORCxS5Xsge6e9TkecY0mV+MSEjKHZ+PsijOfEwJ5Jm5EmGDYJQMuzzBmMLWNUl IT5+1C/BMBuFg99b95FD63BNtqY6nKitACyT/dTJOE3dOAu5L2YpJtqrN7mAWklJAGcz 2R40p1yMLUiLrK0TYfJ+0ShhK9VyvXfy53Sw+Trqgei+YBHHbuA50/bn1P3jDuTAtdGN KiAC+rd4XxXyS+2tvCdHygPtX3hbErXl8AjUI4XefteVNG3cn0Q+3HlFxF/YuP2ALnk2 iuDfUB7pmYQodMCTZx2PWH4ycZ5CVh/MZ+9b7X3mjvI3poIRIAjPoH3F6xaTIaK3cAtG Tjjw== X-Gm-Message-State: AJIora+8i34b3Qprck1I3gFA6pFLnwF9igyqYjLbDWxg3Ex/Vn1NH1ys RF8xS1uYgtXiogk9As7tAD5QDw== X-Google-Smtp-Source: AGRyM1uP/WLujNhFdsV0YO4ORJCZugnYr/SZIxlxb4LrrM+QOFw59S510K5XJ/Ja1tWRgCtYXK8ERg== X-Received: by 2002:a5d:6d0e:0:b0:21d:6d4c:e0e4 with SMTP id e14-20020a5d6d0e000000b0021d6d4ce0e4mr1667662wrq.355.1656922312014; 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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 01:11:51 -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 00/13] coresight: Add new API to allocate trace source ID values Date: Mon, 4 Jul 2022 09:11:36 +0100 Message-Id: <20220704081149.16797-1-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_011157_186447_E2E0B2CC X-CRM114-Status: GOOD ( 22.23 ) 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 current method for allocating trace source ID values to sources is to use a fixed algorithm for CPU based sources of (cpu_num * 2 + 0x10). The STM is allocated ID 0x1. This fixed algorithm is used in both the CoreSight driver code, and by perf when writing the trace metadata in the AUXTRACE_INFO record. The method needs replacing as currently:- 1. It is inefficient in using available IDs. 2. Does not scale to larger systems with many cores and the algorithm has no limits so will generate invalid trace IDs for cpu number > 44. Additionally requirements to allocate additional system IDs on some systems have been seen. This patch set introduces an API that allows the allocation of trace IDs in a dynamic manner. Architecturally reserved IDs are never allocated, and the system is limited to allocating only valid IDs. Each of the current trace sources ETM3.x, ETM4.x and STM is updated to use the new API. For the ETMx.x devices IDs are allocated on certain events a) When using sysfs, an ID will be allocated on hardware enable, or a read of sysfs TRCTRACEID register and freed when the sysfs reset is written. b) When using perf, ID is allocated on hardware enable, and freed on hardware disable. IDs are communicated using the AUX_OUTPUT_HW_ID packet. The ID allocator is notified when perf sessions start and stop so CPU based IDs are kept constant throughout any perf session. Note: This patchset breaks backward compatibility for perf record and perf report. Because the method for generating the AUXTRACE_INFO meta data has changed, using an older perf record will result in metadata that does not match the trace IDs used in the recorded trace data. This mismatch will cause subsequent decode to fail. The version of the AUXTRACE_INFO has been updated to reflect the fact that the trace source IDs are no longer present in the metadata. This will mean older versions of perf report cannot decode the file. Applies to coresight/next [c06475910b52] Tested on DB410c Changes since v1: (after feedback & discussion with Mathieu & Suzuki). 1) API has changed. The global trace ID map is managed internally, so it is no longer passed in to the API functions. 2) perf record does not use sysfs to find the trace IDs. These are now output as AUX_OUTPUT_HW_ID events. The drivers, perf record, and perf report have been updated accordingly to generate and handle these events. Mike Leach (13): coresight: trace-id: Add API to dynamically assign Trace ID values coresight: trace-id: update CoreSight core to use Trace ID API coresight: stm: Update STM driver to use Trace ID API coresight: etm4x: Update ETM4 driver to use Trace ID API coresight: etm3x: Update ETM3 driver to use Trace ID API coresight: etmX.X: stm: Remove unused legacy source Trace ID ops coresight: perf: traceid: Add perf notifiers for Trace ID perf: cs-etm: Move mapping of Trace ID and cpu into helper function perf: cs-etm: Update record event to use new Trace ID protocol kernel: events: Export perf_report_aux_output_id() perf: cs-etm: Handle PERF_RECORD_AUX_OUTPUT_HW_ID packet coresight: events: PERF_RECORD_AUX_OUTPUT_HW_ID used for Trace ID coresight: trace-id: Add debug & test macros to Trace ID allocation drivers/hwtracing/coresight/Makefile | 2 +- drivers/hwtracing/coresight/coresight-core.c | 49 +--- .../hwtracing/coresight/coresight-etm-perf.c | 17 ++ drivers/hwtracing/coresight/coresight-etm.h | 3 +- .../coresight/coresight-etm3x-core.c | 85 +++--- .../coresight/coresight-etm3x-sysfs.c | 28 +- .../coresight/coresight-etm4x-core.c | 65 ++++- .../coresight/coresight-etm4x-sysfs.c | 32 ++- drivers/hwtracing/coresight/coresight-etm4x.h | 3 + drivers/hwtracing/coresight/coresight-stm.c | 49 +--- .../hwtracing/coresight/coresight-trace-id.c | 263 ++++++++++++++++++ .../hwtracing/coresight/coresight-trace-id.h | 65 +++++ include/linux/coresight-pmu.h | 31 ++- include/linux/coresight.h | 3 - kernel/events/core.c | 1 + tools/include/linux/coresight-pmu.h | 31 ++- tools/perf/arch/arm/util/cs-etm.c | 21 +- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 9 + tools/perf/util/cs-etm.c | 220 +++++++++++++-- tools/perf/util/cs-etm.h | 14 +- 20 files changed, 784 insertions(+), 207 deletions(-) create mode 100644 drivers/hwtracing/coresight/coresight-trace-id.c create mode 100644 drivers/hwtracing/coresight/coresight-trace-id.h