Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


make bitmap operations atomic, fixes potential barrier race condition
Jack Lange [Wed, 4 Jul 2012 22:03:15 +0000 (18:03 -0400)]
palacios/include/palacios/vmm_bitmap.h
palacios/src/palacios/vmm_bitmap.c

index 29cabb7..04ae22d 100644 (file)
 
 #ifdef __V3VEE__
 #include <palacios/vmm_types.h>
+#include <palacios/vmm_lock.h>
 
 
 
 struct v3_bitmap {
+    v3_lock_t lock; 
     int num_bits;      // number of valid bit positions in the bitmap
     uint8_t * bits;   // actual bitmap. Dynamically allocated... ugly
 };
index 14b042d..ff7a7a7 100644 (file)
 int v3_bitmap_init(struct v3_bitmap * bitmap, int num_bits) {
     int num_bytes = (num_bits / 8) + ((num_bits % 8) > 0);
 
+    v3_lock_init(&(bitmap->lock));
     bitmap->num_bits = num_bits;
     bitmap->bits = V3_Malloc(num_bytes);
 
+
     if (bitmap->bits == NULL) {
        PrintError("Could not allocate bitmap of %d bits\n", num_bits);
        return -1;
@@ -55,6 +57,7 @@ int v3_bitmap_set(struct v3_bitmap * bitmap, int index) {
     int major = index / 8;
     int minor = index % 8;
     int old_val = 0;
+    uint32_t flags = 0;
 
     if (index > (bitmap->num_bits - 1)) {
        PrintError("Index out of bitmap range: (pos = %d) (num_bits = %d)\n", 
@@ -62,9 +65,14 @@ int v3_bitmap_set(struct v3_bitmap * bitmap, int index) {
        return -1;
     }
 
+
+    flags = v3_lock_irqsave(bitmap->lock);
+
     old_val = (bitmap->bits[major] & (0x1 << minor));
     bitmap->bits[major] |= (0x1 << minor);
 
+    v3_unlock_irqrestore(bitmap->lock, flags);
+
     return old_val;
 }
 
@@ -73,6 +81,7 @@ int v3_bitmap_clear(struct v3_bitmap * bitmap, int index) {
     int major = index / 8;
     int minor = index % 8;
     int old_val = 0;
+    uint32_t flags = 0;
 
     if (index > (bitmap->num_bits - 1)) {
        PrintError("Index out of bitmap range: (pos = %d) (num_bits = %d)\n", 
@@ -80,9 +89,13 @@ int v3_bitmap_clear(struct v3_bitmap * bitmap, int index) {
        return -1;
     }
 
+    flags = v3_lock_irqsave(bitmap->lock);
+
     old_val = (bitmap->bits[major] & (0x1 << minor));
     bitmap->bits[major] &= ~(0x1 << minor);
 
+    v3_unlock_irqrestore(bitmap->lock, flags);
+
     return old_val;
 }