Provide functions to check for CPU topology information: - the number of sockets on sbsa-ref platform. - the number of clusters in one socket. - the number of cores in one cluster. - the number of threads in one core.
As SMC calls can return up to 4 return values. the number of sockets, clusters and cores are read from TF-A using platform specific SMC calls. And the number of threads is caluculated using the total number of cpus and the number of sockets, clusters and cores. Signed-off-by: Xiong Yining <xiongyining1...@phytium.com.cn> Signed-off-by: Marcin Juszkiewicz <marcin.juszkiew...@linaro.org> --- .../SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h | 1 + .../Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h | 26 ++++++++++++++ .../SbsaQemuHardwareInfoLib.c | 36 ++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h index af6b120561ad..b57573735ace 100644 --- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h +++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h @@ -16,6 +16,7 @@ #define SIP_SVC_GET_GIC_ITS SMC_SIP_FUNCTION_ID(101) #define SIP_SVC_GET_CPU_COUNT SMC_SIP_FUNCTION_ID(200) #define SIP_SVC_GET_CPU_NODE SMC_SIP_FUNCTION_ID(201) +#define SIP_SVC_GET_CPU_TOPOLOGY SMC_SIP_FUNCTION_ID(202) #define SIP_SVC_GET_MEMORY_NODE_COUNT SMC_SIP_FUNCTION_ID(300) #define SIP_SVC_GET_MEMORY_NODE SMC_SIP_FUNCTION_ID(301) diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h index e5076274fa0a..cef6f6f58194 100644 --- a/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h +++ b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h @@ -15,6 +15,19 @@ typedef struct { UINT64 AddressSize; } MemoryInfo; +/** + Sockets: the number of sockets on sbsa-ref platform. + Clusters: the number of clusters in one socket. + Cores: the number of cores in one cluster. + Threads: the number of threads in one core. +**/ +typedef struct { + UINT32 Sockets; + UINT32 Clusters; + UINT32 Cores; + UINT32 Threads; +} CpuTopology; + /** Get CPU count from information passed by Qemu. @@ -83,4 +96,17 @@ GetNumaNodeCount ( VOID ); +/** + Get cpu topology(sockets, clusters, cores, threads) from device tree passed by Qemu. + + @param [out] CpuTopo A pointer to the cpu topology. + + + @retval the information of cpu topology. +**/ +VOID +GetCpuTopology ( + OUT CpuTopology *CpuTopo + ); + #endif /* HARDWARE_INFO_LIB */ diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c index 596a3453c70f..a2ea8a523625 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c @@ -181,3 +181,39 @@ GetNumaNodeCount ( return NumberNumaNodes; } + +/** + Get CPU topology. +**/ +VOID +GetCpuTopology ( + OUT CpuTopology *CpuTopo + ) +{ + UINTN SmcResult; + UINTN Arg0; + UINTN Arg1; + UINTN Arg2; + UINT32 NumCores = GetCpuCount (); + + SmcResult = ArmCallSmc0 (SIP_SVC_GET_CPU_TOPOLOGY, &Arg0, &Arg1, &Arg2); + if (SmcResult != SMC_SIP_CALL_SUCCESS) { + DEBUG ((DEBUG_ERROR, "%a: SIP_SVC_GET_CPU_TOPOLOGY call failed. We have no cpu topology information.\n", __FUNCTION__)); + ResetShutdown (); + } else { + CpuTopo->Sockets = Arg0; + CpuTopo->Clusters = Arg1; + CpuTopo->Cores = Arg2; + CpuTopo->Threads = NumCores / (CpuTopo->Sockets * CpuTopo->Clusters * CpuTopo->Cores); + } + + DEBUG (( + DEBUG_INFO, + "%a: CPU Topology: sockets: %d, clusters: %d, cores: %d, threads: %d\n", + __FUNCTION__, + CpuTopo->Sockets, + CpuTopo->Clusters, + CpuTopo->Cores, + CpuTopo->Threads + )); +} -- 2.45.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119763): https://edk2.groups.io/g/devel/message/119763 Mute This Topic: https://groups.io/mt/107003193/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-