Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1718737rdb; Thu, 7 Dec 2023 07:08:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6eO0FCcuHyQFOeGAVEPhHMh57lnAC9KdR7fHHXZxAVvGn7Bq4dxRo1WKcguIoS0ofyoNf X-Received: by 2002:a17:90a:189:b0:286:6cc1:7809 with SMTP id 9-20020a17090a018900b002866cc17809mr2698751pjc.76.1701961694047; Thu, 07 Dec 2023 07:08:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701961694; cv=none; d=google.com; s=arc-20160816; b=WBVRlX2DCyA2ulji3+XRielHkYrqtRXhDlXzYJMeyqFF7quC0c2XbBivxq4TrST5ZT J7lbPOjBGNxZYxtwEsYIakJQah2QAVVpN681+5y/MrOmBkLRr5Oi0QfLlcJ0MFabbDfG janxF29wqCS6bzufQTwWOBR3qLSc1mcbhAcZQTZtnvCQE+gnpphzKJG71Cc64j5uzfm9 hqCAdw+Kdq8FGHKS2mwSpRn4oXv5TvJgvCXS3N4ntnZqNfJL2MDezZvoHcrVk0IloNTM fZffBgh+qSm1EZvkg2e9KOP9imnk60nfw0iNZm1bk3pVxa4QY34JMQEFpgBliXnNZJRA urKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Copp2ndGZ68t6KATBAuS2R34UMtC0q0chiu6mkWyRdw=; fh=ghJZAeZ4zrru54jVI3XtuZXbadJtp4HIJMVSTZEe2l4=; b=LLA7jxnbhvJz+BA28EO6EEhE5tR01+6xD5Ha/yzoK7RBnqvfW/yLR00VvaE34I2YPk xXlO/MOFiy/rgtSPGdZlUWjyXklPpuAM1mDJCYbpyF7cF4lGDvI5rcvhMkm/XgBEmSDL ltr7Amf8bogqvQOYijssaYxXHFBn3wgMyOfr+mJFwGmdwc7amfCrOoNOECXCZRMMDVkP lVdBo2hVM7zQZTHVm2GGrXUg5xzJOxvB2gpT6nDcRLJNfRbCHQ3OCvuSSl22NYnevj5c OZioZS3pgJI9Wp3U/7MtQA9d13YYulhSu6p79ocMgWOCHKZWNjtmgGmWGRs6A13mPIns 0pcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=u8t5vxmE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id cl21-20020a17090af69500b00286e9d394d0si1219436pjb.23.2023.12.07.07.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 07:08:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=u8t5vxmE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9BF4980A8DB7; Thu, 7 Dec 2023 07:08:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443254AbjLGPHx (ORCPT + 99 others); Thu, 7 Dec 2023 10:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442917AbjLGPHv (ORCPT ); Thu, 7 Dec 2023 10:07:51 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5562D1AD for ; Thu, 7 Dec 2023 07:07:57 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50bfd8d5c77so971000e87.1 for ; Thu, 07 Dec 2023 07:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1701961675; x=1702566475; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Copp2ndGZ68t6KATBAuS2R34UMtC0q0chiu6mkWyRdw=; b=u8t5vxmEmHrKhlXGx9Y1N22VRqEFQuUadlfMtoo8YlaN1NJBs4b/TI9x6wdcbrDmBr 6o+Dq6kP9F/uNNwM6YxO1CGcDP7qK32Qpk+G2r9A9sMO0JDQeB44UvlKaXvCUBc059bN NOiEocdglH4p1FidzTJeE+aIFXQpuZtYPGwQZxpELUowMXVbTv6b/9p7HFmo2YdouxH2 zbjCTJqHU/b4WJQ0pCo6ldSOPSyPKWVu24Tt4RI+KjISKwg8ljY/WsOXs/mSCrik4XGo V78oY1Rt2tpGheqk4yjuj/sDv3vWdtCN9THm+uvqy1W6KJMfV+h4tBJayW3Yjn5vbXJM NjgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701961675; x=1702566475; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Copp2ndGZ68t6KATBAuS2R34UMtC0q0chiu6mkWyRdw=; b=llWcqIbl5PDTalrj6J+yxpt1OFtKxQ97ZbONG0+gnv3JothHduFhVGB+WIjUehH0yt Mhah+6GlFmUxv7R2gRDnB7J5xUGZHs8ui4cphPb4ipjaJCz+WS3PvJGQUCKM8+U8169E wOi1EKIH8jXxkH5g8PhS4LSMc9xdQwJDRMauKRV9v1ycYiZlnsszSfNo3tbBKyl8h4+r TvNhdahiL6ccr6cI/a9NQNlSrns/M1WTjqgZ86XryVhXXP3gsCzXIrlV7wIAMbRAamMt gaPhP5YVpvdg1WWMRJLFL7IseXaj0eAt58f3ddNCjLZ+mw8oEYo5/HFML93eG4SvDPmn nxSA== X-Gm-Message-State: AOJu0YzmFdaFH0OzAy/pu44fcuJrYA6B0W2npLe4iUeCBMdnoW9VWO6F EybjIGS1FY3+TITZe37zYzcUxA== X-Received: by 2002:ac2:5147:0:b0:50b:debe:d35d with SMTP id q7-20020ac25147000000b0050bdebed35dmr702137lfd.133.1701961675502; Thu, 07 Dec 2023 07:07:55 -0800 (PST) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id i11-20020a5d438b000000b003332ef77db4sm1647628wrq.44.2023.12.07.07.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 07:07:55 -0800 (PST) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Thomas Bogendoerfer , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Morton , Ved Shanbhogue , Matt Evans , Dylan Jhong , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH RFC/RFT 4/4] TEMP: riscv: Add debugfs interface to retrieve #sfence.vma Date: Thu, 7 Dec 2023 16:03:48 +0100 Message-Id: <20231207150348.82096-5-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231207150348.82096-1-alexghiti@rivosinc.com> References: <20231207150348.82096-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 07 Dec 2023 07:08:10 -0800 (PST) This is useful for testing/benchmarking. Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable.h | 6 ++++-- arch/riscv/include/asm/tlbflush.h | 4 ++++ arch/riscv/kernel/sbi.c | 12 ++++++++++++ arch/riscv/mm/tlbflush.c | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 89aa5650f104..b0855a620cfd 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -550,7 +550,7 @@ static inline int ptep_set_access_flags(struct vm_area_struct *vma, return false; } -extern u64 nr_sfence_vma_handle_exception; +extern u64 nr_sfence_vma_spurious_read; extern bool tlb_caching_invalid_entries; #define flush_tlb_fix_spurious_read_fault flush_tlb_fix_spurious_read_fault @@ -558,8 +558,10 @@ static inline void flush_tlb_fix_spurious_read_fault(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { - if (tlb_caching_invalid_entries) + if (tlb_caching_invalid_entries) { + __sync_fetch_and_add(&nr_sfence_vma_spurious_read, 1UL); flush_tlb_page(vma, address); + } } #define __HAVE_ARCH_PTEP_GET_AND_CLEAR diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index a09196f8de68..f419ec9d2207 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -14,14 +14,18 @@ #ifdef CONFIG_MMU extern unsigned long asid_mask; +extern u64 nr_sfence_vma, nr_sfence_vma_all, nr_sfence_vma_all_asid; + static inline void local_flush_tlb_all(void) { + __sync_fetch_and_add(&nr_sfence_vma_all, 1UL); __asm__ __volatile__ ("sfence.vma" : : : "memory"); } /* Flush one page from local TLB */ static inline void local_flush_tlb_page(unsigned long addr) { + __sync_fetch_and_add(&nr_sfence_vma, 1UL); ALT_FLUSH_TLB_PAGE(__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory")); } #else /* CONFIG_MMU */ diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index c672c8ba9a2a..ac1617759583 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -376,6 +376,8 @@ int sbi_remote_fence_i(const struct cpumask *cpu_mask) } EXPORT_SYMBOL(sbi_remote_fence_i); +extern u64 nr_sfence_vma, nr_sfence_vma_all, nr_sfence_vma_all_asid; + /** * sbi_remote_sfence_vma() - Execute SFENCE.VMA instructions on given remote * harts for the specified virtual address range. @@ -389,6 +391,11 @@ int sbi_remote_sfence_vma(const struct cpumask *cpu_mask, unsigned long start, unsigned long size) { + if (size == (unsigned long)-1) + __sync_fetch_and_add(&nr_sfence_vma_all, 1UL); + else + __sync_fetch_and_add(&nr_sfence_vma, ALIGN(size, PAGE_SIZE) / PAGE_SIZE); + return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, cpu_mask, start, size, 0, 0); } @@ -410,6 +417,11 @@ int sbi_remote_sfence_vma_asid(const struct cpumask *cpu_mask, unsigned long size, unsigned long asid) { + if (size == (unsigned long)-1) + __sync_fetch_and_add(&nr_sfence_vma_all_asid, 1UL); + else + __sync_fetch_and_add(&nr_sfence_vma, ALIGN(size, PAGE_SIZE) / PAGE_SIZE); + return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, cpu_mask, start, size, asid, 0); } diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 77be59aadc73..75a3e2dff16a 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -3,11 +3,16 @@ #include #include #include +#include #include #include +u64 nr_sfence_vma, nr_sfence_vma_all, nr_sfence_vma_all_asid, + nr_sfence_vma_handle_exception, nr_sfence_vma_spurious_read; + static inline void local_flush_tlb_all_asid(unsigned long asid) { + __sync_fetch_and_add(&nr_sfence_vma_all_asid, 1); __asm__ __volatile__ ("sfence.vma x0, %0" : : "r" (asid) @@ -17,6 +22,7 @@ static inline void local_flush_tlb_all_asid(unsigned long asid) static inline void local_flush_tlb_page_asid(unsigned long addr, unsigned long asid) { + __sync_fetch_and_add(&nr_sfence_vma, 1); __asm__ __volatile__ ("sfence.vma %0, %1" : : "r" (addr), "r" (asid) @@ -149,3 +155,14 @@ void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, __flush_tlb_range(vma->vm_mm, start, end - start, PMD_SIZE); } #endif + +static int debugfs_nr_sfence_vma(void) +{ + debugfs_create_u64("nr_sfence_vma", 0444, NULL, &nr_sfence_vma); + debugfs_create_u64("nr_sfence_vma_all", 0444, NULL, &nr_sfence_vma_all); + debugfs_create_u64("nr_sfence_vma_all_asid", 0444, NULL, &nr_sfence_vma_all_asid); + debugfs_create_u64("nr_sfence_vma_handle_exception", 0444, NULL, &nr_sfence_vma_handle_exception); + debugfs_create_u64("nr_sfence_vma_spurious_read", 0444, NULL, &nr_sfence_vma_spurious_read); + return 0; +} +device_initcall(debugfs_nr_sfence_vma); -- 2.39.2