Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752920AbbDUMqI (ORCPT ); Tue, 21 Apr 2015 08:46:08 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:35253 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752272AbbDUMqF (ORCPT ); Tue, 21 Apr 2015 08:46:05 -0400 Date: Tue, 21 Apr 2015 14:45:58 +0200 From: Ingo Molnar To: Andy Lutomirski Cc: Andrew Cooper , Xen-devel , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, Konrad Rzeszutek Wilk , Boris Ostrovsky , David Vrabel , Rusty Russell , lguest@lists.ozlabs.org, Denys Vlasenko , Linus Torvalds , Borislav Petkov Subject: [RFC PATCH] x86/asm/irq: Don't use POPF but STI Message-ID: <20150421124558.GA3483@gmail.com> References: <1429549782-12962-1-git-send-email-andrew.cooper3@citrix.com> <55359B57.3070008@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55359B57.3070008@kernel.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3115 Lines: 87 * Andy Lutomirski wrote: > > Another different approach would be to formally state that > > pv_irq_ops.save_fl() needs to return all the flags, which would > > make local_irq_save() safe to use in this circumstance, but that > > makes a hotpath longer for the sake of a single boot time check. > > ...which reminds me: > > Why does native_restore_fl restore anything other than IF? A branch > and sti should be considerably faster than popf. Yes, this has come up in the past, something like the patch below? Totally untested and not signed off yet: because we'd first have to make sure (via irq flags debugging) that it's not used in reverse, to re-disable interrupts: local_irq_save(flags); local_irq_enable(); ... local_irq_restore(flags); /* effective local_irq_disable() */ I don't think we have many (any?) such patterns left, but it has to be checked first. If we have such cases then we'll have to use different primitives there. But this patch should be good enough to give an good overview of the effects: the text impact does not look too horrible, if we decide to do this. The bloat of +1K on x86 defconfig is better than I first feared. Thanks, Ingo ======================> >From 6f01f6381e8293c360b7a89f516b8605e357d563 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Tue, 21 Apr 2015 13:32:13 +0200 Subject: [PATCH] x86/asm/irq: Don't use POPF but STI 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 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/