Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A231DCD4F54 for ; Wed, 20 May 2026 12:31:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1313918.1583936 (Exim 4.92) (envelope-from ) id 1wPg4f-0004fn-Ja; Wed, 20 May 2026 12:30:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1313918.1583936; Wed, 20 May 2026 12:30:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wPg4f-0004fg-Gf; Wed, 20 May 2026 12:30:57 +0000 Received: by outflank-mailman (input) for mailman id 1313918; Wed, 20 May 2026 12:30:57 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wPg4f-0004fa-1Y for xen-devel@lists.xenproject.org; Wed, 20 May 2026 12:30:57 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wPg4e-00H5Oa-Di for xen-devel@lists.xenproject.org; Wed, 20 May 2026 14:30:56 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a0da97a-bab6-0a2a0a5309dd-0a2a4503bdc0-30 for ; Wed, 20 May 2026 14:30:56 +0200 Received: from [209.85.128.48] (helo=mail-wm1-f48.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a0da980-672d-0a2a45030019-d1558030b49f-3 for ; Wed, 20 May 2026 14:30:56 +0200 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-488af96f6b2so51998425e9.0 for ; Wed, 20 May 2026 05:30:56 -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-45d9ed2f738sm52371893f8f.16.2026.05.20.05.30.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 May 2026 05:30:55 -0700 (PDT) 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:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1779280255; x=1779885055; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=DyrjVMz/CBFQOrBzEWGj1Z+FYpZqcVY8M5LwV9dqMSM=; b=SdSAEV+IEEPJoI2rRi6+IVx4fb+/8ZYvWIMstZIWpmV92TNJOojXs72JCxXyLB2+VJ eXLZWkh8OTd84qsIlvethWbc9a9tvrs8eGp22IXlk61wxksi+zklSiLyiBetBTRHAW7w NMEPWs2s4iYCiMrykcKEfpTIhPLagTcFjpc5PhhH2CQWl11ImNb44UX3u8Xd8IpR2Cnb mmeiLcwhRj8gJ6M8x+joSPLrTJP6nUNHhP0s6uq2CHTCU9wFrtPR/XdvFYvCo/sQ5oEG uqayOIu1Yps+f4MMmkQ0gW7yermi/yzvm200lJRiwre+rGGPw2yJAJynbdQVRkVnmBM8 FFdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779280255; x=1779885055; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to: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=DyrjVMz/CBFQOrBzEWGj1Z+FYpZqcVY8M5LwV9dqMSM=; b=Y1w9nYTGvJrWi2Cz8F0uwVqckdUH77IJ0nGZxzPcnFOWl+cT6JLhtoz9eQN+nbSXJ/ n/26CfZoCDkN68gMXs7EnM8CUwd/E7DUJ70mQZ/pwaFwJR2nAKKBs8fm4DRdNvqcpu25 zUgocjY9cEUyrPAS/lCRcLTcahvlthR2N3XoZgw+4FbDb72tsdIBtw2vQu24Fwq77L+6 zlu2tyv3+1zo+RZ5K7XK+a2kSxIwhA3Frt/nNAt+QNnRXUXH8zFCMiwNhgb3zN4JYNGx xnjArI+cwkrhI/rfdsS5LCeq/U0zetE2w0Nuaos3gekGpsu4XGHQ1VPBiU+3hbxr5ZaQ UNRA== X-Gm-Message-State: AOJu0YxEnK8kJald4uxzue5c7ecmBBFdguko3QtYamNUVDkWCFgi/gb7 XE4kKUH/2zDNEfcrgMFBw8TLy2FGHd5gsWpKcFEWDjeAf2yLy0iZAhRay7QpfVv8hMERsV49wx+ WtBU= X-Gm-Gg: Acq92OGd7dSKEreIDyt+JBFKDFqMpk6XfhLj8gDlAZnRNITzEo/rJgG3AnPiCTcGPu2 V/xMZLXwutprTrlNZEMnZ7MiWly/9X5kE/VtDqR15I08ccQ6tkBkdKeBTbYdhYr7f+u/CXPKMSP iZq+AAX0RjeAteR74ZKXbsIk4NzxjJtEuedZINa5TFCHh1rVjZycVSAKhZubKTi+6x9OlNWUWsY Z5qdd5+B15lE7AId+zPERXj9Pu0kCgS3hHP0BKV9TRLT6U/Yy21b00ewSQrQRVzSOXDGBxWhFfb MDTAsv/mYn6TcqA8iMEoVCtk6/O2u7JVeeJrPE2jCB6YlZF4uOtT7LqLtPlDjbUVsmM2+uthc3Y IHMzhcgV9PFHHBuiXPPqh1FFlhgA2EXcrMJppHS+Pvgw8GMjDwnt8o27nl2YzfTLrNYU2efQ0Su /Vsrhno/s4ebinA9v+g4+7HILhAopAeqMQysRdFSXgMGs/O6WepQXNZ2Ry8Qk93B/k52g6UjvcD hwf2MrrL5aaKZI= X-Received: by 2002:a05:600c:4504:b0:48f:d1b8:9a9c with SMTP id 5b1f17b1804b1-48fe60e14bamr350630225e9.7.1779280255553; Wed, 20 May 2026 05:30:55 -0700 (PDT) Message-ID: <02d7f002-dc14-497e-bae9-a8c0c9460fac@suse.com> Date: Wed, 20 May 2026 14:30:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 RFC] x86/time: avoid early uses of NOW() to return zero To: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Cc: "xen-devel@lists.xenproject.org" , Andrew Cooper , Teddy Astie References: <68b1607a-f2a1-4f53-84c5-43c61eeb1869@suse.com> <8fbab1f4-3078-4ac3-b147-84d1b5f5abd1@suse.com> <547161b2-2fea-4576-a635-62838ffa2d33@suse.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4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BH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-33051d/1779280256-3754F938-9332087E/0/0 X-purgate-type: clean X-purgate-size: 3325 On 20.05.2026 12:02, Roger Pau Monné wrote: > On Mon, May 18, 2026 at 10:05:41AM +0200, Jan Beulich wrote: >> On 15.05.2026 15:12, Roger Pau Monné wrote: >>> On Fri, May 15, 2026 at 09:15:40AM +0200, Jan Beulich wrote: >>>> On 14.05.2026 17:56, Roger Pau Monné wrote: >>>>> On Wed, May 13, 2026 at 08:44:46AM +0200, Jan Beulich wrote: >>>>>> @@ -2623,6 +2640,21 @@ int __init init_xen_time(void) >>>>>> return 0; >>>>>> } >>>>>> >>>>>> +/* BSP-only function to pre-set an approximate TSC scale. */ >>>>>> +void __init preset_tsc_scale(unsigned long freq) >>>>>> +{ >>>>>> + struct cpu_time *t = &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 += DIV_ROUND_UP(freq, 100); >>>>> >>>>> To avoid such possible jump backwards, won't it safer to also update >>>>> the ->local_stime and ->local_tsc fields at the time the new scale is >>>>> set? Updatign those ahead of setting the new scale should avoid any >>>>> backward jumps. >>>> >>>> ->stamp.local_tsc does get updated; you merely dropped that line from reply >>>> context. As to local_stime - how could we possibly set that, when we didn't >>>> get through init_platform_timer() yet? Leaving it at 0 is the correct >>>> match for setting local_tsc to boot_tsc_stamp. >>> >>> Please bear with me, maybe I'm not understanding exactly to what the >>> code comment refers to as "possible backwards jump once the final >>> scale is set". I assume you refer to the setting of scale >>> early_time_init()? The ->stamp.local_tsc value also gets updated at >>> that point, so it's not possible for the timer going backwards? >> >> It is updated there, but only to boot_tsc_stamp. I.e. no change at all >> if preset_tsc_scale() set the field already. > > Couldn't we do the following in early_init_time() to ensure time > doesn't go backwards: > > if ( t->tsc_scale.mul_frac ) > { > /* > * Update time snapshot to ensure time doesn't go backwards as a > * result of the scale change done below. > */ > t->stamp.local_tsc = rdtsc_ordered(); > t->stamp.local_stime = get_s_time_fixed(t->stamp.local_tsc); > } > else > t->stamp.local_tsc = boot_tsc_stamp; > > set_time_scale(&t->tsc_scale, tmp); > init_percpu_time(); Yes, this would prevent stime going backwards. But at the same time it would latch the imprecise calculations done initially. The farther off the initial scale (e.g. when using "high" in case "nominal" isn't available, as discussed previously), the bigger the error. That may be mainly (only?) a cosmetic thing, but still. Actually, if we did that, what would prevent stime going backwards by the update done in init_percpu_time()? Aiui we really want .local_stime to be written there for the very first time. > That's kind of the same logic that's used in cpu_frequency_change() > ahead of calling set_time_scale(). That function is ripe for removal anyway, so I'm hesitant to derive anything from it. Jan