* cpu_relax(), rep: nop, and PAUSE
@ 2013-02-19 12:20 David Shwatrz
2013-02-19 18:58 ` Mulyadi Santosa
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David Shwatrz @ 2013-02-19 12:20 UTC (permalink / raw)
To: kernelnewbies
Hi, kernel newbies,
We have:
#define cpu_relax() asm volatile("rep; nop")
in arch/x86/boot/boot.h.
Why don't we use the PAUSE assembler instruction here ?
According to Intel manuals,
Intel? 64 and IA-32 Architectures
Software Developer?s Manual
Volume 2B:
"This instruction was introduced in the Pentium 4 processors, but is
backward compatible with all IA-32 processors.
In earlier IA-32 processors, the PAUSE instruction operates like a NOP
instruction. The Pentium 4 and Intel Xeon
processors implement the PAUSE instruction as a delay. The delay is
finite and can be zero for some processors.
This instruction does not change the architectural state of the
processor (that is, it performs essentially a delaying
no-op operation).
This instruction?s operation is the same in non-64-bit modes and 64-bit mode."
And AFAIK, in spinlocks , PAUSE indeed replaced the rep;nop.
Any ideas?
Best,
DS
^ permalink raw reply [flat|nested] 5+ messages in thread
* cpu_relax(), rep: nop, and PAUSE
2013-02-19 12:20 cpu_relax(), rep: nop, and PAUSE David Shwatrz
@ 2013-02-19 18:58 ` Mulyadi Santosa
2013-02-19 21:41 ` Valdis.Kletnieks at vt.edu
2013-02-20 3:35 ` Adam Lee
2013-02-20 21:18 ` Rainer Müller
2 siblings, 1 reply; 5+ messages in thread
From: Mulyadi Santosa @ 2013-02-19 18:58 UTC (permalink / raw)
To: kernelnewbies
On Tue, Feb 19, 2013 at 7:20 PM, David Shwatrz <dshwatrz@gmail.com> wrote:
> Hi, kernel newbies,
>
> We have:
> #define cpu_relax() asm volatile("rep; nop")
> in arch/x86/boot/boot.h.
>
> Why don't we use the PAUSE assembler instruction here ?
Just guessing, maybe rep+nop could do better power saving because
processor is considered as idle.
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* cpu_relax(), rep: nop, and PAUSE
2013-02-19 18:58 ` Mulyadi Santosa
@ 2013-02-19 21:41 ` Valdis.Kletnieks at vt.edu
0 siblings, 0 replies; 5+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-02-19 21:41 UTC (permalink / raw)
To: kernelnewbies
On Wed, 20 Feb 2013 01:58:17 +0700, Mulyadi Santosa said:
> On Tue, Feb 19, 2013 at 7:20 PM, David Shwatrz <dshwatrz@gmail.com> wrote:
> > Hi, kernel newbies,
> >
> > We have:
> > #define cpu_relax() asm volatile("rep; nop")
> > in arch/x86/boot/boot.h.
> >
> > Why don't we use the PAUSE assembler instruction here ?
>
> Just guessing, maybe rep+nop could do better power saving because
> processor is considered as idle.
The 'rep; nop' is actually a placeholder - for some CPUs, a different opcode
gets filled in during boot time. See arch/x86/kernel/alternative.c and
arch/x86/include/asm/alternative.h for the gory details.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130219/a0c43ea8/attachment.bin
^ permalink raw reply [flat|nested] 5+ messages in thread
* cpu_relax(), rep: nop, and PAUSE
2013-02-19 12:20 cpu_relax(), rep: nop, and PAUSE David Shwatrz
2013-02-19 18:58 ` Mulyadi Santosa
@ 2013-02-20 3:35 ` Adam Lee
2013-02-20 21:18 ` Rainer Müller
2 siblings, 0 replies; 5+ messages in thread
From: Adam Lee @ 2013-02-20 3:35 UTC (permalink / raw)
To: kernelnewbies
On Tue, Feb 19, 2013 at 02:20:11PM +0200, David Shwatrz wrote:
> Hi, kernel newbies,
>
> We have:
> #define cpu_relax() asm volatile("rep; nop")
> in arch/x86/boot/boot.h.
>
> Why don't we use the PAUSE assembler instruction here ?
But rep_nop and pause ought to be the same, why we change it? "If it
ain't broke, don't fix it."
You can see that by disassembling, they both are "f3 90", "f3" is rep,
"90" is nop.
> And AFAIK, in spinlocks , PAUSE indeed replaced the rep;nop.
Where? I haven't found that.
--
Regards,
Adam Lee
http://adam8157.info
^ permalink raw reply [flat|nested] 5+ messages in thread
* cpu_relax(), rep: nop, and PAUSE
2013-02-19 12:20 cpu_relax(), rep: nop, and PAUSE David Shwatrz
2013-02-19 18:58 ` Mulyadi Santosa
2013-02-20 3:35 ` Adam Lee
@ 2013-02-20 21:18 ` Rainer Müller
2 siblings, 0 replies; 5+ messages in thread
From: Rainer Müller @ 2013-02-20 21:18 UTC (permalink / raw)
To: kernelnewbies
On 2013-02-19 13:20, David Shwatrz wrote:
> We have:
> #define cpu_relax() asm volatile("rep; nop")
> in arch/x86/boot/boot.h.
>
> Why don't we use the PAUSE assembler instruction here ?
If you dig further into the Intel x86 manual, the machine instructions
'pause' and 'rep;nop' actually use the exact same encoding. As some
older assembler might not know the 'pause' mnemonic, using 'rep;nop'
here is most probably for backwards compatibility.
Rainer
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-02-20 21:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-19 12:20 cpu_relax(), rep: nop, and PAUSE David Shwatrz
2013-02-19 18:58 ` Mulyadi Santosa
2013-02-19 21:41 ` Valdis.Kletnieks at vt.edu
2013-02-20 3:35 ` Adam Lee
2013-02-20 21:18 ` Rainer Müller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).