Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9158555ybl; Fri, 17 Jan 2020 07:16:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzvs5e3iE3twNemRdfri8/4W6m9C0NdFmlAlXHZNi5BdpqlreJBXe+lYKWUZvI25pyA2n3u X-Received: by 2002:aca:4a87:: with SMTP id x129mr3620097oia.165.1579274189741; Fri, 17 Jan 2020 07:16:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579274189; cv=none; d=google.com; s=arc-20160816; b=Y/U+9ljqY7UAoUyHXFbe5QZ7DTHnJ8au4uQB4qFR5pL7IeSgyR2es63ztB4n1zNdo8 awTbt29GH2jWZ8lzZOSNPoUncWM0VOt/OSCVXBP3mS9g5vcqaqTg2YFye1+iqpb+uezz VvNRtrg0pIJ+mStOE3F7322FuMEXdy/21G4EP5N3O7JwocPlLDQDRKq/uASQaAtjOL63 hidh+bVj2uD4DdB6ScI3qXr+xAKw3+FTxKU1AIyDRMuFzP7FVFaibwBNRvQ+7rhPLYJ0 pcsDNCiyb/OW/1hbzb4fauFQU2Jz+jra2X2BZql3Ug3TVIoU2NJkN4gnEua/DNa0wtQj uM1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :feedback-id:message-id:subject:reply-to:from:to:dkim-signature:date; bh=bQrJQ2tPkY3J9bw/IJpTnUr830uKKD9zDmVamxGtpI4=; b=jr59RhRPX/ZNeuh4vGVAezr5UccJhAqw5H2tPmUGD3T6PtgWtWTBfr6+NsEahgEWRM h4ipS4J/v3ED/4o/sEW6gnC3eGLOfOd4myfrAa8l9oExbPEXsVEGH88sycUoAh7eUMyw cr0knc9s2Rmpsuzf9v+GE7I6uwRrWrjl0HQ3I432C2VozL63gHiJDmLWviPhzNuDSvNi JUwuSNKN5xvG5XKR2L2lDNGx/ohRokcaXvai7kXs1cClI5ZoGmH1hcCKCQh2MWHvQi8H +GzOGYEX2kONXmneQI4BPaMOJDGL5x+HJMn8UjYFPXsDp5A3CZsV+PYqz7HfRcxBdera hJvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=default header.b=tRdm+bh+; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si14638315otc.160.2020.01.17.07.16.17; Fri, 17 Jan 2020 07:16:29 -0800 (PST) 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; dkim=pass header.i=@protonmail.com header.s=default header.b=tRdm+bh+; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729121AbgAQPN4 (ORCPT + 99 others); Fri, 17 Jan 2020 10:13:56 -0500 Received: from mail-40130.protonmail.ch ([185.70.40.130]:33299 "EHLO mail-40130.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729095AbgAQPN4 (ORCPT ); Fri, 17 Jan 2020 10:13:56 -0500 Date: Fri, 17 Jan 2020 15:13:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1579274033; bh=bQrJQ2tPkY3J9bw/IJpTnUr830uKKD9zDmVamxGtpI4=; h=Date:To:From:Reply-To:Subject:Feedback-ID:From; b=tRdm+bh+MbfqJn6k9IA0Wm15CYQWqMAm9cYjPn1ENlcdA08Gr6bP3qkzmvwFbiUzL IKXK5BNF2B36gHomKuSTQLFIC8Usb+Cw3gT1UaQx944Z+rV+V7HNFpm4YVCp+4Qv0Y yEAE9udsvVVaW0Of4wOdhulvIfqKkh0BA2Bd6uZU= To: "corbet@lwn.net" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "hpa@zytor.com" , "x86@kernel.org" , "mchehab+samsung@kernel.org" , "jpoimboe@redhat.com" , "gregkh@linuxfoundation.org" , "pawan.kumar.gupta@linux.intel.com" , "paulmck@linux.ibm.com" , "jgross@suse.com" , "rafael.j.wysocki@intel.com" , "viresh.kumar@linaro.org" , "drake@endlessm.com" , "malat@debian.org" , "mzhivich@akamai.com" , "piecuch@protonmail.com" , "juri.lelli@redhat.com" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" From: Krzysztof Piecuch Reply-To: Krzysztof Piecuch Subject: [PATCH] x86/tsc: Add tsc_tuned_baseclk flag disabling CPUID.16h use for tsc calibration Message-ID: <9rN6HvBfpUYE7XjHYSTKXKkKOUHQd_skSYGqjXlI0jTIk4nqLoLUloev1jgSayOdvzmkXgRNP8j_mgcikMJy6L_JN_vJhUJn9vD9xm_ueSo=@protonmail.com> Feedback-ID: krphKiiPlx_XKIryTSpdJ_XtBwogkHXWA-Us-PsTeaBSrzOTAKWxwbFkseT4Z85b_7PMRvSnq3Ah7f9INXrOMw==:Ext:ProtonMail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changing base clock frequency directly impacts tsc hz but not CPUID.16h values. An overclocked CPU supporting CPUID.16h and partial CPUID.15h support will set tsc hz according to "best guess" given by CPUID.16h relying on tsc_refine_calibration_work to give better numbers later. tsc_refine_calibration_work will refuse to do its work when the outcome is off the early tsc hz value by more than 1% which is certain to happen on an overclocked system. Fix this by adding tsc_tuned_baseclk command line parameter that makes the kernel ignore CPUID.16h data during TSC calibration. Signed-off-by: Krzysztof Piecuch --- Documentation/admin-guide/kernel-parameters.txt | 11 +++++++++++ arch/x86/kernel/tsc.c | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index ade4e6ec23e0..b251169692a8 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4905,6 +4905,17 @@ =09=09=09interruptions from clocksource watchdog are not =09=09=09acceptable). +=09tsc_tuned_baseclk=3D +=09=09=09[X86,INTEL] Ignore data provided by CPUID.16h during +=09=09=09early tsc calibration. Useful when changing base clock +=09=09=09frequency (overclocking). +=09=09=09Warning: in case your system does not provide +=09=09=09alternatives to determine cpu speed (HPET, PIT, complete +=09=09=09CPUID.15h support, MSR) the kernel will fail to +=09=09=09calibrate the clocksource and local APIC. +=09=09=09Format: (1/Y/y=3Denabled, 0/N/n=3Ddisabled) +=09=09=09default: disabled + =09tsx=3D=09=09[X86] Control Transactional Synchronization =09=09=09Extensions (TSX) feature in Intel processors that =09=09=09support TSX control. diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 7e322e2daaf5..c9b638dd8f4d 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -59,6 +59,17 @@ struct cyc2ns { static DEFINE_PER_CPU_ALIGNED(struct cyc2ns, cyc2ns); +static bool __read_mostly tsc_tuned_baseclk; +static int __init tsc_tuned_baseclk_setup(char *buf) +{ +=09int ret =3D strtobool(buf, &tsc_tuned_baseclk); + +=09if (tsc_tuned_baseclk) +=09=09pr_warn("tsc_tuned_baseclk: This will allow your CPU to use TSC with= an overclocked base clock but your system will require some means of TSC c= alibration other than CPUID 16h."); +=09return ret; +} +early_param("tsc_tuned_baseclk", tsc_tuned_baseclk_setup); + __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data) { =09int seq, idx; @@ -654,7 +665,8 @@ unsigned long native_calibrate_tsc(void) =09 * clock, but we can easily calculate it to a high degree of accuracy =09 * by considering the crystal ratio and the CPU speed. =09 */ -=09if (crystal_khz =3D=3D 0 && boot_cpu_data.cpuid_level >=3D 0x16) { +=09if (crystal_khz =3D=3D 0 && !tsc_tuned_baseclk && +=09=09boot_cpu_data.cpuid_level >=3D 0x16) { =09=09unsigned int eax_base_mhz, ebx, ecx, edx; =09=09cpuid(0x16, &eax_base_mhz, &ebx, &ecx, &edx); @@ -692,7 +704,7 @@ static unsigned long cpu_khz_from_cpuid(void) =09if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL) =09=09return 0; -=09if (boot_cpu_data.cpuid_level < 0x16) +=09if (boot_cpu_data.cpuid_level < 0x16 || tsc_tuned_baseclk) =09=09return 0; =09eax_base_mhz =3D ebx_max_mhz =3D ecx_bus_mhz =3D edx =3D 0; -- 2.20.1