Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1106664ybl; Fri, 9 Aug 2019 20:34:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRdatDFbrIlabzyn9IsC/wLNTrJKsOfmTtJMA5H2O6xJv9Q5upMp2Tp3WHwlqlgBtD8T/1 X-Received: by 2002:a63:e62:: with SMTP id 34mr20111618pgo.331.1565408062257; Fri, 09 Aug 2019 20:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565408062; cv=none; d=google.com; s=arc-20160816; b=a9U72NilRyAqIpxXpTxpLRpAJ07UYzicTS0V/1YPRUI6JeNkJdzqGTXLrhQma7y0zb fR17io7ZXBbNhppKrsOgBKuOf8DzPkn/jPc0uPn77xukHzaq/IsXaLbBkcTuSdbH6syW xtwqy8AALeYjZQqIYMnw1ywc3Bhscf6zIdpuHbfTrEAM7CzCXmVnfFKneMgSzULXWB9U JT4xO0Zql7wvQPs5MTuUECgxlQ8OU/TC7Jw5ySynT21JKFNzzLzn/kzhQqB1U5APqkjI hJLUUPfZKwXCtAWTEHn2teM/aIUPOLYZV7by8yvH15SsUffGfBtnnKGKDa+KCsuEzz1x iqHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=pI294dVKjBseXZ5d+Q9IVYt0QRka2gVN/5uVW6i/NR0=; b=Q/QIkipVqI/XwfDhrgsL5ehxDhaym5UheI6Xgcw+ODPK7HgnZgJxwXEO3Q7q/hd4K5 6T4fqh4sNFYvSQ++4bN3XoOdrTeDQiS/dMmDbVtqq032kMnJnBYmULnn2TgEYiJGueGK +kQNBksvQxPdeaU93e5MigSKR7hHKUtixqonDuEeBCDmyejieyqYTTEC0GNe4kycGWfd JGFRhgoHOMOuCGSUhNNKxmNxnSLa1p8M8UgpwuMtn/zhebbzLN5Zj+0dhT4OF9U3TQ2r 1j+Z5uEUW7qa14zsMpm5ZuzEO3XthWJxmr0YLzB15GeSBU4wBjP7TlMzoMmeW/1Z8pVX QmZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=J5PTbOEB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si60021662pfr.182.2019.08.09.20.33.53; Fri, 09 Aug 2019 20:34:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=J5PTbOEB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726055AbfHJDam (ORCPT + 99 others); Fri, 9 Aug 2019 23:30:42 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46698 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbfHJDam (ORCPT ); Fri, 9 Aug 2019 23:30:42 -0400 Received: by mail-wr1-f65.google.com with SMTP id z1so99894233wru.13 for ; Fri, 09 Aug 2019 20:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pI294dVKjBseXZ5d+Q9IVYt0QRka2gVN/5uVW6i/NR0=; b=J5PTbOEBgIKGa91XI8KrCeqtVkQDuGjs7vraImHqT8kgRrlykP4s4YYx4ReuuE7kOy cozMiwvKqevnP2ilsTl2/bG1Q6YauFFcfgbB+0CbUJ80YGpfbVvi4xdJY7AVw+bqwmkn 9Wt8jiZFeRxeztak/hhCM6pDlwtJXBC0Y7+nWkXJWCLmfMFPTyUtXfos1Y/hgtJvuazT XRijkkIvmKiTPjUeqTxL+rJZqrk3Zcny9cnMbiZ/AG/mbncKQmCL9fBHoF+33VTU0Xnz lJoSqwG/fwKpAJ5j4mGzGXCuRAL9z3pGVsOKHrgEaqVUMBsuUatch+aaNJGaot4P2gw+ SD9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pI294dVKjBseXZ5d+Q9IVYt0QRka2gVN/5uVW6i/NR0=; b=VMmuDBfivoP0h4rH4bHQDYmT5Rglw1XtOukx2ihJCkZo9ZAFslPJsBtVRO8tvChGJ1 QUXYZSJwsogStI/58cEwU1XKoPoR7F6uxf9+dATwkftwvDsAbhaD9YQWuAJF8TzknzMo FbNIQQ9m6P8F/Tq4z+uDHZG2CYwOtStkMUGBnY/LvM2q33zRpLpkpXlSHszvkjDa7mEQ rXzeyWdA1fuTTSI5ZnHwZWLpc6std5oz9SAhshxgFK2rXxzuCI6pW4be8aNhNPxxAT3K R0CUodK+z3rcePdqCxMo/GBTLDJ5Cre2XCiZrrwQJM353b5saA+P7HkEoL11+vYc/7Qu 7Ziw== X-Gm-Message-State: APjAAAUHoRX+xRggjVLBYtRhA1LW2RlV8me8HQHXBqZCLaNek3xhCwUT nsrKQAD4E4pQAGlIaBr2Pj2KDPccQXg/KauQR8AcRg== X-Received: by 2002:adf:f641:: with SMTP id x1mr24936115wrp.179.1565407840017; Fri, 09 Aug 2019 20:30:40 -0700 (PDT) MIME-Version: 1.0 References: <20190810014309.20838-1-atish.patra@wdc.com> In-Reply-To: <20190810014309.20838-1-atish.patra@wdc.com> From: Anup Patel Date: Sat, 10 Aug 2019 09:00:29 +0530 Message-ID: Subject: Re: [PATCH] RISC-V: Issue a local tlb flush if possible. To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Albert Ou , Alexios Zavras , Greg Kroah-Hartman , Palmer Dabbelt , Anup Patel , Paul Walmsley , linux-riscv , Allison Randal Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 10, 2019 at 7:13 AM Atish Patra wrote: > > In RISC-V, tlb flush happens via SBI which is expensive. > If the target cpumask contains a local hartid, some cost > can be saved by issuing a local tlb flush as we do that > in OpenSBI anyways. > > Signed-off-by: Atish Patra > --- > arch/riscv/include/asm/tlbflush.h | 33 +++++++++++++++++++++++++++---- > 1 file changed, 29 insertions(+), 4 deletions(-) > > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h > index 687dd19735a7..b32ba4fa5888 100644 > --- a/arch/riscv/include/asm/tlbflush.h > +++ b/arch/riscv/include/asm/tlbflush.h > @@ -8,6 +8,7 @@ > #define _ASM_RISCV_TLBFLUSH_H > > #include > +#include > #include > > /* > @@ -46,14 +47,38 @@ static inline void remote_sfence_vma(struct cpumask *cmask, unsigned long start, > unsigned long size) > { > struct cpumask hmask; > + struct cpumask tmask; > + int cpuid = smp_processor_id(); > > cpumask_clear(&hmask); > - riscv_cpuid_to_hartid_mask(cmask, &hmask); > - sbi_remote_sfence_vma(hmask.bits, start, size); > + cpumask_clear(&tmask); > + > + if (cmask) > + cpumask_copy(&tmask, cmask); > + else > + cpumask_copy(&tmask, cpu_online_mask); This can be further simplified. We can totally avoid tmask, cpumask_copy(), and cpumask_clear() by directly updating hmask. In addition to this patch, we should also handle the case of empty hart mask in OpenSBI. > + > + if (cpumask_test_cpu(cpuid, &tmask)) { > + /* Save trap cost by issuing a local tlb flush here */ > + if ((start == 0 && size == -1) || (size > PAGE_SIZE)) > + local_flush_tlb_all(); > + else if (size == PAGE_SIZE) > + local_flush_tlb_page(start); > + cpumask_clear_cpu(cpuid, &tmask); > + } else if (cpumask_empty(&tmask)) { > + /* cpumask is empty. So just do a local flush */ > + local_flush_tlb_all(); > + return; > + } > + > + if (!cpumask_empty(&tmask)) { > + riscv_cpuid_to_hartid_mask(&tmask, &hmask); > + sbi_remote_sfence_vma(hmask.bits, start, size); > + } > } > > -#define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1) > -#define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, 0) > +#define flush_tlb_all() remote_sfence_vma(NULL, 0, -1) > +#define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, (addr) + PAGE_SIZE) > #define flush_tlb_range(vma, start, end) \ > remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) - (start)) > #define flush_tlb_mm(mm) \ > -- > 2.21.0 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv Regards, Anup