-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Changes from all commits
6c0a7d1
7948f50
c7cbe2e
402ec68
8386d29
7a770ce
9cdbc36
bf917a1
a59652d
8a9066f
676f98f
b61f477
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| RT_CPUS_NR = 8; | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,20 @@ if [ ! -f $path_image ]; then | |
| exit | ||
| fi | ||
|
|
||
| qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin \ | ||
| QEMU_CMD="qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin" | ||
|
|
||
| if grep -q "#define RT_USING_SMP" ./rtconfig.h 2>/dev/null; then | ||
| hart_num=$(grep "RT_CPUS_NR = [0-9]*;" ./link_cpus.lds 2>/dev/null | awk -F'[=;]' '{gsub(/ /, "", $2); print $2}') | ||
| if [ -z "$hart_num" ] || [ "$hart_num" -lt 1 ]; then | ||
| echo "Warning: Invalid or missing RT_CPUS_NR, defaulting to 1" | ||
| hart_num=1 | ||
| fi | ||
| QEMU_CMD="$QEMU_CMD -smp $hart_num" | ||
| fi | ||
|
Comment on lines
+29
to
+36
|
||
|
|
||
| QEMU_CMD="$QEMU_CMD \ | ||
| -drive if=none,file=$path_image,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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,29 +69,47 @@ | |
| .endm | ||
|
|
||
| /* | ||
| * #ifdef RT_USING_SMP | ||
| * void rt_hw_context_switch_to(rt_ubase_t to, stuct rt_thread *to_thread); | ||
| * #else | ||
| * void rt_hw_context_switch_to(rt_ubase_t to); | ||
| * | ||
| * a0 --> to SP pointer | ||
| * #endif | ||
| * a0 --> to | ||
| * a1 --> to_thread | ||
| */ | ||
| .globl rt_hw_context_switch_to | ||
| rt_hw_context_switch_to: | ||
| LOAD sp, (a0) | ||
|
|
||
| #ifdef RT_USING_SMP | ||
| /* Pass the previous CPU lock status to rt_cpus_lock_status_restore for restoration */ | ||
| mv a0, a1 | ||
| call rt_cpus_lock_status_restore | ||
| #endif | ||
|
|
||
| call rt_thread_self | ||
| mv s1, a0 | ||
|
|
||
| #ifndef RT_USING_SMP | ||
| //if enable RT_USING_SMP, it will finished by rt_cpus_lock_status_restore. | ||
| #ifdef RT_USING_SMART | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这块代码要格式化下,#ifdef前不需要有缩进 |
||
| call lwp_aspace_switch | ||
| call lwp_aspace_switch | ||
| #endif | ||
| #endif | ||
|
|
||
| RESTORE_CONTEXT | ||
| sret | ||
|
|
||
| /* | ||
| * #ifdef RT_USING_SMP | ||
| * void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread); | ||
| * #else | ||
| * void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to); | ||
| * #endif | ||
| * | ||
| * a0 --> from SP pointer | ||
| * a1 --> to SP pointer | ||
| * a2 --> to_thread | ||
| * | ||
| * It should only be used on local interrupt disable | ||
| */ | ||
|
|
@@ -103,13 +121,22 @@ rt_hw_context_switch: | |
| // restore to thread SP | ||
| LOAD sp, (a1) | ||
|
|
||
| #ifdef RT_USING_SMP | ||
| /* Pass the previous CPU lock status to rt_cpus_lock_status_restore for restoration */ | ||
| mv a0, a2 | ||
| call rt_cpus_lock_status_restore | ||
| #endif /*RT_USING_SMP*/ | ||
|
|
||
| // restore Address Space | ||
| call rt_thread_self | ||
| mv s1, a0 | ||
|
|
||
| #ifndef RT_USING_SMP | ||
| // if enable RT_USING_SMP, it will finished by rt_cpus_lock_status_restore. | ||
| #ifdef RT_USING_SMART | ||
| call lwp_aspace_switch | ||
| call lwp_aspace_switch | ||
| #endif | ||
| #endif | ||
|
|
||
| RESTORE_CONTEXT | ||
| sret | ||
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.