Skip to contentSkip to conversation

Fix calculation of number of bits in the migration bitmap

PATCH In review Orit Wasserman 3 participants 5 messages Oct 31, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix calculation of number of bits in the migration bitmap

The number of bits is off by one, for example if last_ram_offset is 0x1000 (the guest has one page) we get 0 bits instead of 1.

---
 arch_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch_init.c +1 -1
index b75a4c5..a80c3c8 100644
@@ -565,7 +565,7 @@ static void reset_ram_globals(void)
 static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
-    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
+    int64_t ram_pages = (last_ram_offset() >> TARGET_PAGE_BITS) + 1;
 
     migration_bitmap = bitmap_new(ram_pages);
     bitmap_set(migration_bitmap, 0, ram_pages);
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 13 lines · Orit Wasserman

The number of bits is off by one, for example if last_ram_offset is 0x1000 (the guest has one page) we get 0 bits instead of 1.

---
 arch_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch_init.c +0 -0
index b75a4c5..a80c3c8 100644

arch_init.c static void reset_ram_globals(void) · line 569

Quoted 6 lines
arch_init.c +1 -1
@@ -565,7 +565,7 @@ static void reset_ram_globals(void)
 static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
-    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
+    int64_t ram_pages = (last_ram_offset() >> TARGET_PAGE_BITS) + 1;
 

The original code calculates 1 for your example case.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Orit Wasserman

The number of bits is off by one, for example if last_ram_offset is 0x1000 (the guest has one page) we get 0 bits instead of 1.

---
 arch_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch_init.c static void reset_ram_globals(void) · line 569

Quoted 11 lines
arch_init.c +1 -1
index b75a4c5..a80c3c8 100644
@@ -565,7 +565,7 @@ static void reset_ram_globals(void)
 static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
-    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
+    int64_t ram_pages = (last_ram_offset() >> TARGET_PAGE_BITS) + 1;
 

The original code calculates 1 for your example case.

You correct ...
sorry ...

Quoted 2 lines
#3 lore raw
In reply to Orit Wasserman
Quoted 13 lines · Orit Wasserman

The number of bits is off by one, for example if last_ram_offset is 0x1000 (the guest has one page) we get 0 bits instead of 1.

---
 arch_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch_init.c +0 -0
index b75a4c5..a80c3c8 100644

arch_init.c static void reset_ram_globals(void) · line 568

Quoted 5 lines
arch_init.c +1 -1
@@ -565,7 +565,7 @@ static void reset_ram_globals(void)
 static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
-    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
+    int64_t ram_pages = (last_ram_offset() >> TARGET_PAGE_BITS) + 1;

This will give you an extra bit if the last_ram_offset()
is an exact multiple of the page size, though. Try
int64_t ram_pages = DIV_ROUND_UP(last_ram_offset(), TARGET_PAGE_SIZE);
?

-- PMM

#4 lore raw
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Orit Wasserman

The number of bits is off by one, for example if last_ram_offset is 0x1000 (the guest has one page) we get 0 bits instead of 1.

---
 arch_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

arch_init.c static void reset_ram_globals(void) · line 568

Quoted 10 lines
arch_init.c +1 -1
index b75a4c5..a80c3c8 100644
@@ -565,7 +565,7 @@ static void reset_ram_globals(void)
 static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
-    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
+    int64_t ram_pages = (last_ram_offset() >> TARGET_PAGE_BITS) + 1;

This will give you an extra bit if the last_ram_offset()
is an exact multiple of the page size, though. Try
int64_t ram_pages = DIV_ROUND_UP(last_ram_offset(), TARGET_PAGE_SIZE);

Good idea ...

Quoted 4 lines

?

-- PMM