mbox series

[00/12] riscv: add new ISA extensions, profiles, and selftests

Message ID 20261118204853.2155173-1-tgamblin@baylibre.com
Headers show
Series riscv: add new ISA extensions, profiles, and selftests | expand

Message

Trevor Gamblin Nov. 18, 2026, 8:48 p.m. UTC
Note: This series is based on an earlier set of RFCs, of which v2 can be found
at [1]. The changes here are also found in my contrib branch at [2]. I've been
reviewing this myself and throwing an LLM at it for feedback, and I believe it's
mature enough now compared to the initial versions that others ought to take
another look, so please let me know what you think.

# Overview

Support for the RISC-V architecture and a basic set of extensions has been
available in oe-core for a long time now, and as of late 2025, QEMU defaults to
the RVA23S64 profile when booting qemuriscv64 images. However, at the userspace
level, we currently support only the standard "riscv64gc" profile (behind a
generic "riscv64" identifier), which is common across the wider open-source
ecosystem, but lacks many of the features which are starting to become necessary
for more advanced experimentation and testing on RISC-V platforms. This series
aims to remedy that by introducing several changes across a handful of files. 

Compared to the previous RFCs, the following changes were submitted and accepted
separately:
  1. tune-riscv: be explicit about riscv32gc, riscv64gc defaults
  2. tune-riscv.inc: add 'riscv64gcv' tune

The patches here do the following, while trying to follow similar design
decisions made for x86-64 and ARM in oe-core:

1. Adopt a new 'RISCVPKGARCH' variable (like 'ARMPKGARCH') which should be set
for any new custom tune files, especially those that happen to have very
complicated/non-standard extension sets
2. Add 'rva20u64', 'rva22u64', and 'rva23u64' tunes along with all extensions
they mandate to arch-riscv.inc
3. Extend lib/oe/tune.py with a RISCV_PROFILES list, which is used to test and
shorten extension strings for build paths
4. Add two new sets of selftests:
  a. lib/oeqa/selftest/cases/oelib/tune.py, for testing the code in
  lib/oe/tune.py
  b. lib/oeqa/selftest/cases/riscvtunes.py, for testing the various RISC-V
  tunings themselves. This includes an "unusual tunes" test where libgcc-initial
  is built for a handful of nonstandard extension combinations, so it's a bit
  heavier.
5. Allow 'superset' package archs to install packages built for subset tunings
6. Extend rust-target-config.bbclass so that it handles all of the extensions
(avoiding a scenario where a build would target e.g. rva23u64 but Rust-based
packages would still build against riscv64gc), and add a selftest for that
7. Report an error and provide a suggestion to the user when a tuning exceeds
the allowable length of a package arch (i.e. set RISCVPKGARCH with a proper tune
name, instead of letting the whole extension string hit the path)

The last entry is possibly the most significant one compared to earlier
revisions of this work - it's now a much simpler and more 'strict' solution to
the extension string length problem discussed in the RFC. Specifically, earlier
attempts were made to try and support a very flexible "set any extension string
you want" approach for users to experiment with, using a bitmask and/or hashing
function to shorten the string for build/sstate paths. However, this required a
lot of extra code to be maintained (including extra selftests) with essentially
the only gain being to allow tunes to be set on-the-fly in local.conf, and it
also meant that build paths became more obscure in order to keep their naming
short. For example, a tuning for the SpacemiT X60 tune would have 'readable' and
'hashed' names like:

|readable: rva22u64_v_zbc_zfh_zicond_zifencei_zihpm_zvfh_zvkt
|hashed: rva22u64_0x089e3d7dd8

