[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] domain: use unsigned loop induction variable in complete_domain_destroy()


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 4 Mar 2026 16:38:46 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9JXynPD0+Hi+BE1VZ+yaXhtAgc15KDOeqO9w/iTbPH8=; b=RO0oR8kkEVew0/JBy5KYFnt4c5gnubRXfDRZG+FxG/P+aDpyR1IyVNLGXu2zKg29Z0KiEucMSodeAbDQmM74FPlIysuk+xfrR5u1c3NEXTp9AUB4HsaonFKcWxGbR22y9HZbB622SQx6UXpkzfBWfw0kX3YVB9BOoTyorZ6wN49D2GwFaxtZlNZwPYAJnWuLwWGv6+tt3XLV7L+nluiQzu7a7dLwm/KhzuIEdGP19BXqdRe272ZH6c6b1JuI1mYae+s0IVff+eq3ye834FVfT4oDHZTt9Y1XQhYPvwXX5qYKIN5mEF5e9IhzJnoD6jCCwt8kEqVaiZnmrDzVPv2PlQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lLRIeppK4R45mskrmzkA0YT9Sl6xcEXicRxy3vI/4veyc/DLgc+fccfcIHF5Fi6qTOU4gduBGNln4WhKcJNqo2saftxPBauzn7IYJrUhKan0oY8tjAx9uh8gfJzkl6PUPbxiSI+jhRfVD8P2Whof5PqoajcUqTZd78Duhe9nRnXyLxo4V0IA2WiEL+A0JSr+5E6ZAnuVtIni/6LtIy/rRLZCsArWuZJoVuFJj3Hge0y2RNDutaRQOyUHXDOeAREyF9fowgap+PjYh3D5SayqHd/eDpjAOPvu+gtdsocidZfogRW+YGT3kwhqjZwwnFPvmrbTyOO1zbAolRFjSGZgqQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Wed, 04 Mar 2026 15:39:02 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxx>
> 
> --- 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.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.