diff mbox

Fix calculation of number of bits in the migration bitmap

Message ID 1351682381-8793-1-git-send-email-owasserm@redhat.com
State New
Headers show

Commit Message

Orit Wasserman Oct. 31, 2012, 11:19 a.m. UTC
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.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 arch_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Avi Kivity Oct. 31, 2012, 11:24 a.m. UTC | #1
On 10/31/2012 01:19 PM, Orit Wasserman wrote:
> 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.
> 
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
> ---
>  arch_init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch_init.c b/arch_init.c
> index b75a4c5..a80c3c8 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -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.
Peter Maydell Oct. 31, 2012, 11:25 a.m. UTC | #2
On 31 October 2012 12:19, Orit Wasserman <owasserm@redhat.com> wrote:
> 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.
>
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
> ---
>  arch_init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch_init.c b/arch_init.c
> index b75a4c5..a80c3c8 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -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
Orit Wasserman Oct. 31, 2012, noon UTC | #3
On 10/31/2012 01:24 PM, Avi Kivity wrote:
> On 10/31/2012 01:19 PM, Orit Wasserman wrote:
>> 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.
>>
>> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
>> ---
>>  arch_init.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch_init.c b/arch_init.c
>> index b75a4c5..a80c3c8 100644
>> --- a/arch_init.c
>> +++ b/arch_init.c
>> @@ -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 ...

> 
>
Orit Wasserman Oct. 31, 2012, 12:04 p.m. UTC | #4
On 10/31/2012 01:25 PM, Peter Maydell wrote:
> On 31 October 2012 12:19, Orit Wasserman <owasserm@redhat.com> wrote:
>> 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.
>>
>> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
>> ---
>>  arch_init.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch_init.c b/arch_init.c
>> index b75a4c5..a80c3c8 100644
>> --- a/arch_init.c
>> +++ b/arch_init.c
>> @@ -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 ...
> ?
> 
> -- PMM
>
diff mbox

Patch

diff --git a/arch_init.c b/arch_init.c
index b75a4c5..a80c3c8 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -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);