From owner-svn-src-stable-12@freebsd.org Wed Apr 29 10:53:35 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E7C1B2AFEA0; Wed, 29 Apr 2020 10:53:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49BwNb5rZBz43j7; Wed, 29 Apr 2020 10:53:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C3CDA4569; Wed, 29 Apr 2020 10:53:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03TArZ0E014625; Wed, 29 Apr 2020 10:53:35 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03TArZen014624; Wed, 29 Apr 2020 10:53:35 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202004291053.03TArZen014624@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 29 Apr 2020 10:53:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360455 - stable/12/sys/x86/x86 X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/sys/x86/x86 X-SVN-Commit-Revision: 360455 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Apr 2020 10:53:36 -0000 Author: kib Date: Wed Apr 29 10:53:35 2020 New Revision: 360455 URL: https://svnweb.freebsd.org/changeset/base/360455 Log: MFC r359997: Improve TSC calibration logic. Modified: stable/12/sys/x86/x86/tsc.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/x86/x86/tsc.c ============================================================================== --- stable/12/sys/x86/x86/tsc.c Wed Apr 29 05:11:17 2020 (r360454) +++ stable/12/sys/x86/x86/tsc.c Wed Apr 29 10:53:35 2020 (r360455) @@ -82,8 +82,8 @@ SYSCTL_INT(_machdep, OID_AUTO, disable_tsc, CTLFLAG_RD "Disable x86 Time Stamp Counter"); static int tsc_skip_calibration; -SYSCTL_INT(_machdep, OID_AUTO, disable_tsc_calibration, CTLFLAG_RDTUN | - CTLFLAG_NOFETCH, &tsc_skip_calibration, 0, +SYSCTL_INT(_machdep, OID_AUTO, disable_tsc_calibration, CTLFLAG_RDTUN, + &tsc_skip_calibration, 0, "Disable TSC frequency calibration"); static void tsc_freq_changed(void *arg, const struct cf_level *level, @@ -230,7 +230,6 @@ probe_tsc_freq(void) u_int regs[4]; uint64_t tmp_freq, tsc1, tsc2; int no_cpuid_override; - uint16_t bootflags; if (cpu_high >= 6) { do_cpuid(6, regs); @@ -291,30 +290,13 @@ probe_tsc_freq(void) break; } - if (!TUNABLE_INT_FETCH("machdep.disable_tsc_calibration", - &tsc_skip_calibration)) { - /* - * User did not give the order about calibration. - * If he did, we do not try to guess. - * - * Otherwise, if ACPI FADT reports that the platform - * is legacy-free and CPUID provides TSC frequency, - * use it. The calibration could fail anyway since - * ISA timer can be absent or power gated. - */ - if (acpi_get_fadt_bootflags(&bootflags) && - (bootflags & ACPI_FADT_LEGACY_DEVICES) == 0 && - tsc_freq_cpuid(&tmp_freq)) { - printf("Skipping TSC calibration since no legacy " - "devices reported by FADT and CPUID works\n"); - tsc_skip_calibration = 1; - } - } if (tsc_skip_calibration) { if (tsc_freq_cpuid(&tmp_freq)) tsc_freq = tmp_freq; else if (cpu_vendor_id == CPU_VENDOR_INTEL) tsc_freq_intel(); + if (tsc_freq == 0) + tsc_disabled = 1; } else { if (bootverbose) printf("Calibrating TSC clock ... "); @@ -328,8 +310,9 @@ probe_tsc_freq(void) * the frequency reported by CPUID 0x15/0x16 leafs * differ significantly, this probably means that * calibration is bogus. It happens on machines - * without 8254 timer and with BIOS not properly - * reporting it in FADT boot flags. + * without 8254 timer. The BIOS rarely properly + * reports it in FADT boot flags, so just compare the + * frequencies directly. */ if (tsc_freq_cpuid(&tmp_freq) && qabs(tsc_freq - tmp_freq) > uqmin(tsc_freq, tmp_freq)) {