On 11/23/2010 05:02 PM, Juan Quintela wrote:
From: Juan Quintela<quint...@trasno.org>

This time is each time that buffered_file ticks happen

Signed-off-by: Juan Quintela<quint...@trasno.org>
Signed-off-by: Juan Quintela<quint...@redhat.com>

This patch is wrong.

The point of the tick is to establish a period during which only a certain amount of traffic is allowed to go through. 100 is used to indicate a period of 100ms even though a tick doesn't technically equal a millisecond (even though it practically happens to be close).

But the crucial part of making this work is scaling the bandwidth computation to the right period length. That is, the following bit of code:

    s->xfer_limit = bytes_per_sec / 10;
    s->put_buffer = put_buffer;
    s->put_ready = put_ready;

To make this generic, you'd need to add:

s->xfer_limit = bytes_per_sec / (get_ticks_per_sec() / buffered_file_interval);

Regards,

Anthony Liguori

---
  buffered_file.c |    6 ++++--
  buffered_file.h |    2 ++
  2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 1836e7e..1f492e6 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -20,6 +20,8 @@

  //#define DEBUG_BUFFERED_FILE

+const int buffered_file_interval = 100;
+
  typedef struct QEMUFileBuffered
  {
      BufferedPutFunc *put_buffer;
@@ -235,7 +237,7 @@ static void buffered_rate_tick(void *opaque)
          return;
      }

-    qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 100);
+    qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 
buffered_file_interval);

      if (s->freeze_output)
          return;
@@ -273,7 +275,7 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,

      s->timer = qemu_new_timer(rt_clock, buffered_rate_tick, s);

-    qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 100);
+    qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 
buffered_file_interval);

      return s->file;
  }
diff --git a/buffered_file.h b/buffered_file.h
index 98d358b..a728316 100644
--- a/buffered_file.h
+++ b/buffered_file.h
@@ -21,6 +21,8 @@ typedef void (BufferedPutReadyFunc)(void *opaque);
  typedef void (BufferedWaitForUnfreezeFunc)(void *opaque);
  typedef int (BufferedCloseFunc)(void *opaque);

+extern const int buffered_file_interval;
+
  QEMUFile *qemu_fopen_ops_buffered(void *opaque, size_t xfer_limit,
                                    BufferedPutFunc *put_buffer,
                                    BufferedPutReadyFunc *put_ready,


Reply via email to