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

[Xen-changelog] [xen-unstable] [XEN] Various cleanups to bitops usage.



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxxxx
# Node ID 30a5eb240a20026ad99bd371dba6ae4051dfe06b
# Parent  02b0ed160e8ef9b8cdfd8b7e4fdd58fb19f7b344
[XEN] Various cleanups to bitops usage.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 xen/arch/x86/hvm/vioapic.c       |   11 +-----
 xen/arch/x86/hvm/vlapic.c        |   10 +++---
 xen/arch/x86/smp.c               |    5 +--
 xen/include/asm-x86/bitops.h     |   30 ++++++++----------
 xen/include/asm-x86/hvm/vlapic.h |   62 ++++++---------------------------------
 xen/include/public/hvm/ioreq.h   |    5 ---
 6 files changed, 36 insertions(+), 87 deletions(-)

diff -r 02b0ed160e8e -r 30a5eb240a20 xen/arch/x86/hvm/vioapic.c
--- a/xen/arch/x86/hvm/vioapic.c        Tue Jun 27 12:17:45 2006 +0100
+++ b/xen/arch/x86/hvm/vioapic.c        Tue Jun 27 14:34:52 2006 +0100
@@ -450,14 +450,9 @@ static void ioapic_deliver(hvm_vioapic_t
 
 static int ioapic_get_highest_irq(hvm_vioapic_t *s)
 {
-    uint32_t irqs;
-
-    ASSERT(s);
-
-    irqs = s->irr & ~s->isr & ~s->imr;
-    return __fls(irqs);
-}
-
+    uint32_t irqs = s->irr & ~s->isr & ~s->imr;
+    return fls(irqs) - 1;
+}
 
 static void service_ioapic(hvm_vioapic_t *s)
 {
diff -r 02b0ed160e8e -r 30a5eb240a20 xen/arch/x86/hvm/vlapic.c
--- a/xen/arch/x86/hvm/vlapic.c Tue Jun 27 12:17:45 2006 +0100
+++ b/xen/arch/x86/hvm/vlapic.c Tue Jun 27 14:34:52 2006 +0100
@@ -50,7 +50,7 @@ int vlapic_find_highest_irr(struct vlapi
 {
     int result;
 
-    result = find_highest_bit((uint32_t *)&vlapic->irr[0], INTR_LEN_32);
+    result = find_highest_bit(vlapic->irr, MAX_VECTOR);
 
     if ( result != -1 && result < 16 )
     {
@@ -79,14 +79,14 @@ int vlapic_find_highest_isr(struct vlapi
 {
     int result;
 
-    result = find_highest_bit((uint32_t *)&vlapic->isr[0], INTR_LEN_32);
+    result = find_highest_bit(vlapic->isr, MAX_VECTOR);
 
     if ( result != -1 && result < 16 )
     {
         int i = 0;
         printk("VLAPIC: isr on reserved bits %d, isr is\n ", result);
-        for ( i = 0; i < INTR_LEN_32; i += 2 )
-            printk("%d: 0x%08x%08x\n", i, vlapic->isr[i], vlapic->isr[i+1]);
+        for ( i = 0; i < ARRAY_SIZE(vlapic->isr); i++ )
+            printk("%d: %p\n", i, (void *)vlapic->isr[i]);
         return -1;
     }
 
@@ -896,7 +896,7 @@ vlapic_check_direct_intr(struct vcpu *v,
     struct vlapic *vlapic = VLAPIC(v);
     int type;
 
-    type = __fls(vlapic->direct_intr.deliver_mode);
+    type = fls(vlapic->direct_intr.deliver_mode) - 1;
     if ( type == -1 )
         return -1;
 
diff -r 02b0ed160e8e -r 30a5eb240a20 xen/arch/x86/smp.c
--- a/xen/arch/x86/smp.c        Tue Jun 27 12:17:45 2006 +0100
+++ b/xen/arch/x86/smp.c        Tue Jun 27 14:34:52 2006 +0100
@@ -302,8 +302,9 @@ int on_selected_cpus(
 
 static void stop_this_cpu (void *dummy)
 {
-    clear_bit(smp_processor_id(), &cpu_online_map);
-
+    cpu_clear(smp_processor_id(), cpu_online_map);
+
+    local_irq_disable();
     disable_local_APIC();
 
     for ( ; ; )
diff -r 02b0ed160e8e -r 30a5eb240a20 xen/include/asm-x86/bitops.h
--- a/xen/include/asm-x86/bitops.h      Tue Jun 27 12:17:45 2006 +0100
+++ b/xen/include/asm-x86/bitops.h      Tue Jun 27 14:34:52 2006 +0100
@@ -335,8 +335,6 @@ static inline unsigned long ffz(unsigned
        return word;
 }
 
-#define fls64(x)   generic_fls64(x)
-
 /**
  * ffs - find first bit set
  * @x: the word to search
@@ -345,15 +343,15 @@ static inline unsigned long ffz(unsigned
  * the libc and compiler builtin ffs routines, therefore
  * differs in spirit from the above ffz (man ffs).
  */
-static inline int ffs(int x)
-{
-       int r;
-
-       __asm__("bsfl %1,%0\n\t"
+static inline int ffs(unsigned long x)
+{
+       long r;
+
+       __asm__("bsf %1,%0\n\t"
                "jnz 1f\n\t"
-               "movl $-1,%0\n"
+               "mov $-1,%0\n"
                "1:" : "=r" (r) : "rm" (x));
-       return r+1;
+       return (int)r+1;
 }
 
 /**
@@ -362,15 +360,15 @@ static inline int ffs(int x)
  *
  * This is defined the same way as ffs.
  */
-static inline int fls(int x)
-{
-       int r;
-
-       __asm__("bsrl %1,%0\n\t"
+static inline int fls(unsigned long x)
+{
+       long r;
+
+       __asm__("bsr %1,%0\n\t"
                "jnz 1f\n\t"
-               "movl $-1,%0\n"
+               "mov $-1,%0\n"
                "1:" : "=r" (r) : "rm" (x));
-       return r+1;
+       return (int)r+1;
 }
 
 /**
diff -r 02b0ed160e8e -r 30a5eb240a20 xen/include/asm-x86/hvm/vlapic.h
--- a/xen/include/asm-x86/hvm/vlapic.h  Tue Jun 27 12:17:45 2006 +0100
+++ b/xen/include/asm-x86/hvm/vlapic.h  Tue Jun 27 14:34:52 2006 +0100
@@ -23,52 +23,12 @@
 #include <asm/msr.h>
 #include <public/hvm/ioreq.h>
 
-#if defined(__i386__) || defined(__x86_64__)
-static inline int __fls(uint32_t word)
+static __inline__ int find_highest_bit(unsigned long *data, int nr_bits)
 {
-    int bit;
-
-    __asm__("bsrl %1,%0"
-      :"=r" (bit)
-      :"rm" (word));
-    return word ? bit : -1;
-}
-#else
-#define __fls(x)    generic_fls(x)
-static __inline__ int generic_fls(uint32_t x)
-{
-    int r = 31;
-
-    if (!x)
-        return -1;
-    if (!(x & 0xffff0000u)) {
-        x <<= 16;
-        r -= 16;
-    }
-    if (!(x & 0xff000000u)) {
-        x <<= 8;
-        r -= 8;
-    }
-    if (!(x & 0xf0000000u)) {
-        x <<= 4;
-        r -= 4;
-    }
-    if (!(x & 0xc0000000u)) {
-        x <<= 2;
-        r -= 2;
-    }
-    if (!(x & 0x80000000u)) {
-        x <<= 1;
-        r -= 1;
-    }
-    return r;
-}
-#endif
-
-static __inline__ int find_highest_bit(uint32_t *data, int length)
-{
-    while(length && !data[--length]);
-    return __fls(data[length]) +  32 * length;
+    int length = BITS_TO_LONGS(nr_bits);
+    while ( length && !data[--length] )
+        continue;
+    return (fls(data[length]) - 1) + (length * BITS_PER_LONG);
 }
 
 #define VLAPIC(v)                       (v->arch.hvm_vcpu.vlapic)
@@ -146,17 +106,17 @@ typedef struct direct_intr_info {
     int source[6];
 } direct_intr_info_t;
 
-struct vlapic
-{
-    //FIXME check what would be 64 bit on EM64T
+#define MAX_VECTOR      256
+
+struct vlapic {
     uint32_t           version;
     uint32_t           status;
     uint32_t           id;
     uint32_t           vcpu_id;
     unsigned long      base_address;
-    uint32_t           isr[8];
-    uint32_t           irr[INTR_LEN_32];
-    uint32_t           tmr[INTR_LEN_32];
+    unsigned long      isr[BITS_TO_LONGS(MAX_VECTOR)];
+    unsigned long      irr[BITS_TO_LONGS(MAX_VECTOR)];
+    unsigned long      tmr[BITS_TO_LONGS(MAX_VECTOR)];
     uint32_t           task_priority;
     uint32_t           processor_priority;
     uint32_t           logical_dest;
diff -r 02b0ed160e8e -r 30a5eb240a20 xen/include/public/hvm/ioreq.h
--- a/xen/include/public/hvm/ioreq.h    Tue Jun 27 12:17:45 2006 +0100
+++ b/xen/include/public/hvm/ioreq.h    Tue Jun 27 14:34:52 2006 +0100
@@ -58,11 +58,6 @@ struct ioreq {
 };
 typedef struct ioreq ioreq_t;
 
-#define MAX_VECTOR      256
-#define BITS_PER_BYTE   8
-#define INTR_LEN        (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint64_t)))
-#define INTR_LEN_32     (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint32_t)))
-
 struct global_iodata {
     uint16_t    pic_elcr;
     uint16_t    pic_irr;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
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®.