From owner-svn-src-all@freebsd.org Wed Oct 2 13:43:24 2019 Return-Path: Delivered-To: svn-src-all@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 B977212F7F5; Wed, 2 Oct 2019 13:43:24 +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 46jy5S4Cb5z4RLg; Wed, 2 Oct 2019 13:43:24 +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 750692C591; Wed, 2 Oct 2019 13:43:24 +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 x92DhOUr060320; Wed, 2 Oct 2019 13:43:24 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x92DhODD060319; Wed, 2 Oct 2019 13:43:24 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201910021343.x92DhODD060319@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 2 Oct 2019 13:43:24 +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: r353006 - 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: 353006 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Oct 2019 13:43:24 -0000 Author: kib Date: Wed Oct 2 13:43:24 2019 New Revision: 353006 URL: https://svnweb.freebsd.org/changeset/base/353006 Log: MFC r352684: x86: Fall back to leaf 0x16 if TSC frequency is obtained by CPUID and leaf 0x15 is not functional. 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 Oct 2 13:36:54 2019 (r353005) +++ stable/12/sys/x86/x86/tsc.c Wed Oct 2 13:43:24 2019 (r353006) @@ -133,7 +133,11 @@ tsc_freq_vmware(void) /* * Calculate TSC frequency using information from the CPUID leaf 0x15 - * 'Time Stamp Counter and Nominal Core Crystal Clock'. It should be + * 'Time Stamp Counter and Nominal Core Crystal Clock'. If leaf 0x15 + * is not functional, as it is on Skylake/Kabylake, try 0x16 'Processor + * Frequency Information'. Leaf 0x16 is described in the SDM as + * informational only, but if 0x15 did not work, and TSC calibration + * is disabled, it is the best we can get at all. It should still be * an improvement over the parsing of the CPU model name in * tsc_freq_intel(), when available. */ @@ -145,10 +149,20 @@ tsc_freq_cpuid(void) if (cpu_high < 0x15) return (false); do_cpuid(0x15, regs); - if (regs[0] == 0 || regs[1] == 0 || regs[2] == 0) + if (regs[0] != 0 && regs[1] != 0 && regs[2] != 0) { + tsc_freq = (uint64_t)regs[2] * regs[1] / regs[0]; + return (true); + } + + if (cpu_high < 0x16) return (false); - tsc_freq = (uint64_t)regs[2] * regs[1] / regs[0]; - return (true); + do_cpuid(0x16, regs); + if (regs[0] != 0) { + tsc_freq = (uint64_t)regs[0] * 1000000; + return (true); + } + + return (false); } static void