All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-trivial@nongnu.org, quintela@redhat.com,
	qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 7/7] migration: do floating-point division
Date: Mon, 26 Jan 2015 18:06:47 +0000	[thread overview]
Message-ID: <20150126180647.GD2291@work-vm> (raw)
In-Reply-To: <1422270747-23994-8-git-send-email-pbonzini@redhat.com>

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> Dividing integer expressions transferred_bytes and time_spent, and then converting
> the integer quotient to type double. Any remainder, or fractional part of the
> quotient, is ignored.  Fix this.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration/migration.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/migration/migration.c b/migration/migration.c
> index b3adbc6..6db75b8 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -646,7 +646,7 @@ static void *migration_thread(void *opaque)
>          if (current_time >= initial_time + BUFFER_DELAY) {
>              uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
>              uint64_t time_spent = current_time - initial_time;
> -            double bandwidth = transferred_bytes / time_spent;
> +            double bandwidth = (double)transferred_bytes / time_spent;
>              max_size = bandwidth * migrate_max_downtime() / 1000000;
>  
>              s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /

This feels like it would be better to fix this by merging it into
the s->mbps calculation just off the bottom; we currently have:

            uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
            uint64_t time_spent = current_time - initial_time;
            double bandwidth = transferred_bytes / time_spent;
            max_size = bandwidth * migrate_max_downtime() / 1000000;

            s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /
                    ((double) time_spent / 1000.0)) / 1000.0 / 1000.0 : -1;

 
Note that the mbps has a check for time_spent being 0 - if that can ever happen,
how come 'bandwidth' has never triggered it?
 
  transferred_bytes    -    bytes
  time_spent           -    ms
  bandwidth            -    bytes/ms
  migrate_max_downtime -    in ns
  s->mbps              -    mbit/s

giving

  max_size = bytes/ms * time-in-ns  / 1000000
           = bytes/ms * time-in-ms
           = bytes

so how about something like:
            uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
            uint64_t time_spent = current_time - initial_time;
            double   bytes_s    = (double) transferred_bytes / ((double) time_spent / 1000.0));
            s->mbps = (bytes_s * 8.0) / 1000000.0;
            max_size = bytes_s * (migrate_max_downtime() / 1000000000.0);

that also needs the trace fixing and the line a few lines below, I *think* we have
   dirty_bytes_rate is in bytes/second ? (arch_init.c)
   expected_downtime in ms ?
                s->expected_downtime = s->dirty_bytes_rate / bandwidth;
so,  bytes/s / bytes/ms    erm that's supposed to come out as time in ms

                s->expected_downtime = (int64_t)(1000 * (double)s->dirty_bytes_rate / bytes_s);

Yeuch.

Dave

> -- 
> 1.8.3.1
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


WARNING: multiple messages have this Message-ID (diff)
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-trivial@nongnu.org, quintela@redhat.com,
	qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 7/7] migration: do floating-point division
Date: Mon, 26 Jan 2015 18:06:47 +0000	[thread overview]
Message-ID: <20150126180647.GD2291@work-vm> (raw)
In-Reply-To: <1422270747-23994-8-git-send-email-pbonzini@redhat.com>

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> Dividing integer expressions transferred_bytes and time_spent, and then converting
> the integer quotient to type double. Any remainder, or fractional part of the
> quotient, is ignored.  Fix this.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration/migration.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/migration/migration.c b/migration/migration.c
> index b3adbc6..6db75b8 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -646,7 +646,7 @@ static void *migration_thread(void *opaque)
>          if (current_time >= initial_time + BUFFER_DELAY) {
>              uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
>              uint64_t time_spent = current_time - initial_time;
> -            double bandwidth = transferred_bytes / time_spent;
> +            double bandwidth = (double)transferred_bytes / time_spent;
>              max_size = bandwidth * migrate_max_downtime() / 1000000;
>  
>              s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /

This feels like it would be better to fix this by merging it into
the s->mbps calculation just off the bottom; we currently have:

            uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
            uint64_t time_spent = current_time - initial_time;
            double bandwidth = transferred_bytes / time_spent;
            max_size = bandwidth * migrate_max_downtime() / 1000000;

            s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /
                    ((double) time_spent / 1000.0)) / 1000.0 / 1000.0 : -1;

 
