feat: Add full RISC-V 64-bit architecture support#3125
Merged
wwbmmm merged 1 commit intoapache:masterfrom Dec 8, 2025
Merged
Conversation
This commit adds full support for RISC-V 64-bit architecture to brpc. Changes include: - Add RISC-V atomic operations implementation - Add RISC-V architecture detection in build system - Add RISC-V context switching (bthread support) - Add RISC-V clock cycle counter support (rdcycle) - Update CMake and Makefile for RISC-V compilation All core functionalities have been tested and verified in QEMU RISC-V environment, including: - Atomic operations (32-bit and 64-bit) - Memory barriers - Context switching - Clock cycle counting Co-authored-by: gong-flying <gongxiaofei24@iscas.ac.cn>
Contributor
|
👍 |
Contributor
|
LGTM |
chenBright
reviewed
Oct 26, 2025
Member
|
Is there any RISC-V CI resource? |
Contributor
Author
|
@wasphin Currently it has not been added yet. If needed, I can add information about RISC-V CI here. |
Member
|
@Dayuxiaoshui Thanks for your contribution, and it's a better to have, maybe in the future, for a more stable maintenance. |
zchuango
pushed a commit
to zchuango/brpc
that referenced
this pull request
May 9, 2026
This commit adds full support for RISC-V 64-bit architecture to brpc. Changes include: - Add RISC-V atomic operations implementation - Add RISC-V architecture detection in build system - Add RISC-V context switching (bthread support) - Add RISC-V clock cycle counter support (rdcycle) - Update CMake and Makefile for RISC-V compilation All core functionalities have been tested and verified in QEMU RISC-V environment, including: - Atomic operations (32-bit and 64-bit) - Memory barriers - Context switching - Clock cycle counting Co-authored-by: gong-flying <gongxiaofei24@iscas.ac.cn>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: N/A
Problem Summary:
brpc currently does not support RISC-V architecture, which is an emerging open-source instruction set architecture gaining significant traction in server and embedded systems. This PR adds complete RISC-V 64-bit support to enable brpc to run natively on RISC-V platforms.
What is changed and the side effects?
Changed:
Core Implementation:
lr.w/lr.dandsc.w/sc.dinstructions insrc/butil/atomicops_internals_riscv_gcc.h(new file, 192 lines)src/bthread/context.cppcpu_relax()implementation usingfence.iinstruction for RISC-V insrc/bthread/processor.hrdcycleCSR instruction insrc/butil/time.hAtomicInteger128mutex operations for architectures without native 128-bit atomic supportBuild System:
ARCH_CPU_RISCV_FAMILY,ARCH_CPU_RISCV64,ARCH_CPU_RISCV32) insrc/butil/build_config.h-march=rv64gc) in CMake and Makefile for optimal code generationTesting & Verification:
Tested on Sophgo SG2044 (RISC-V 64-bit) platform with successful results:
Build Verification:
libbrpc.a(410MB) successfully builtparallel_http(76MB)protoc-gen-mcpack(19MB)rpc_press(77MB)rpc_replay(76MB)rpc_view(76MB)trackme_server(76MB)Functional Verification:
fenceinstructions)rdcycleCSR)fence.iinstruction)Side effects:
Performance effects:
fence.iinstruction usage improves spin-lock performance on RISC-VBreaking backward compatibility:
Check List:
Files Changed: 11 files changed, 316 insertions(+), 3 deletions(-)
Co-authored-by: gong-flying gongxiaofei24@iscas.ac.cn