From nobody Sat Jan 15 01:30:36 2022 X-Original-To: dev-commits-src-all@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 045671943F42; Sat, 15 Jan 2022 01:30:40 +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 4JbLG643Bcz3L6n; Sat, 15 Jan 2022 01:30:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642210239; 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=jpPf48+4fnY6yAeEGOTh3zPZllHcv/roBUHqjVDeGOY=; b=g1P4BBTsjfgKtTP8jvoJ/kaQuMnjCZxhRBwE27x8hyXauyMDCWiNYWJv8OGuzfqRxpjsK0 6WQkEjJNUxnMZ59/wNSsQCmY7Yk1+MWA51ukQuP7lopq3wEurTOU13gf9Rz+PUxMZCoKdc YA5LepxKW/QH4EG34gSH1EEDKHob64DZSZ2N1FAU1jl3LninO1BNfK/+IJM6XN6vdIFKE5 SMbPRBj8Zl1Qt2VrNSedL2U0dTbg+HoiYpDyFtOXosGQbrA4F4g7thoEe3bwxzgW4kIMcr vLk6JNhEaqRBKml4+AL0ZmDbxVlKuMD7NZzMup1Pm0TgHLXJxeOV1CHe+f4QzA== 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 ECB891E1B5; Sat, 15 Jan 2022 01:30:36 +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 20F1UaQc083140; Sat, 15 Jan 2022 01:30:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20F1UaHG083139; Sat, 15 Jan 2022 01:30:36 GMT (envelope-from git) Date: Sat, 15 Jan 2022 01:30:36 GMT Message-Id: <202201150130.20F1UaHG083139@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: de1292c6ff8a - main - Use CPUID leaf 0x40000010 for local APIC freq List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: de1292c6ff8a445fd453effba8cc23c38cea223f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642210239; 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=jpPf48+4fnY6yAeEGOTh3zPZllHcv/roBUHqjVDeGOY=; b=WNoOEhib4yCCdBQCKOgrgaHpMYjjReyx6ahSmLon3xNjBODDEo/XKPUF0+bVBoYGBF5Kmg RhQLtQIjzy/1Z1lcV9xmxz1z4E5mpsBuYTn5kB43W6LISYgpwMRowbIzpVKTV330KgOm4Z 5MMmW+ImtDVCT8AHF6g/KquKYBjvD3EkQGH+mH5OyDonpJfurvpuRn810ha09hAXsmsefR pUd4tOXinFekQ5CEHFBB2NFpsjrquSK0rbq0ewvhoVQ/E6gRBqI4/7r2xpamzEHPB5Jqav sPFhKJXMAAcObZYXVXXfWyrgSx5ev8AJ/z8/iHGJRN6iROFkhQTqoIaKvM2VIA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642210239; a=rsa-sha256; cv=none; b=e6wxCW2xfZ+CTXImCMzthAbbat39sk1VUxvr4NqcOthDXxzXn1+Qd/TxHXw9+w+i1hpU6p m/bpqcEg53rGj6AcKh6ThGYd4yhdHWX2HzHkeFtHllBgx3LKFN9DucmNB3vOgR8Ng8PLP2 yTdRtOcK6HDyyadCK9LwoXaxhUepYpPYq0XvwAQhpOjMRG2VgSYm1HkbeCIGZYUwRPAcjw 8atRajCsITxjlISOE75oy6UJMUXVcCbgRhcJyI5MOXRbMbQUI3TMMVOlTqfH2BCW9s9CHH +rWXZAcTtb3yzcn0nkq6XpycHpk+G3ADcmpPkW1sEieL65DzknxWWuHrQACuwQ== 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=de1292c6ff8a445fd453effba8cc23c38cea223f commit de1292c6ff8a445fd453effba8cc23c38cea223f Author: Colin Percival AuthorDate: 2022-01-09 00:59:31 +0000 Commit: Colin Percival CommitDate: 2022-01-15 01:30:17 +0000 Use CPUID leaf 0x40000010 for local APIC freq Some VM systems announce the frequency of the local APIC via the CPUID leaf 0x40000010. Using this allows us to boot slightly faster by avoiding the need for timer calibration. Reviewed by: markj Sponsored by: https://www.patreon.com/cperciva --- sys/x86/x86/local_apic.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c index 4b66d10cb5ae..7be603c71146 100644 --- a/sys/x86/x86/local_apic.c +++ b/sys/x86/x86/local_apic.c @@ -1002,6 +1002,35 @@ native_lapic_disable_pmc(void) #endif } +static int +lapic_calibrate_initcount_cpuid_vm(void) +{ + u_int regs[4]; + uint64_t freq; + + /* Get value from CPUID leaf if possible. */ + if (vm_guest == VM_GUEST_NO) + return (false); + if (hv_high < 0x40000010) + return (false); + do_cpuid(0x40000010, regs); + freq = (uint64_t)(regs[1]) * 1000; + + /* Pick timer divisor. */ + lapic_timer_divisor = 2; + do { + if (freq / lapic_timer_divisor < APIC_TIMER_MAX_COUNT) + break; + lapic_timer_divisor <<= 1; + } while (lapic_timer_divisor <= 128); + if (lapic_timer_divisor > 128) + return (false); + + /* Record divided frequency. */ + count_freq = freq / lapic_timer_divisor; + return (true); +} + static uint64_t cb_lapic_getcount(void) { @@ -1014,6 +1043,9 @@ lapic_calibrate_initcount(struct lapic *la) { uint64_t freq; + if (lapic_calibrate_initcount_cpuid_vm()) + goto done; + /* Calibrate the APIC timer frequency. */ lapic_timer_set_divisor(2); lapic_timer_oneshot_nointr(la, APIC_TIMER_MAX_COUNT); @@ -1031,6 +1063,7 @@ lapic_calibrate_initcount(struct lapic *la) if (lapic_timer_divisor > 128) panic("lapic: Divisor too big"); count_freq = freq * 2 / lapic_timer_divisor; +done: if (bootverbose) { printf("lapic: Divisor %lu, Frequency %lu Hz\n", lapic_timer_divisor, count_freq);