Note that the mbps has a check for time_spent being 0 - if that can ever happen,
how come 'bandwidth' has never triggered it?
 
  transferred_bytes    -    bytes
  time_spent           -    ms
  bandwidth            -    bytes/ms
  migrate_max_downtime -    in ns
  s->mbps              -    mbit/s

giving

  max_size = bytes/ms * time-in-ns  / 1000000
           = bytes/ms * time-in-ms
           = bytes

so how about something like:
            uint64_t transferred_bytes = qemu_ftell(s->file) - initial_bytes;
            uint64_t time_spent = current_time - initial_time;
            double   bytes_s    = (double) transferred_bytes / ((double) time_spent / 1000.0));
            s->mbps = (bytes_s * 8.0) / 1000000.0;
            max_size = bytes_s * (migrate_max_downtime() / 1000000000.0);

that also needs the trace fixing and the line a few lines below, I *think* we have
   dirty_bytes_rate is in bytes/second ? (arch_init.c)
   expected_downtime in ms ?
                s->expected_downtime = s->dirty_bytes_rate / bandwidth;
so,  bytes/s / bytes/ms    erm that's supposed to come out as time in ms

                s->expected_downtime = (int64_t)(1000 * (double)s->dirty_bytes_rate / bytes_s);

Yeuch.

Dave

> -- 
> 1.8.3.1
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2015-01-26 18:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-26 11:12 [Qemu-trivial] [PATCH 0/7] Six coverity fixes and a cleanup Paolo Bonzini
2015-01-26 11:12 ` [Qemu-devel] " Paolo Bonzini
2015-01-26 11:12 ` [Qemu-trivial] [PATCH 1/7] cpu-exec: drop dead assignment Paolo Bonzini
2015-01-26 11:12   ` [Qemu-devel] " Paolo Bonzini
2015-01-26 11:12 ` [Qemu-trivial] [PATCH 2/7] cpu-exec: simplify icount code Paolo Bonzini
2015-01-26 11:12   ` [Qemu-devel] " Paolo Bonzini
2015-01-26 11:12 ` [Qemu-trivial] [PATCH 3/7] uri: avoid NULL arguments to strcmp Paolo Bonzini
2015-01-26 11:12   ` [Qemu-devel] " Paolo Bonzini
2015-01-26 11:12 ` [Qemu-trivial] [PATCH 4/7] qemu-sockets: improve error reporting in unix_listen_opts Paolo Bonzini
2015-01-26 11:12   ` [Qemu-devel] " Paolo Bonzini
2015-01-26 11:12 ` [Qemu-trivial] [PATCH 5/7] cutils: refine strtol error handling in parse_debug_env Paolo Bonzini
2015-01-26 11:12   ` [Qemu-devel] " Paolo Bonzini
2015-02-07  8:52   ` [Qemu-trivial] " Michael Tokarev
2015-02-07  8:52     ` [Qemu-devel] " Michael Tokarev
2015-01-26 11:12 ` [Qemu-trivial] [PATCH 6/7] aes: remove a dead return statement Paolo Bonzini
2015-01-26 11:12   ` [Qemu-devel] " Paolo Bonzini
2015-01-26 11:12 ` [Qemu-trivial] [PATCH 7/7] migration: do floating-point division Paolo Bonzini
2015-01-26 11:12   ` [Qemu-devel] " Paolo Bonzini
2015-01-26 18:06   ` Dr. David Alan Gilbert [this message]
2015-01-26 18:06     ` Dr. David Alan Gilbert
2015-01-26 18:15     ` [Qemu-trivial] " Juan Quintela
2015-01-26 18:15       ` [Qemu-devel] " Juan Quintela
2015-02-07  9:00 ` [Qemu-trivial] [PATCH 0/7] Six coverity fixes and a cleanup Michael Tokarev
2015-02-07  9:00   ` [Qemu-devel] " Michael Tokarev
2015-02-07 20:01   ` Paolo Bonzini
2015-02-07 20:01     ` [Qemu-devel] " Paolo Bonzini
2015-02-07 20:39     ` Michael Tokarev
2015-02-07 20:39       ` [Qemu-devel] " Michael Tokarev
2015-02-09 12:17     ` Juan Quintela
2015-02-09 12:17       ` [Qemu-devel] " Juan Quintela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150126180647.GD2291@work-vm \
    --to=dgilbert@redhat.com \
    --cc=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.