All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nam Cao <namcao@linutronix.de>
To: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	Jisheng Zhang <jszhang@kernel.org>
Subject: Re: [PATCH v2] riscv: Add support for BATCHED_UNMAP_TLB_FLUSH
Date: Mon, 8 Jan 2024 21:44:48 +0100	[thread overview]
Message-ID: <20240108214448.025977ac@namcao> (raw)
In-Reply-To: <20240108214346.5fd93127@namcao>

On Mon, 8 Jan 2024 21:43:46 +0100 Nam Cao <namcao@linutronix.de> wrote:

> On Mon,  8 Jan 2024 20:36:40 +0100 Alexandre Ghiti <alexghiti@rivosinc.com> wrote:
> > Allow to defer the flushing of the TLB when unmapping pages, which allows
> > to reduce the numbers of IPI and the number of sfence.vma.
> > 
> > The ubenchmarch used in commit 43b3dfdd0455 ("arm64: support
> > batched/deferred tlb shootdown during page reclamation/migration") that
> > was multithreaded to force the usage of IPI shows good performance
> > improvement on all platforms:
> > 
> > * Unmatched: ~34%
> > * TH1520   : ~78%
> > * Qemu     : ~81%
> > 
> > In addition, perf on qemu reports an important decrease in time spent
> > dealing with IPIs:
> > 
> > Before:  68.17%  main     [kernel.kallsyms]            [k] __sbi_rfence_v02_call
> > After :   8.64%  main     [kernel.kallsyms]            [k] __sbi_rfence_v02_call
> > 
> > * Benchmark:
> > 
> > int stick_this_thread_to_core(int core_id) {
> >         int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
> >         if (core_id < 0 || core_id >= num_cores)
> >            return EINVAL;
> > 
> >         cpu_set_t cpuset;
> >         CPU_ZERO(&cpuset);
> >         CPU_SET(core_id, &cpuset);
> > 
> >         pthread_t current_thread = pthread_self();
> >         return pthread_setaffinity_np(current_thread,
> > sizeof(cpu_set_t), &cpuset);
> > }
> > 
> > static void *fn_thread (void *p_data)
> > {
> >         int ret;
> >         pthread_t thread;
> > 
> >         stick_this_thread_to_core((int)p_data);
> > 
> >         while (1) {
> >                 sleep(1);
> >         }
> > 
> >         return NULL;
> > }
> > 
> > int main()
> > {
> >         volatile unsigned char *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
> >                                          MAP_SHARED | MAP_ANONYMOUS, -1, 0);
> >         pthread_t threads[4];
> >         int ret;
> > 
> >         for (int i = 0; i < 4; ++i) {
> >                 ret = pthread_create(&threads[i], NULL, fn_thread, (void *)i);
> >                 if (ret)
> >                 {
> >                         printf("%s", strerror (ret));
> >                 }
> >         }
> > 
> >         memset(p, 0x88, SIZE);
> > 
> >         for (int k = 0; k < 10000; k++) {
> >                 /* swap in */
> >                 for (int i = 0; i < SIZE; i += 4096) {
> >                         (void)p[i];
> >                 }
> > 
> >                 /* swap out */
> >                 madvise(p, SIZE, MADV_PAGEOUT);
> >         }
> > 
> >         for (int i = 0; i < 4; i++)
> >         {
> >                 pthread_cancel(threads[i]);
> >         }
> > 
> >         for (int i = 0; i < 4; i++)
> >         {
> >                 pthread_join(threads[i], NULL);
> >         }
> > 
> >         return 0;
> > }
> > 
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
> > Tested-by: Jisheng Zhang <jszhang@kernel.org> # Tested on TH1520  
> 
> Before:
>     real 0m36.674s
>     user 0m0.173s
>     sys  0m36.493s
> After:
>     real 0m18.016s
>     user 0m0.125s
>     sys  0m17.885s
> 
> Tested-by: Nam Cao <namcao@linutronix.de>

I forgot to mention: this is for Starfive's Visionfive 2 board.

Best regards,
Nam


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: Nam Cao <namcao@linutronix.de>
To: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	Jisheng Zhang <jszhang@kernel.org>
Subject: Re: [PATCH v2] riscv: Add support for BATCHED_UNMAP_TLB_FLUSH
Date: Mon, 8 Jan 2024 21:44:48 +0100	[thread overview]
Message-ID: <20240108214448.025977ac@namcao> (raw)
In-Reply-To: <20240108214346.5fd93127@namcao>

