Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5278162ybl; Tue, 14 Jan 2020 06:26:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwvfX3miYkK2ngDRa0x/2PklDGr2BiNypZPPPetzXzEpqc1w2h68nuz03udRyXGAe5XV5f7 X-Received: by 2002:a9d:5545:: with SMTP id h5mr17529416oti.296.1579011988855; Tue, 14 Jan 2020 06:26:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579011988; cv=none; d=google.com; s=arc-20160816; b=z8BIf4MB/qC/NUkk01lYErCK2Io9zaSBI3EQdmB/1mBV0Bh6fNowECiSij9BYa8Kwn GqJECiy2oeF0kp0N+cJBhdCcM4l1rHfZQuYTHlGYh99KL9A8+SzXM/BkTZfWU3mVeOG/ Hyva5TKEdbcvf9153WjWpDxwPThnTgNyTeqLYRMPyXVm+HeTmtRTPjCvY+PxZZYpnJ2T om9PCHsk4T9V684vB46LTZ11skynC2azcwjUj8PZXU/g56EAr6xOVcdvnjAZJcyAhPM4 DwFHthqE1fRl9Jiu7xlEFCi4VvceZenoRhlF673pzwzLFhzpUqpDJD/NxYze7ViGSPiZ vPCQ== 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:cc:from:to:dkim-signature :date; bh=lpMOa+iJAF3MtHqUdxDVUs+npedWnm91Kj5dgmwc2PU=; b=f3sktSZZIb4ozjTq0kYm9Sf4K+fqCp00DFCGowytLtDJYEI82nRLkm6Euqz0qoWQv1 uMNF0UvcstoH8Og458hVC6v1f3RIvCpmoZnGrBz0yCNWLht7mbN2kZT5UEQEe3owkZkG EQBwC19Z5Enlb+vLGHL9AM0lkAFL4768AT5K74lSCdgvD1wkcxQA35WZLkWiuzGdp+7Q 0khSzmByOLXHItnbZk6TjYkzFCbm/f6+KCh6O2iVfePP0csHuQnT7FF4Jgh71tu97dUM DPszijxUi4Io3WjgZc+sY8UB458+eq+8aEy2KM0Zt4vl4JfGZZZ/Gwc7xo2rdguLpauV GlMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=default header.b=LpgACcfJ; 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 j20si7418213oie.212.2020.01.14.06.26.16; Tue, 14 Jan 2020 06:26:28 -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=LpgACcfJ; 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 S1729014AbgANOYI (ORCPT + 99 others); Tue, 14 Jan 2020 09:24:08 -0500 Received: from mail-40135.protonmail.ch ([185.70.40.135]:11461 "EHLO mail-40135.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728874AbgANOYH (ORCPT ); Tue, 14 Jan 2020 09:24:07 -0500 Date: Tue, 14 Jan 2020 14:23:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1579011844; bh=lpMOa+iJAF3MtHqUdxDVUs+npedWnm91Kj5dgmwc2PU=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=LpgACcfJBOF6PL+bDsMcoJJZdQvw9qO/eb+oldm8VU5m3y2y6eWPKyLaMc5e1v7Y0 AIosKcpKusScaGatpoudpOicuiXXECuT2SVMLh5+WpUt1/36LuBQdxIhvqZOqlfnZ1 A6Zm6mLGoduMzBzKiI/2CieLiJ/JSMbXV1CLd1KQ= To: "linux-kernel@vger.kernel.org" From: Krzysztof Piecuch Cc: "juri.lelli@redhat.com" , "malat@debian.org" , "piecuch@protonmail.com" , Peter Zijlstra , "mzhivich@akamai.com" , "viresh.kumar@linaro.org" , "drake@endlessm.com" , "rafael.j.wysocki@intel.com" , "x86@kernel.org" , "hpa@zytor.com" , "bp@alien8.de" , "mingo@redhat.com" , "tglx@linutronix.de" Reply-To: Krzysztof Piecuch Subject: [PATCH] x86/tsc: Add tsc_guess flag disabling CPUID.16h use for tsc calibration Message-ID: <03j72W25Dne_HDSwI8Y7xiXPzvEBX5Ezw_xw8ed8DC83bpdMxoPcjhbinNcDD0yeoX9GGN691f3kqqtGLztTnW8Pay3FrbO5sTlj3vjnh-Y=@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=2.8 required=7.0 tests=ALL_TRUSTED,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: ** 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. Signed-off-by: Krzysztof Piecuch --- Documentation/admin-guide/kernel-parameters.txt | 6 ++++++ arch/x86/kernel/tsc.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index ade4e6ec23e0..54ae9e153a19 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4905,6 +4905,12 @@ =09=09=09interruptions from clocksource watchdog are not =09=09=09acceptable). +=09tsc_guess=3D=09[X86,INTEL] Don't use data provided by CPUID.16h during +=09=09=09early tsc calibration. Disabling this may be useful for +=09=09=09CPUs with altered base clocks. +=09=09=09Format: (1/Y/y=3Denable, 0/N/n=3Ddisable) +=09=09=09default: enabled + =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..a807c33a3d41 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -59,6 +59,13 @@ struct cyc2ns { static DEFINE_PER_CPU_ALIGNED(struct cyc2ns, cyc2ns); +static bool _read_mostly tsc_guess =3D 1; +static int __init tsc_guess_setup(char *buf) +{ +=09return strtobool(buf, &tsc_guess); +} +early_param("tsc_guess", tsc_guess_setup); + __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data) { =09int seq, idx; @@ -654,7 +661,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_guess && +=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 +700,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_guess) =09=09return 0; =09eax_base_mhz =3D ebx_max_mhz =3D ecx_bus_mhz =3D edx =3D 0; -- 2.20.1