From 0e5b0a2d54f4dca2f6d1a676da8ec089dc143001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Mon, 8 Jun 2015 18:17:41 +0200 Subject: throttle: Extract timers from ThrottleState into a separate structure Group throttling will share ThrottleState between multiple bs. As a consequence the ThrottleState will be accessed by multiple aio context. Timers are tied to their aio context so they must go out of the ThrottleState structure. This commit paves the way for each bs of a common ThrottleState to have its own timer. Signed-off-by: Benoit Canet Signed-off-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Message-id: 6cf9ea96d8b32ae2f8769cead38f68a6a0c8c909.1433779731.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi --- block/io.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'block/io.c') diff --git a/block/io.c b/block/io.c index e394d92626..61a9d1da28 100644 --- a/block/io.c +++ b/block/io.c @@ -65,7 +65,7 @@ void bdrv_set_io_limits(BlockDriverState *bs, { int i; - throttle_config(&bs->throttle_state, cfg); + throttle_config(&bs->throttle_state, &bs->throttle_timers, cfg); for (i = 0; i < 2; i++) { qemu_co_enter_next(&bs->throttled_reqs[i]); @@ -98,7 +98,7 @@ void bdrv_io_limits_disable(BlockDriverState *bs) bdrv_start_throttled_reqs(bs); - throttle_destroy(&bs->throttle_state); + throttle_timers_destroy(&bs->throttle_timers); } static void bdrv_throttle_read_timer_cb(void *opaque) @@ -123,12 +123,13 @@ void bdrv_io_limits_enable(BlockDriverState *bs) clock_type = QEMU_CLOCK_VIRTUAL; } assert(!bs->io_limits_enabled); - throttle_init(&bs->throttle_state, - bdrv_get_aio_context(bs), - clock_type, - bdrv_throttle_read_timer_cb, - bdrv_throttle_write_timer_cb, - bs); + throttle_init(&bs->throttle_state); + throttle_timers_init(&bs->throttle_timers, + bdrv_get_aio_context(bs), + clock_type, + bdrv_throttle_read_timer_cb, + bdrv_throttle_write_timer_cb, + bs); bs->io_limits_enabled = true; } @@ -142,7 +143,9 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs, bool is_write) { /* does this io must wait */ - bool must_wait = throttle_schedule_timer(&bs->throttle_state, is_write); + bool must_wait = throttle_schedule_timer(&bs->throttle_state, + &bs->throttle_timers, + is_write); /* if must wait or any request of this type throttled queue the IO */ if (must_wait || @@ -155,7 +158,8 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs, /* if the next request must wait -> do nothing */ - if (throttle_schedule_timer(&bs->throttle_state, is_write)) { + if (throttle_schedule_timer(&bs->throttle_state, &bs->throttle_timers, + is_write)) { return; } -- cgit v1.2.3