From: Mark Cartwright Date: Thu, 19 Jul 2012 21:24:19 +0000 (-0500) Subject: Additional features for vmm_bitmap X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=e61e0890e6f13b1362cfffdcd287e90f1d41e443;p=palacios.git Additional features for vmm_bitmap --- diff --git a/palacios/include/palacios/vmm_bitmap.h b/palacios/include/palacios/vmm_bitmap.h index 4842585..29cabb7 100644 --- a/palacios/include/palacios/vmm_bitmap.h +++ b/palacios/include/palacios/vmm_bitmap.h @@ -41,7 +41,8 @@ int v3_bitmap_set(struct v3_bitmap * bitmap, int index); int v3_bitmap_clear(struct v3_bitmap * bitmap, int index); int v3_bitmap_check(struct v3_bitmap * bitmap, int index); - +int v3_bitmap_count(struct v3_bitmap * bitmap); +int v3_bitmap_copy(struct v3_bitmap * dst, struct v3_bitmap * src); #endif diff --git a/palacios/src/palacios/vmm_bitmap.c b/palacios/src/palacios/vmm_bitmap.c index 0f26473..14b042d 100644 --- a/palacios/src/palacios/vmm_bitmap.c +++ b/palacios/src/palacios/vmm_bitmap.c @@ -99,3 +99,36 @@ int v3_bitmap_check(struct v3_bitmap * bitmap, int index) { return ((bitmap->bits[major] & (0x1 << minor)) != 0); } + +int v3_bitmap_count(struct v3_bitmap * bitmap) { + + int cnt = 0; + int i; + uint8_t x; + uint8_t * bytes = bitmap->bits; + int num_bytes = (bitmap->num_bits / 8) + ((bitmap->num_bits % 8) > 0); + + for (i=0; i < num_bytes; i++) { + x = bytes[i]; + while (x) { + cnt += (x & 0x1); + x>>=1; + } + } + + return cnt; +} + +int v3_bitmap_copy(struct v3_bitmap * dst, struct v3_bitmap * src) { + + if (src->num_bits != dst->num_bits) { + PrintError("src and dst must be the same size.\n"); + return -1; + } + + int num_bytes = (src->num_bits / 8) + ((src->num_bits % 8)!=0); + + memcpy(dst->bits,src->bits,num_bytes); + + return 0; +}