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

[xen staging] x86/hpet: use an atomic add instead of a cmpxchg loop



commit f49fb70d3d4c1729fce825f0fda6863ac3ec00e0
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Mon Feb 26 10:16:56 2024 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Feb 26 10:16:56 2024 +0100

    x86/hpet: use an atomic add instead of a cmpxchg loop
    
    The usage of a cmpxchg loop in hpet_get_channel() is unnecessary, as the 
same
    can be achieved with an atomic increment, which is both simpler to read, and
    avoid any need for a loop.
    
    Note there can be a small divergence in the channel returned if next_channel
    overflows, but returned channel will always be in the [0, num_hpets_used)
    range, and that's fine for the purpose of balancing HPET channels across 
CPUs.
    
    Signed-of-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 xen/arch/x86/hpet.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/xen/arch/x86/hpet.c b/xen/arch/x86/hpet.c
index d9e9c8ffa3..0759eae055 100644
--- a/xen/arch/x86/hpet.c
+++ b/xen/arch/x86/hpet.c
@@ -457,11 +457,7 @@ static struct hpet_event_channel 
*hpet_get_channel(unsigned int cpu)
     if ( num_hpets_used >= nr_cpu_ids )
         return &hpet_events[cpu];
 
-    do {
-        next = next_channel;
-        if ( (i = next + 1) == num_hpets_used )
-            i = 0;
-    } while ( cmpxchg(&next_channel, next, i) != next );
+    next = arch_fetch_and_add(&next_channel, 1) % num_hpets_used;
 
     /* try unused channel first */
     for ( i = next; i < next + num_hpets_used; i++ )
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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