-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
RISC-V: Combine 3 variables that depend on CPU amount into one #5985
Conversation
@xiaoxiang781216 can you take a look when you have time. I marked this as draft as it does not compile yet / needs fixing but the basic structure should be in place. The question I have:
Or something along those lines ? |
but all arch call the chip specific setintstack macro setup the interrupt stack. It work very well, do you have any problem with it? |
I'm not sure what this "setintstack" macro does, can you provide and example of what you mean ? For RISC-V, riscv_exception_common.S defines 1 interrupt stack per CPU: And every exception its location is calculated again:
My idea was to pre-calculate the location of the IRQ stack per hart and use the riscv_percpu.c structure and [m/s]scratch register for this. However, for it to work, you need to call riscv_percpu_add_hart to register the hart there. Only MPFS does this now. My question was, is it OK to force registering for other RISC-V targets too or should I do the wrapper. |
Here is an example:
Basically, you can provide setintstack to do what you describe above. |
I see, I wanted to store access to the interrupt stack directly to the scratch register, but for this someone would have to set the scratch register. With flat mode the macro should work, with S-mode reading mhartid fails, so I don't see a way to calculate the index for g_cpu_intstack_top. So the macro would work as is for M-mode, but for S-mode someone will have to set the percpu / sscratch anyway (to get hart id). But maybe I can make uintptr_t riscv_irqstack(void) into an asm macro instead. |
setintstack is implemented by chip, so you can define setintstack in mpfs to fetch the interrupt stack pointer from scratch register without breaking other chip's implementation. Basically, you can:
Other chip could reuse this, or the developer can provide setintstack in other way if they have a better solution. |
Yes this is workable. I was worried because now the equivalent of "setintstack" for RISC-V is now in the common code (riscv_exception_common.S), I think I can provide a solution for the common code too. Something like:
Maybe needs a bit of fixing / tidying up but the basic idea would be like that. You need the percpu structure if the kernel is in S-mode. That cannot be avoided. |
169ba3d
to
538bbde
Compare
581c005
to
85620b2
Compare
Made a fixup error in rebase, restored now |
1478f1f
to
ade6087
Compare
There was a CI issue for k210 and qemu with SMP configuration, I added setintstack for those platforms because they did not have one. I think the SMP targets shared 1 IRQ stack for multiple CPUs or maybe the #ifdef stuff in riscv_internal.h saved it. |
Still seems to have some issue with the setintstack macro, the wrong macro is used. |
b3a6b3b
to
f2b1522
Compare
IRQ_NSTACKS, ARCH_CPU_COUNT, CONFIG_SMP_NCPUS all relate to each other. However, a bit of clean up can be done and everything can be merged into SMP_NCPUS. The MPFS bootloader case works also as it requires only 1 IRQ stack for the hart that executes as bootloader.
riscv_mhartid is no longer called by exception_common, so can remove this file from platforms that don't need it. Also fixes make warning: Makefile:123: target 'riscv_cpuindex.o' given more than once in the same rule
This fixes CI issue, and I think the old implementation with SMP shared 1 IRQ stack for multiple CPUs.
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. I just had one curious comment.
IRQ_NSTACKS, ARCH_CPU_COUNT, CONFIG_SMP_NCPUS all relate to each
other. However, a bit of clean up can be done and everything can
be merged into SMP_NCPUS.
The MPFS bootloader case works also as it requires only 1 IRQ stack
for the hart that executes as bootloader.
Summary
Merges three related Kconfig parameters into one
Impact
Reduces configuration complexity by reducing related parameters
Testing
MPFS icicle:knsh + CI passed