Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2214673imm; Thu, 19 Jul 2018 15:35:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeX/PP0vQ8X1i2HmuR8owku9N7CfgsD6aOl/W5doQg6uZp367w01WIk6UrSOvAIiOA9nL0t X-Received: by 2002:a63:de10:: with SMTP id f16-v6mr11492017pgg.97.1532039741869; Thu, 19 Jul 2018 15:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532039741; cv=none; d=google.com; s=arc-20160816; b=uOmLDMtkQVAQEDuaZFr3kPMqgtglL/aitS6O9eP3VjxvJwinwCe66Qe/nYwkN4YaN5 hpxF/H3F/MzCMGr33k483/xU6lCpC1QeUiNVKRJN+2JvyzF02S98EavhCU9W5JJ5ErBD OXEeb/1NX/5JiKRNs0X0Ji55CTuJbHp+q8apeS2swJuwUNRVk+9qYs6Mq4XnhzT2Id50 66RCqiKaTIW4n60oP52afjW6eAMtjOfcN9E5HS8AQUKgJ6j4/SQ2JJgnCZeRAcoFXrbN nlDDbreFUYDZAEgmWEcyGqYhanKxcqadEXX5CkFBxoPzELFfYR8nS9O3U2EOn5ElitbU Mmuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=/WtlBdRBv+GpUjjFU0yI7w2Pc88bUqyhcsxFJZqHuSY=; b=U/uXw93z3sdRBn/a4FsWR7HksWy16TJcR87qs2Get5Cmho8vF2vZcEc+cnUwhjJBa7 VJdwyh9SjvJn7FBYmSa2PL7f6ZmTr7VbQ80WoStXhVUft3xW2H7ieXzO3tQbVyMyIpxX On4utDsMROnH3r1X0L3eq9lkyGUx4e0R+VWGNmXKSc6x8qQzafXXVDibuAXBfY1g8XXG 1xnCqBKcVc+i+kV4iXeA7QldEr7aMJbwNGScvqxe7TBIyACCiFVz50xVtjZchoY+55nL fNAyOrO4eXSuwcw+O9ZdgxaWlp9nLJ/Txa5l8MUIzbWOA1lYOIad+uwBziiZZ37whi5v GtUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x188-v6si314575pfx.19.2018.07.19.15.35.27; Thu, 19 Jul 2018 15:35:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731541AbeGSXTp (ORCPT + 99 others); Thu, 19 Jul 2018 19:19:45 -0400 Received: from terminus.zytor.com ([198.137.202.136]:46063 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731090AbeGSXTp (ORCPT ); Thu, 19 Jul 2018 19:19:45 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6JMYS292439952 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 15:34:28 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6JMYScP2439949; Thu, 19 Jul 2018 15:34:28 -0700 Date: Thu, 19 Jul 2018 15:34:28 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Pavel Tatashin Message-ID: Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com, pasha.tatashin@oracle.com Reply-To: tglx@linutronix.de, hpa@zytor.com, pasha.tatashin@oracle.com, linux-kernel@vger.kernel.org, mingo@kernel.org In-Reply-To: <20180719205545.16512-26-pasha.tatashin@oracle.com> References: <20180719205545.16512-26-pasha.tatashin@oracle.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/timers] x86/tsc: Split native_calibrate_cpu() into early and late parts Git-Commit-ID: 03821f451d2d2d7599061244734245be139014ea 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 X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 03821f451d2d2d7599061244734245be139014ea Gitweb: https://git.kernel.org/tip/03821f451d2d2d7599061244734245be139014ea Author: Pavel Tatashin AuthorDate: Thu, 19 Jul 2018 16:55:44 -0400 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 00:02:44 +0200 x86/tsc: Split native_calibrate_cpu() into early and late parts During early boot TSC and CPU frequency can be calibrated using MSR, CPUID, and quick PIT calibration methods. The other methods PIT/HPET/PMTIMER are available only after ACPI is initialized. Split native_calibrate_cpu() into early and late parts so they can be called separately during early and late tsc calibration. Signed-off-by: Pavel Tatashin Signed-off-by: Thomas Gleixner Cc: steven.sistare@oracle.com Cc: daniel.m.jordan@oracle.com Cc: linux@armlinux.org.uk Cc: schwidefsky@de.ibm.com Cc: heiko.carstens@de.ibm.com Cc: john.stultz@linaro.org Cc: sboyd@codeaurora.org Cc: hpa@zytor.com Cc: douly.fnst@cn.fujitsu.com Cc: peterz@infradead.org Cc: prarit@redhat.com Cc: feng.tang@intel.com Cc: pmladek@suse.com Cc: gnomes@lxorguk.ukuu.org.uk Cc: linux-s390@vger.kernel.org Cc: boris.ostrovsky@oracle.com Cc: jgross@suse.com Cc: pbonzini@redhat.com Link: https://lkml.kernel.org/r/20180719205545.16512-26-pasha.tatashin@oracle.com --- arch/x86/include/asm/tsc.h | 1 + arch/x86/kernel/tsc.c | 54 ++++++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h index c4368ff73652..88140e4f2292 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -40,6 +40,7 @@ extern int unsynchronized_tsc(void); extern int check_tsc_unstable(void); extern void mark_tsc_async_resets(char *reason); extern unsigned long native_calibrate_cpu(void); +extern unsigned long native_calibrate_cpu_early(void); extern unsigned long native_calibrate_tsc(void); extern unsigned long long native_sched_clock_from_tsc(u64 tsc); diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 9277ae9b68b3..60586779b02c 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -680,30 +680,17 @@ static unsigned long cpu_khz_from_cpuid(void) return eax_base_mhz * 1000; } -/** - * native_calibrate_cpu - calibrate the cpu on boot +/* + * calibrate cpu using pit, hpet, and ptimer methods. They are available + * later in boot after acpi is initialized. */ -unsigned long native_calibrate_cpu(void) +static unsigned long pit_hpet_ptimer_calibrate_cpu(void) { u64 tsc1, tsc2, delta, ref1, ref2; unsigned long tsc_pit_min = ULONG_MAX, tsc_ref_min = ULONG_MAX; - unsigned long flags, latch, ms, fast_calibrate; + unsigned long flags, latch, ms; int hpet = is_hpet_enabled(), i, loopmin; - fast_calibrate = cpu_khz_from_cpuid(); - if (fast_calibrate) - return fast_calibrate; - - fast_calibrate = cpu_khz_from_msr(); - if (fast_calibrate) - return fast_calibrate; - - local_irq_save(flags); - fast_calibrate = quick_pit_calibrate(); - local_irq_restore(flags); - if (fast_calibrate) - return fast_calibrate; - /* * Run 5 calibration loops to get the lowest frequency value * (the best estimate). We use two different calibration modes @@ -846,6 +833,37 @@ unsigned long native_calibrate_cpu(void) return tsc_pit_min; } +/** + * native_calibrate_cpu_early - can calibrate the cpu early in boot + */ +unsigned long native_calibrate_cpu_early(void) +{ + unsigned long flags, fast_calibrate = cpu_khz_from_cpuid(); + + if (!fast_calibrate) + fast_calibrate = cpu_khz_from_msr(); + if (!fast_calibrate) { + local_irq_save(flags); + fast_calibrate = quick_pit_calibrate(); + local_irq_restore(flags); + } + return fast_calibrate; +} + + +/** + * native_calibrate_cpu - calibrate the cpu + */ +unsigned long native_calibrate_cpu(void) +{ + unsigned long tsc_freq = native_calibrate_cpu_early(); + + if (!tsc_freq) + tsc_freq = pit_hpet_ptimer_calibrate_cpu(); + + return tsc_freq; +} + void recalibrate_cpu_khz(void) { #ifndef CONFIG_SMP