Re: [PATCH v3 2/5] block-copy: let ratelimit handle a speed of 0

2021-06-19 Thread Vladimir Sementsov-Ogievskiy

14.06.2021 11:11, Emanuele Giuseppe Esposito wrote:

From: Paolo Bonzini 

Reviewed-by: Vladimir Sementsov-Ogievskiy 
Signed-off-by: Paolo Bonzini 
Signed-off-by: Emanuele Giuseppe Esposito 
---
  block/block-copy.c | 28 +++-
  1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/block/block-copy.c b/block/block-copy.c
index 5808cfe657..943e30b7e6 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -114,7 +114,6 @@ typedef struct BlockCopyState {
  
  SharedResource *mem;
  
-uint64_t speed;

  RateLimit rate_limit;
  } BlockCopyState;
  
@@ -647,21 +646,19 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)

  task->copy_range = false;
  }
  
-if (s->speed) {

-if (!call_state->ignore_ratelimit) {
-uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0);
-if (ns > 0) {
-block_copy_task_end(task, -EAGAIN);
-g_free(task);
-qemu_co_sleep_ns_wakeable(&call_state->sleep,
-  QEMU_CLOCK_REALTIME, ns);
-continue;
-}
+if (!call_state->ignore_ratelimit) {
+uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0);
+if (ns > 0) {
+block_copy_task_end(task, -EAGAIN);
+g_free(task);
+qemu_co_sleep_ns_wakeable(&call_state->sleep,
+QEMU_CLOCK_REALTIME, ns);


Indentation broken. Can be fixed when applying, not worth resending


+continue;
  }
-
-ratelimit_calculate_delay(&s->rate_limit, task->bytes);
  }
  
+ratelimit_calculate_delay(&s->rate_limit, task->bytes);

+
  trace_block_copy_process(s, task->offset);
  
  co_get_from_shres(s->mem, task->bytes);

@@ -853,10 +850,7 @@ void block_copy_set_skip_unallocated(BlockCopyState *s, 
bool skip)
  
  void block_copy_set_speed(BlockCopyState *s, uint64_t speed)

  {
-s->speed = speed;
-if (speed > 0) {
-ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME);
-}
+ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME);
  
  /*

   * Note: it's good to kick all call states from here, but it should be 
done




--
Best regards,
Vladimir



[PATCH v3 2/5] block-copy: let ratelimit handle a speed of 0

2021-06-14 Thread Emanuele Giuseppe Esposito
From: Paolo Bonzini 

Reviewed-by: Vladimir Sementsov-Ogievskiy 
Signed-off-by: Paolo Bonzini 
Signed-off-by: Emanuele Giuseppe Esposito 
---
 block/block-copy.c | 28 +++-
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/block/block-copy.c b/block/block-copy.c
index 5808cfe657..943e30b7e6 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -114,7 +114,6 @@ typedef struct BlockCopyState {
 
 SharedResource *mem;
 
-uint64_t speed;
 RateLimit rate_limit;
 } BlockCopyState;
 
@@ -647,21 +646,19 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
 task->copy_range = false;
 }
 
-if (s->speed) {
-if (!call_state->ignore_ratelimit) {
-uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0);
-if (ns > 0) {
-block_copy_task_end(task, -EAGAIN);
-g_free(task);
-qemu_co_sleep_ns_wakeable(&call_state->sleep,
-  QEMU_CLOCK_REALTIME, ns);
-continue;
-}
+if (!call_state->ignore_ratelimit) {
+uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0);
+if (ns > 0) {
+block_copy_task_end(task, -EAGAIN);
+g_free(task);
+qemu_co_sleep_ns_wakeable(&call_state->sleep,
+QEMU_CLOCK_REALTIME, ns);
+continue;
 }
-
-ratelimit_calculate_delay(&s->rate_limit, task->bytes);
 }
 
+ratelimit_calculate_delay(&s->rate_limit, task->bytes);
+
 trace_block_copy_process(s, task->offset);
 
 co_get_from_shres(s->mem, task->bytes);
@@ -853,10 +850,7 @@ void block_copy_set_skip_unallocated(BlockCopyState *s, 
bool skip)
 
 void block_copy_set_speed(BlockCopyState *s, uint64_t speed)
 {
-s->speed = speed;
-if (speed > 0) {
-ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME);
-}
+ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME);
 
 /*
  * Note: it's good to kick all call states from here, but it should be done
-- 
2.31.1




[PATCH v3 2/5] block-copy: let ratelimit handle a speed of 0

2021-06-14 Thread Emanuele Giuseppe Esposito
From: Paolo Bonzini 

Reviewed-by: Vladimir Sementsov-Ogievskiy 
Signed-off-by: Paolo Bonzini 
Signed-off-by: Emanuele Giuseppe Esposito 
---
 block/block-copy.c | 28 +++-
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/block/block-copy.c b/block/block-copy.c
index 5808cfe657..943e30b7e6 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -114,7 +114,6 @@ typedef struct BlockCopyState {
 
 SharedResource *mem;
 
-uint64_t speed;
 RateLimit rate_limit;
 } BlockCopyState;
 
@@ -647,21 +646,19 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
 task->copy_range = false;
 }
 
-if (s->speed) {
-if (!call_state->ignore_ratelimit) {
-uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0);
-if (ns > 0) {
-block_copy_task_end(task, -EAGAIN);
-g_free(task);
-qemu_co_sleep_ns_wakeable(&call_state->sleep,
-  QEMU_CLOCK_REALTIME, ns);
-continue;
-}
+if (!call_state->ignore_ratelimit) {
+uint64_t ns = ratelimit_calculate_delay(&s->rate_limit, 0);
+if (ns > 0) {
+block_copy_task_end(task, -EAGAIN);
+g_free(task);
+qemu_co_sleep_ns_wakeable(&call_state->sleep,
+QEMU_CLOCK_REALTIME, ns);
+continue;
 }
-
-ratelimit_calculate_delay(&s->rate_limit, task->bytes);
 }
 
+ratelimit_calculate_delay(&s->rate_limit, task->bytes);
+
 trace_block_copy_process(s, task->offset);
 
 co_get_from_shres(s->mem, task->bytes);
@@ -853,10 +850,7 @@ void block_copy_set_skip_unallocated(BlockCopyState *s, 
bool skip)
 
 void block_copy_set_speed(BlockCopyState *s, uint64_t speed)
 {
-s->speed = speed;
-if (speed > 0) {
-ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME);
-}
+ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME);
 
 /*
  * Note: it's good to kick all call states from here, but it should be done
-- 
2.31.1