From: Christoph Hellwig <hch@infradead.org>
To: Gary Guo <gary@garyguo.net>
Cc: Palmer Dabbelt <palmer@sifive.com>,
Anup Patel <Anup.Patel@wdc.com>,
Christoph Hellwig <hch@infradead.org>,
Atish Patra <atish.patra@wdc.com>,
Albert Ou <aou@eecs.berkeley.edu>,
"linux-riscv@lists.infradead.org"
<linux-riscv@lists.infradead.org>
Subject: Re: [PATCH v4 4/5] riscv: rewrite tlb flush for performance
Date: Wed, 27 Mar 2019 00:25:57 -0700 [thread overview]
Message-ID: <20190327072557.GE3210@infradead.org> (raw)
In-Reply-To: <d60a62cfbbf63382a47e3c2226c5dd6148f8b814.1553647082.git.gary@garyguo.net>
> @@ -27,53 +19,47 @@ static inline void local_flush_tlb_all(void)
> __asm__ __volatile__ ("sfence.vma" : : : "memory");
> }
>
> -/* Flush one page from local TLB */
> -static inline void local_flush_tlb_page(unsigned long addr)
> +static inline void local_flush_tlb_mm(struct mm_struct *mm)
> {
> - __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory");
> + /* Flush ASID 0 so that global mappings are not affected */
> + __asm__ __volatile__ ("sfence.vma x0, %0" : : "r" (0) : "memory");
> }
>
> -#ifndef CONFIG_SMP
> -
> -#define flush_tlb_all() local_flush_tlb_all()
> -#define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
> +static inline void local_flush_tlb_page(struct vm_area_struct *vma,
> + unsigned long addr)
> +{
> + __asm__ __volatile__ ("sfence.vma %0, %1"
> + : : "r" (addr), "r" (0)
> + : "memory");
> +}
Why do we pass the vma argument here even if it is never used? That
just seems to create some rather pointless churn. Also I'd add
local_flush_tlb_mm below local_flush_tlb_page to avoid churn as well,
nevermind that it seems the more logical order to me.
> +void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
> + unsigned long end);
> +void local_flush_tlb_kernel_range(unsigned long start, unsigned long end);
As far as I can tell these are only used for the !SMP case and only
to implement the non-local prefixed versions. In that case we should
just drop the local_prefix and implement those APIs directly, and only
for !SMP builds.
> +
> +#include <linux/mm.h>
> +#include <asm/sbi.h>
> +
> +#define SFENCE_VMA_FLUSH_ALL ((unsigned long) -1)
> +
> +/*
> + * This controls the maximum amount of page-level sfence.vma that the kernel
> + * can issue when the kernel needs to flush a range from the TLB. If the size
> + * of range goes beyond this threshold, a full sfence.vma is issued.
> + *
> + * Increase this number can negatively impact performance on implementations
> + * where sfence.vma's address operand is ignored and always perform a global
> + * TLB flush. On the other hand, implementations with page-level TLB flush
> + * support can benefit from a larger number.
> + */
> +static unsigned long tlbi_range_threshold = PAGE_SIZE;
I really hate having this is a tunable in the kernel code. I think
the right answer is to have a device tree entry to carry this number
so that the platform can supply it. Btw, what are examples of
platforms that flush globalls vs per-page at the moment? What is a good
larger value for the latter based on your testing?
Also I wonder if we should also split this tunable and the optional
global flush into a separate patch. This is in this first patch
just make use of the asid, and then another patch to add the threshold
for doing the full flush.
> +void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
> + unsigned long end)
> +{
> + if (end - start > tlbi_range_threshold) {
> + local_flush_tlb_mm(vma->vm_mm);
> + return;
> + }
> +
> + while (start < end) {
> + __asm__ __volatile__ ("sfence.vma %0, %1"
> + : : "r" (start), "r" (0)
> + : "memory");
I think this should just call local_flush_tlb_page.
> + start += PAGE_SIZE;
> + }
And maybe use a for loop to short cut it a bit:
for (; start < end; start += PAGE_SIZE)
local_flush_tlb_page(start);
> +void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
> +{
> + if (end - start > tlbi_range_threshold) {
> + local_flush_tlb_all();
> + return;
> + }
> +
> + while (start < end) {
> + __asm__ __volatile__ ("sfence.vma %0"
> + : : "r" (start)
> + : "memory");
> + start += PAGE_SIZE;
Same here, just with local_flush_tlb_kernel_page.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2019-03-27 7:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-27 0:41 [PATCH v4 0/5] TLB/I$ flush cleanups and improvements Gary Guo
2019-03-27 0:41 ` [PATCH v4 1/5] riscv: move flush_icache_{all,mm} to cacheflush.c Gary Guo
2019-03-27 7:06 ` Christoph Hellwig
2019-03-28 6:45 ` Anup Patel
2019-03-27 0:41 ` [PATCH v4 3/5] riscv: fix sbi_remote_sfence_vma{,_asid} Gary Guo
2019-03-27 7:08 ` Christoph Hellwig
2019-03-28 6:47 ` Anup Patel
2019-03-27 0:41 ` [PATCH v4 4/5] riscv: rewrite tlb flush for performance Gary Guo
2019-03-27 7:25 ` Christoph Hellwig [this message]
2019-03-27 13:56 ` Gary Guo
2019-03-28 16:17 ` Christoph Hellwig
2019-03-28 16:39 ` Gary Guo
2019-03-28 16:55 ` Christoph Hellwig
2019-03-27 0:41 ` [PATCH v4 2/5] riscv: move switch_mm to its own file Gary Guo
2019-03-27 7:08 ` Christoph Hellwig
2019-03-27 7:18 ` Christoph Hellwig
2019-03-28 6:47 ` Anup Patel
2019-03-27 0:41 ` [PATCH v4 5/5] riscv: implement IPI-based remote TLB shootdown Gary Guo
2019-03-27 7:31 ` Christoph Hellwig
2019-03-27 14:03 ` Gary Guo
2019-03-28 16:36 ` Christoph Hellwig
2019-03-28 16:47 ` Gary Guo
2019-03-28 16:57 ` Christoph Hellwig
2019-03-28 6:50 ` Anup Patel
2019-04-10 7:04 ` [PATCH v4 0/5] TLB/I$ flush cleanups and improvements Christoph Hellwig
2019-04-10 9:01 ` Anup Patel
2019-04-10 10:11 ` Christoph Hellwig
2019-04-10 10:22 ` Anup Patel
2019-04-11 1:24 ` Atish Patra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190327072557.GE3210@infradead.org \
--to=hch@infradead.org \
--cc=Anup.Patel@wdc.com \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@wdc.com \
--cc=gary@garyguo.net \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).