-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
arch/riscv/qemu-rv: Add S-mode support #12178
Conversation
b595e1b
to
5e6e679
Compare
Thanks @inochisa, I have some questions:
Please gimme some time to read and understand the code, also to test on Ox64. Thanks! |
Thanks for reminding, I have attached test log file.
No luck, this is another problem. The change on IPI is mainly for using different IPI code in different mode.
I struggled whether to break this PR into several ones, or just squash them as a whole. But finally, I decide to submmit this PR as is. IPI change allows to using another change for S mode. dynamic stack allocation make a progress on booting with non-zero hart (which is kind of necessary for booting with SBI). and SSTC give better performance in S-mode. This three are important for qemu-rv S-mode. For the last commit, it is a squash commit. Because I have no idea to separate them. |
Thanks @inochisa. I'll write some Review Notes to explain the SSTC Extension, this is new to me and many folks too :-) Hi @yf13 please let us know if you have comments on the K230 changes thanks! |
Tested OK on Ox64 BL808 SBC, Kernel Mode. (See the Test Log) @inochisa Thanks for the Test Logs for QEMU Kernel Mode: rv-virt:knsh32 and rv-virt:knsh64. As a Regression Test, could you also run QEMU Flat Mode: rv-virt:nsh and rv-virt:nsh64? Thanks for the excellent work in refactoring QEMU Startup for Kernel Mode, I'm just making sure that QEMU Flat Mode is still OK after refactoring. Thanks! |
@lupyuen I have added new log files.
Thanks for this improvement. |
@inochisa |
@masayuki2009 Thanks, it seems that I removed a branch jump by mistake. Could you test the new PR on the k210? |
@inochisa |
@inochisa Could you change to the text below, so I can approve the PR? Thanks! Documentation/platforms/risc-v/qemu-rv/boards/rv-virt/index.rst
|
@lupyuen Do you have any suggestions? In fact, I am not sure how to explain this change. Maybe just add new command line for kernel mode will be better? |
@inochisa Sorry I didn't understand your question? You inserted this line at Documentation/platforms/risc-v/qemu-rv/boards/rv-virt/index.rst:
The text has typos. Could you change the text so that it reads:
There's no need to explain the change or add a command line. Thanks! |
Thanks, I will fix it. |
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.
LGTM Thank you so much :-)
Documentation/platforms/risc-v/qemu-rv/boards/rv-virt/index.rst
Outdated
Show resolved
Hide resolved
@inochisa please rebase and fix the conflicts |
@inochisa |
67f1ff2
to
0831f43
Compare
Add ipi process abstract function support. Signed-off-by: Inochi Amaoto <[email protected]>
It is misleading to allocate stack from static array and heap, make all stack allocated from heap area. Signed-off-by: Inochi Amaoto <[email protected]>
As `up_get_intstackbase` supports per cpu stack base, fix the report value with the cpu specific one. Signed-off-by: Inochi Amaoto <[email protected]>
SSTC extension allows nuttx to implement S-mode timer directly, which is useful for starting at S-mode. Signed-off-by: Inochi Amaoto <[email protected]>
The qemu-rv use a small init code for M mode in kernel build. It is hard-coding and is difficult to change. Due to the fact, introduce a already mature SBI implement (e.g OpenSBI) to replace existing code is a better choice. This patch introduce some change for qemu-rv: 1. use SSTC to provide time interrupt in kernel build 2. remove uncessary M mode trap. For simplicity, this patch does not add support for booting nuttx for any core, but force boot core to start core 0 and let core 0 do the initialization. Signed-off-by: Inochi Amaoto <[email protected]>
|
||
static inline void riscv_ipi_send(int cpu) | ||
{ | ||
#if defined(RISCV_IPI) |
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.
remove, it's better to generate the.compiler error instead runtime panic.
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.
Right, I think it is better to add this when adding sbi_ipi_send
function.
|
||
static inline void riscv_ipi_clear(int cpu) | ||
{ | ||
#if defined(RISCV_IPI) |
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.
ditto
|
||
for (i = 0; i < CONFIG_SMP_NCPUS; i++) | ||
{ | ||
g_cpux_idlestack[i] = (const uint8_t *)(base + size * i); |
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.
why not initialize the array at the definition place?
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.
Initializing this array at the definition sounds like good, but it needs lots of ugly macro test like CONFIG_SMP_NCPUS < x
. I don't think it is good.
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.
but it still better to runtime initialize it in all chip specific file.
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.
I agree, initializing this array statically does have benefits. The only problem is how to achieve it.The only way I find at now is just generating g_cpux_idlestack
based on the CONFIG_SMP_NCPUS
. Could you have some better idea?
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.
I don't find a better method than this too.:(
* Parameter: | ||
* base - Pointer to where the stack is allocated (e.g. _ebss) | ||
* size - Stack size for pre cpu to allocate | ||
* size - Hart id register of this hart (Usually a0) |
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.
size to hartid
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.
Thanks.
|
||
/* ensure the last XCPTCONTEXT_SIZE is reserved for non boot CPU */ | ||
|
||
bnez \hartid, 998f |
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.
why not remove the reserve from up_initial_state to make the code mofe consistent? or skip calling riscv_set_inital_sp for boot cpu.
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.
I have seen up_initial_state reserve something, It just return after setting the idle stack for the idle process 0. Do I miss somthing?
And skip calling riscv_set_inital_sp is not a good idea, this means chip always need to set it manually, which is weird.
@xiaoxiang781216 I see @acassis already merged this before your comment. Is it better to open a new PR to fix this? |
Yes. |
Sorry @inochisa @xiaoxiang781216 I missed these comments, I just saw the other approvals and merged it |
Not your problem, the patch was merged before I submit the comment. |
@inochisa There might be a problem with QEMU SMP and OpenSBI / SSTC: When I tested with QEMU
$ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 -bios none -kernel nuttx -nographic So we might have to remove Here's how I reproduced the problem. Thanks! https://gist.github.com/lupyuen/df2c9a552b1679257c9ff5d871ce0a4f $ git clone https://github.com/inochisa/nuttx --branch qemu-s-mode
$ git clone https://github.com/XuNeo/incubator-nuttx-apps apps --branch fix-lvgl-distclean-warning
$ cat nuttx.hash
NuttX Source (26 Apr 2024): https://github.com/apache/nuttx/tree/02c1a95c96069ea59401255169961c082471f826
NuttX Apps (30 Apr 2024): https://github.com/apache/nuttx-apps/tree/0f0caee0d0367c4664c05c5c14807f5d70f2e1de
$ qemu-system-riscv64 --version
QEMU emulator version 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1)
## OpenSBI v1.3
## Runtime SBI Version : 1.0
$ qemu-system-riscv64 \
-semihosting \
-M virt,aclint=on \
-cpu rv64 \
-smp 8 \
-kernel nuttx \
-nographic
## Out of 16 tries, 3 will boot OK
$ neofetch
.-/+oossssoo+/-. luppy@luppy-macbook-ubuntu
`:+ssssssssssssssssss+:` --------------------------
-+ssssssssssssssssssyyssss+- OS: Ubuntu 24.04 LTS x86_64
.ossssssssssssssssssdMMMNysssso. Host: MacBookPro10,1 1.0
/ssssssssssshdmmNNmmyNMMMMhssssss/ Kernel: 6.8.0-31-generic
+ssssssssshmydMMMMMMMNddddyssssssss+ Uptime: 1 hour, 29 mins
/sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Packages: 1911 (dpkg), 16 (snap
.ssssssssdMMMNhsssssssssshNMMMdssssssss. Shell: bash 5.2.21
+sssshhhyNMMNyssssssssssssyNMMMysssssss+ Resolution: 1920x1080
ossyNMMMNyMMhsssssssssssssshmmmhssssssso DE: Unity
ossyNMMMNyMMhsssssssssssssshmmmhssssssso WM: Mutter
+sssshhhyNMMNyssssssssssssyNMMMysssssss+ WM Theme: Adwaita
.ssssssssdMMMNhsssssssssshNMMMdssssssss. Theme: Yaru-dark [GTK2/3]
/sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ Icons: Yaru [GTK2/3]
+sssssssssdmydMMMMMMMMddddyssssssss+ Terminal: vscode
/ssssssssssshdmNNNNmyNMMMMhssssss/ CPU: Intel i7-3820QM (8) @ 3.70
.ossssssssssssssssssdMMMNysssso. GPU: NVIDIA GeForce GT 650M Mac
-+sssssssssssssssssyyyssss+- GPU: Intel 3rd Gen Core process
`:+ssssssssssssssssss+:` Memory: 3667MiB / 15898MiB
.-/+oossssoo+/-.
|
I think this is simple because SBI does not guarantee the boot hart is 0, which is required for nuttx (Although the firmware used by qemu support setting boot hart, qemu itself does not provide this interface IIRC). If you set the correct hart number for the build, everything works well.
At least for now, it seems we need to update the doc. I think setting the right number of CPU is always required. |
@inochisa Thanks, does it mean that https://nuttx.apache.org/docs/latest/platforms/risc-v/qemu-rv/boards/rv-virt/index.html#ksmp64 |
It works only when the cpu number will set to 4 (the CPU number in config). I think the boot command for kernel mode may need to change as the following. $ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp <cpu number> -kernel nuttx -nographic |
This patch series introduce some optimization for S-mode only nuttx:
At last, it introduces S-mode only on qemu-rv platform, which can boot
with SBI provided by QEMU.
Logfiles:
nuttx-qemu32.log
nuttx-qemu64.log
nuttx-nsh32.log
nuttx-nsh64.log