From nobody Fri Mar 18 09:21:11 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 B9E191A13970; Fri, 18 Mar 2022 09:21:11 +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 4KKdmR4n3Xz3Q26; Fri, 18 Mar 2022 09:21:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647595271; 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=I7odd/uTvQxxeecGwR9NbC9GX0Q3oka5DSdppvyTlag=; b=shCjtDSkbJcdcr+Z9KNjz525PVupEI8CPwX5wFffVd33TD+ybdvWpNjoAGHOzg6LqcdP0S nnJ3QCOLx4p1d3WWvIi0V0kEwUIId5XCOa1NeAdJ0KQztwtlaGY3IFs+jbszs2p7w9Ks8r KPGhFOPD9jBlArX6TAULn/GUV3G8yv4cdKkuC547NB62RjpttPo/283uk9K2jlbl9wocVh UyTOOcTumrBv99UQ+VyLR7ONXCgF94+rDonfC6fGMPVKjDYq0VgZThea8/A5jQ5habksSO bEaaEP0rPp9CWlR2d1mu8UiLfv1w7mAbmgS5gXkWEeGDspxp7Mcx0JY0h0aeGw== 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 84D281C170; Fri, 18 Mar 2022 09:21:11 +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 22I9LBQ3075288; Fri, 18 Mar 2022 09:21:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22I9LBR7075287; Fri, 18 Mar 2022 09:21:11 GMT (envelope-from git) Date: Fri, 18 Mar 2022 09:21:11 GMT Message-Id: <202203180921.22I9LBR7075287@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Roger Pau Monn=C3=A9?= Subject: git: 1ca34862dc45 - main - x86/tsc: fetch frequency from CPUID when running on Xen 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: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1ca34862dc45e0074b5aa31d9e491a2684ac6640 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647595271; 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=I7odd/uTvQxxeecGwR9NbC9GX0Q3oka5DSdppvyTlag=; b=HUkYDyofmwTFw1fNtOe4CUqUjWrfcqGh6QXpYA7FK0veAyg6YTQr0QNAOI7KdKagh2Eean 4/0s91Upl7scqCY0imnZlghDT1lelld6mgXc2eRDTs0hzRjUTq1K+g3WUZSRUZ3uMN1HJt D/ODaL5btBXo95eCC78t8gQUNHh1ClLH1zkGg3hHN2J7zpFK33VlAEEWVoxvSj2Y+ROKJU T8JiKID0GbMRFVj3TwYcshC3JckNjNVhvPM7LjWe6yQ9aSO+cKbnamKATaeSYz+Tv4LiQn B8m3weaXvOq7dr5cBvPYQKnmyMQfWjyPeK1/nYHRQrL+ec/r+uvlb82zhh5tAg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647595271; a=rsa-sha256; cv=none; b=hOH6VQvV6aJrhlp5qcaPnB1Ysb9Xs6UpBroV2YXAM92scnTOLNC8rkUiBB5EnPaxtw7egM OIz9XAieBsHMxqu8tiiE8slQcevTt4tAlDMDV+Yl5eqq92soyMjsng6HMc3+wOzm6aNZmh DXtZ0juK+rptWZWQW8ex5PvgROuBA4pnLVbg4X0p4MhMh/uGl29GQZcRVplaQcgIWYiz/6 fQzQv3YZ6y1T0+FKfOCF2Q6Rr+35t5gQyXcks1mcAuLoJZM5CD+F96yC/WSUNCZsH+R94Q XocirD0vMFXKdfPcHePndEnvsLNZfHfYwy3LWWJvSCmtQdujk6i7Bkj/PgN97Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=1ca34862dc45e0074b5aa31d9e491a2684ac6640 commit 1ca34862dc45e0074b5aa31d9e491a2684ac6640 Author: Roger Pau Monné AuthorDate: 2022-03-16 08:56:40 +0000 Commit: Roger Pau Monné CommitDate: 2022-03-18 09:21:04 +0000 x86/tsc: fetch frequency from CPUID when running on Xen Introduce a helper to fetch the TSC frequency from CPUID when running under Xen. Since the TSC can also be initialized early when running as a Xen guest pull out the call to tsc_init() from the early_clock_source_init() handlers and place it in clock_init(), as otherwise all handlers would call tsc_init() anyway. Reviewed by: markj Sponsored by: Citrix Systems R&D Differential revision: https://reviews.freebsd.org/D34581 --- sys/amd64/amd64/machdep.c | 1 - sys/i386/i386/machdep.c | 1 - sys/x86/isa/clock.c | 1 + sys/x86/x86/tsc.c | 21 +++++++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index b7810440a551..55a278de6020 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -1167,7 +1167,6 @@ static void native_clock_source_init(void) { i8254_init(); - tsc_init(); } static void diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 6913c0691fd4..9fee973d9e82 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -208,7 +208,6 @@ static void i386_clock_source_init(void) { i8254_init(); - tsc_init(); } static void diff --git a/sys/x86/isa/clock.c b/sys/x86/isa/clock.c index f21f847709cd..730aee5e9a2a 100644 --- a/sys/x86/isa/clock.c +++ b/sys/x86/isa/clock.c @@ -129,6 +129,7 @@ clock_init(void) mtx_init(&clock_lock, "clk", NULL, MTX_SPIN | MTX_NOPROFILE); /* Init the clock in order to use DELAY */ init_ops.early_clock_source_init(); + tsc_init(); } static int diff --git a/sys/x86/x86/tsc.c b/sys/x86/x86/tsc.c index 0fdd70a690a3..96f209e4c08d 100644 --- a/sys/x86/x86/tsc.c +++ b/sys/x86/x86/tsc.c @@ -147,6 +147,21 @@ tsc_freq_vmware(void) tsc_early_calib_exact = 1; } +static void +tsc_freq_xen(void) +{ + u_int regs[4]; + + /* + * Must run *after* generic tsc_freq_cpuid_vm, so that when Xen is + * emulating Viridian support the Viridian leaf is used instead. + */ + KASSERT(hv_high >= 0x40000003, ("Invalid max hypervisor leaf on Xen")); + cpuid_count(0x40000003, 0, regs); + tsc_freq = (uint64_t)(regs[2]) * 1000; + tsc_early_calib_exact = 1; +} + /* * Calculate TSC frequency using information from the CPUID leaf 0x15 'Time * Stamp Counter and Nominal Core Crystal Clock'. If leaf 0x15 is not @@ -358,6 +373,12 @@ probe_tsc_freq_early(void) printf( "Early TSC frequency %juHz derived from VMWare hypercall\n", (uintmax_t)tsc_freq); + } else if (vm_guest == VM_GUEST_XEN) { + tsc_freq_xen(); + if (bootverbose) + printf( + "Early TSC frequency %juHz derived from Xen CPUID\n", + (uintmax_t)tsc_freq); } else if (tsc_freq_cpuid(&tsc_freq)) { /* * If possible, use the value obtained from CPUID as the initial