From nobody Sat Jul 4 21:05:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1782828379; cv=none; d=zohomail.com; s=zohoarc; b=dW5HpTzkelxBNTahzEgDPXWN7Mq6FEOpma9or9N0FoXHZhrpso8//G4ehqbOWznEKd3jUBCNTkqkrE0tU9ucjZde622qpqH8EcnoLLPcNBR5fWsSJw82RnZtXj1WyIIvXRN0puteB9BB3HKdr9oxdAmenEsgAGZa3ZMKaLC48qA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782828379; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Sy1KCusVbxEhJSonLb4NPvm532hzrQz4ITq3H87NwNE=; b=Qc/P693i0rkBBOm/qMmzBT6TpK/ExYpIfKqdUnCTcNs5mx4FDxrVOToXctJBgTs90EfFpovtcIsEq5qH5fXXXKEm6ZQDbd/3Ce6ICazqXm8ua1DV+ZlGYQg8rFlaiPxAtnV5LUsFUEX/26md0ui5j3zal1lFgACwyydH5jA2Chs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1782828379087199.12977104609172; Tue, 30 Jun 2026 07:06:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1348998.1606785 (Exim 4.92) (envelope-from ) id 1weZ6C-0005gL-DX; Tue, 30 Jun 2026 14:06:04 +0000 Received: by outflank-mailman (output) from mailman id 1348998.1606785; Tue, 30 Jun 2026 14:06:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1weZ6C-0005gE-9f; Tue, 30 Jun 2026 14:06:04 +0000 Received: by outflank-mailman (input) for mailman id 1348998; Tue, 30 Jun 2026 14:06:03 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1weZ6B-0005g2-6C for xen-devel@lists.xenproject.org; Tue, 30 Jun 2026 14:06:03 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1weZ6A-0087sb-J3 for xen-devel@lists.xenproject.org; Tue, 30 Jun 2026 16:06:02 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a43cd3d-e002-0a2a0a5209dd-0a2a450cb83c-46 for ; Tue, 30 Jun 2026 16:06:02 +0200 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a43cd4a-f399-0a2a450c0019-d155dd2ec174-3 for ; Tue, 30 Jun 2026 16:06:02 +0200 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-473dc4cf238so1388085f8f.3 for ; Tue, 30 Jun 2026 07:06:02 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-475671d02f5sm8756652f8f.28.2026.06.30.07.06.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jun 2026 07:06:00 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1782828362; x=1783433162; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=Sy1KCusVbxEhJSonLb4NPvm532hzrQz4ITq3H87NwNE=; b=XcOwk0X6oF82dmsG7nmesmFD6kkgVcbGAP8Si4u9+T7a7hx1PORkihcFK8IcACI2sp dX4in+M4EIxOUINwOSPSWv2eyYhMLxAsbFneYK8dZpfik0+FSXgM5XVN6ePj7aAlORFH 8ZUcmMe7t0sU5Sa9I55TnMeeoLGKpR7ktHnUy+IjLu+hcdcE8ZafYHAxcEIQhNJyAJ2e /OiWzxsyCa4jWu2IYfpIsz8NHy1e3GjxQPP/C0nv6monGK86IdtxuPxLT/57wRU2495B VMonjCPfOthgJLqumXBRdSMI8UCqlspYnvArNdpyTpLFqemvOrAhrLHjnFGdLnfGI/BQ pd3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782828362; x=1783433162; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Sy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2002:a05:6000:2011:b0:46d:d5da:f0aa with SMTP id ffacd0b85a97d-4755311d4bbmr4830507f8f.45.1782828361866; Tue, 30 Jun 2026 07:06:01 -0700 (PDT) Message-ID: Date: Tue, 30 Jun 2026 16:06:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 1/3] time: add "NOW() good" indicator From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Julien Grall , Stefano Stabellini , Anthony PERARD , Michal Orzel , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie , Bertrand Marquis , Volodymyr Babchuk , Oleksii Kurochko References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1782828362-0EB3DD51-2E6F3598/0/0 X-purgate-type: clean X-purgate-size: 2820 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1782828379781158500 Content-Type: text/plain; charset="utf-8" printk_start_of_line() checks for a value of 0 right now. In order to be able to have NOW() return at least monotonically increasing values, that needs replacing by an explicit indicator. Signed-off-by: Jan Beulich --- Arm and RISC-V may want to consider whether their initial get_cycles() can't be moved yet earlier, such that the indicator also can be set yet earlier. --- v4: Add barriers. v3: New. --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -145,6 +145,8 @@ void __init preinit_xen_time(void) panic("Timer: Cannot initialize platform timer\n"); =20 boot_count =3D get_cycles(); + smp_wmb(); + NOW_good =3D true; } =20 static void __init init_dt_xen_time(void) --- a/xen/arch/riscv/time.c +++ b/xen/arch/riscv/time.c @@ -87,6 +87,8 @@ void __init preinit_xen_time(void) panic("%s: ACPI isn't supported\n", __func__); =20 boot_clock_cycles =3D get_cycles(); + smp_wmb(); + NOW_good =3D true; =20 /* set_xen_timer must have been set by sbi_init() already */ ASSERT(set_xen_timer); --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -2660,6 +2660,7 @@ void __init early_time_init(void) =20 set_time_scale(&t->tsc_scale, tmp); t->stamp.local_tsc =3D boot_tsc_stamp; + NOW_good =3D true; =20 init_percpu_time(); =20 --- a/xen/common/time.c +++ b/xen/common/time.c @@ -22,6 +22,8 @@ #include #include =20 +bool __ro_after_init NOW_good; + /* Nonzero if YEAR is a leap year (every 4 years, except every 100th isn't, and every 400th is). */ #define __isleap(year) \ --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -975,11 +975,11 @@ static void printk_start_of_line(const c } /* fall through */ case TSM_BOOT: - sec =3D NOW(); - nsec =3D do_div(sec, 1000000000); - - if ( sec | nsec ) + if ( NOW_good ) { + smp_rmb(); + sec =3D NOW(); + nsec =3D do_div(sec, 1000000000); snprintf(tstr, sizeof(tstr), "[%5"PRIu64".%06"PRIu64"] ", sec, nsec / 1000); break; --- a/xen/include/xen/time.h +++ b/xen/include/xen/time.h @@ -62,6 +62,12 @@ struct tm wallclock_time(uint64_t *ns); /* Chosen so (NOW() + delta) wont overflow without an uptime of 200 years = */ #define STIME_DELTA_MAX ((s_time_t)((uint64_t)~0ULL>>2)) =20 +/* + * Indicator that the value returned by NOW() is good (earlier invocations= may + * return zero or very small, merely monotonically increasing values). + */ +extern bool NOW_good; + /* Explicitly OR with 1 just in case version number gets out of sync. */ #define version_update_begin(v) (((v) + 1) | 1) #define version_update_end(v) ((v) + 1) From nobody Sat Jul 4 21:05:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1782828402; cv=none; d=zohomail.com; s=zohoarc; b=YtBVfJcb6Ob3QAVaPSGF5aLeYHFJWA+EJ4pEGeammHoStO4dWbp+iCi8MAsseEXx9GEbaUWztzrt/EeaVUZEvO746f2ZynbMKsdqEZzcE2o6BWqmB8eVl8IBcqq9AAuz9nzE/dkImWgc37SO+kFelmvYSfwDM6ieXTfkwM0h21o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782828402; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Yi1J6oBQQCDF544YYXBhrqWzrznLLlVPi+0upj+pGUE=; b=PgC/tDTSV7wRXx0HTsHi7xaeiQRLQJSPh0V0AsonYgUp6Pgn/8oziDuu7kOYgt26Kypnkfpe3JUfPCp9jeAPx0sbt6vwKfIsKkEnq98LzAnHeaU6MfJn/QAnNkKvIYY1+XK4G7jHs7ZQ9dZAniBj4Y4Jlob08P7CxOp16EPTgII= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1782828402714439.4839804965668; Tue, 30 Jun 2026 07:06:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1349001.1606793 (Exim 4.92) (envelope-from ) id 1weZ6X-00068f-Mw; Tue, 30 Jun 2026 14:06:25 +0000 Received: by outflank-mailman (output) from mailman id 1349001.1606793; Tue, 30 Jun 2026 14:06:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1weZ6X-00068Y-JM; Tue, 30 Jun 2026 14:06:25 +0000 Received: by outflank-mailman (input) for mailman id 1349001; Tue, 30 Jun 2026 14:06:23 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1weZ6V-00064h-Qb for xen-devel@lists.xenproject.org; Tue, 30 Jun 2026 14:06:23 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1weZ6V-001DFv-6x for xen-devel@lists.xenproject.org; Tue, 30 Jun 2026 16:06:23 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a43cd56-2eae-0a2a0a5409dd-0a2a4502b914-18 for ; Tue, 30 Jun 2026 16:06:23 +0200 Received: from [209.85.128.49] (helo=mail-wm1-f49.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a43cd5e-5a27-0a2a45020019-d1558031e9ad-3 for ; Tue, 30 Jun 2026 16:06:23 +0200 Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-493ba729dbdso4037665e9.3 for ; Tue, 30 Jun 2026 07:06:23 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47563d195b3sm8581655f8f.8.2026.06.30.07.06.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jun 2026 07:06:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1782828382; x=1783433182; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=Yi1J6oBQQCDF544YYXBhrqWzrznLLlVPi+0upj+pGUE=; b=Dvd3rSRHyLiDHGHVr3xqezpDx2wF5qbLH5pWmA30t64udIPYdOZ55hPgkK4CtRSvpB 8K0+jC10tmqWJfKNvgCwc9JxYzO/0CpMZ48tB2ukEkrWw3pbmVh6WrPsh18We3W3OOzA XgplcLJuM7EsVpy3d6rHoaJgTMjZtv9omB7DHWUe9ye6Tlb6pVPCeQf0WaOlx4o0Sds8 hLxcN+BYK7+zUbZcl+CeV7j4HFzrCO5NCFynl5N+V0f6DZ5KfjjZoDqj4sxapuUjizUx mjS1lfVceWt9USXbBmAfiQsUXVqtROg9irfuxdp7fzk7Q4ijwzH1i2Z5LdHMeZV37dlQ Cl/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782828382; x=1783433182; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Yi1J6oBQQCDF544YYXBhrqWzrznLLlVPi+0upj+pGUE=; b=RnbeYbBRqwvV9ymKSvPd/LEvBRFsXyr7NhPDF1pIQqgossAwu2LRWkzKsiUdRFfhfS xWkAMimUSgPVF+7yrUNNxzls6ubtKTS07mZ+aEbr/XCmjaQhbCNHqSZ/shgjO5qg3xOE WDZECWZ84nhz8FGXaKxoxHK51KnC6GlNCcbdaFB8jN2XwX8d4Au6an7mcQs7SkRLu7zS OQArLjsGDcXJ+8Vdk1pvmuOwQrs0sBHTRS1cDbRZih+SHlLCUQKcfkn0hiDTBpKKb6vP mo1CKzX3izC/WjhW54CO5BQWfv+TxdOkg+Bh8+DICftMV56vE48Zb1KHhj/0QXmWjmCg ZBRw== X-Gm-Message-State: AOJu0Yz2qW4mrMPQb8eyBVcDcDj5RLHWOOhkz/JWyBIUisxCariKVKo9 RQMdBFQSL0d+1xW0MvuoAhMJUCMgmUloQZvQYAR4oEg6/Iwz3u05eR+3k7TWDCKUXro+ISHrmhK 7fk0bCg== X-Gm-Gg: AfdE7ckOY7YxtSBbth5RJTpDNDdCPKR5hDvvpX97SERU7/sfuHrPlL7Rd6PQQTH04iC ZnNvBeOmuy8OTmRHi32uWAc8Wv4VDogtVY/lWzIGB+rb0eNzL7sPBKVFSdnUhQ3M/pCxSnA+qWr 57kqM7VFAvVzsJwGf3UwZMUkdv2jqjcKl5cSV6L0OgylImzOkWoWncBFgIvVkBCtAxL6xYawuE+ HDVrkDj8bwMwbdsCxsirLkfmTgra6Aw2wJ1UhT/ZkHmIL/U0vhHgolQzWCoWreFYEoB0t4RKdUd IhGKo8hDyCQi4p2eo6BJFnJydvgc2a0PSGsZ4VOFWvkQ9NhX7JpMvZKhiSkoakg5Rp8STTU0yOQ A2ckrK8M289c/AQFzby82hvPhn1HqzGp7svt8j97Dlu2wLKr8M905Rdy8k1LDkQw+q8K44GG1oc gTEEu0iBnpjN3YmJL0dvgnHxY+l1X5AEdOo6DQO9LX7x1g/UgbdOGgoVRTc+GpvSl0LAroEre2P Qi9 X-Received: by 2002:a05:600c:8411:b0:493:a893:1200 with SMTP id 5b1f17b1804b1-493b82815d4mr49963145e9.5.1782828382542; Tue, 30 Jun 2026 07:06:22 -0700 (PDT) Message-ID: <80b20aa4-8954-47ed-85f0-3f09d46717cf@suse.com> Date: Tue, 30 Jun 2026 16:06:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 2/3] x86/Intel: split model-specific freq calculation off of intel_log_freq() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS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-720697/1782828383-4E7157C5-4ECB21C3/0/0 X-purgate-type: clean X-purgate-size: 4526 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1782828403909158500 Content-Type: text/plain; charset="utf-8" ..., for that logic to become reusable. While doing so undo the open- coding of DIV_ROUND_UP(). Also switch to the new struct cpuinfo_x86 field names. Signed-off-by: Jan Beulich --- If Misra didn't dislike non-static functions without external callers, the new function could be put below the old one, thus reducing churn and improving readability of the diff (really I moved the code for the new function up, but the diff representation is the other way around). --- v3: New. --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -476,51 +476,14 @@ static int num_cpu_cores(struct cpuinfo_ return 1; } =20 -static void intel_log_freq(const struct cpuinfo_x86 *c) +static void intel_process_freq(const struct cpuinfo_x86 *c, + unsigned int *min_mhz, unsigned int *max_mh= z) { - unsigned int eax, ebx, ecx, edx, factor; uint64_t msrval; uint8_t max_ratio, min_ratio; + unsigned int factor; =20 - if ( c->cpuid_level >=3D 0x15 ) - { - cpuid(0x15, &eax, &ebx, &ecx, &edx); - if ( ecx && ebx && eax ) - { - unsigned long long val =3D ecx; - - val *=3D ebx; - printk("CPU%u: TSC: %u Hz * %u / %u =3D %Lu Hz\n", - smp_processor_id(), ecx, ebx, eax, val / eax); - } - else if ( ecx | eax | ebx ) - { - printk("CPU%u: TSC:", smp_processor_id()); - if ( ecx ) - printk(" core: %u Hz", ecx); - if ( ebx && eax ) - printk(" ratio: %u / %u", ebx, eax); - printk("\n"); - } - } - - if ( c->cpuid_level >=3D 0x16 ) - { - cpuid(0x16, &eax, &ebx, &ecx, &edx); - if ( ecx | eax | ebx ) - { - printk("CPU%u:", smp_processor_id()); - if ( ecx ) - printk(" bus: %u MHz", ecx); - if ( eax ) - printk(" base: %u MHz", eax); - if ( ebx ) - printk(" max: %u MHz", ebx); - printk("\n"); - } - } - - switch ( c->x86 ) + switch ( c->family ) { static const unsigned short core_factors[] =3D { 26667, 13333, 20000, 16667, 33333, 10000, 40000 }; @@ -533,7 +496,7 @@ static void intel_log_freq(const struct if ( !max_ratio ) return; =20 - switch ( c->x86_model ) + switch ( c->model ) { case 0x0e: /* Core */ case 0x0f: case 0x16: case 0x17: case 0x1d: /* Core2 */ @@ -578,10 +541,61 @@ static void intel_log_freq(const struct return; } =20 + if ( min_mhz ) + *min_mhz =3D DIV_ROUND_UP(factor * min_ratio, 100); + *max_mhz =3D DIV_ROUND_UP(factor * max_ratio, 100); +} + +static void intel_log_freq(const struct cpuinfo_x86 *c) +{ + unsigned int eax, ebx, ecx, edx, min_mhz =3D 0, max_mhz =3D 0; + + if ( c->cpuid_level >=3D 0x15 ) + { + cpuid(0x15, &eax, &ebx, &ecx, &edx); + if ( ecx && ebx && eax ) + { + unsigned long long val =3D ecx; + + val *=3D ebx; + printk("CPU%u: TSC: %u Hz * %u / %u =3D %Lu Hz\n", + smp_processor_id(), ecx, ebx, eax, val / eax); + } + else if ( ecx | eax | ebx ) + { + printk("CPU%u: TSC:", smp_processor_id()); + if ( ecx ) + printk(" core: %u Hz", ecx); + if ( ebx && eax ) + printk(" ratio: %u / %u", ebx, eax); + printk("\n"); + } + } + + if ( c->cpuid_level >=3D 0x16 ) + { + cpuid(0x16, &eax, &ebx, &ecx, &edx); + if ( ecx | eax | ebx ) + { + printk("CPU%u:", smp_processor_id()); + if ( ecx ) + printk(" bus: %u MHz", ecx); + if ( eax ) + printk(" base: %u MHz", eax); + if ( ebx ) + printk(" max: %u MHz", ebx); + printk("\n"); + } + } + + intel_process_freq(c, &min_mhz, &max_mhz); + if ( !max_mhz ) + return; + printk("CPU%u: ", smp_processor_id()); - if ( min_ratio ) - printk("%u ... ", (factor * min_ratio + 50) / 100); - printk("%u MHz\n", (factor * max_ratio + 50) / 100); + if ( min_mhz ) + printk("%u ... ", min_mhz); + printk("%u MHz\n", max_mhz); } =20 static void init_intel_perf(struct cpuinfo_x86 *c) From nobody Sat Jul 4 21:05:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1782828420; cv=none; d=zohomail.com; s=zohoarc; b=MiOsVzyWQ2XSoOyTpuwPkPbMpWNFfaqzGsEfHjoOmM2Ql6AFJ3p8KnIZ8xI45LC4StGHdcFexyPwLBRCJx1qwcL7YVkm06y6liqRELTMYHwKAocGgFL0UV5uu3YUF8vxGGmoCC6JPxlyHe+jt8H74Sp8kGvNpxf/0cl3DgwvGxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782828420; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VjQBjU4tlaZc2czbe1uHDpNUNQT539ySugQmprLUVZ0=; b=dioghkDNjWNm74MCRS3y4RAW8PHio0mlE5rpmRFqVUq6wVo/Gh15crPNTbex0w27TSGmK49n2x1GApDCN0m2gaVghGdLMPZuqMTnpL7AMANDQhIzFD/Vz0Af/irvAXPN4Rfb+hsoom4IL3XSN7N0JSUvrMmV5PxO/cxyVA9X5sc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1782828420678871.6100052405543; Tue, 30 Jun 2026 07:07:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1349012.1606804 (Exim 4.92) (envelope-from ) id 1weZ6s-0006eG-06; Tue, 30 Jun 2026 14:06:46 +0000 Received: by outflank-mailman (output) from mailman id 1349012.1606804; Tue, 30 Jun 2026 14:06:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1weZ6r-0006e9-R6; Tue, 30 Jun 2026 14:06:45 +0000 Received: by outflank-mailman (input) for mailman id 1349012; Tue, 30 Jun 2026 14:06:44 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1weZ6q-0006dU-1Q for xen-devel@lists.xenproject.org; Tue, 30 Jun 2026 14:06:44 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1weZ6p-001DQy-Ec for xen-devel@lists.xenproject.org; Tue, 30 Jun 2026 16:06:43 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a43cd6c-2eae-0a2a0a5409dd-0a2a450bb082-38 for ; Tue, 30 Jun 2026 16:06:43 +0200 Received: from [209.85.221.53] (helo=mail-wr1-f53.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a43cd73-ac48-0a2a450b0019-d155dd35c005-3 for ; Tue, 30 Jun 2026 16:06:43 +0200 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-4758b2a9e2aso514502f8f.2 for ; Tue, 30 Jun 2026 07:06:43 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-475641e4659sm8380977f8f.12.2026.06.30.07.06.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jun 2026 07:06:41 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1782828403; x=1783433203; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=VjQBjU4tlaZc2czbe1uHDpNUNQT539ySugQmprLUVZ0=; b=FX5sGYet1vTEYctxXEU2pCrtRAitNGkUGHovGjbOab4mRCErDpnbsUnvW8jZbpDwJr 8lLHDYfFBvWsSjFp7bVjLqX/3Gx0QrDQo7BtT83HOaT7KpmW/f1wE2OYpX/vMcuR6vFe 7mIrW+/Oa5D41lJaTuGhnPKYvUBQfYlKAJ3XU+i2Bd0j4w3+7uSaNmYo+gdtOSszg40Y HB0LTJa0IOb1rViCtA8w7JCXFw3aP4+mpBIP23Y+D6zZSgc1U7/PL2hkTilWHX+jvBqP iesxEohz+cJEmMflKF9YvWq8x0+jUZNI+Iy+7WidK1HKI0gFeESoeCIuXyWywJdVo3NA DX4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782828403; x=1783433203; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VjQBjU4tlaZc2czbe1uHDpNUNQT539ySugQmprLUVZ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109 with SMTP id ffacd0b85a97d-47550f8e22cmr5238707f8f.20.1782828402457; Tue, 30 Jun 2026 07:06:42 -0700 (PDT) Message-ID: Date: Tue, 30 Jun 2026 16:06:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 3/3] x86/time: avoid early uses of NOW() to return zero From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1782828403-39D27220-25993D5B/0/0 X-purgate-type: clean X-purgate-size: 6199 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1782828422136158500 Waiting loops like the one in flush_command_buffer() will degenerate to infinite ones when used early enough for NOW() to still return constant zero. Make sure the returned value at least monotonically increases. When available, use nominal frequency values as initial approximation. Do this only in get_s_time(), as producing a sane value in get_s_time_fixed() for non-zero inputs won't be reasonably possible. Put an assertion there. Reported-by: Roger Pau Monn=C3=A9 Signed-off-by: Jan Beulich --- RFC: While generally the mentioned waiting loops will take longer to time out, on a very fast CPU tight loops may time out too early. RFC: On the 2nd pass through early_cpu_init() it may be okay to skip the new additions. With "x86/time: set AP's TSC scale estimate earlier" the counter update may not need to be atomic anymore, as then only the BSP can reasonably hit that path. I don't think Fixes: tags should be put here. If we did, we'd have to enumerate all introductions of early uses of NOW() (or get_s_time()), with the exception of those dealing with getting back 0 (which I expect is only printk_start_of_line()). Will want backporting nevertheless (unless deemed too risky). --- v3: Use "high" / "max" freq if "nominal" isn't available. Set NOW_good. v2: Add assertion to get_s_time_fixed(). Use nominal frequencies for very early setting, if available. --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -19,6 +19,7 @@ #include #include #include +#include #include =20 #include @@ -403,6 +404,36 @@ void __init early_cpu_init(bool verbose) &c->x86_capability[FEATURESET_7d1]); } =20 + if (c->cpuid_level >=3D 0x15) { + cpuid(0x15, &eax, &ebx, &ecx, &edx); + + if (ecx && ebx && eax) + preset_tsc_scale(DIV_ROUND_UP(ecx * 1UL * ebx, eax)); + else if (c->cpuid_level >=3D 0x16) { + /* Assume CPU base freq =E2=89=88 TSC freq. */ + cpuid(0x16, &eax, &ebx, &ecx, &edx); + if (eax) + preset_tsc_scale(eax * 1000000UL); + else if (ebx) /* See preset_tsc_scale() for why. */ + preset_tsc_scale(ebx * 1000000UL); + } + } else if (c->vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) { + unsigned int nom_mhz =3D 0, hi_mhz =3D 0; + + amd_process_freq(c, NULL, &nom_mhz, &hi_mhz); + if (nom_mhz) + preset_tsc_scale(nom_mhz * 1000000UL); + else if (hi_mhz) /* See preset_tsc_scale() for why. */ + preset_tsc_scale(hi_mhz * 1000000UL); + } else if (c->vendor & X86_VENDOR_INTEL) { + unsigned int hi_mhz =3D 0; + + /* See preset_tsc_scale() for why. */ + intel_process_freq(c, NULL, &hi_mhz); + if (hi_mhz) + preset_tsc_scale(hi_mhz * 1000000UL); + } + eax =3D cpuid_eax(0x80000000); if ((eax >> 16) =3D=3D 0x8000 && eax >=3D 0x80000008) { ebx =3D eax >=3D 0x8000001f ? cpuid_ebx(0x8000001f) : 0; --- a/xen/arch/x86/include/asm/time.h +++ b/xen/arch/x86/include/asm/time.h @@ -23,6 +23,7 @@ mktime (unsigned int year, unsigned int int time_suspend(void); int time_resume(void); =20 +void preset_tsc_scale(unsigned long freq); void init_percpu_time(void); void time_latch_stamps(void); =20 --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -476,8 +476,8 @@ static int num_cpu_cores(struct cpuinfo_ return 1; } =20 -static void intel_process_freq(const struct cpuinfo_x86 *c, - unsigned int *min_mhz, unsigned int *max_mh= z) +void intel_process_freq(const struct cpuinfo_x86 *c, + unsigned int *min_mhz, unsigned int *max_mhz) { uint64_t msrval; uint8_t max_ratio, min_ratio; --- a/xen/arch/x86/include/asm/processor.h +++ b/xen/arch/x86/include/asm/processor.h @@ -417,6 +417,9 @@ static inline uint8_t get_cpu_family(uin return fam; } =20 +void intel_process_freq(const struct cpuinfo_x86 *c, + unsigned int *min_mhz, unsigned int *max_mhz); + #ifdef CONFIG_INTEL extern int8_t opt_tsx; extern bool rtm_disabled; --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1664,6 +1664,9 @@ s_time_t get_s_time_fixed(uint64_t at_ts const struct cpu_time *t =3D &this_cpu(cpu_time); uint64_t tsc, delta; =20 + /* scale_delta() degenerates when the scale wasn't set yet. */ + ASSERT(t->tsc_scale.mul_frac); + if ( at_tsc ) tsc =3D at_tsc; else @@ -1679,6 +1682,20 @@ s_time_t get_s_time_fixed(uint64_t at_ts =20 s_time_t get_s_time(void) { + /* + * Before the TSC scale is set, avoid returning constant 0 (or whatever + * this_cpu(cpu_time).stamp.local_stime is set to). While the returned + * value is in no way representing time, it at least increases + * monotonically, thus avoiding e.g. waiting loops to degenerate to + * entirely infinite ones. + */ + if ( unlikely(!this_cpu(cpu_time).tsc_scale.mul_frac) ) + { + static s_time_t counter; + + return arch_fetch_and_add(&counter, 1); + } + return get_s_time_fixed(0); } =20 @@ -2632,6 +2649,22 @@ int __init init_xen_time(void) return 0; } =20 +/* BSP-only function to pre-set an approximate TSC scale. */ +void __init preset_tsc_scale(unsigned long freq) +{ + struct cpu_time *t =3D &this_cpu(cpu_time); + + /* + * The incoming frequency is only approximate (nominal). Increase it = by + * 1% to make NOW() output rather a little too slow than too fast, thus + * avoiding a possible backwards jump once the final scale is set. + */ + freq +=3D DIV_ROUND_UP(freq, 100); + + set_time_scale(&t->tsc_scale, freq); + t->stamp.local_tsc =3D boot_tsc_stamp; + NOW_good =3D true; +} =20 /* Early init function. */ void __init early_time_init(void) @@ -2649,6 +2682,9 @@ void __init early_time_init(void) "TSC ADJUST set to %lx on boot CPU - clearing\n", tmp); wrmsrl(MSR_IA32_TSC_ADJUST, 0); boot_tsc_stamp -=3D tmp; + + if ( t->stamp.local_tsc ) + t->stamp.local_tsc -=3D tmp; } } =20