After discussion in a recent technical call, this seems best suited to inclusion
in the meta-riscv layer (if we feel it's needed at all). For now, This series
(and a corresponding meta-riscv PR to add BSP-specific tunings) should be
sufficient with its 'strict' tunes. The new profiles with explicit tunes get
build paths in the TMPDIR like:

|rva20u64_zifencei
|rva22u64_zifencei
|rva23u64_zifencei

## Implementation, and Relation to meta-riscv

With this series in, oe-core will support all **mandated** extensions for all
ratified profiles up to and including RVA23, according to the spec in [3], but
not optional/development/expansion options. Some of these will be incorporated
in the aforementioned companion PR [4], which will add 'spacemit-x60' and
'spacemit-x100' tunes along with corresponding selftests. Those extensions may
be worth moving to oe-core as well eventually (especially if many future boards
and/or profiles mandate them), but for now I think the mandated extension sets
are enough to manage. 

The selftests have been designed largely with Claude Code Opus 5.5, with the
goal of helping us track any changes that may occur over time with toolchains or
variable/logic changes in oe-core. That being said, I doubt the profiles
themselves will change, so setting things like RISCV_PROFILES in tune.py should
be stable. With riscvtunes.py, the objective is to ensure that the tune files
themselves follow a consistent standard, which means that changes will need to
be made there in the future if we alter the way different architectures' tunings
are defined. Also worth noting that, compared to the RFC versions, the selftest
suites have been expanded significantly - the initial versions were very 'thin'
and often only covered a few cases at most, so I've made a point to increase the
variety of asserts running in each test to handle more edge cases.

For now, the default tuning for qemuriscv64 remains 'riscv64gc', so there are
still no explicit consumers of the new profiles in oe-core. They can be enabled
easily by setting DEFAULTTUNE in local.conf when building for qemuriscv64, e.g.
`DEFAULTTUNE = 'rva23u64'`. They **are** consumed by two new BSP-specific
tunings added in [4]. qemuriscv32 and the 'riscv32gc' tuning have been mostly
untouched by this series, other than to provide some selftests.

## Testing

### Selftests

oe-selftest -r oelib.tune:

|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_abbreviation: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_duplicates: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_explicit: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_multi_letter_prefixes: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_not_riscv: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_profile: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_profile_sizes: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_rva22u64_additions: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_rva23u64_additions: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_separators: PASSED (0.00s)
|2026-11-18 15:25:02,173 - oe-selftest - INFO - SUMMARY:
|2026-11-18 15:25:02,173 - oe-selftest - INFO - oe-selftest () - Ran 10 tests in 5.167s
|2026-11-18 15:25:02,173 - oe-selftest - INFO - oe-selftest - OK - All required tests passed (successes=10, skipped=0, failures=0, errors=0)

oe-selftest -r riscvtunes:

|2026-11-18 15:30:51,286 - oe-selftest - INFO - RESULTS:
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_default_tunes: PASSED (12.07s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_pkgarch_fallback: PASSED (2.01s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_profile_ccargs: PASSED (3.16s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_rust_target_features: PASSED (32.90s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_unusual_tunes: PASSED (84.92s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - SUMMARY:
|2026-11-18 15:30:51,287 - oe-selftest - INFO - oe-selftest () - Ran 5 tests in 147.710s
|2026-11-18 15:30:51,287 - oe-selftest - INFO - oe-selftest - OK - All required tests passed (successes=5, skipped=0, failures=0, errors=0)

### QEMU Tests

To showcase what the tuning differences look like in practice, below are some
examples of how things look when core-image-ptest-coreutils (which I've used as
a benchmark in the RFC) is built, booted (including a ptest run) for qemuriscv64
with each profile set for DEFAULTTUNE in turn. This was all performed on my
local 12-core workstation and with QEMU's TCG emulation mode. The buildinfo data
was set using: 

|IMAGE_CLASSES += "image-buildinfo"
|IMAGE_BUILDINFO_VARS = "DISTRO DISTRO_VERSION MACHINE TUNE_FEATURES"

Also note that the 'rva23u64' coreutils ptest took significantly longer than the
others. I suspect that some packages which make use of the new extensions will
show similar differences. An example is ffmpeg, which needs 'zba' and 'zbb'
(among others) - an upstream discussion [5] suggests that building it without
those (which we'd do with the riscv64gc tune) could have performance
implications.

riscv64gc:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c zicsr zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#

|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 758
|END: /usr/lib/coreutils/ptest
|2026-11-18T19:20
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0

rva20u64:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c ziccamoa ziccif zicclsm ziccrse zicntr zicsr zmmul za128rs zaamo zalrsc zca zcd zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#

|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 760
|END: /usr/lib/coreutils/ptest
|2026-11-18T19:36
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0
|root@qemuriscv64:~#

rva22u64:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c b zic64b zicbom zicbop zicboz ziccamoa ziccif zicclsm ziccrse zicntr zicsr zihintpause zihpm zmmul za64rs zaamo zalrsc zfhmin zca zcd zba zbb zbs zkt zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#

|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 730
|END: /usr/lib/coreutils/ptest
|2026-11-18T19:52
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0
|root@qemuriscv64:~#

rva23u64:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c b v zic64b zicbom zicbop zicboz ziccamoa ziccif zicclsm ziccrse zicntr zicond zicsr zihintntl zihintpause zihpm zimop zmmul za64rs zaamo zalrsc zawrs zfa zfhmin zca zcb zcd zcmop zba zbb zbs zkt zvbb zve32f zve32x zve64d zve64f zve64x zvfhmin zvkb zvkt zvl128b zvl32b zvl64b supm zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#

|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 1102
|END: /usr/lib/coreutils/ptest
|2026-11-18T20:14
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0
|root@qemuriscv64:~#


[1]: https://lore.kernel.org/openembedded-core/20260930-riscv-tuning-rework-v2-0-9e29f3531d0e@baylibre.com/
[2]: https://git.openembedded.org/openembedded-core-contrib/log/?h=tgamblin/riscv-tuning-strict
[3]: https://docs.riscv.org/reference/rva23/v1.0/rva23-profiles.html
[4]: https://github.com/riscv/meta-riscv/pull/739
[5]: https://www.mail-archive.com/ffmpeg-trac@avcodec.org/msg69408.html

Trevor Gamblin (12):
  arch-riscv.inc, tune-riscv.inc: add RISCVPKGARCH
  arch-riscv.inc: add zmmul, zaamo, zalrsc, zca, zcd
  lib/oe/tune.py: support RISC-V profiles in riscv_isa_to_tune()
  lib/oeqa/selftest/cases/oelib/tune.py: add selftests for
    lib/oe/tune.py
  arch-riscv.inc, tune-riscv.inc: add rva20u64 tune
  arch-riscv.inc, tune-riscv.inc: add rva22u64 tune
  arch-riscv.inc, tune-riscv.inc: add rva23u64 tune
  tune-riscv.inc: set PACKAGE_EXTRA_ARCHS for supersets
  meta/conf/machine/include/riscv/arch-riscv.inc: error on very long
    package archs
  lib/oeqa/selftest/cases/riscvtunes.py: add RISC-V tune selftests
  rust-target-config.bbclass: pass on all RISC-V extensions to LLVM
  lib/oeqa/selftest/cases/riscvtunes.py: test Rust target features

 .../classes-recipe/rust-target-config.bbclass |  34 +---
 meta/conf/machine/include/riscv/README        |  14 +-
 .../conf/machine/include/riscv/arch-riscv.inc | 189 +++++++++++++++++-
 .../conf/machine/include/riscv/tune-riscv.inc |  40 +++-
 meta/lib/oe/tune.py                           |  26 ++-
 meta/lib/oeqa/selftest/cases/oelib/tune.py    |  81 ++++++++
 meta/lib/oeqa/selftest/cases/riscvtunes.py    | 174 ++++++++++++++++
 7 files changed, 519 insertions(+), 39 deletions(-)
 create mode 100644 meta/lib/oeqa/selftest/cases/oelib/tune.py
 create mode 100644 meta/lib/oeqa/selftest/cases/riscvtunes.py