From aa1355f971287932e2ba09dfb04a6122ecc3951f Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Fri, 10 Jun 2011 10:47:03 +0200 Subject: tools: merge several bitop functions into xc_bitops.h Bitmaps are used in save/restore, xenpaging and blktap2. Merge the code into a private xc_bitops.h file. All users are single threaded, so locking is not an issue. The array of bits is handled as volatile because the x86 save/restore code passes the bitmap to the hypervisor which in turn modifies the bitmap. blktap2 uses a private bitmap. There was a possible overflow in the bitmap_size() function, the remainder was not considered. ia64 save/restore uses a bitmap to send the number of vcpus to the host. x86 save/restore uses a bitmap to track dirty pages. This bitmap is shared with the hypervisor. An unused function count_bits() was removed and a new bitmap_size() function is now used. xenpaging uses 3 private bitmaps to track the gfns which are in paged-out state. It had a copy of some Linux bitops.h, which is now obsolete. Also the BITS_PER_LONG macro was hardcoded to 64 which made it impossible to run 32bit tools on a 64bit host. Wether this works at all has to be tested, yet. Signed-off-by: Olaf Hering Committed-by: Ian Jackson --- tools/xenpaging/policy_default.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'tools/xenpaging/policy_default.c') diff --git a/tools/xenpaging/policy_default.c b/tools/xenpaging/policy_default.c index a53f5560f6..55a0ae8470 100644 --- a/tools/xenpaging/policy_default.c +++ b/tools/xenpaging/policy_default.c @@ -21,8 +21,7 @@ */ -#include "bitops.h" -#include "xc.h" +#include "xc_bitops.h" #include "policy.h" @@ -35,26 +34,23 @@ static unsigned int mru_size; static unsigned long *bitmap; static unsigned long *unconsumed; static unsigned long current_gfn; -static unsigned long bitmap_size; static unsigned long max_pages; int policy_init(xenpaging_t *paging) { int i; - int rc; + int rc = -ENOMEM; /* Allocate bitmap for pages not to page out */ - rc = alloc_bitmap(&bitmap, paging->bitmap_size); - if ( rc != 0 ) + bitmap = bitmap_alloc(paging->domain_info->max_pages); + if ( !bitmap ) goto out; /* Allocate bitmap to track unusable pages */ - rc = alloc_bitmap(&unconsumed, paging->bitmap_size); - if ( rc != 0 ) + unconsumed = bitmap_alloc(paging->domain_info->max_pages); + if ( !unconsumed ) goto out; - /* record bitmap_size */ - bitmap_size = paging->bitmap_size; max_pages = paging->domain_info->max_pages; /* Initialise MRU list of paged in pages */ @@ -65,10 +61,7 @@ int policy_init(xenpaging_t *paging) mru = malloc(sizeof(*mru) * mru_size); if ( mru == NULL ) - { - rc = -ENOMEM; goto out; - } for ( i = 0; i < mru_size; i++ ) mru[i] = INVALID_MFN; @@ -76,6 +69,7 @@ int policy_init(xenpaging_t *paging) /* Don't page out page 0 */ set_bit(0, bitmap); + rc = 0; out: return rc; } -- cgit v1.2.3