From patchwork Thu May 27 00:30:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484377 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=Xq2oy2TY; 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=XNvz0p6R; 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 4Fr7zf2n5bz9s24 for ; Thu, 27 May 2021 10:31:42 +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: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=J/i7ivvFhV3acUk9KstA4PDf4GWnQJHwgpQ4C19/hQs=; b=Xq2oy2TYLz3WjR QGbV03ffR59GYymtpMoqb5hRGABnrxueB5pK/nuScE4h0p6l9EZWqaRtkCAYUcM2XQjdMKI8iqvoG WBATMLjNu4uKRUyVW+gB7COBF3rtFQ0aH8wq+ombaVdKQzDtx//qW3Z7FUs8yC9NpUc9G7zCLV0TD oJ46myeToNWJrxdo3+4ZDLbbUwcCGUCi/6JJH/Hll+ZLNZ6oMRrW5qKhcttgCShqQw0EV+91sbvko TiQtg+aXZRDNgfk1l1uotuqXRlTFwFLgTX7Z8BRWMpiau65+bTbL3gRDYt0qUZKJXyPY/vZdjq7dk 0OkTkeGZP4IY1zP/wozA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3w1-001Anp-Lv; Thu, 27 May 2021 00:31:37 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vy-001Aiy-4j for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:36 +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=1622075500; x=1653611500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ixFfjKoj5fQs+FiQW1iSw0wdC5YfR8RVS7LkSlohsYk=; b=XNvz0p6R0fyOCoBrZwbE2TyvV8STxj3+8RLLGqUxk0MzdYuP8XxtXrVj WJ2CWNInaLPI456iA7l2kJ0eAlWeZ/XpO9RN+GlUPCOXIDM5vmfk/kl1z +CtNOjqXyXiL+UFtqEl4iHq2KYjGUDvXJDSiYEZDqCRGl5gQizbVD42HY I+HvBQLUXWJrNTMd0jfnoksL2tnYl60DCMHtoKROfQiUBaS+NNmSFZUew qpbF0mjTvmqOw0FEg2liB7TXN/r1Nc5FDtfJdKLm7WjTUlyQeM5lXROU8 1Jn3NJxpKTk8N6LdmZYV0xU4/Tn7uxek9+WOn++QWW3C4VhaDhSzDe2Th g==; IronPort-SDR: XUnDK2NE4c8ftiGKoE+Sjn4GYN57gZWPCnJ80yOeVPTXuSapH46ZC0nLHy16rgkEc711BKP13/ iXAZXJ8PNFVniOfC0yK0so/TBv741cBladOti5dXEHDIpk2V16k9BVGYWY/oxq1Uxh6gXZYbdI hUnXsWzYkPVfrF94o7GTq6JDgMskfE7UXOMdiknKb5MPWkl3PHOMMrlZK5/+TLDDQTD7XITwoY euiRLwgWY+7e3aPog0UOCScvztu/O9YuwRt1uVfgHIIoaz0aWbuhO8MbZTFsCscSxcZj0t7DO0 u/g= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477852" 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; 27 May 2021 08:31:39 +0800 IronPort-SDR: qhK/feBYMExFp7JIIthIjkaaTKBU+5dXnwhvEf5EBQYXLepFJEmT6VGM1TQKfQClde/esR4+oG V9ijrAzKDoPmTo5Utl4gt0/HQwAxqfQq/T5w81bj5xe0pI4vADPx64ZMzaKp4UlQrPmybyAey6 o74NRKrkgaWzySgaqi38O7wD1W2p8Vg9hJ0vJGkrtCo6DKF6/0na4BTx4AdvVCJutglKm8F/Iw 1hUqbo0DHTubmdGJOCy8lQ5OWx6uU8q0utJ0e9b4DdTGXHc8mi+o0Ystf2FgrmjGxPMAFAJ7ik qRyC0SNU9+siv7HcWxzvqJtb 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; 26 May 2021 17:10:59 -0700 IronPort-SDR: kZsikMwQ5AbSjZUUXa58wByDShf+A4QCVQa4+wreZowTsES1cDxnnzJPixxo4eB0Ad5Gq8eDnf CWEtgdGMkNKEb6Okf35u2rgiuMf5pyuHpuyv+mIJbkdAzeyNux0pbfu+V7+OHzk1GQYr55Ik68 KCXLc56szYMEJ1QmP1x7BKvhh2B1QI5HvQPGKs5cB8hSox8ORfWCYFfRQ/6g81H4UlzMYWK0vy INY2UC6714wCvg/xLTB7Fswyt7ILn7fUnyHXF/YIPzxo7jBd7+pcJJq8+Rv+T7aUZgc41+uhFV DQU= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:31 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 13/15] lib: sbi: Implement firmware counters Date: Wed, 26 May 2021 17:30:42 -0700 Message-Id: <20210527003044.889681-14-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210526_173134_353330_D5ABE372 X-CRM114-Status: GOOD ( 17.66 ) 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: RISC-V SBI v0.3 specification defines a set of firmware events that can provide additional information about the current firmware context. All of the firmware event monitoring are enabled now. The fir [...] 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.143.124 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 RISC-V SBI v0.3 specification defines a set of firmware events that can provide additional information about the current firmware context. All of the firmware event monitoring are enabled now. The firmware events must be defined as raw perf event with MSB set as specified in the specification. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- lib/sbi/sbi_ecall_replace.c | 1 + lib/sbi/sbi_illegal_insn.c | 2 ++ lib/sbi/sbi_ipi.c | 6 ++++++ lib/sbi/sbi_misaligned_ldst.c | 5 +++++ lib/sbi/sbi_timer.c | 2 ++ lib/sbi/sbi_tlb.c | 38 +++++++++++++++++++++++++++++++++++ lib/sbi/sbi_trap.c | 5 +++++ 7 files changed, 59 insertions(+) diff --git a/lib/sbi/sbi_ecall_replace.c b/lib/sbi/sbi_ecall_replace.c index a7935d97300d..fb1235d66fa9 100644 --- a/lib/sbi/sbi_ecall_replace.c +++ b/lib/sbi/sbi_ecall_replace.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index 9af3d24d797e..bfe7d6195898 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -129,6 +130,7 @@ int sbi_illegal_insn_handler(ulong insn, struct sbi_trap_regs *regs) * instruction trap. */ + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ILLEGAL_INSN); if (unlikely((insn & 3) != 3)) { insn = sbi_get_insn(regs->mepc, &uptrap); if (uptrap.cause) { diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index bfaf4e9766e1..563db2cf9e55 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include struct sbi_ipi_data { unsigned long ipi_type; @@ -64,6 +67,8 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid, if (ipi_dev && ipi_dev->ipi_send) ipi_dev->ipi_send(remote_hartid); + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT); + if (ipi_ops->sync) ipi_ops->sync(scratch); @@ -183,6 +188,7 @@ void sbi_ipi_process(void) sbi_scratch_offset_ptr(scratch, ipi_data_off); u32 hartid = current_hartid(); + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD); if (ipi_dev && ipi_dev->ipi_clear) ipi_dev->ipi_clear(hartid); diff --git a/lib/sbi/sbi_misaligned_ldst.c b/lib/sbi/sbi_misaligned_ldst.c index 5057cb5ecd58..c879ce72f61a 100644 --- a/lib/sbi/sbi_misaligned_ldst.c +++ b/lib/sbi/sbi_misaligned_ldst.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,8 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, struct sbi_trap_info uptrap; int i, fp = 0, shift = 0, len = 0; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD); + if (tinst & 0x1) { /* * Bit[0] == 1 implies trapped instruction value is @@ -149,6 +152,8 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, struct sbi_trap_info uptrap; int i, len = 0; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE); + if (tinst & 0x1) { /* * Bit[0] == 1 implies trapped instruction value is diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c index 63e8ea98eadc..c7f1c80b8939 100644 --- a/lib/sbi/sbi_timer.c +++ b/lib/sbi/sbi_timer.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -88,6 +89,7 @@ void sbi_timer_set_delta_upper(ulong delta_upper) void sbi_timer_event_start(u64 next_event) { + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SET_TIMER); if (timer_dev && timer_dev->timer_event_start) timer_dev->timer_event_start(next_event); csr_clear(CSR_MIP, MIP_STIP); diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 73f59e8681e2..6e9e4f0b1916 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -21,6 +21,7 @@ #include #include #include +#include static unsigned long tlb_sync_off; static unsigned long tlb_fifo_off; @@ -39,6 +40,8 @@ void sbi_tlb_local_hfence_vvma(struct sbi_tlb_info *tinfo) unsigned long vmid = tinfo->vmid; unsigned long i, hgatp; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_RCVD); + hgatp = csr_swap(CSR_HGATP, (vmid << HGATP_VMID_SHIFT) & HGATP_VMID_MASK); @@ -61,6 +64,8 @@ void sbi_tlb_local_hfence_gvma(struct sbi_tlb_info *tinfo) unsigned long size = tinfo->size; unsigned long i; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_RCVD); + if ((start == 0 && size == 0) || (size == SBI_TLB_FLUSH_ALL)) { __sbi_hfence_gvma_all(); return; @@ -77,6 +82,8 @@ void sbi_tlb_local_sfence_vma(struct sbi_tlb_info *tinfo) unsigned long size = tinfo->size; unsigned long i; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_RCVD); + if ((start == 0 && size == 0) || (size == SBI_TLB_FLUSH_ALL)) { sbi_tlb_flush_all(); return; @@ -98,6 +105,8 @@ void sbi_tlb_local_hfence_vvma_asid(struct sbi_tlb_info *tinfo) unsigned long vmid = tinfo->vmid; unsigned long i, hgatp; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD); + hgatp = csr_swap(CSR_HGATP, (vmid << HGATP_VMID_SHIFT) & HGATP_VMID_MASK); @@ -126,6 +135,8 @@ void sbi_tlb_local_hfence_gvma_vmid(struct sbi_tlb_info *tinfo) unsigned long vmid = tinfo->vmid; unsigned long i; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_VMID_RCVD); + if (start == 0 && size == 0) { __sbi_hfence_gvma_all(); return; @@ -148,6 +159,8 @@ void sbi_tlb_local_sfence_vma_asid(struct sbi_tlb_info *tinfo) unsigned long asid = tinfo->asid; unsigned long i; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_ASID_RCVD); + if (start == 0 && size == 0) { sbi_tlb_flush_all(); return; @@ -172,9 +185,32 @@ void sbi_tlb_local_sfence_vma_asid(struct sbi_tlb_info *tinfo) void sbi_tlb_local_fence_i(struct sbi_tlb_info *tinfo) { + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_FENCE_I_RECVD); + __asm__ __volatile("fence.i"); } +static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data) +{ + if (unlikely(!data)) + return; + + if (data->local_fn == sbi_tlb_local_fence_i) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_FENCE_I_SENT); + else if (data->local_fn == sbi_tlb_local_sfence_vma) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_SENT); + else if (data->local_fn == sbi_tlb_local_sfence_vma_asid) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_ASID_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_gvma) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_gvma_vmid) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_VMID_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_vvma) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_vvma_asid) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT); +} + static void sbi_tlb_entry_process(struct sbi_tlb_info *tinfo) { u32 rhartid; @@ -368,6 +404,8 @@ int sbi_tlb_request(ulong hmask, ulong hbase, struct sbi_tlb_info *tinfo) if (!tinfo->local_fn) return SBI_EINVAL; + tlb_pmu_incr_fw_ctr(tinfo); + return sbi_ipi_send_many(hmask, hbase, tlb_event, tinfo); } diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 1ba649074b75..dda68d4375af 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -257,6 +258,10 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) rc = sbi_ecall_handler(regs); msg = "ecall handler failed"; break; + case CAUSE_LOAD_ACCESS: + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_LOAD); + case CAUSE_STORE_ACCESS: + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_STORE); default: /* If the trap came from S or U mode, redirect it there */ trap.epc = regs->mepc;