Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1363982rwb; Fri, 28 Jul 2023 08:23:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlG9rpL15KZ74CKrpNUZ0f5ZWntUm4AZU/oU09N8cewsJXFlXuMP3U7uT1MECG36uVn9fzyC X-Received: by 2002:a17:90a:c58e:b0:262:f928:618d with SMTP id l14-20020a17090ac58e00b00262f928618dmr1385763pjt.35.1690557782204; Fri, 28 Jul 2023 08:23:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690557782; cv=none; d=google.com; s=arc-20160816; b=OOGFpUE4jd4mR9ViqhdPOPzbjKsPsIc0CQto5P54JFosXCYfm5fScGf+fbI48s2pjo HZ++FGIRPv70v2VTSAjUWf92ypO+eYXV2Oeo7LvVw3qeUP6PEYWnrkPYvvh8QgX0qSZZ w2vyjGUlINI850UYmAdTDbmAZCM2jkiaQW7lfH8araqjI6MdH8vhXd/sumPM7m/M5JL6 0KggDJE7wecJHi4ahil2OJj22pAlZ6TALyOEBGhbLAcVSR62O0cU0tzta/yzlV6G5SqP TLANpaUKNlRK8Ixoi0iOuN5L10NJLyZPx38HWx09nuvF5WUL3hcw8ow8SYD2Fyksl06g 32sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yfPWFATzg2F/vGl+Rugnp8J3pij37XeUvwzh4yvIFCk=; fh=PT7uWiHsMDulxPw+SzAnwRDP9jn/UBIbv5TZuChOeZ4=; b=Yb/YPCT5zAZ+5NKSL6aXuKx3gdJQHh3GeYBTVBCcAhmVKT0CNh24htvbIMIYe0Qw7y tN25bee8dJ3Sra+2YDwMrQWkl+8XHOd99xEBwdTiM8Dt5+qTgDDtAjFS6mcBnhLL8cgc XYGvFBWa5ICtXK/ynEytMTFx2lXrkrGtIjFghIxBRILHg+5iKBhe02dFfyMBIfklTUYg 4ui3gSmTiYytYYXVeibayfhtNfUUMMtuWEgWi89rc7B0b6Mtsu+Y+HtYhkryNSuTdZ10 EoPrGNZzTTDoDfJy5BxGbNAZV6gpIHc/SKy1j+5IcqZpiP0NR9kei4kVoBIsu+6YQVA5 0SMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SjWIgG6+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a17090a49c900b0025c1f64f29dsi2573671pjm.171.2023.07.28.08.22.49; Fri, 28 Jul 2023 08:23:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SjWIgG6+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235965AbjG1Ne0 (ORCPT + 99 others); Fri, 28 Jul 2023 09:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235760AbjG1NeY (ORCPT ); Fri, 28 Jul 2023 09:34:24 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A6BA4231 for ; Fri, 28 Jul 2023 06:33:48 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2b703a0453fso32771611fa.3 for ; Fri, 28 Jul 2023 06:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690551157; x=1691155957; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=yfPWFATzg2F/vGl+Rugnp8J3pij37XeUvwzh4yvIFCk=; b=SjWIgG6+pK5Kii8Yby+9NO7xIGyFBTEUn4+5wU/eQ5I0TU3hGh3GWvV9Scui3YYgFS AKpFsMUSp/P/TYQRDsiVUHZLauCM1MHhu2AkYu24OezBCBiGfpycIhgdfy/lx01Q8ia8 7uNmyrFh2/3iUkHZmihu706TB82aCptMxg2JYUJ2EE+zFVkcWqKyzYjYKmf6dCaSJ/KV ozszfhbwpEQXwR66f9qjQPwxFF6KCTPtQ1HO3Qb8lDbpMCmmmYmGSBW01NcP6jXg49vy tVOTwgYAsDmTDYDWHz8TMg9gRXcZJ29nzcG4/l1+BM7IBkWJdefiASqT3FJht9c0rWsr cLOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690551157; x=1691155957; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yfPWFATzg2F/vGl+Rugnp8J3pij37XeUvwzh4yvIFCk=; b=clGhnLUyB/NO07YrgiDK3HJL7fq3PNhy/k4FHjfylqdmVH6dAo06okZV65++BPDXLD 3b9kItrOkgF+wdATXxyIq+Vg8cPBnRCjfUIEz0RCGlYElNqHjm6ha/p3L5tO/cw4pIlz X2hp8gdYtvfXmzMdunER4ytg/oF+9boa1yDZNDz1eAkzJfAQctGI234eivXIEmmZ56Tj 9MG3KcavpyveMqPxyciZWtFYk27OkCypJvhMmjPocIV8BiFZYWaWbQ9uuJ+pco+6KtWc 30k0qMj3c8IJ4kPm7ZCWYlT2UWeh4pN12CX8ratF6BIUSaFGKS5L+YYvQXBiA+PHZmgL X5mQ== X-Gm-Message-State: ABy/qLaFq+DvOfrtxQphXw4UclAxBkfVo636yf+N/qafER9AX3GMyOfv uNscUD7wKmdQGiMVyvAv3wwn4g== X-Received: by 2002:a2e:9444:0:b0:2b9:bbf5:7c6 with SMTP id o4-20020a2e9444000000b002b9bbf507c6mr1825736ljh.43.1690551156738; Fri, 28 Jul 2023 06:32:36 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id h19-20020a17090634d300b0098e422d6758sm2054351ejb.219.2023.07.28.06.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 06:32:36 -0700 (PDT) Date: Fri, 28 Jul 2023 15:32:35 +0200 From: Andrew Jones To: Alexandre Ghiti Cc: Will Deacon , "Aneesh Kumar K . V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Mayuresh Chitale , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/4] riscv: Make __flush_tlb_range() loop over pte instead of flushing the whole tlb Message-ID: <20230728-f2cd8ddd252c2ece2e438790@orel> References: <20230727185553.980262-1-alexghiti@rivosinc.com> <20230727185553.980262-4-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230727185553.980262-4-alexghiti@rivosinc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 27, 2023 at 08:55:52PM +0200, Alexandre Ghiti wrote: > Currently, when the range to flush covers more than one page (a 4K page or > a hugepage), __flush_tlb_range() flushes the whole tlb. Flushing the whole > tlb comes with a greater cost than flushing a single entry so we should > flush single entries up to a certain threshold so that: > threshold * cost of flushing a single entry < cost of flushing the whole > tlb. > > This threshold is microarchitecture dependent and can/should be > overwritten by vendors. > > Co-developed-by: Mayuresh Chitale > Signed-off-by: Mayuresh Chitale > Signed-off-by: Alexandre Ghiti > --- > arch/riscv/mm/tlbflush.c | 41 ++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 39 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > index 3e4acef1f6bc..8017d2130e27 100644 > --- a/arch/riscv/mm/tlbflush.c > +++ b/arch/riscv/mm/tlbflush.c > @@ -24,13 +24,48 @@ static inline void local_flush_tlb_page_asid(unsigned long addr, > : "memory"); > } > > +/* > + * Flush entire TLB if number of entries to be flushed is greater > + * than the threshold below. Platforms may override the threshold > + * value based on marchid, mvendorid, and mimpid. > + */ > +static unsigned long tlb_flush_all_threshold __read_mostly = 64; > + > +static void local_flush_tlb_range_threshold_asid(unsigned long start, > + unsigned long size, > + unsigned long stride, > + unsigned long asid) > +{ > + u16 nr_ptes_in_range = DIV_ROUND_UP(size, stride); > + int i; > + > + if (nr_ptes_in_range > tlb_flush_all_threshold) { > + if (asid != -1) > + local_flush_tlb_all_asid(asid); > + else > + local_flush_tlb_all(); > + return; > + } > + > + for (i = 0; i < nr_ptes_in_range; ++i) { > + if (asid != -1) > + local_flush_tlb_page_asid(start, asid); > + else > + local_flush_tlb_page(start); > + start += stride; > + } > +} > + > static inline void local_flush_tlb_range(unsigned long start, > unsigned long size, unsigned long stride) > { > if (size <= stride) > local_flush_tlb_page(start); > - else > + else if (size == (unsigned long)-1) The more we scatter this -1 around, especially now that we also need to cast it, the more I think we should introduce a #define for it. > local_flush_tlb_all(); > + else > + local_flush_tlb_range_threshold_asid(start, size, stride, -1); > + > } > > static inline void local_flush_tlb_range_asid(unsigned long start, > @@ -38,8 +73,10 @@ static inline void local_flush_tlb_range_asid(unsigned long start, > { > if (size <= stride) > local_flush_tlb_page_asid(start, asid); > - else > + else if (size == (unsigned long)-1) > local_flush_tlb_all_asid(asid); > + else > + local_flush_tlb_range_threshold_asid(start, size, stride, asid); > } > > static void __ipi_flush_tlb_all(void *info) > -- > 2.39.2 > Otherwise, Reviewed-by: Andrew Jones Thanks, drew