From owner-svn-src-stable-11@freebsd.org Wed May 2 07:42:48 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 55B4CFC4EBC; Wed, 2 May 2018 07:42:48 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 036F86BF55; Wed, 2 May 2018 07:42:48 +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 F28826225; Wed, 2 May 2018 07:42:47 +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 w427glqG075125; Wed, 2 May 2018 07:42:47 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w427glQ4075124; Wed, 2 May 2018 07:42:47 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201805020742.w427glQ4075124@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 2 May 2018 07:42:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r333161 - stable/11/sys/x86/x86 X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/x86/x86 X-SVN-Commit-Revision: 333161 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-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 May 2018 07:42:48 -0000 Author: kib Date: Wed May 2 07:42:47 2018 New Revision: 333161 URL: https://svnweb.freebsd.org/changeset/base/333161 Log: MFC r333002: Use CPUID leaf 0x15 to get TSC frequency when the calibration is disabled. Modified: stable/11/sys/x86/x86/tsc.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/x86/x86/tsc.c ============================================================================== --- stable/11/sys/x86/x86/tsc.c Wed May 2 07:40:04 2018 (r333160) +++ stable/11/sys/x86/x86/tsc.c Wed May 2 07:42:47 2018 (r333161) @@ -128,6 +128,26 @@ tsc_freq_vmware(void) tsc_is_invariant = 1; } +/* + * Calculate TSC frequency using information from the CPUID leaf 0x15 + * 'Time Stamp Counter and Nominal Core Crystal Clock'. It should be + * an improvement over the parsing of the CPU model name in + * tsc_freq_intel(), when available. + */ +static bool +tsc_freq_cpuid(void) +{ + u_int regs[4]; + + if (cpu_high < 0x15) + return (false); + do_cpuid(0x15, regs); + if (regs[0] == 0 || regs[1] == 0 || regs[2] == 0) + return (false); + tsc_freq = (uint64_t)regs[2] * regs[1] / regs[0]; + return (true); +} + static void tsc_freq_intel(void) { @@ -252,17 +272,18 @@ probe_tsc_freq(void) } if (tsc_skip_calibration) { - if (cpu_vendor_id == CPU_VENDOR_INTEL) + if (tsc_freq_cpuid()) + ; + else if (cpu_vendor_id == CPU_VENDOR_INTEL) tsc_freq_intel(); - return; + } else { + if (bootverbose) + printf("Calibrating TSC clock ... "); + tsc1 = rdtsc(); + DELAY(1000000); + tsc2 = rdtsc(); + tsc_freq = tsc2 - tsc1; } - - if (bootverbose) - printf("Calibrating TSC clock ... "); - tsc1 = rdtsc(); - DELAY(1000000); - tsc2 = rdtsc(); - tsc_freq = tsc2 - tsc1; if (bootverbose) printf("TSC clock: %ju Hz\n", (intmax_t)tsc_freq); }