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

[Xen-changelog] [xen-unstable] x86/hpet: simplify hpet_get_channel()



# HG changeset patch
# User Jan Beulich <jbeulich@xxxxxxxx>
# Date 1332515609 -3600
# Node ID 2ca43b65718fbe2d3f9ea36132e139ef774d9a11
# Parent  5863a55b807ef9111e3159e61e0ca52a55b5c215
x86/hpet: simplify hpet_get_channel()

There's no need for a lock here, elimination of which makes the
function a leaf one, thus allowing for better (and smaller) code.

Further, use the variable next_channel according to its name - so far
it represented the most recently used channel rather than the next one
to use.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Keir Fraser <keir@xxxxxxx>
---


diff -r 5863a55b807e -r 2ca43b65718f xen/arch/x86/hpet.c
--- a/xen/arch/x86/hpet.c       Fri Mar 23 15:08:17 2012 +0000
+++ b/xen/arch/x86/hpet.c       Fri Mar 23 16:13:29 2012 +0100
@@ -402,16 +402,17 @@
 static struct hpet_event_channel *hpet_get_channel(unsigned int cpu)
 {
     static unsigned int next_channel;
-    static spinlock_t next_lock = SPIN_LOCK_UNLOCKED;
     unsigned int i, next;
     struct hpet_event_channel *ch;
 
     if ( num_hpets_used == 0 )
         return hpet_events;
 
-    spin_lock(&next_lock);
-    next = next_channel = (next_channel + 1) % num_hpets_used;
-    spin_unlock(&next_lock);
+    do {
+        next = next_channel;
+        if ( (i = next + 1) == num_hpets_used )
+            i = 0;
+    } while ( cmpxchg(&next_channel, next, i) != next );
 
     /* try unused channel first */
     for ( i = next; i < next + num_hpets_used; i++ )

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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