mbox series

[v4,00/12] riscv: ASID-related and UP-related TLB flush enhancements

Message ID 20240102220134.3229156-1-samuel.holland@sifive.com (mailing list archive)
Headers show
Series riscv: ASID-related and UP-related TLB flush enhancements | expand

Message

Samuel Holland Jan. 2, 2024, 10 p.m. UTC
While reviewing Alexandre Ghiti's "riscv: tlb flush improvements"
series[1], I noticed that most TLB flush functions end up as a call to
local_flush_tlb_all() when SMP is disabled. This series resolves that,
and also optimizes the scenario where SMP is enabled but only one CPU is
present or online. Along the way, I realized that we should be using
single-ASID flushes wherever possible, so I implemented that as well.

Here are some numbers from D1 (with SMP disabled) which show the
performance impact:

v6.7-rc8:
 System Benchmarks Partial Index              BASELINE       RESULT    INDEX
 Execl Throughput                                 43.0        207.4     48.2
 File Copy 1024 bufsize 2000 maxblocks          3960.0      52187.4    131.8
 File Copy 256 bufsize 500 maxblocks            1655.0      14872.6     89.9
 File Copy 4096 bufsize 8000 maxblocks          5800.0     146597.8    252.8
 Pipe Throughput                               12440.0     125318.4    100.7
 Pipe-based Context Switching                   4000.0      17804.2     44.5
 Process Creation                                126.0        479.2     38.0
 Shell Scripts (1 concurrent)                     42.4        564.5    133.1
 Shell Scripts (16 concurrent)                     ---         36.8      ---
 Shell Scripts (8 concurrent)                      6.0         74.3    123.9
 System Call Overhead                          15000.0     182050.7    121.4
                                                                    ========
 System Benchmarks Index Score (Partial Only)                           93.2

v6.7-rc8 plus this patch series:
 System Benchmarks Partial Index              BASELINE       RESULT    INDEX
 Execl Throughput                                 43.0        208.5     48.5
 File Copy 1024 bufsize 2000 maxblocks          3960.0      56847.0    143.6
 File Copy 256 bufsize 500 maxblocks            1655.0      17728.9    107.1
 File Copy 4096 bufsize 8000 maxblocks          5800.0     168016.2    289.7
 Pipe Throughput                               12440.0     133376.2    107.2
 Pipe-based Context Switching                   4000.0      19736.3     49.3
 Process Creation                                126.0        484.5     38.4
 Shell Scripts (1 concurrent)                     42.4        564.1    133.0
 Shell Scripts (16 concurrent)                     ---         36.6      ---
 Shell Scripts (8 concurrent)                      6.0         74.1    123.5
 System Call Overhead                          15000.0     210181.8    140.1
                                                                    ========
 System Benchmarks Index Score (Partial Only)                          100.1

[1]: https://lore.kernel.org/linux-riscv/20231030133027.19542-1-alexghiti@rivosinc.com/

Changes in v4:
 - Fix a possible race between flush_icache_*() and SMP bringup
 - Refactor riscv_use_ipi_for_rfence() to make later changes cleaner
 - Optimize kernel TLB flushes with only one CPU online
 - Optimize global cache/TLB flushes with only one CPU online
 - Merge the two copies of __flush_tlb_range() and rely on the compiler
   to optimize out the broadcast path (both clang and gcc do this)
 - Merge the two copies of flush_tlb_all() and rely on constant folding
 - Only set tlb_flush_all_threshold when CONFIG_MMU=y.

Changes in v3:
 - Fixed a performance regression caused by executing sfence.vma in a
   loop on implementations affected by SiFive CIP-1200
 - Rebased on v6.7-rc1

Changes in v2:
 - Move the SMP/UP merge earlier in the series to avoid build issues
 - Make a copy of __flush_tlb_range() instead of adding ifdefs inside
 - local_flush_tlb_all() is the only function used on !MMU (smpboot.c)

Samuel Holland (12):
  riscv: Flush the instruction cache during SMP bringup
  riscv: Use IPIs for remote cache/TLB flushes by default
  riscv: mm: Broadcast kernel TLB flushes only when needed
  riscv: Only send remote fences when some other CPU is online
  riscv: mm: Combine the SMP and UP TLB flush code
  riscv: Apply SiFive CIP-1200 workaround to single-ASID sfence.vma
  riscv: Avoid TLB flush loops when affected by SiFive CIP-1200
  riscv: mm: Introduce cntx2asid/cntx2version helper macros
  riscv: mm: Use a fixed layout for the MM context ID
  riscv: mm: Make asid_bits a local variable
  riscv: mm: Preserve global TLB entries when switching contexts
  riscv: mm: Always use an ASID to flush mm contexts

 arch/riscv/errata/sifive/errata.c    |  5 ++
 arch/riscv/include/asm/errata_list.h | 12 ++++-
 arch/riscv/include/asm/mmu.h         |  3 ++
 arch/riscv/include/asm/mmu_context.h |  2 -
 arch/riscv/include/asm/sbi.h         |  4 ++
 arch/riscv/include/asm/smp.h         | 15 +-----
 arch/riscv/include/asm/tlbflush.h    | 50 ++++++++----------
 arch/riscv/kernel/sbi-ipi.c          | 11 +++-
 arch/riscv/kernel/smp.c              | 11 +---
 arch/riscv/kernel/smpboot.c          |  7 +--
 arch/riscv/mm/Makefile               |  5 +-
 arch/riscv/mm/cacheflush.c           |  7 +--
 arch/riscv/mm/context.c              | 26 ++++------
 arch/riscv/mm/tlbflush.c             | 76 +++++++++-------------------
 drivers/clocksource/timer-clint.c    |  2 +-
 15 files changed, 102 insertions(+), 134 deletions(-)