From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail04.groups.io (mail04.groups.io [45.79.224.9]) by spool.mail.gandi.net (Postfix) with ESMTPS id 7E4A49416C6 for ; Wed, 17 Apr 2024 11:27:45 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=QExkU4IJq2PO3moAScHv5fSoTFAxSSqwg5ed1fSGzZU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1713353264; v=1; b=T8m0Mn9qJbPBDhq0U4LhMiz3JzUzbNaAcbI8F4XOYGjN8g+xaeVjPzk1xY8SAwp+Aioe5Wqr fEeNDhc5SW+uL2vE+/DxpQML46u0Vp22vCKct/dmnfZtJDgRbtk1oXXmIEJNrrbzDZlplnXewl7 uv0G6Cy3xCF3ksNf987m/bu7croIZdqU4ljDYNxVGT44/isPDrvQ7Z0xN/U3sNwRX4VO6pJl/vj rgtIdflpjJnvAOq49dzdpQrSCANyTmImJC+qkougIsd23jv3ruEaRJQZaf4sanzwi5+AvzDWTF8 MDXHILw3S5SyBiEzxWkuaR2MkvmfDRPHX1sREin2V3uJA== X-Received: by 127.0.0.2 with SMTP id ddy5YY7687511xyJR2horvhZ; Wed, 17 Apr 2024 04:27:44 -0700 X-Received: from zg8tmja5ljk3lje4ms43mwaa.icoremail.net (zg8tmja5ljk3lje4ms43mwaa.icoremail.net [209.97.181.73]) by mx.groups.io with SMTP id smtpd.web11.10507.1713353258330015666 for ; Wed, 17 Apr 2024 04:27:38 -0700 X-Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with SMTP id AQAAfwD3_2snsh9mZEpLEw--.13644S2; Wed, 17 Apr 2024 19:27:35 +0800 (CST) X-Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAfwDneaMdsh9mcowAAA--.1062S4; Wed, 17 Apr 2024 19:27:30 +0800 (CST) From: "Xiong Yining" To: devel@edk2.groups.io Cc: quic_llindhol@quicinc.com, ardb+tianocore@kernel.org, graeme@xora.org.uk, marcin.juszkiewicz@linaro.org, chenbaozi@phytium.com.cn, Xiong Yining Subject: [edk2-devel] [PATCH 1/2] Platform/SbsaQemu: get the information of CPU topology via SMC calls Date: Wed, 17 Apr 2024 11:26:33 +0000 Message-Id: <20240417112634.120633-2-xiongyining1480@phytium.com.cn> In-Reply-To: <20240417112634.120633-1-xiongyining1480@phytium.com.cn> References: <20240417112634.120633-1-xiongyining1480@phytium.com.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAfwDneaMdsh9mcowAAA--.1062S4 X-CM-SenderInfo: x0lr0wp1lqx0bjrumio6sk53xlxphulrpou0/1tbiAQASBmYe0uQEdQACso X-Coremail-Antispam: 1Uk129KBjvJXoWxJw15KF1xCFW5Gw43WF13twb_yoWrWFyfpF 92yFZakr45Jr97tw4xGayS9FyrKF1Sg3yDGrZFvw1jyr4DJFWFqrWqqFn5XF15GFnrC3yr Kay8Xa4Uur95GrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Wed, 17 Apr 2024 04:27:38 -0700 Resent-From: xiongyining1480@phytium.com.cn Reply-To: devel@edk2.groups.io,xiongyining1480@phytium.com.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: kM7x6E1K7iyfFMrkKwZXuZFyx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=T8m0Mn9q; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.9 as permitted sender) smtp.mailfrom=bounce@groups.io 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 cores. 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 --- .../Include/IndustryStandard/SbsaQemuSmc.h | 1 + .../Include/Library/HardwareInfoLib.h | 26 +++++++++++++++ .../SbsaQemuHardwareInfoLib.c | 33 +++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h index e3092007d27d..9d9780ca70fe 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 46fdad45353c..3e451ee344c7 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 4c22e7d6ee47..a12dc0244da5 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c @@ -179,3 +179,36 @@ 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 are %d, clusters are %d, cores are %d, threads are %d\n", + __FUNCTION__, + CpuTopo->Sockets, + CpuTopo->Clusters, + CpuTopo->Cores, + CpuTopo->Threads )); +} \ No newline at end of file -- 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117915): https://edk2.groups.io/g/devel/message/117915 Mute This Topic: https://groups.io/mt/105575034/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-