Re: [edk2-devel] 回复: [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()

2021-03-16 Thread Ankur Arora

On 2021-03-16 6:08 p.m., gaoliming wrote:

Ankur:
   Can you give the detail usage for the lower power state when enter into
CpuDeadLoop()?


I'm not really familiar with ARM and RiscV, both of which also have 
implementations
for CpuPause(), for the details for X86 variants are below.

From Intel's instruction-set reference:
"An additional function of the PAUSE instruction is to reduce the power consumed
by a processor while executing a spin loop. A processor can execute a spin-wait
loop extremely quickly, causing the processor to consume a lot of power while it
waits for the resource it is spinning on to become available. Inserting a pause
instruction in a spin-wait loop greatly reduces the processor’s power
consumption."

And, from AMD's instruction-set reference:
"Improves the performance of spin loops, by providing a hint to the processor
that the current code is in a spin loop. The processor may use this to optimize
power consumption while in the spin loop. Architecturally, this instruction
behaves like a NOP instruction."

Happy to add this to the commit message if you think it'll be useful.

Thanks
Ankur



Thanks
Liming

-邮件原件-
发件人: Ankur Arora 
发送时间: 2021年3月17日 6:59
收件人: devel@edk2.groups.io
抄送: Ankur Arora ; Liming Gao
; Michael D Kinney

主题: [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()

Use CpuPause() to allow the CPU to go into a lower power state
state while we spin wait.

Cc: Liming Gao 
Signed-off-by: Ankur Arora 
Reviewed-by: Michael D Kinney 
---
  MdePkg/Library/BaseLib/CpuDeadLoop.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Library/BaseLib/CpuDeadLoop.c
b/MdePkg/Library/BaseLib/CpuDeadLoop.c
index 9e110cacbc96..3cd304351a65 100644
--- a/MdePkg/Library/BaseLib/CpuDeadLoop.c
+++ b/MdePkg/Library/BaseLib/CpuDeadLoop.c
@@ -28,5 +28,7 @@ CpuDeadLoop (
  {
volatile UINTN  Index;

-  for (Index = 0; Index == 0;);
+  for (Index = 0; Index == 0;) {
+CpuPause();
+  }
  }
--
2.9.3







-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72949): https://edk2.groups.io/g/devel/message/72949
Mute This Topic: https://groups.io/mt/81393215/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] 回复: [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()

2021-03-16 Thread gaoliming
Ankur:
  Can you give the detail usage for the lower power state when enter into
CpuDeadLoop()?

Thanks
Liming
> -邮件原件-
> 发件人: Ankur Arora 
> 发送时间: 2021年3月17日 6:59
> 收件人: devel@edk2.groups.io
> 抄送: Ankur Arora ; Liming Gao
> ; Michael D Kinney
> 
> 主题: [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()
> 
> Use CpuPause() to allow the CPU to go into a lower power state
> state while we spin wait.
> 
> Cc: Liming Gao 
> Signed-off-by: Ankur Arora 
> Reviewed-by: Michael D Kinney 
> ---
>  MdePkg/Library/BaseLib/CpuDeadLoop.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/MdePkg/Library/BaseLib/CpuDeadLoop.c
> b/MdePkg/Library/BaseLib/CpuDeadLoop.c
> index 9e110cacbc96..3cd304351a65 100644
> --- a/MdePkg/Library/BaseLib/CpuDeadLoop.c
> +++ b/MdePkg/Library/BaseLib/CpuDeadLoop.c
> @@ -28,5 +28,7 @@ CpuDeadLoop (
>  {
>volatile UINTN  Index;
> 
> -  for (Index = 0; Index == 0;);
> +  for (Index = 0; Index == 0;) {
> +CpuPause();
> +  }
>  }
> --
> 2.9.3





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72940): https://edk2.groups.io/g/devel/message/72940
Mute This Topic: https://groups.io/mt/81393215/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-