public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marcin Juszkiewicz" <marcin.juszkiewicz@linaro.org>
To: Xiong Yining <xiongyining1480@phytium.com.cn>, devel@edk2.groups.io
Cc: quic_llindhol@quicinc.com, ardb+tianocore@kernel.org,
	graeme@xora.org.uk, chenbaozi@phytium.com.cn
Subject: Re: [edk2-devel] [PATCH 1/2] Platform/SbsaQemu: get the information of CPU topology via SMC calls
Date: Fri, 21 Jun 2024 10:29:51 +0200	[thread overview]
Message-ID: <111932b5-a3e3-4fa5-87a3-ac64403e8b08@linaro.org> (raw)
In-Reply-To: <20240417112634.120633-2-xiongyining1480@phytium.com.cn>

W dniu 17.04.2024 o 13:26, Xiong Yining pisze:
> 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 <xiongyining1480@phytium.com.cn>
> ---
>   .../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);

Can you use ArmCallSmc() directly? TF-A returns 5 arguments for this SMC 
call, we use 4 and calculate 5th one. Once we improve SMCCC code in EDK2 
the 5th one would be used directly.

> +  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);

Once SMCCC gets improved this would be read directly from TF-A.

> +  }
> +
> +  DEBUG(( DEBUG_INFO, "%a: CPU Topology: sockets are %d, clusters are %d, cores are %d, threads are %d\n",

Can you replace " are" with ":" ("sockets: %d, clusters: %d")? Those 
numbers can be singular.

> +      __FUNCTION__,
> +      CpuTopo->Sockets,
> +      CpuTopo->Clusters,
> +      CpuTopo->Cores,
> +      CpuTopo->Threads ));
> +}
> \ No newline at end of file



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119668): https://edk2.groups.io/g/devel/message/119668
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]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2024-06-21  8:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 11:26 [edk2-devel] [PATCH 0/2] Align the PPTT tables with qemu configuration Xiong Yining
2024-04-17 11:26 ` [edk2-devel] [PATCH 1/2] Platform/SbsaQemu: get the information of CPU topology via SMC calls Xiong Yining
2024-06-21  8:29   ` Marcin Juszkiewicz [this message]
2024-04-17 11:26 ` [edk2-devel] [PATCH 2/2] Silicon/SbsaQemu: align the PPTT tables with qemu configuration Xiong Yining
2024-06-21  8:29   ` Marcin Juszkiewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=111932b5-a3e3-4fa5-87a3-ac64403e8b08@linaro.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox