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
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
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.
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
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
participants (5)
-
Adam Lee -
David Shwatrz -
Mulyadi Santosa -
Rainer Müller -
Valdis.Kletnieks@vt.edu