Message ID | 20240102220134.3229156-5-samuel.holland@sifive.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-14914-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4706116dyb; Tue, 2 Jan 2024 14:06:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuwYhy6uy33hcJrs7nYZuOG4IGoRjkuMM80fF8W8hNDRajo7VdDulLRVX2AoR26yrl7X4F X-Received: by 2002:a50:c282:0:b0:556:17d4:b18b with SMTP id o2-20020a50c282000000b0055617d4b18bmr1629004edf.96.1704233172934; Tue, 02 Jan 2024 14:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704233172; cv=none; d=google.com; s=arc-20160816; b=ChnmyuS+KZuDp7f6E8SWkrv+be0Q/gcYvTtiZvEGJlw4WI54yjrCH/6EFZb6s5tlzs v10M8SHaqjXBdSlYJOt8PmEM9Ssv+dOBC2Zx1Bp9/TPLWStEcQ6IqxWV9DB9hzlDfei+ YKJkSBWcNTz6JHqmxhjGOr0x8jowvH6Ue5DNQAkkh1/hSZ8YyaiIY6og3PPmhQBZ6+Xv KJpMu7UoZEkpXem5EDGhfIbN6fjbQJ98VG65E/xg7QuaLDE8253/xYvD6qN10gPcrv+A XEkPvNws/+YA+e2M2JagEo3YSQswqee0NCq5wwfQV39T+e2FUpmubxmqr1ruZM02d3ZM y4kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YDpWqQ4mc+jX/Roh6ocibeJ1LmLlK7pqWIKc4/L4AE8=; fh=dlotjpk72cYcmDz0+AxIEXTz48ooVBc8lhZ+ndNwuOg=; b=qmYqARhSXa5nDjF8rbLwpdL4Pr6EjuHy4YP7Sl1I8uq+EZsgegsJpZNKRlISse5/jg lIFdnDCufAOoCu+fDNvODDnIm2w48pNDzMo3y8zHOlkSGtHe7LqdKJbGISOwWmeGgRB/ Jd3juaBBj41S0cu00qCAUV1nDYfD5rpS8SHm/0J/BcArO3U2TrdwrLDTjuU/LfIadTqo HfelBSzgJvJeXtw6lM+Gru0MXAX+wTUUg0DjCKVln+MauWLZ4zdG5NN7o2pk5MhJf+iA de62ygzQrHbTyShQIFT83BRF9rbscBkW6y2ZHiVHgMNnIc1IILHHMQvGsIo4SA2Y6ddT 0Drw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DgRqkJoN; spf=pass (google.com: domain of linux-kernel+bounces-14914-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14914-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v20-20020a50a454000000b0054cd1a2460asi11815005edb.672.2024.01.02.14.06.12 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:06:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14914-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DgRqkJoN; spf=pass (google.com: domain of linux-kernel+bounces-14914-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14914-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8A0CF1F2249B for <ouuuleilei@gmail.com>; Tue, 2 Jan 2024 22:06:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEC1919447; Tue, 2 Jan 2024 22:01:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="DgRqkJoN" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15FB418C35 for <linux-kernel@vger.kernel.org>; Tue, 2 Jan 2024 22:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5c229dabbb6so2569289a12.0 for <linux-kernel@vger.kernel.org>; Tue, 02 Jan 2024 14:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232901; x=1704837701; 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=YDpWqQ4mc+jX/Roh6ocibeJ1LmLlK7pqWIKc4/L4AE8=; b=DgRqkJoN7jmq4C8Mete+CRT6XrLFu/qo41dxk46PW9v6kz+g8QgJvnk6qO7xoHR+JN vm3DhCNlDOJ+DzdkuZPjd3T1BzPLejafjTfOLF9j0KNqj5ghgmvqV1dIWAECjHALDlXz LoMnfwTR1mPwilWyEifFn4whkLsUqDNqlxffLPsZvoNUXWF0ZBs/8p2SUuuj6DPLkbid W26tySgW6sKFChUQYQsKU8fT2ZkvAJFy4sgT6sK/1jihvVJEIOuLwvfcp4/JDOke5ggL ws9zS7AzG4voaTu2urPb1f2YSLkfXuO1DNTURKWFMuR5yrKzBI4NmEtEdoEZq8f0cxZp 0VjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704232901; x=1704837701; 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=YDpWqQ4mc+jX/Roh6ocibeJ1LmLlK7pqWIKc4/L4AE8=; b=WKqC4CvQFhUZbVjhiOCu5QGJDxhePG1vwLIRK771A9cfW8OiP8/JuwDnbWKuFCx00j UPJVyoaOTyMsZKyXEwC6Pm8evkOSTUAazrFypPTP0qP8N3Aw1IYSOGjX75juwUTqkyaR B/DAIcDDs8SjMVx43FY+uFprarfiOFN2Go1ni0KXQQ7sFvlZZOfykeleVj4QFxlP+7AQ IolhiN891P55EcsCgeccsgSxr/rvD7FyTEv9pQdy5SPqzeuo2azW2/sL6OwZRctgSE/r Sn9c8oXuNn4TlbR4215G0MyFsCZMFDzQWnnncK1E8tZFkUQNR2iFegVe1JNTtYRQP+7j HwCA== X-Gm-Message-State: AOJu0YzkEUSkws0sJRqQAp4MihPl0FEzcQ41BcVUjEZNk0gClqldWGLt Rzabx5d94U8tpAvOu+ice3MOP9xdkfsENCZS4vkccVSGlE0= X-Received: by 2002:a17:90a:6ba6:b0:28c:640b:ce0b with SMTP id w35-20020a17090a6ba600b0028c640bce0bmr4536054pjj.33.1704232901387; Tue, 02 Jan 2024 14:01:41 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id r59-20020a17090a43c100b0028ce507cd7dsm101724pjg.55.2024.01.02.14.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:01:41 -0800 (PST) From: Samuel Holland <samuel.holland@sifive.com> To: Palmer Dabbelt <palmer@dabbelt.com>, linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti <alexghiti@rivosinc.com>, Samuel Holland <samuel.holland@sifive.com> Subject: [PATCH v4 04/12] riscv: Only send remote fences when some other CPU is online Date: Tue, 2 Jan 2024 14:00:41 -0800 Message-ID: <20240102220134.3229156-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240102220134.3229156-1-samuel.holland@sifive.com> References: <20240102220134.3229156-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787018003519615186 X-GMAIL-MSGID: 1787018003519615186 |
Series |
riscv: ASID-related and UP-related TLB flush enhancements
|
|
Commit Message
Samuel Holland
Jan. 2, 2024, 10 p.m. UTC
If no other CPU is online, a local cache or TLB flush is sufficient.
These checks can be constant-folded when SMP is disabled.
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
---
Changes in v4:
- New patch for v4
arch/riscv/mm/cacheflush.c | 4 +++-
arch/riscv/mm/tlbflush.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
Comments
On Tue, Jan 02, 2024 at 02:00:41PM -0800, Samuel Holland wrote: > If no other CPU is online, a local cache or TLB flush is sufficient. > These checks can be constant-folded when SMP is disabled. > > Signed-off-by: Samuel Holland <samuel.holland@sifive.com> > --- > > Changes in v4: > - New patch for v4 > > arch/riscv/mm/cacheflush.c | 4 +++- > arch/riscv/mm/tlbflush.c | 4 +++- > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c > index 47c485bc7df0..f7933ae88a55 100644 > --- a/arch/riscv/mm/cacheflush.c > +++ b/arch/riscv/mm/cacheflush.c > @@ -21,7 +21,9 @@ void flush_icache_all(void) > { > local_flush_icache_all(); > > - if (riscv_use_sbi_for_rfence()) > + if (num_online_cpus() < 2) with patch5, I think it's better to short cut for !SMP, I.E if (!IS_ENABLED(CONFIG_SMP) || num_online_cpus()) < 2) so that the UP case can avoid a atomic read and check > + return; > + else if (riscv_use_sbi_for_rfence()) > sbi_remote_fence_i(NULL); > else > on_each_cpu(ipi_remote_fence_i, NULL, 1); > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > index 2f18fe6fc4f3..37b3c93e3c30 100644 > --- a/arch/riscv/mm/tlbflush.c > +++ b/arch/riscv/mm/tlbflush.c > @@ -73,7 +73,9 @@ static void __ipi_flush_tlb_all(void *info) > > void flush_tlb_all(void) > { > - if (riscv_use_sbi_for_rfence()) > + if (num_online_cpus() < 2) ditto > + local_flush_tlb_all(); > + else if (riscv_use_sbi_for_rfence()) > sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID); > else > on_each_cpu(__ipi_flush_tlb_all, NULL, 1); > -- > 2.42.0 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv
On Wed, Jan 03, 2024 at 10:58:01PM +0800, Jisheng Zhang wrote: > On Tue, Jan 02, 2024 at 02:00:41PM -0800, Samuel Holland wrote: > > If no other CPU is online, a local cache or TLB flush is sufficient. > > These checks can be constant-folded when SMP is disabled. > > > > Signed-off-by: Samuel Holland <samuel.holland@sifive.com> > > --- > > > > Changes in v4: > > - New patch for v4 > > > > arch/riscv/mm/cacheflush.c | 4 +++- > > arch/riscv/mm/tlbflush.c | 4 +++- > > 2 files changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c > > index 47c485bc7df0..f7933ae88a55 100644 > > --- a/arch/riscv/mm/cacheflush.c > > +++ b/arch/riscv/mm/cacheflush.c > > @@ -21,7 +21,9 @@ void flush_icache_all(void) > > { > > local_flush_icache_all(); > > > > - if (riscv_use_sbi_for_rfence()) > > + if (num_online_cpus() < 2) > > with patch5, I think it's better to short cut for !SMP, I.E > if (!IS_ENABLED(CONFIG_SMP) || num_online_cpus()) < 2) aha, plz ignore this comment, I see the num_online_cpus() is defined as 1U for UP. > > so that the UP case can avoid a atomic read and check > > > + return; > > + else if (riscv_use_sbi_for_rfence()) > > sbi_remote_fence_i(NULL); > > else > > on_each_cpu(ipi_remote_fence_i, NULL, 1); > > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > > index 2f18fe6fc4f3..37b3c93e3c30 100644 > > --- a/arch/riscv/mm/tlbflush.c > > +++ b/arch/riscv/mm/tlbflush.c > > @@ -73,7 +73,9 @@ static void __ipi_flush_tlb_all(void *info) > > > > void flush_tlb_all(void) > > { > > - if (riscv_use_sbi_for_rfence()) > > + if (num_online_cpus() < 2) > > ditto > > > + local_flush_tlb_all(); > > + else if (riscv_use_sbi_for_rfence()) > > sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID); > > else > > on_each_cpu(__ipi_flush_tlb_all, NULL, 1); > > -- > > 2.42.0 > > > > > > _______________________________________________ > > linux-riscv mailing list > > linux-riscv@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-riscv
On Tue, Jan 2, 2024 at 11:01 PM Samuel Holland <samuel.holland@sifive.com> wrote: > > If no other CPU is online, a local cache or TLB flush is sufficient. > These checks can be constant-folded when SMP is disabled. > > Signed-off-by: Samuel Holland <samuel.holland@sifive.com> > --- > > Changes in v4: > - New patch for v4 > > arch/riscv/mm/cacheflush.c | 4 +++- > arch/riscv/mm/tlbflush.c | 4 +++- > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c > index 47c485bc7df0..f7933ae88a55 100644 > --- a/arch/riscv/mm/cacheflush.c > +++ b/arch/riscv/mm/cacheflush.c > @@ -21,7 +21,9 @@ void flush_icache_all(void) > { > local_flush_icache_all(); > > - if (riscv_use_sbi_for_rfence()) > + if (num_online_cpus() < 2) > + return; > + else if (riscv_use_sbi_for_rfence()) > sbi_remote_fence_i(NULL); > else > on_each_cpu(ipi_remote_fence_i, NULL, 1); > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > index 2f18fe6fc4f3..37b3c93e3c30 100644 > --- a/arch/riscv/mm/tlbflush.c > +++ b/arch/riscv/mm/tlbflush.c > @@ -73,7 +73,9 @@ static void __ipi_flush_tlb_all(void *info) > > void flush_tlb_all(void) > { > - if (riscv_use_sbi_for_rfence()) > + if (num_online_cpus() < 2) > + local_flush_tlb_all(); > + else if (riscv_use_sbi_for_rfence()) > sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID); > else > on_each_cpu(__ipi_flush_tlb_all, NULL, 1); > -- > 2.42.0 > on_each_cpu() already deals correctly with a single online cpu, the only thing to optimize here is the SBI rfence. So I'd move this new test in sbi_remote_sfence_vma_asid() and sbi_remote_fence_i() to avoid the superfluous M-mode entry when only one cpu is online by checking the cpumask. And since sbi_remote_fence_i() is used in another function (flush_icache_mm()), we could also take advantage of this optimization when only the local cpu must be flushed.
Hi Alex, On 2024-01-04 6:33 AM, Alexandre Ghiti wrote: > On Tue, Jan 2, 2024 at 11:01 PM Samuel Holland > <samuel.holland@sifive.com> wrote: >> >> If no other CPU is online, a local cache or TLB flush is sufficient. >> These checks can be constant-folded when SMP is disabled. >> >> Signed-off-by: Samuel Holland <samuel.holland@sifive.com> >> --- >> >> Changes in v4: >> - New patch for v4 >> >> arch/riscv/mm/cacheflush.c | 4 +++- >> arch/riscv/mm/tlbflush.c | 4 +++- >> 2 files changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c >> index 47c485bc7df0..f7933ae88a55 100644 >> --- a/arch/riscv/mm/cacheflush.c >> +++ b/arch/riscv/mm/cacheflush.c >> @@ -21,7 +21,9 @@ void flush_icache_all(void) >> { >> local_flush_icache_all(); >> >> - if (riscv_use_sbi_for_rfence()) >> + if (num_online_cpus() < 2) >> + return; >> + else if (riscv_use_sbi_for_rfence()) >> sbi_remote_fence_i(NULL); >> else >> on_each_cpu(ipi_remote_fence_i, NULL, 1); >> diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c >> index 2f18fe6fc4f3..37b3c93e3c30 100644 >> --- a/arch/riscv/mm/tlbflush.c >> +++ b/arch/riscv/mm/tlbflush.c >> @@ -73,7 +73,9 @@ static void __ipi_flush_tlb_all(void *info) >> >> void flush_tlb_all(void) >> { >> - if (riscv_use_sbi_for_rfence()) >> + if (num_online_cpus() < 2) >> + local_flush_tlb_all(); >> + else if (riscv_use_sbi_for_rfence()) >> sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID); >> else >> on_each_cpu(__ipi_flush_tlb_all, NULL, 1); >> -- >> 2.42.0 >> > > on_each_cpu() already deals correctly with a single online cpu, the > only thing to optimize here is the SBI rfence. So I'd move this new > test in sbi_remote_sfence_vma_asid() and sbi_remote_fence_i() to avoid > the superfluous M-mode entry when only one cpu is online by checking > the cpumask. And since sbi_remote_fence_i() is used in another What specific cpumask check are you suggesting? In sbi_remote_sfence_vma_asid() I don't think we can assume the local cpu is always included in the cpumask (which we _can_ assume here), so it would need to construct/compare the whole bitmap. That's much more expensive than the atomic load here. > function (flush_icache_mm()), we could also take advantage of this > optimization when only the local cpu must be flushed. flush_icache_mm() already has a "local" variable which it uses to skip the call to sbi_remote_fence_i(). Same with the broadcast check in __flush_tlb_range(). So no additional check is needed there. Those two functions, plus the two changed in this patch, are the only call sites of the sbi_*() functions. I think it makes more sense to optimize the four call sites than adding an additional check in the sbi_*() functions. Regards, Samuel
diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 47c485bc7df0..f7933ae88a55 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -21,7 +21,9 @@ void flush_icache_all(void) { local_flush_icache_all(); - if (riscv_use_sbi_for_rfence()) + if (num_online_cpus() < 2) + return; + else if (riscv_use_sbi_for_rfence()) sbi_remote_fence_i(NULL); else on_each_cpu(ipi_remote_fence_i, NULL, 1); diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 2f18fe6fc4f3..37b3c93e3c30 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -73,7 +73,9 @@ static void __ipi_flush_tlb_all(void *info) void flush_tlb_all(void) { - if (riscv_use_sbi_for_rfence()) + if (num_online_cpus() < 2) + local_flush_tlb_all(); + else if (riscv_use_sbi_for_rfence()) sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID); else on_each_cpu(__ipi_flush_tlb_all, NULL, 1);