public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()
@ 2021-03-16 22:59 Ankur Arora
  2021-03-17  1:08 ` 回复: " gaoliming
  2021-03-17 18:30 ` [edk2-devel] " Laszlo Ersek
  0 siblings, 2 replies; 4+ messages in thread
From: Ankur Arora @ 2021-03-16 22:59 UTC (permalink / raw)
  To: devel; +Cc: Ankur Arora, Liming Gao, Michael D Kinney

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

Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* 回复: [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()
  2021-03-16 22:59 [PATCH] MdePkg: use CpuPause() in CpuDeadLoop() Ankur Arora
@ 2021-03-17  1:08 ` gaoliming
  2021-03-17  3:54   ` Ankur Arora
  2021-03-17 18:30 ` [edk2-devel] " Laszlo Ersek
  1 sibling, 1 reply; 4+ messages in thread
From: gaoliming @ 2021-03-17  1:08 UTC (permalink / raw)
  To: 'Ankur Arora', devel; +Cc: 'Michael D Kinney'

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

Thanks
Liming
> -----邮件原件-----
> 发件人: Ankur Arora <ankur.a.arora@oracle.com>
> 发送时间: 2021年3月17日 6:59
> 收件人: devel@edk2.groups.io
> 抄送: Ankur Arora <ankur.a.arora@oracle.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Michael D Kinney
> <michael.d.kinney@intel.com>
> 主题: [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 <gaoliming@byosoft.com.cn>
> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
> ---
>  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




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 回复: [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()
  2021-03-17  1:08 ` 回复: " gaoliming
@ 2021-03-17  3:54   ` Ankur Arora
  0 siblings, 0 replies; 4+ messages in thread
From: Ankur Arora @ 2021-03-17  3:54 UTC (permalink / raw)
  To: gaoliming, devel; +Cc: 'Michael D Kinney'

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 <ankur.a.arora@oracle.com>
>> 发送时间: 2021年3月17日 6:59
>> 收件人: devel@edk2.groups.io
>> 抄送: Ankur Arora <ankur.a.arora@oracle.com>; Liming Gao
>> <gaoliming@byosoft.com.cn>; Michael D Kinney
>> <michael.d.kinney@intel.com>
>> 主题: [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 <gaoliming@byosoft.com.cn>
>> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
>> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
>> ---
>>   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
> 
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] [PATCH] MdePkg: use CpuPause() in CpuDeadLoop()
  2021-03-16 22:59 [PATCH] MdePkg: use CpuPause() in CpuDeadLoop() Ankur Arora
  2021-03-17  1:08 ` 回复: " gaoliming
@ 2021-03-17 18:30 ` Laszlo Ersek
  1 sibling, 0 replies; 4+ messages in thread
From: Laszlo Ersek @ 2021-03-17 18:30 UTC (permalink / raw)
  To: devel, ankur.a.arora; +Cc: Liming Gao, Michael D Kinney

On 03/16/21 23:59, Ankur Arora wrote:
> Use CpuPause() to allow the CPU to go into a lower power state
> state while we spin wait.
> 
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
> ---
>  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();
> +  }
>  }
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

(for RISC-V and ARM64, the implementations seem to be "nop" instructions)

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-17 18:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-16 22:59 [PATCH] MdePkg: use CpuPause() in CpuDeadLoop() Ankur Arora
2021-03-17  1:08 ` 回复: " gaoliming
2021-03-17  3:54   ` Ankur Arora
2021-03-17 18:30 ` [edk2-devel] " Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox