[PATCH] x86/asm/irq: Don't use POPF but STI

From: Ingo Molnar
Date: Tue Apr 21 2015 - 07:32:13 EST


So because the POPF instruction is slow and STI is faster on
essentially all x86 CPUs that matter, instead of:

ffffffff81891848: 9d popfq

we can do:

ffffffff81661a2e: 41 f7 c4 00 02 00 00 test $0x200,%r12d
ffffffff81661a35: 74 01 je ffffffff81661a38 <snd_pcm_stream_unlock_irqrestore+0x28>
ffffffff81661a37: fb sti
ffffffff81661a38:

This bloats the kernel a bit, by about 1K on the 64-bit defconfig:

text data bss dec hex filename
12258634 1812120 1085440 15156194 e743e2 vmlinux.before
12259582 1812120 1085440 15157142 e74796 vmlinux.after

the other cost is the extra branching, adding extra pressure to the
branch prediction hardware and also potential branch misses.
---
arch/x86/include/asm/irqflags.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index b77f5edb03b0..8bc2a9bc7a06 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -69,7 +69,8 @@ static inline notrace unsigned long arch_local_save_flags(void)

static inline notrace void arch_local_irq_restore(unsigned long flags)
{
- native_restore_fl(flags);
+ if (likely(flags & X86_EFLAGS_IF))
+ native_irq_enable();
}

static inline notrace void arch_local_irq_disable(void)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/