All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/5] riscv: Use riscv_has_extension_{likely,unlikely}
@ 2025-10-20  9:09 ` Vivian Wang
  0 siblings, 0 replies; 14+ messages in thread
From: Vivian Wang @ 2025-10-20  9:09 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Yury Norov, Rasmus Villemoes, Paul Walmsley
  Cc: Charlie Jenkins, Xiao Wang, Christoph Müllner, Vivian Wang,
	Vivian Wang, linux-riscv, linux-kernel

There are about a dozen uses of asm goto in arch/riscv just to select
between two code paths with the alternative mechanism. Convert them to
the existing helpers riscv_has_extension_{likely,unlikely}.

In each case, I have preserved the existing code's choice of asm goto
pattern while picking between "likely" and "unlikely", namely:

  ALTERNATIVE("j %l[no]", "nop", ...)   -> "likely"
  ALTERNATIVE("nop", "j %l[yes]", ...)  -> "unlikely"

Since the helpers are just implementations of these patterns, the
performance should be the same as before.

There are some oddities:

- The two pgtable checks for Svvptc are not guarded behind
  CONFIG_RISCV_ALTERNATIVE (or something that implies it). However since
  TLB flushes are slow, relatively speaking, it should still be
  beneficial to check at runtime for Svvptc.
- arch/riscv/include/asm/{bitops.h,swab.h} have a check for
  defined(NO_ALTERNATIVE), which is defined in efistub where
  alternatives are not a thing. It's not checked in any other header
  file. I verified that currently no actual asm(ALTERNATIVE(...)) usage
  in efistub exists (by inserting an assembly .error if NO_ALTERNATIVE),
  so I've decided against preemptively adding checks for it.

These patches are also available at:

https://github.com/dramforever/linux/tree/riscv/altn-helper/v4

---
Changes in v4:
- Rebase on v6.18-rc1
- Use riscv_has_extension_{likely,unlikely} instead of double-underscore
  version __riscv_has_extension_{likely,unlikely} (See oddities in cover
  letter body)
- Link to v3: https://lore.kernel.org/r/20251011-riscv-altn-helper-wip-v3-0-d40ddaa1985a@iscas.ac.cn

Changes in v3:
- Rebased on riscv for-next
  - Resolve conflict, use ALT_RISCV_PAUSE() in moved lines
- Link to v2: https://lore.kernel.org/r/20250821-riscv-altn-helper-wip-v2-0-9586fa702f78@iscas.ac.cn

Changes in v2:
- Cc'd authors who initially introduced the asm goto blocks
- Use existing __riscv_has_extension_{likely,unlikely} instead
- Remove bogus comment for Zbb being likely (checksum)
- Restructured patch to minimize diff (bitops, hweight, cmpxchg)
- Link to v1: https://lore.kernel.org/r/20250820-riscv-altn-helper-wip-v1-0-c3c626c1f7e6@iscas.ac.cn

---
Vivian Wang (5):
      riscv: pgtable: Use riscv_has_extension_unlikely
      riscv: checksum: Use riscv_has_extension_likely
      riscv: hweight: Use riscv_has_extension_likely
      riscv: bitops: Use riscv_has_extension_likely
      riscv: cmpxchg: Use riscv_has_extension_likely

 arch/riscv/include/asm/arch_hweight.h | 24 ++++++----------
 arch/riscv/include/asm/bitops.h       | 32 ++++++---------------
 arch/riscv/include/asm/checksum.h     | 13 +++------
 arch/riscv/include/asm/cmpxchg.h      | 12 +++-----
 arch/riscv/include/asm/pgtable.h      | 15 +++++-----
 arch/riscv/lib/csum.c                 | 53 ++++++++---------------------------
 arch/riscv/mm/pgtable.c               | 22 +++++++--------
 7 files changed, 53 insertions(+), 118 deletions(-)
---
base-commit: cb6649f6217c0331b885cf787f1d175963e2a1d2
change-id: 20250820-riscv-altn-helper-wip-00af3a552c37

Best regards,
-- 
Vivian "dramforever" Wang


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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-11-18  8:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20  9:09 [PATCH v4 0/5] riscv: Use riscv_has_extension_{likely,unlikely} Vivian Wang
2025-10-20  9:09 ` Vivian Wang
2025-10-20  9:09 ` [PATCH v4 1/5] riscv: pgtable: Use riscv_has_extension_unlikely Vivian Wang
2025-10-20  9:09   ` Vivian Wang
2025-10-20  9:09 ` [PATCH v4 2/5] riscv: checksum: Use riscv_has_extension_likely Vivian Wang
2025-10-20  9:09   ` Vivian Wang
2025-10-20  9:09 ` [PATCH v4 3/5] riscv: hweight: " Vivian Wang
2025-10-20  9:09   ` Vivian Wang
2025-10-20  9:09 ` [PATCH v4 4/5] riscv: bitops: " Vivian Wang
2025-10-20  9:09   ` Vivian Wang
2025-10-20  9:10 ` [PATCH v4 5/5] riscv: cmpxchg: " Vivian Wang
2025-10-20  9:10   ` Vivian Wang
2025-11-18  8:13 ` [PATCH v4 0/5] riscv: Use riscv_has_extension_{likely,unlikely} patchwork-bot+linux-riscv
2025-11-18  8:13   ` patchwork-bot+linux-riscv

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.