From nobody Sat Jan 15 01:30:35 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 855181943E61; Sat, 15 Jan 2022 01:30:37 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JbLG44R3cz3LCD; Sat, 15 Jan 2022 01:30:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642210237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9m0YUFtbRbontwwqTr3Ubzu3iiLBoHbv91fXmBnFQeI=; b=qEbhriunDMD6VPIG53m/vrxkidTX8lNIxx3kpUDOwC73BuIGS+AQ6qCh7SW0vPAejUeJFg y0mO/9jJaaw/4EVOnINONqzyHIlcEdu+BJ29za90rKyPDI7s/uO9+BmBt8qGOEOrZXYMT4 Vdx6otOWZtH9Vis53EfaJb/haD29qp9Asv4BTP4ErroapSRSE1Z2O+AysYJYYDvF4rG8+b eZZvLFmlEbYTnovxXdUiJRJHkq0l/Xkox1cDrqgU8KxA3WwRoXFPjcvv8CCyL26IozIRle +jRahd5wweQ1Tlx2rU3ZNb1+uV/2GLQapYWnqMCbUNhtpl1uqPHB6gb6qFlNVw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C9F5A1E448; Sat, 15 Jan 2022 01:30:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20F1UZ7P083116; Sat, 15 Jan 2022 01:30:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20F1UZiS083115; Sat, 15 Jan 2022 01:30:35 GMT (envelope-from git) Date: Sat, 15 Jan 2022 01:30:35 GMT Message-Id: <202201150130.20F1UZiS083115@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Colin Percival Subject: git: 4a432614f68c - main - TSC: Use 0x40000010 CPUID leaf for all VM types List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4a432614f68cf35879dbb4ebef089f5b8db95334 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642210236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9m0YUFtbRbontwwqTr3Ubzu3iiLBoHbv91fXmBnFQeI=; b=CFEe8pyU2sXG34AhDG0qfs9bsPqNx1xG4UtjUU+lBTcPmghEvHnw1wHSpbR4bEQ3CqBmrg kHmk7mAQAwqLB2FouhTLWisTIyNVltooKHseA5jlyEnZHzAQlDec5ITgu2iX/9UtKjqypK MoXfEcl6SJ/R/oEWYey75vMpusDOe34UMkDn6c0EHp3zCMphUyntQbuMjRMi+eIgYt/C4u U0RKg+N2VI0jyqnkt01c64jHBE0sIorFOYPiRq92tQF+pq681yFhV/enQ/sG5H1WYXC/xq o3quXPkkWUzpPEsfByEDqPZuj5pFjn8tmlKU54RqiWSfGHTR6iAYkukoOAqzTg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642210236; a=rsa-sha256; cv=none; b=KGtsKkW4YDfDLm99SV7FIvdj3E/NpKl/rZUXSkyNg9ARk34z2ETPQlTtIwaD09H2ohDA24 yiKXiooHn2OmuIte+qJGqmPSJ3aeJVD+oc/QSRPF0+WTjHCrSorYW6trrf29aOHTUZUlhL i6ofxdLsy3rcyyeXB1hXdVu1fjFAlrcNShWZTndptcf9lyNLRe7VlMzZg5E9cRk4gbe+jf h0tpvE6pF9bDZJ8zkP9GgLmRkGHLMEWsQ+Ds1MgS1JpKB0jpyGHHrgTIiG7Xxx+2ePxH36 r9JFPfxDvVpoT1qhjJ0ORF/NNYr7PRReO0hiWXibPx0DgE3Ysoy38Uo6V7AZ5g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=4a432614f68cf35879dbb4ebef089f5b8db95334 commit 4a432614f68cf35879dbb4ebef089f5b8db95334 Author: Colin Percival AuthorDate: 2022-01-04 07:28:36 +0000 Commit: Colin Percival CommitDate: 2022-01-15 01:30:17 +0000 TSC: Use 0x40000010 CPUID leaf for all VM types While this CPUID leaf was originally only used by VMWare, other hypervisors now also use it to announce the TSC frequency to guests. This speeds up the boot process by 100 ms in EC2 and other systems, by allowing the early calibration DELAY to be skipped. Reviewed by: markj Sponsored by: https://www.patreon.com/cperciva --- sys/x86/x86/tsc.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sys/x86/x86/tsc.c b/sys/x86/x86/tsc.c index 75c452f365cf..317be8979feb 100644 --- a/sys/x86/x86/tsc.c +++ b/sys/x86/x86/tsc.c @@ -121,19 +121,29 @@ static struct timecounter tsc_timecounter = { #endif }; +static int +tsc_freq_cpuid_vm(void) +{ + u_int regs[4]; + + if (vm_guest == VM_GUEST_NO) + return (false); + if (hv_high < 0x40000010) + return (false); + do_cpuid(0x40000010, regs); + tsc_freq = (uint64_t)(regs[0]) * 1000; + tsc_early_calib_exact = 1; + return (true); +} + static void tsc_freq_vmware(void) { u_int regs[4]; - if (hv_high >= 0x40000010) { - do_cpuid(0x40000010, regs); - tsc_freq = regs[0] * 1000; - } else { - vmware_hvcall(VMW_HVCMD_GETHZ, regs); - if (regs[1] != UINT_MAX) - tsc_freq = regs[0] | ((uint64_t)regs[1] << 32); - } + vmware_hvcall(VMW_HVCMD_GETHZ, regs); + if (regs[1] != UINT_MAX) + tsc_freq = regs[0] | ((uint64_t)regs[1] << 32); tsc_early_calib_exact = 1; } @@ -305,6 +315,9 @@ probe_tsc_freq(void) break; } + if (tsc_freq_cpuid_vm()) + return; + if (vm_guest == VM_GUEST_VMWARE) { tsc_freq_vmware(); return;