Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2215515imm; Thu, 19 Jul 2018 15:36:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeay8/qL9b5rVcn6PeKKIdhd2AJ0vyrYFFpAPNwTQxmvTwfovhSTyNoLU6b2xzkHCPEBscI X-Received: by 2002:a17:902:7482:: with SMTP id h2-v6mr11968888pll.185.1532039811217; Thu, 19 Jul 2018 15:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532039811; cv=none; d=google.com; s=arc-20160816; b=I+0lM5YlEIW9CUdIIaJpdIpEL//ooPh2FPMQ2J3YyEePxy1wTa/hidL97WYwFPJEY2 wxhWGyuihmEJtiZ2FtPe3NSJS1zu9fcit6nJ0zRD2T7y9F3StPTGGW0B2zBM7bonuUBd UvPkE4FLIy/ABwAU+6uENDOIAEGDJB5nMyNXXukTpqciWcaiFMnq4MhlgkRZVOsux7bM MThngKNdjJUUFmcOGOQGfyNkDx7f5fpWb26k/jzEiizV7iDm+D/njgu/DfZPgyIygTEZ GEDwk+3IOMMgtUcMgyjdWLFfXVRFB0hPgDcVE17ZoKS9MOtIlSIaWSQGdnheRB/8S6Zm USnQ== 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=tUQxeVhns61LWRVhMfpDp+0YpXLOrzqv26QEZB9IFJU=; b=a/D3OUj5c1p2HGm+oQVQjfkv22XuCL6f9Pr1aX1kBanKQ8Cx74SRmm2TWysDQ5s/bA Z37asB4e6g7BmmkG4doQAu3XaX8/00y3b18qKZcs6V9X6/A9+nC6ScMgmgnadxtx2e/M qGYPW39AB+8nzw5MwMiJX6xhQi+DnfmM8nsAJlKoNygUgtV/cXUh/ByKy35sec/5q6Dr 1OroieKUFshyqRV1NBQuQcjOgJWdukZT+7Wc7We2sRq5I3DQ8ynb+qXLPDMNIGe7U4T8 LH92RRZ/8GxAc5n/u8SOZSRdzcDNZQO4yNZG2RxLkOBDvOZ0x3O7f1+hwGlYDgwGsf7e 5dQg== 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 a7-v6si236636plz.510.2018.07.19.15.36.36; Thu, 19 Jul 2018 15:36:51 -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 S1731578AbeGSXUS (ORCPT + 99 others); Thu, 19 Jul 2018 19:20:18 -0400 Received: from terminus.zytor.com ([198.137.202.136]:38541 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730913AbeGSXUR (ORCPT ); Thu, 19 Jul 2018 19:20:17 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6JMZ1vJ2439993 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 15:35:01 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6JMZ0b22439990; Thu, 19 Jul 2018 15:35:00 -0700 Date: Thu, 19 Jul 2018 15:35:00 -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: hpa@zytor.com, tglx@linutronix.de, pasha.tatashin@oracle.com, mingo@kernel.org, linux-kernel@vger.kernel.org Reply-To: mingo@kernel.org, pasha.tatashin@oracle.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, hpa@zytor.com In-Reply-To: <20180719205545.16512-27-pasha.tatashin@oracle.com> References: <20180719205545.16512-27-pasha.tatashin@oracle.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/timers] x86/tsc: Make use of tsc_calibrate_cpu_early() Git-Commit-ID: 8dbe438589f373544a1af8b4a859e4da853c0f90 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: 8dbe438589f373544a1af8b4a859e4da853c0f90 Gitweb: https://git.kernel.org/tip/8dbe438589f373544a1af8b4a859e4da853c0f90 Author: Pavel Tatashin AuthorDate: Thu, 19 Jul 2018 16:55:45 -0400 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 00:02:44 +0200 x86/tsc: Make use of tsc_calibrate_cpu_early() During early boot enable tsc_calibrate_cpu_early() and switch to tsc_calibrate_cpu() only later. Do this unconditionally, because it is unknown what methods other cpus will use to calibrate once they are onlined. If by the time tsc_init() is called tsc frequency is still unknown do only pit_hpet_ptimer_calibrate_cpu() to calibrate, as this function contains the only methods wich have not been called and tried earlier. 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-27-pasha.tatashin@oracle.com --- arch/x86/include/asm/tsc.h | 1 - arch/x86/kernel/tsc.c | 25 +++++++++++++++++++------ arch/x86/kernel/x86_init.c | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h index 88140e4f2292..eb5bbfeccb66 100644 --- a/arch/x86/include/asm/tsc.h +++ b/arch/x86/include/asm/tsc.h @@ -39,7 +39,6 @@ extern void mark_tsc_unstable(char *reason); 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 60586779b02c..02e416b87ac1 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -854,7 +854,7 @@ unsigned long native_calibrate_cpu_early(void) /** * native_calibrate_cpu - calibrate the cpu */ -unsigned long native_calibrate_cpu(void) +static unsigned long native_calibrate_cpu(void) { unsigned long tsc_freq = native_calibrate_cpu_early(); @@ -1374,13 +1374,19 @@ unreg: */ device_initcall(init_tsc_clocksource); -static bool __init determine_cpu_tsc_frequencies(void) +static bool __init determine_cpu_tsc_frequencies(bool early) { /* Make sure that cpu and tsc are not already calibrated */ WARN_ON(cpu_khz || tsc_khz); - cpu_khz = x86_platform.calibrate_cpu(); - tsc_khz = x86_platform.calibrate_tsc(); + if (early) { + cpu_khz = x86_platform.calibrate_cpu(); + tsc_khz = x86_platform.calibrate_tsc(); + } else { + /* We should not be here with non-native cpu calibration */ + WARN_ON(x86_platform.calibrate_cpu != native_calibrate_cpu); + cpu_khz = pit_hpet_ptimer_calibrate_cpu(); + } /* * Trust non-zero tsc_khz as authorative, @@ -1419,7 +1425,7 @@ void __init tsc_early_init(void) { if (!boot_cpu_has(X86_FEATURE_TSC)) return; - if (!determine_cpu_tsc_frequencies()) + if (!determine_cpu_tsc_frequencies(true)) return; loops_per_jiffy = get_loops_per_jiffy(); @@ -1431,6 +1437,13 @@ void __init tsc_early_init(void) void __init tsc_init(void) { + /* + * native_calibrate_cpu_early can only calibrate using methods that are + * available early in boot. + */ + if (x86_platform.calibrate_cpu == native_calibrate_cpu_early) + x86_platform.calibrate_cpu = native_calibrate_cpu; + if (!boot_cpu_has(X86_FEATURE_TSC)) { setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER); return; @@ -1438,7 +1451,7 @@ void __init tsc_init(void) if (!tsc_khz) { /* We failed to determine frequencies earlier, try again */ - if (!determine_cpu_tsc_frequencies()) { + if (!determine_cpu_tsc_frequencies(false)) { mark_tsc_unstable("could not calculate TSC khz"); setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER); return; diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index 3ab867603e81..2792b5573818 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -109,7 +109,7 @@ struct x86_cpuinit_ops x86_cpuinit = { static void default_nmi_init(void) { }; struct x86_platform_ops x86_platform __ro_after_init = { - .calibrate_cpu = native_calibrate_cpu, + .calibrate_cpu = native_calibrate_cpu_early, .calibrate_tsc = native_calibrate_tsc, .get_wallclock = mach_get_cmos_time, .set_wallclock = mach_set_rtc_mmss,