From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932106AbbGFPpi (ORCPT ); Mon, 6 Jul 2015 11:45:38 -0400 Received: from terminus.zytor.com ([198.137.202.10]:49520 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753607AbbGFPpc (ORCPT ); Mon, 6 Jul 2015 11:45:32 -0400 Date: Mon, 6 Jul 2015 08:44:28 -0700 From: tip-bot for Andy Lutomirski Message-ID: Cc: john.stultz@linaro.org, luto@amacapital.net, mingo@kernel.org, kvm@vger.kernel.org, lenb@kernel.org, hpa@zytor.com, brgerst@gmail.com, dvlasenk@redhat.com, ray.huang@amd.com, bp@alien8.de, torvalds@linux-foundation.org, ralf@linux-mips.org, tglx@linutronix.de, luto@kernel.org, bp@suse.de, peterz@infradead.org, linux-kernel@vger.kernel.org Reply-To: john.stultz@linaro.org, luto@amacapital.net, kvm@vger.kernel.org, mingo@kernel.org, lenb@kernel.org, hpa@zytor.com, dvlasenk@redhat.com, brgerst@gmail.com, bp@alien8.de, ray.huang@amd.com, torvalds@linux-foundation.org, ralf@linux-mips.org, tglx@linutronix.de, luto@kernel.org, bp@suse.de, peterz@infradead.org, linux-kernel@vger.kernel.org In-Reply-To: <387c4c3a75f875bcde6cd68cee013273a744f364.1434501121.git.luto@kernel.org> References: <387c4c3a75f875bcde6cd68cee013273a744f364.1434501121.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86/asm/tsc/sync: Use rdtsc_ordered() in check_tsc_warp() and drop extra barriers Git-Commit-ID: eee6946e44510b61c35cf754f5505537c7a8eb77 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: eee6946e44510b61c35cf754f5505537c7a8eb77 Gitweb: http://git.kernel.org/tip/eee6946e44510b61c35cf754f5505537c7a8eb77 Author: Andy Lutomirski AuthorDate: Thu, 25 Jun 2015 18:44:09 +0200 Committer: Ingo Molnar CommitDate: Mon, 6 Jul 2015 15:23:29 +0200 x86/asm/tsc/sync: Use rdtsc_ordered() in check_tsc_warp() and drop extra barriers Using get_cycles was unnecessary: check_tsc_warp() is not called on TSC-less systems. Replace rdtsc_barrier(); get_cycles() with rdtsc_ordered(). While we're at it, make the somewhat more dangerous change of removing barrier_before_rdtsc after RDTSC in the TSC warp check code. This should be okay, though -- the vDSO TSC code doesn't have that barrier, so, if removing the barrier from the warp check would cause us to detect a warp that we otherwise wouldn't detect, then we have a genuine bug. Signed-off-by: Andy Lutomirski Signed-off-by: Borislav Petkov Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Huang Rui Cc: John Stultz Cc: Len Brown Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Ralf Baechle Cc: Thomas Gleixner Cc: kvm ML Link: http://lkml.kernel.org/r/387c4c3a75f875bcde6cd68cee013273a744f364.1434501121.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/kernel/tsc_sync.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/tsc_sync.c b/arch/x86/kernel/tsc_sync.c index dd8d079..78083bf 100644 --- a/arch/x86/kernel/tsc_sync.c +++ b/arch/x86/kernel/tsc_sync.c @@ -39,16 +39,15 @@ static cycles_t max_warp; static int nr_warps; /* - * TSC-warp measurement loop running on both CPUs: + * TSC-warp measurement loop running on both CPUs. This is not called + * if there is no TSC. */ static void check_tsc_warp(unsigned int timeout) { cycles_t start, now, prev, end; int i; - rdtsc_barrier(); - start = get_cycles(); - rdtsc_barrier(); + start = rdtsc_ordered(); /* * The measurement runs for 'timeout' msecs: */ @@ -63,9 +62,7 @@ static void check_tsc_warp(unsigned int timeout) */ arch_spin_lock(&sync_lock); prev = last_tsc; - rdtsc_barrier(); - now = get_cycles(); - rdtsc_barrier(); + now = rdtsc_ordered(); last_tsc = now; arch_spin_unlock(&sync_lock); @@ -126,7 +123,7 @@ void check_tsc_sync_source(int cpu) /* * No need to check if we already know that the TSC is not - * synchronized: + * synchronized or if we have no TSC. */ if (unsynchronized_tsc()) return; @@ -190,6 +187,7 @@ void check_tsc_sync_target(void) { int cpus = 2; + /* Also aborts if there is no TSC. */ if (unsynchronized_tsc() || tsc_clocksource_reliable) return;