This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 5de9d957e6 ricv/riscv_cpuid: Return meaningful values for CPU/Hart ID
when SMP=no
5de9d957e6 is described below
commit 5de9d957e61150a9f067815981b64b89b0945a1e
Author: Ville Juven <[email protected]>
AuthorDate: Fri Oct 18 12:08:07 2024 +0300
ricv/riscv_cpuid: Return meaningful values for CPU/Hart ID when SMP=no
Return 0 for CPU ID for any hart ID, and return the current Hart ID for
any CPU ID. At least these values are somewhat usable / meaningful in
non-SMP configurations.
---
arch/risc-v/src/common/riscv_cpuindex.c | 12 ++++++++++--
arch/risc-v/src/common/riscv_internal.h | 2 +-
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/risc-v/src/common/riscv_cpuindex.c
b/arch/risc-v/src/common/riscv_cpuindex.c
index 8586d1cf55..c8c5c45703 100644
--- a/arch/risc-v/src/common/riscv_cpuindex.c
+++ b/arch/risc-v/src/common/riscv_cpuindex.c
@@ -71,9 +71,13 @@ int up_this_cpu(void)
*
****************************************************************************/
-int weak_function riscv_hartid_to_cpuid(int cpu)
+int weak_function riscv_hartid_to_cpuid(int hart)
{
- return cpu - CONFIG_ARCH_RV_HARTID_BASE;
+#ifdef CONFIG_SMP
+ return hart - CONFIG_ARCH_RV_HARTID_BASE;
+#else
+ return 0;
+#endif
}
/****************************************************************************
@@ -87,5 +91,9 @@ int weak_function riscv_hartid_to_cpuid(int cpu)
int weak_function riscv_cpuid_to_hartid(int cpu)
{
+#ifdef CONFIG_SMP
return cpu + CONFIG_ARCH_RV_HARTID_BASE;
+#else
+ return (int)riscv_mhartid();
+#endif
}
diff --git a/arch/risc-v/src/common/riscv_internal.h
b/arch/risc-v/src/common/riscv_internal.h
index bb6737f4a4..ffa85d5450 100644
--- a/arch/risc-v/src/common/riscv_internal.h
+++ b/arch/risc-v/src/common/riscv_internal.h
@@ -436,7 +436,7 @@ uintptr_t riscv_mhartid(void);
*
****************************************************************************/
-int riscv_hartid_to_cpuid(int cpu);
+int riscv_hartid_to_cpuid(int hart);
/****************************************************************************
* Name: riscv_cpuid_to_hartid