feat: Add support for RISC-V architecture - #3053
Conversation
|
Hi, the workflow for this PR is awaiting maintainer approval. Could someone help review and approve it? Thank you! |
|
I feel we're unable to maintain this if we cannot check it in CI stage. |
|
Yeah it would be great if we have CI support for rv support. Also, why TBB is downgraded? Any reason for this? |
|
|
Hi @wanghan-sanechips , Thanks very much for your effort! 😊
Best Regards, |
Thank you for the helpful resources! I'll work on enhancing the CI pipeline to add RISC-V support using QEMU simulation. I'll keep you updated on the progress. |
|
Hi @wanghan-sanechips , Maybe you could run CI in your forked repo first, just enable the GitHub Actions and trigger by push, or a draft PR in your repo. Best Regards, |
fd40e9c to
d2c2d0e
Compare
Maybe we can try v2022.1.0 instead of v2021.13.0? |
|
|
||
| import platform | ||
| if platform.machine() == 'riscv64': | ||
| cmake_options += ["-DENABLE_LUAJIT=OFF", "-DENABLE_LUA=ON"] | ||
|
|
There was a problem hiding this comment.
Two problems here:
-DENABLE_LUA=ONis useless and can be removed.- We can move this logic to
CMakeLists.txt, e.g.
if(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
set(ENABLE_LUAJIT OFF)
endif()
There was a problem hiding this comment.
Thanks for your review! I'll address these issues in the next push.
4fcbeda to
9682ce0
Compare
02d996c to
1c8edbb
Compare
|
Hi @PragmaTwice , the CI test failed in https://github.com/apache/kvrocks/actions/runs/16559876513/job/46918902321?pr=3053, but it might be a flaky test. |
|
Hi @wanghan-sanechips , Thanks for your effort!😊 I will review this PR later today. Best Regards, |
|
Hi @wanghan-sanechips , The cross compile and unit test flow generally LGTM. We'd better adapt it to the current workflow, just like below. kvrocks/.github/workflows/kvrocks.yaml Lines 218 to 225 in 4450da2 And the go integration test and kvrocks2redis test should also be executed in our general test flow. Best Regards, |
Thank you for your review and suggestions. I've implemented the changes to adapt the cross-compilation and unit test flow to the current workflow. |
f203520 to
ee0b4a6
Compare
| if(DEFINED ENV{RISCV_CROSSCOMPILE}) | ||
| set(CMAKE_SYSTEM_NAME Linux CACHE STRING "") | ||
| set(CMAKE_SYSTEM_PROCESSOR riscv64 CACHE STRING "") | ||
| set(CMAKE_CROSSCOMPILING TRUE CACHE BOOL "") | ||
| endif() |
There was a problem hiding this comment.
https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html
After reading the CMake cross-compiling docs, I wonder if we can maintain some "toolchain files" instead of such intrusive modifications? Also current we rely on an env var "RISCV_CROSSCOMPILE", and it seems not a classic way of tuning cmake files.
There was a problem hiding this comment.
Thanks for the feedback! I've switched to using proper CMake toolchain files as suggested and removed the RISCV_CROSSCOMPILE env var dependency.
The key improvements made include:
1.Created dedicated toolchain files (cmake/riscv64.cmake) for cross-compilation configurations
2.Removed all dependencies on the RISCV_CROSSCOMPILE environment variable
3.Updated the build system to use -DCMAKE_TOOLCHAIN_FILE for cross-compilation
4.Modified the CI workflows to use the new toolchain file approach
Appreciate the suggestion - this is indeed a cleaner approach.
ee0b4a6 to
6e89302
Compare
d287e23 to
680b1b9
Compare
| if(NOT DEFINED JEMALLOC_CROSS_FLAGS) | ||
| set(JEMALLOC_CROSS_FLAGS "") | ||
| endif() | ||
|
|
There was a problem hiding this comment.
seems useless? it is evaluated to empty if it is not defined in cmake.
PragmaTwice
left a comment
There was a problem hiding this comment.
generally looks good to me!
680b1b9 to
3d48ded
Compare
|
Hi @wanghan-sanechips , Thank you very much for your excellent work! LGTM 😊 @PragmaTwice , do we need to create a new PR after this to cache the toolchain tarball, which is approximately 600 MB, and should we cache it? Best Regards, |
Nope. We do not need to cache it as long as the download time is short. |
There was a problem hiding this comment.
LGTM. One last question. As I observed the difference of test executing time (unit test and golang test) between native (x86) and qemu (x86-riscv) is quite small (less than 2x time). Previously I think that the speed can be more than 2x slower because of the riscv -> x86 transpilation. Is it expected?
I checked some benchmark (e.g. rv8 vs qemu: https://michaeljclark.github.io/bench.html) and it seems the performance of qemu is not so good. But maybe kvrocks is more IO-bound (network and file IO) so that the emulation performance (user-mode emulation?) is not critical.
|
Thanks for raising this question! I've run more detailed benchmarks using these test cases: Results (x86 native vs QEMU RISC-V):
These results confirm your suspicion:
This explains the performance gap. |



Changes:
Tested on openEuler-RISC-V - compilation passed