* [RESEND v2] MdePkg: use CpuPause() in CpuDeadLoop()
@ 2021-03-19 18:14 Ankur Arora
2021-03-22 1:40 ` 回复: " gaoliming
[not found] ` <166E86818BEFA632.26767@groups.io>
0 siblings, 2 replies; 4+ messages in thread
From: Ankur Arora @ 2021-03-19 18:14 UTC (permalink / raw)
To: devel; +Cc: Ankur Arora, Liming Gao, Michael D Kinney, Laszlo Ersek
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* 回复: [RESEND v2] MdePkg: use CpuPause() in CpuDeadLoop()
2021-03-19 18:14 [RESEND v2] MdePkg: use CpuPause() in CpuDeadLoop() Ankur Arora
@ 2021-03-22 1:40 ` gaoliming
[not found] ` <166E86818BEFA632.26767@groups.io>
1 sibling, 0 replies; 4+ messages in thread
From: gaoliming @ 2021-03-22 1:40 UTC (permalink / raw)
To: 'Ankur Arora', devel
Cc: 'Michael D Kinney', 'Laszlo Ersek'
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Thanks
Liming
> -----邮件原件-----
> 发件人: Ankur Arora <ankur.a.arora@oracle.com>
> 发送时间: 2021年3月20日 2:14
> 收件人: 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>
> 主题: [RESEND 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 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* 回复: [edk2-devel] 回复: [RESEND v2] MdePkg: use CpuPause() in CpuDeadLoop()
[not found] ` <166E86818BEFA632.26767@groups.io>
@ 2021-03-25 3:15 ` gaoliming
2021-03-25 18:13 ` Ankur Arora
0 siblings, 1 reply; 4+ messages in thread
From: gaoliming @ 2021-03-25 3:15 UTC (permalink / raw)
To: devel, gaoliming, 'Ankur Arora'
Cc: 'Michael D Kinney', 'Laszlo Ersek'
Create PR https://github.com/tianocore/edk2/pull/1515
Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 gaoliming
> 发送时间: 2021年3月22日 9:40
> 收件人: 'Ankur Arora' <ankur.a.arora@oracle.com>; devel@edk2.groups.io
> 抄送: 'Michael D Kinney' <michael.d.kinney@intel.com>; 'Laszlo Ersek'
> <lersek@redhat.com>
> 主题: [edk2-devel] 回复: [RESEND v2] MdePkg: use CpuPause() in
> CpuDeadLoop()
>
> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
>
> Thanks
> Liming
> > -----邮件原件-----
> > 发件人: Ankur Arora <ankur.a.arora@oracle.com>
> > 发送时间: 2021年3月20日 2:14
> > 收件人: 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>
> > 主题: [RESEND 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 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
>
>
>
>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 回复: [edk2-devel] 回复: [RESEND v2] MdePkg: use CpuPause() in CpuDeadLoop()
2021-03-25 3:15 ` 回复: [edk2-devel] " gaoliming
@ 2021-03-25 18:13 ` Ankur Arora
0 siblings, 0 replies; 4+ messages in thread
From: Ankur Arora @ 2021-03-25 18:13 UTC (permalink / raw)
To: gaoliming, devel; +Cc: 'Michael D Kinney', 'Laszlo Ersek'
On 2021-03-24 8:15 p.m., gaoliming wrote:
> Create PR https://github.com/tianocore/edk2/pull/1515
Thanks Liming.
Ankur
>
> Thanks
> Liming
>> -----邮件原件-----
>> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 gaoliming
>> 发送时间: 2021年3月22日 9:40
>> 收件人: 'Ankur Arora' <ankur.a.arora@oracle.com>; devel@edk2.groups.io
>> 抄送: 'Michael D Kinney' <michael.d.kinney@intel.com>; 'Laszlo Ersek'
>> <lersek@redhat.com>
>> 主题: [edk2-devel] 回复: [RESEND v2] MdePkg: use CpuPause() in
>> CpuDeadLoop()
>>
>> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
>>
>> Thanks
>> Liming
>>> -----邮件原件-----
>>> 发件人: Ankur Arora <ankur.a.arora@oracle.com>
>>> 发送时间: 2021年3月20日 2:14
>>> 收件人: 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>
>>> 主题: [RESEND 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 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
>>
>>
>>
>>
>>
>>
>>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-25 18:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-19 18:14 [RESEND v2] MdePkg: use CpuPause() in CpuDeadLoop() Ankur Arora
2021-03-22 1:40 ` 回复: " gaoliming
[not found] ` <166E86818BEFA632.26767@groups.io>
2021-03-25 3:15 ` 回复: [edk2-devel] " gaoliming
2021-03-25 18:13 ` Ankur Arora
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox