From patchwork Sat Jun 26 00:57:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1497517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=JSs27i61; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=foJQdFZ0; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GBb7w0XQ3z9sWQ for ; Sat, 26 Jun 2021 10:57:48 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=pQVAmbtfrY0xEUNS1DTeg7MCqAJrk19tMwJbWEmlZdo=; b=JSs27i61AvhrYi VTH4SApaAl6YEOOPS6LCbRfihtg0IPmH6xTvYt5Drakka4tprc49X7X5F8BdVSYnShyT+9XZZxdN6 fYQoob1lQTvIUnG/lphf4E8nP2FBFXopbNGRci39RByz96HUAIVPpA6QePyM0Pyzu1wrb7JFumxzS 7DhRu3aDBSExOgSXM6BSiijax/FVtchqbjAg59SzI/EwUhqzFhrh9tGv9bGwe//AMWtv2md8zK9kZ SdZfW/iTyCcS9h4rsSfua4gWOd7WoTkno5CPby3J2I1gbrflu3Ez7vpaf3I4nWHuDylve4SduOT87 vNfqo/22CNuRGCD2EL7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwwdi-003Axa-QR; Sat, 26 Jun 2021 00:57:42 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwwde-003AvC-36 for opensbi@lists.infradead.org; Sat, 26 Jun 2021 00:57:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1624669058; x=1656205058; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Gj7yjNFPMneluGM/FrlNOnW9mQ76uvoJbFPikS1xAI4=; b=foJQdFZ08U+c6O1u0Dhmc+GwTKMDTIkNB5EUVD/Y9M5B1V9D6IJvJnfO 1yHrLg2k9PLCuRKgqWDhC6cvHzTtoH0bjee2PN14pcP3FOa2lUzhnjzSL asbGtD71nCLHqrU9pYxLSf35iRzfl2a7EYjhuz7AjfzzKxr9uQtpTq/cp EY3MkQWBNprZJgV2msRrKaKK+9GvqAFV7QmLnSQi8nHrI5ymFhYVZi3Ss oY3Vqcq0cxFrFRx6O7vFOaqElazTKb7BQW2OVaTHqUyldVohC4A4Dv2FF jxCmwhv+dCyT32efYaNcu0iGc46C1ybY9PIIw5D064kveSjT3E16B0gRY Q==; IronPort-SDR: DUMiVX1C1Dt+XX1ehrXxff38dGJ40Auu2Incz+nm2NBHZK7jfbet661TIkWpM1SHD2Jk7AdRUK kzHeYwb9FwhL7R3QjKxdUyz2sO8s54cd5vOwcDyYH550sUOc5M8mFuysyZNXAfaaEWkc5KDtt+ P7L4Fo+lFdcQ8IkUgP5/JxNsDA0HjB02LNekkfZWl0+4diBYkcRpHHP0GmLL7VpNUWpDOZxDfW 7FO+7TWYvkBVstlQ0fJPRit6g3ERnex0MXwTl0rugs0WQOoZ9kNQ+BtQf6M0qUNYcm6TOo9S0H +t4= X-IronPort-AV: E=Sophos;i="5.83,300,1616428800"; d="scan'208";a="284438588" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2021 08:57:33 +0800 IronPort-SDR: xSNnfpZbwr/Mb3KBrPjqLmS2N51/h3EvwFcI/yavfBYFpCEkg0rWrSgxxHGNRK6Xj91sEOLqzJ wHB8tpGIVOBReULkfqD2gB3a8n4LNpuABQiy05zWvxTIEs3Rjr5BpyQqt4DUzHtpjM+vWCATqD LOAKvWJMKR0H59A+JmDZKdHYeHKJfXmbcDeDYDIgdNv4Rr+0Dt0IvtVk+wESZZWP9V36MmMB7t l/mFViBGl5vp/AxSERYmzYTTPcuKwNdw7am8XYi7cgo7I1MbhAMDg8NHwkE6r2yxJ74ZGMzAAq /qU5NxBc1FYegG4/B04C/kq5 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2021 17:36:06 -0700 IronPort-SDR: Gjw1xkYQUcDR4B+144qSHU0m8FmZC43ve2o5+PCQsCkxEvS0z52+sUMmb32GSVJ2H98aug5Nwf 5D3z+O5VJtig57QN6N+rtvwzJ3dAQSxu167AEJvgFVZU6scL9s+4lDrAtUs/QjpbtH3CawlbGz 3P49x7/h/rhZ02Vp2Nh8lF0oKVAg5QiVYyI1i+7pncNpT/+eKVbSUN4StslAKV4njuzZ/egkgT BFUOsB2pIJzB4sZyhlQtO1JCtWxv5R27zGblxcXdVP+MBowNCXhtpYvEXBQRnXrtcaJ+qp3S8L pFk= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.19]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Jun 2021 17:57:33 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v3 00/15] SBI PMU extension support Date: Fri, 25 Jun 2021 17:57:06 -0700 Message-Id: <20210626005721.3600114-1-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210625_175738_722589_D402DCF1 X-CRM114-Status: GOOD ( 14.56 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The latest version of the SBI specification includes a Performance Monitoring Unit(PMU) extension[1] which allows the supervisor to start/stop/configure various PMU events. This series implements the [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The latest version of the SBI specification includes a Performance Monitoring Unit(PMU) extension[1] which allows the supervisor to start/stop/configure various PMU events. This series implements the SBI PMU extension in OpenSBI. It doesn't implement the bits required to support "Sscof" extension yet. That will be added later along with qemu support. This series can be found at github[4] as well. It has been tested with Linux kernel patches[3] for different hardware/firmware events on Qemu. This patch requires basic QEMU support series[2] to work. As the Qemu did not support mhpmevent/mhpmcounter before this series, these changes are not backward compatible to avoid code churn. Anybody who wants to use perf must include Qemu, OpenSBI, Linux kernel patches. [1] https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc [2] https://github.com/atishp04/qemu/tree/riscv_pmu_v1 [3] https://github.com/atishp04/linux/tree/riscv_pmu_v3 [4] https://github.com/atishp04/opensbi/tree/riscv_pmu_v3 Changes from v2->v3: 1. Fixed several small fixes in sbi_pmu.c 2. Added additional sanity check for TM bit. 3. Minor fixes in firmware counter patch. 4. Return failure during probe for PMU extension if mcountinhibit is not available 5. Enable the cycle and instruction counter by default. Changes from v1->v2: 1. Addressed all the comments from v1. 2. Improved the series by following latest SBI PMU extension[1] Atish Patra (5): utils: fdt: Add fdt helper functions to parse PMU DT nodes lib: sbi: Implement SBI PMU extension lib: sbi: Implement firmware counters lib:sbi:tlb: Improve function naming platform: generic: Add PMU support Atish Patra (15): docs: Add device tree bindings for SBI PMU extension lib: sbi: Detect mcountinihibit support at runtime lib: sbi: Remove stray '' character lib: sbi: Detect number of bits implemented in mhpmcounter lib: sbi: Disable m/scounteren & enable mcountinhibit include: Add a list empty check function lib: sbi: Remove redundant boot time print statement lib: sbi: Use csr_read/write_num to read/update PMU counters lib: sbi: Add PMU specific platform hooks lib: sbi: Add PMU support utils: fdt: Add fdt helper functions to parse PMU DT nodes lib: sbi: Implement SBI PMU extension lib: sbi: Implement firmware counters lib:sbi:tlb: Improve function naming platform: generic: Add PMU support docs/pmu_support.md | 83 ++++ include/sbi/sbi_ecall.h | 1 + include/sbi/sbi_ecall_interface.h | 138 ++++++- include/sbi/sbi_error.h | 2 + include/sbi/sbi_hart.h | 5 +- include/sbi/sbi_list.h | 11 + include/sbi/sbi_platform.h | 39 ++ include/sbi/sbi_pmu.h | 73 ++++ include/sbi_utils/fdt/fdt_pmu.h | 46 +++ lib/sbi/objects.mk | 2 + lib/sbi/riscv_asm.c | 35 ++ lib/sbi/sbi_ecall.c | 5 + lib/sbi/sbi_ecall_pmu.c | 93 +++++ lib/sbi/sbi_hart.c | 86 ++++- lib/sbi/sbi_illegal_insn.c | 2 + lib/sbi/sbi_init.c | 11 +- lib/sbi/sbi_ipi.c | 6 + lib/sbi/sbi_misaligned_ldst.c | 5 + lib/sbi/sbi_pmu.c | 620 ++++++++++++++++++++++++++++++ lib/sbi/sbi_timer.c | 2 + lib/sbi/sbi_tlb.c | 79 +++- lib/sbi/sbi_trap.c | 7 + lib/utils/fdt/fdt_fixup.c | 2 + lib/utils/fdt/fdt_pmu.c | 111 ++++++ lib/utils/fdt/objects.mk | 1 + platform/generic/platform.c | 30 ++ 26 files changed, 1465 insertions(+), 30 deletions(-) create mode 100644 docs/pmu_support.md create mode 100644 include/sbi/sbi_pmu.h create mode 100644 include/sbi_utils/fdt/fdt_pmu.h create mode 100644 lib/sbi/sbi_ecall_pmu.c create mode 100644 lib/sbi/sbi_pmu.c create mode 100644 lib/utils/fdt/fdt_pmu.c --- 2.25.1