On Mon, 8 Jan 2024 21:43:46 +0100 Nam Cao <namcao@linutronix.de> wrote:

> On Mon,  8 Jan 2024 20:36:40 +0100 Alexandre Ghiti <alexghiti@rivosinc.com> wrote:
> > Allow to defer the flushing of the TLB when unmapping pages, which allows
> > to reduce the numbers of IPI and the number of sfence.vma.
> > 
> > The ubenchmarch used in commit 43b3dfdd0455 ("arm64: support
> > batched/deferred tlb shootdown during page reclamation/migration") that
> > was multithreaded to force the usage of IPI shows good performance
> > improvement on all platforms:
> > 
> > * Unmatched: ~34%
> > * TH1520   : ~78%
> > * Qemu     : ~81%
> > 
> > In addition, perf on qemu reports an important decrease in time spent
> > dealing with IPIs:
> > 
> > Before:  68.17%  main     [kernel.kallsyms]            [k] __sbi_rfence_v02_call
> > After :   8.64%  main     [kernel.kallsyms]            [k] __sbi_rfence_v02_call
> > 
> > * Benchmark:
> > 
> > int stick_this_thread_to_core(int core_id) {
> >         int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
> >         if (core_id < 0 || core_id >= num_cores)
> >            return EINVAL;
> > 
> >         cpu_set_t cpuset;
> >         CPU_ZERO(&cpuset);
> >         CPU_SET(core_id, &cpuset);
> > 
> >         pthread_t current_thread = pthread_self();
> >         return pthread_setaffinity_np(current_thread,
> > sizeof(cpu_set_t), &cpuset);
> > }
> > 
> > static void *fn_thread (void *p_data)
> > {
> >         int ret;
> >         pthread_t thread;
> > 
> >         stick_this_thread_to_core((int)p_data);
> > 
> >         while (1) {
> >                 sleep(1);
> >         }
> > 
> >         return NULL;
> > }
> > 
> > int main()
> > {
> >         volatile unsigned char *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
> >                                          MAP_SHARED | MAP_ANONYMOUS, -1, 0);
> >         pthread_t threads[4];
> >         int ret;
> > 
> >         for (int i = 0; i < 4; ++i) {
> >                 ret = pthread_create(&threads[i], NULL, fn_thread, (void *)i);
> >                 if (ret)
> >                 {
> >                         printf("%s", strerror (ret));
> >                 }
> >         }
> > 
> >         memset(p, 0x88, SIZE);
> > 
> >         for (int k = 0; k < 10000; k++) {
> >                 /* swap in */
> >                 for (int i = 0; i < SIZE; i += 4096) {
> >                         (void)p[i];
> >                 }
> > 
> >                 /* swap out */
> >                 madvise(p, SIZE, MADV_PAGEOUT);
> >         }
> > 
> >         for (int i = 0; i < 4; i++)
> >         {
> >                 pthread_cancel(threads[i]);
> >         }
> > 
> >         for (int i = 0; i < 4; i++)
> >         {
> >                 pthread_join(threads[i], NULL);
> >         }
> > 
> >         return 0;
> > }
> > 
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
> > Tested-by: Jisheng Zhang <jszhang@kernel.org> # Tested on TH1520  
> 
> Before:
>     real 0m36.674s
>     user 0m0.173s
>     sys  0m36.493s
> After:
>     real 0m18.016s
>     user 0m0.125s
>     sys  0m17.885s
> 
> Tested-by: Nam Cao <namcao@linutronix.de>

I forgot to mention: this is for Starfive's Visionfive 2 board.

Best regards,
Nam


  reply	other threads:[~2024-01-08 20:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-08 19:36 [PATCH v2] riscv: Add support for BATCHED_UNMAP_TLB_FLUSH Alexandre Ghiti
2024-01-08 19:36 ` Alexandre Ghiti
2024-01-08 20:43 ` Nam Cao
2024-01-08 20:43   ` Nam Cao
2024-01-08 20:44   ` Nam Cao [this message]
2024-01-08 20:44     ` Nam Cao
2024-01-12  6:30 ` patchwork-bot+linux-riscv
2024-01-12  6:30   ` patchwork-bot+linux-riscv

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=20240108214448.025977ac@namcao \
    --to=namcao@linutronix.de \
    --cc=alexghiti@rivosinc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=jszhang@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.