-
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
arch/risc-v: Make CPU index handling based on ARCH_RV_CPUID_MAP #15396
Conversation
[Experimental Bot, please feedback here] Fill In The Commit Message: This PR contains a Commit with an Empty Commit Message. Please fill in the Commit Message with the PR Summary. Yes, this PR appears to meet the NuttX requirements, although some sections could be more explicit. Strengths:
Weaknesses (and suggestions for improvement):
Example for the Testing Section:
Testing logs after change (demonstrating the fix):
Tests Performed:
|
a6b79b4
to
ec8d44c
Compare
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 make things dependent on CONFIG_ARCH_RV_HARTID_BASE? Without this patch you can overload riscv_hartid_to_cpuid / riscv_cpuid_to_hartid? I'd prefer this breaking change was not merged at all...
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.
Hi @no1wudi please include a short explanation in the git commit message
@pussuw I am attempting to decouple the implementation of CONFIG_RISCV_PERCPU_SCRATCH and riscv_mhartid, as the SCRATCH register is generally always available. In the current implementation, it seems that only the CONFIG_ARCH_RV_HARTID_BASE configuration affects the behavior of riscv_mhartid (when it is set to 0, the CPU ID and HART ID have a 1:1 mapping). Do you have any other suggestions? |
I use an overloaded version (defined by board logic) of hartid<->cpuid mapping in my downstream project. This was the whole point to define those as weak symbols. Please do not break this functionality. |
20cb066
to
b040170
Compare
Another point to note is that in this PR, CONFIG_ARCH_RV_HARTID_BASE is used to select the implementation of up_cpu_index. Please confirm if this aligns with your requirements. #ifdef CONFIG_ARCH_HAVE_MULTICPU
#if CONFIG_ARCH_RV_HARTID_BASE != 0
int up_cpu_index(void) noinstrument_function;
#else
noinstrument_function static inline int up_cpu_index(void)
{
return READ_CSR(CSR_MHARTID);
}
#endif /* CONFIG_ARCH_RV_HARTID_BASE */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */ |
80e4f55
to
8ec4e5b
Compare
aef20f0
to
2ebe678
Compare
Sorry for delayed reply, but yes this will also not work for me. CONFIG_ARCH_RV_HARTID_BASE is too limited for me, as it only allows offset based CPUID mapping. I need to map the cores dynamically as I have AMP in my target as well as SMP. Also the previous patch 6eb2f33 breaks up_cpu_index() for me :( |
Maybe as a kludge solution I can set CONFIG_ARCH_RV_HARTID_BASE to != 0, since I don't use this offset value anyway. |
@pussuw If that's the case, should an additional option be introduced to control the behavior of the current CPU index mapping? The existing configurations or their combinations do not seem suitable as switches to control it (CONFIG_RISCV_PERCPU_SCRATCH/CONFIG_ARCH_RV_HARTID_BASE), and the conditions for enabling it are also quite ambiguous to me. This makes it difficult to synchronize general optimizations from other architectures (such as inlining small functions) onto the RISC-V platform. |
That would make sense, since the problem here really is that we don't have a dedicated flag for enabling CPUID mapping. |
Now a new option |
@pussuw could you give the concrete return value from up_cpud_index and up_this_cpu on your platform? |
I need the conversion functions as well, because in mpfs_start we need to do the conversion before we can use up_cpu_index(): nuttx/arch/risc-v/src/mpfs/mpfs_start.c Line 88 in cd83dc1
nuttx/arch/risc-v/src/mpfs/mpfs_start.c Line 120 in cd83dc1
nuttx/arch/risc-v/src/mpfs/mpfs_start.c Line 210 in cd83dc1
In supervisor mode, the hartid is available ONLY as the input parameter for mpfs_start(), before it is installed to the scratch register. The whole reason we need the scratch register to store hartid is the fact that supervisor mode simply does not have the hartid CSR. |
a1b8b24
to
dc5fb32
Compare
BTW, the naming of the function riscv_mhartid is highly misleading. Literally, it appears to be a simple wrapper for CSR_MHARTID, but in reality, under CONFIG_RISCV_PERCPU_SCRATCH, it reads the logical ID from percpu data. I believe it should be renamed. |
The reason we need the wrapper is that we read the hartid from two places, depeding on runlevel / mode:
In supervisor mode SBI gives the hartid in a0 register (this is an SBI ABI requirement) and it is up to the payload OS to store this internally somewhere. We use the percpu scratch register for this, as it is the only place that is unique for every CPU that is not volatile.
It reads the physical ID from percpu data. I guess in flat (machine) mode you could read hartid from CSR mhartid even if CONFIG_RISCV_PERCPU_SCRATCH is enabled.. |
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
Sure, let's add more detail for riscv_mhartid |
This patch refactors the CPU index handling in the RISC-V architecture to be based on the ARCH_RV_CPUID_MAP configuration. Signed-off-by: Huang Qi <[email protected]>
Summary
Changes Overview
Refactored CPU index handling in RISC-V architecture to use new
ARCH_RV_CPUID_MAP
configuration.Key Changes
1. New Configuration
ARCH_RV_CPUID_MAP
Kconfig option2. Documentation Improvements
3. Code Refactoring
4. Build System Updates
ARCH_HAVE_MULTICPU
checks withARCH_RV_CPUID_MAP
Purpose
Provides better support for RISC-V systems with:
Impact
RISCV SMP
Testing
GitHub CI and QEMU