-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Qemu-virt64-riscv BSP support SMP architecture #10887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tm-C-mT
wants to merge
11
commits into
RT-Thread:master
Choose a base branch
from
Tm-C-mT:qemu-virt64-riscv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,103
−166
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6c0a7d1
[libcpu-riscv]: [common64 virt64]:Fix compilation errors after enabli…
Tm-C-mT 7948f50
[libcpu-riscv]: [common64 virt64]:Fix the normal startup of the SMP a…
Tm-C-mT c7cbe2e
[libcpu-riscv]: [common64 virt64]:Add the specific implementation of …
Tm-C-mT 402ec68
[libcpu-riscv]: [common64 virt64]: Add the dual-core feature under th…
Tm-C-mT 8386d29
[libcpu-riscv]: [surpport SMP]: Add IPI handling.
Tm-C-mT 7a770ce
[libcpu-riscv]: [surpport SMP]: Add dynamic startup based on core con…
Tm-C-mT 9cdbc36
[libcpu-riscv]: [surpport SMP]: Fix issues with non-standard formatting
Tm-C-mT bf917a1
[libcpu-riscv]: [surpport SMP]: Fix the overflow issue of the spinloc…
Tm-C-mT a59652d
[libcpu-riscv]: [surpport SMP]: Support the SMP feature under the Sma…
Tm-C-mT 8a9066f
[libcpu-riscv]: [surpport SMP]: Fix issues with non-standard formatting
Tm-C-mT c43d720
[libcpu-riscv]: [surpport SMP]: Fix issues with non-standard formatting
Tm-C-mT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| RT_CPUS_NR = 8; | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,16 @@ | ||
| qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin -s -S \ | ||
| QEMU_CMD="qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin -s -S" | ||
|
|
||
| if grep -q "#define RT_USING_SMP" ./rtconfig.h 2>/dev/null; then | ||
| hart_num=$(grep "RT_CPUS_NR = [0-9]*;" ./link_cpus.lds | awk -F'[=;]' '{gsub(/ /, "", $2); print $2}') | ||
| if [ -z "$hart_num" ]; then | ||
| hart_num=1 | ||
| fi | ||
| QEMU_CMD="$QEMU_CMD -smp $hart_num" | ||
| fi | ||
|
|
||
| QEMU_CMD="$QEMU_CMD \ | ||
| -drive if=none,file=sd.bin,format=raw,id=blk0 -device virtio-blk-device,drive=blk0,bus=virtio-mmio-bus.0 \ | ||
| -netdev user,id=tap0 -device virtio-net-device,netdev=tap0,bus=virtio-mmio-bus.1 \ | ||
| -device virtio-serial-device -chardev socket,host=127.0.0.1,port=4321,server=on,wait=off,telnet=on,id=console0 -device virtserialport,chardev=console0 | ||
| -device virtio-serial-device -chardev socket,host=127.0.0.1,port=4321,server=on,wait=off,telnet=on,id=console0 -device virtserialport,chardev=console0" | ||
|
|
||
| eval $QEMU_CMD |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * Copyright (c) 2006-2023, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2023-03-14 WangShun first version | ||
| */ | ||
|
|
||
| #include <rtthread.h> | ||
|
|
||
| rt_atomic_t rt_hw_atomic_exchange(volatile rt_atomic_t *ptr, rt_atomic_t val) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoswap.w %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoswap.d %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_add(volatile rt_atomic_t *ptr, rt_atomic_t val) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoadd.w %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoadd.d %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_sub(volatile rt_atomic_t *ptr, rt_atomic_t val) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| val = -val; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoadd.w %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoadd.d %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_xor(volatile rt_atomic_t *ptr, rt_atomic_t val) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoxor.w %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoxor.d %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_and(volatile rt_atomic_t *ptr, rt_atomic_t val) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoand.w %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoand.d %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_or(volatile rt_atomic_t *ptr, rt_atomic_t val) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoor.w %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoor.d %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_load(volatile rt_atomic_t *ptr) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoxor.w %0, x0, (%1)" : "=r"(result) : "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoxor.d %0, x0, (%1)" : "=r"(result) : "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| void rt_hw_atomic_store(volatile rt_atomic_t *ptr, rt_atomic_t val) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoswap.w %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoswap.d %0, %1, (%2)" : "=r"(result) : "r"(val), "r"(ptr) : "memory"); | ||
| #endif | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_flag_test_and_set(volatile rt_atomic_t *ptr) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| rt_atomic_t temp = 1; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoor.w %0, %1, (%2)" : "=r"(result) : "r"(temp), "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoor.d %0, %1, (%2)" : "=r"(result) : "r"(temp), "r"(ptr) : "memory"); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| void rt_hw_atomic_flag_clear(volatile rt_atomic_t *ptr) | ||
| { | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile("amoand.w %0, x0, (%1)" : "=r"(result) : "r"(ptr) : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile("amoand.d %0, x0, (%1)" : "=r"(result) : "r"(ptr) : "memory"); | ||
| #endif | ||
| } | ||
|
|
||
| rt_atomic_t rt_hw_atomic_compare_exchange_strong(volatile rt_atomic_t *ptr, rt_atomic_t *old, rt_atomic_t desired) | ||
| { | ||
| rt_atomic_t tmp = *old; | ||
| rt_atomic_t result = 0; | ||
| #if __riscv_xlen == 32 | ||
| asm volatile( | ||
| " fence iorw, ow\n" | ||
| "1: lr.w.aq %[result], (%[ptr])\n" | ||
| " bne %[result], %[tmp], 2f\n" | ||
| " sc.w.rl %[tmp], %[desired], (%[ptr])\n" | ||
| " bnez %[tmp], 1b\n" | ||
| " li %[result], 1\n" | ||
| " j 3f\n" | ||
| " 2:sw %[result], (%[old])\n" | ||
| " li %[result], 0\n" | ||
| " 3:\n" | ||
| : [result] "+r"(result), [tmp] "+r"(tmp), [ptr] "+r"(ptr) | ||
| : [desired] "r"(desired), [old] "r"(old) | ||
| : "memory"); | ||
| #elif __riscv_xlen == 64 | ||
| asm volatile( | ||
| " fence iorw, ow\n" | ||
| "1: lr.d.aq %[result], (%[ptr])\n" | ||
| " bne %[result], %[tmp], 2f\n" | ||
| " sc.d.rl %[tmp], %[desired], (%[ptr])\n" | ||
| " bnez %[tmp], 1b\n" | ||
| " li %[result], 1\n" | ||
| " j 3f\n" | ||
| " 2:sd %[result], (%[old])\n" | ||
| " li %[result], 0\n" | ||
| " 3:\n" | ||
| : [result] "+r"(result), [tmp] "+r"(tmp), [ptr] "+r"(ptr) | ||
| : [desired] "r"(desired), [old] "r"(old) | ||
| : "memory"); | ||
| #endif | ||
| return result; | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] [Best Practices/最佳实践]: Hardcoded maximum CPUs value in linker script.
English: The value
RT_CPUS_NR = 8is hardcoded in the linker script but may not match the actualRT_CPUS_NRconfigured in rtconfig.h. While the SConstruct script generates this file, having a default of 8 could be misleading.中文:值
RT_CPUS_NR = 8在链接器脚本中硬编码,但可能与 rtconfig.h 中配置的实际RT_CPUS_NR不匹配。虽然 SConstruct 脚本生成此文件,但默认值为 8 可能会产生误导。Suggestion/建议: Add a comment explaining that this file is auto-generated:
Or add this to a .gitignore to avoid committing the generated file.