Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2061972ybl; Thu, 5 Dec 2019 11:19:33 -0800 (PST) X-Google-Smtp-Source: APXvYqw4bjcC08GctBe4nYDhAdSzZAtkZI4Sy8veeZMx35eTL/8eMeNV9O9+OF378+Ag0iDbgmE2 X-Received: by 2002:a9d:5902:: with SMTP id t2mr8474679oth.151.1575573573720; Thu, 05 Dec 2019 11:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575573573; cv=none; d=google.com; s=arc-20160816; b=nfsXWml0GwxV1k25VPIl9BG2oEiDVOniGuzGBQHML809Naz4qoDkp1MrMnRWriKNno Wq2POcyX4opIfuIeV8vwhks3UQDSorV21VARxuXgLOU7dc6mGjBm89dvDQKCziibGdhl 0KdWvEohj5bUclPn2DyYKcmOGNVWfMNJLv4v0RU72sA9REVEHma4HOmeDPf5mqEd6BAt 9yNUv8Cy+cjxQ99T+gSai4zVMS/fXqorRhkDFbn5GCDHjeOSnx2ZKz0pUIuQ9oIdtU6A XVt15t7EDenqhR1UI7UJyUyqp05yEjeG+t3NOHP0g6qhNF1vcMVi+nod8EMudo7PU+tI AaKg== 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=vb4xN0McS6Sjd9AgIw6FMJzU4MIU0iiQYzK5EcMynOI=; b=dUibjRa7bcGe3tOxocgTUufxS680zhszxciJT3qWfzhrZ6r7b5W/41r7FABPBHJ1/p naSU3oe6D7p6eofghapQo7XkP62dNNw3JAgv5SGKhov5wR00DppcNC2CETuqptTKQJx5 i6ctepZqlY5gHBOduYlY+PMRpcPzYU/P5SfTUTG5St8gBMFD9PFHIjI5Hz1JNS1JKKCs 1mtlWIoEECOeg8ofwosdIZ8afhAu21Uoh+f8rtfrwkZ+yJnZsoQlUsEQXaIxv8eIbQ8e olMgqA5OCpTqEIXXKzJ7vJHSNGDr3M1KPbGLf94EQxzNgqaFZZvnMD58y9dXi1p+V3KI rc/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=default header.b=hoCaCJMp; 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 l21si3081742otk.142.2019.12.05.11.19.20; Thu, 05 Dec 2019 11:19:33 -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=hoCaCJMp; 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 S1729240AbfLETPP (ORCPT + 99 others); Thu, 5 Dec 2019 14:15:15 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:37001 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbfLETPO (ORCPT ); Thu, 5 Dec 2019 14:15:14 -0500 Date: Thu, 05 Dec 2019 19:15:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1575573312; bh=vb4xN0McS6Sjd9AgIw6FMJzU4MIU0iiQYzK5EcMynOI=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=hoCaCJMp0ardbB4eMvVQDdkFvPwrTp8wFZttEepDfWwocHq1I9iSlP8nfVUTHaFwx jh/KEdgFAp4Cvn01Yv/HzkB0/KRPtrQPfLMx5uUncNPN4ovwEOf9zX/7b24NeJY4mB 15kF/lNowyFXuiwakTuKTu0HtAs5ZeVyzlwDUuK4= To: "linux-kernel@vger.kernel.org" From: Krzysztof Piecuch Cc: "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "hpa@zytor.com" , "x86@kernel.org" , "viresh.kumar@linaro.org" , "rafael.j.wysocki@intel.com" , "drake@endlessm.com" , "piecuch@protonmail.com" , "malat@debian.org" , "peterz@infradead.org" , "juri.lelli@redhat.com" Reply-To: Krzysztof Piecuch Subject: [PATCH] x86/tsc: Don't use cpuid 0x16 leaf to determine cpu speed. Message-ID: 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM 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 This patch corrects tsc drift on systems with changed base clock frequency (e.g. overclocking). We can't use 0x16 cpu leaf as it's documented as "not reflecting actual values" and is supposed to be used only as a mean to determine "processor brand string and for determining the appropriate range to use when displaying processor information e.g. frequency history graphs". Signed-off-by: Krzysztof Piecuch --- arch/x86/kernel/tsc.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 7e322e2daaf5..fc9a000a814c 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -641,29 +641,16 @@ unsigned long native_calibrate_tsc(void) =09=09=09boot_cpu_data.x86_model =3D=3D INTEL_FAM6_ATOM_GOLDMONT_D) =09=09crystal_khz =3D 25000; +=09if (crystal_khz =3D=3D 0) +=09=09return 0; + =09/* =09 * TSC frequency reported directly by CPUID is a "hardware reported" =09 * frequency and is the most accurate one so far we have. This =09 * is considered a known frequency. =09 */ -=09if (crystal_khz !=3D 0) -=09=09setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); - -=09/* -=09 * Some Intel SoCs like Skylake and Kabylake don't report the crystal -=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) { -=09=09unsigned int eax_base_mhz, ebx, ecx, edx; - -=09=09cpuid(0x16, &eax_base_mhz, &ebx, &ecx, &edx); -=09=09crystal_khz =3D eax_base_mhz * 1000 * -=09=09=09eax_denominator / ebx_numerator; -=09} -=09if (crystal_khz =3D=3D 0) -=09=09return 0; +=09setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); =09/* =09 * For Atom SoCs TSC is the only reliable clocksource. -- 2.17.1