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

Ankur Arora posted 1 patch 3 years, 1 month ago
Failed in applying to current master (apply log)
There is a newer version of this series
MdePkg/Library/BaseLib/CpuDeadLoop.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[edk2-devel] [PATCH v2] MdePkg: use CpuPause() in CpuDeadLoop()
Posted by Ankur Arora 3 years, 1 month ago
CpuPause() might allow the CPU to go into a lower power state
state while we spin.

On X86, CpuPause() executes a PAUSE instruction which the Intel
and AMD specs describe as follows:

Intel:
  "PAUSE: 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."

AMD:
  "PAUSE: 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."

On RISC-V and ARM64, CpuPause() executes a NOP, which is no worse than
the tight loop we have.

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>
Reviewed-by: Laszlo Ersek <lersek@redhat.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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#73018): https://edk2.groups.io/g/devel/message/73018
Mute This Topic: https://groups.io/mt/81437102/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


回复: [edk2-devel] [PATCH v2] MdePkg: use CpuPause() in CpuDeadLoop()
Posted by gaoliming 3 years, 1 month ago
Ankur:
  Seemly, the patch is missing in this mail. 

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Ankur Arora
> 发送时间: 2021年3月19日 2:45
> 收件人: 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>; Laszlo Ersek <lersek@redhat.com>
> 主题: [edk2-devel] [PATCH v2] MdePkg: use CpuPause() in CpuDeadLoop()
> 
> CpuPause() might allow the CPU to go into a lower power state
> state while we spin.
> 
> On X86, CpuPause() executes a PAUSE instruction which the Intel
> and AMD specs describe as follows:
> 
> Intel:
>   "PAUSE: 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 processorb




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#73026): https://edk2.groups.io/g/devel/message/73026
Mute This Topic: https://groups.io/mt/81445311/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: 回复: [edk2-devel] [PATCH v2] MdePkg: use CpuPause() in CpuDeadLoop()
Posted by Laszlo Ersek 3 years, 1 month ago
Hi Liming,

On 03/19/21 02:04, gaoliming wrote:
> Ankur:
>   Seemly, the patch is missing in this mail. 

I can see the patch body just fine in my mailbox / list folder.

Also, the list archives seem to have it:

- https://edk2.groups.io/g/devel/message/73018
- http://mid.mail-archive.com/20210318184504.2745112-1-ankur.a.arora@oracle.com
- https://listman.redhat.com/archives/edk2-devel-archive/2021-March/msg00765.html

Ankur, can you post a "RESEND v2" please, anyway?

Thanks
Laszlo

> 
> Thanks
> Liming
>> -----邮件原件-----
>> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Ankur Arora
>> 发送时间: 2021年3月19日 2:45
>> 收件人: 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>; Laszlo Ersek <lersek@redhat.com>
>> 主题: [edk2-devel] [PATCH v2] MdePkg: use CpuPause() in CpuDeadLoop()
>>
>> CpuPause() might allow the CPU to go into a lower power state
>> state while we spin.
>>
>> On X86, CpuPause() executes a PAUSE instruction which the Intel
>> and AMD specs describe as follows:
>>
>> Intel:
>>   "PAUSE: 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 processorb
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#73043): https://edk2.groups.io/g/devel/message/73043
Mute This Topic: https://groups.io/mt/81445311/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-