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>,
Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>,
Anthony PERARD <anthony.perard@vates.tech>,
Michal Orzel <michal.orzel@amd.com>
Subject: Re: [PATCH] domain: use unsigned loop induction variable in complete_domain_destroy()
Date: Wed, 4 Mar 2026 16:38:46 +0100 [thread overview]
Message-ID: <aahSBk--J_xqEzOq@macbook.local> (raw)
In-Reply-To: <7af56fa6-4254-4704-9843-a0d099e6bb0b@suse.com>
On Thu, Feb 26, 2026 at 10:01:45AM +0100, Jan Beulich wrote:
> Using plain (signed) int variables as array indexes can be unhelpful on at
> least x86, where the compiler may see the need to insert sign-extension
> insns (strictly speaking it should be able to avoid that when the loop
> continuation condition says >= 0, but that's not generally the case even
> with gcc15).
>
> Observed effects with gcc15 (will of course vary with compiler version and
> level of optimization):
> - on x86, one less preserved register in use, yet due to sub-optimal
> choice of register variables still a small code size increase (%r12
> isn't a good choice when it's used for base-without-index addressing, as
> it requires a SIB byte which other registers wouldn't require),
> - on Arm64 code size decreases, albeit that's eaten up by padding which is
> being inserted ahead of a few labels,
> - on Arm32 code size increases for a reason I didn't fully understand (my
> ability to read Arm assembly is still somewhat limited).
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -1475,7 +1475,7 @@ static void cf_check complete_domain_des
> {
> struct domain *d = container_of(head, struct domain, rcu);
> struct vcpu *v;
> - int i;
> + unsigned int i;
>
> /*
> * Flush all state for the vCPU previously having run on the current CPU.
> @@ -1485,7 +1485,7 @@ static void cf_check complete_domain_des
> */
> sync_local_execstate();
>
> - for ( i = d->max_vcpus - 1; i >= 0; i-- )
> + for ( i = d->max_vcpus; i-- > 0; )
Is there any reason we need to do those loops backwards?
I would rather do:
for ( i = 0; i < d->max_vcpus; i++ )
?
Thanks, Roger.
next prev parent reply other threads:[~2026-03-04 15:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 9:01 [PATCH] domain: use unsigned loop induction variable in complete_domain_destroy() Jan Beulich
2026-03-04 15:38 ` Roger Pau Monné [this message]
2026-03-04 15:48 ` Jan Beulich
2026-03-04 17:36 ` Roger Pau Monné
2026-03-05 8:07 ` Jan Beulich
2026-03-05 8:15 ` Roger Pau Monné
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=aahSBk--J_xqEzOq@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--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.