From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH] x86/time: adjust handling of negative delta in stime2tsc()
Date: Wed, 25 Mar 2026 18:57:19 +0100 [thread overview]
Message-ID: <acQh__WRAoav6IHN@macbook.local> (raw)
In-Reply-To: <f97bbfb5-389c-4845-84fb-e6f07ba0ade8@suse.com>
On Tue, Feb 10, 2026 at 11:04:59AM +0100, Jan Beulich wrote:
> When we cap negative values to 0 (see code comment as to why), going
> through scale_delta() is pointless - it'll return 0 anyway. Therefore make
> the call conditional (and then also the one to scale_reciprocal()), adding
> a comment as to why there is this capping.
>
> Modernize types used while there, and switch to usiong initializers for
> the local variables.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> Adding likely() to the conditional here does make a difference. Question
> is whether to do so, seeing that there looks to be a possibility (of
> unknown frequency) for the delta to be non-positive.
Hm, what I've done lately with {un}likely() is not attempting to
optimize for the most taken path, but rather use it to force the
compiler to optimize the fast path, if the function has one. The slow
path will be slow anyway, and hence any compiler optimization should
be towards making the fast path possibly faster IMO.
This function doesn't seem to have any fast (or slow) paths, so I
would leave it as-is.
>
> --- a/xen/arch/x86/time.c
> +++ b/xen/arch/x86/time.c
> @@ -1176,20 +1176,26 @@ uint64_t __init calibrate_apic_timer(voi
> return elapsed * CALIBRATE_FRAC;
> }
>
> -u64 stime2tsc(s_time_t stime)
> +uint64_t stime2tsc(s_time_t stime)
> {
> - struct cpu_time *t;
> - struct time_scale sys_to_tsc;
> - s_time_t stime_delta;
> + const struct cpu_time *t = &this_cpu(cpu_time);
> + s_time_t stime_delta = stime - t->stamp.local_stime;
> + int64_t delta = 0;
Why do you make delta a signed integer, the value returned by
scale_delta() is unsigned.
>
> - t = &this_cpu(cpu_time);
> - sys_to_tsc = scale_reciprocal(t->tsc_scale);
> + /*
> + * While for reprogram_timer() the capping at 0 isn't relevant (the returned
The capping might want mentioning in the function prototype, as maybe
new users expect stime2tsc() to return TSC values from times in the
past.
Otherwise LGTM.
Thanks, Roger.
next prev parent reply other threads:[~2026-03-25 17:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-10 10:04 [PATCH] x86/time: adjust handling of negative delta in stime2tsc() Jan Beulich
2026-03-25 17:57 ` Roger Pau Monné [this message]
2026-03-26 8:05 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=acQh__WRAoav6IHN@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.