ThrottleGroup configuration fixes
cover ThrottleGroup configuration fixes
Since in the future ThrottleGroup configuration will be done even if it has no members, we need to separate the two.
Manos Pitsidianakis (2):
block: add clock_type field to ThrottleGroup
block: remove timer canceling in throttle_config()
block/throttle-groups.c | 27 ++++++++++----------------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 2 +- tests/test-throttle.c | 4 ++-- util/throttle.c | 18 +++--------------- 5 files changed, 17 insertions(+), 36 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/2 block: add clock_type field to ThrottleGroup
Clock type in throttling is currently inferred by the ThrottleTimer's clock type even though it is a per-ThrottleGroup property; it doesn't make sense to have different clock types in the same group. Moving this to a field in ThrottleGroup can simplify some of the throttle functions.
--- block/throttle-groups.c | 20 ++++++++++---------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 1 + tests/test-throttle.c | 4 ++-- util/throttle.c | 4 +++- 5 files changed, 17 insertions(+), 14 deletions(-)
block/throttle-groups.c +10 -10
@@ -61,6 +61,7 @@ typedef struct ThrottleGroup { QLIST_HEAD(, BlockBackendPublic) head;BlockBackend *tokens[2 ];bool any_timer_armed[2 ]; +QEMUClockType clock_type;/* These two are protected by the global throttle_groups_lock */ unsigned refcount;
@@ -98,6 +99,12 @@ ThrottleState *throttle_group_incref(const char *name)if (!tg) { tg =g_new0 (ThrottleGroup,1 ); tg->name =g_strdup (name); + tg->clock_type =QEMU_CLOCK_REALTIME ; + +if (qtest_enabled ()) { +/* For testing block IO throttling only */ + tg->clock_type =QEMU_CLOCK_VIRTUAL ; + }qemu_mutex_init (&tg->lock);throttle_init (&tg->ts);QLIST_INIT (&tg->head);
@@ -310,7 +317,7 @@ static void schedule_next_request(BlockBackend *blk, bool is_write) token = blk; }else {ThrottleTimers *tt = &blk_get_public (token)->throttle_timers; -int64_t now =qemu_clock_get_ns (tt->clock_type); +int64_t now =qemu_clock_get_ns (tg->clock_type);timer_mod (tt->timers[is_write], now); tg->any_timer_armed[is_write] = true; }
@@ -430,7 +437,7 @@ void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg)if (timer_pending (tt->timers[1 ])) { tg->any_timer_armed[1 ] = false; } -throttle_config (ts, tt, cfg); +throttle_config (ts, tg->clock_type, tt, cfg);qemu_mutex_unlock (&tg->lock);throttle_group_restart_blk (blk);
@@ -497,13 +504,6 @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname)BlockBackendPublic *blkp =blk_get_public (blk);ThrottleState *ts =throttle_group_incref (groupname);ThrottleGroup *tg =container_of (ts, ThrottleGroup, ts); -int clock_type =QEMU_CLOCK_REALTIME ; - -if (qtest_enabled ()) { -/* For testing block IO throttling only */ - clock_type =QEMU_CLOCK_VIRTUAL ; - } - blkp->throttle_state = ts;qemu_mutex_lock (&tg->lock);
@@ -518,7 +518,7 @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname)throttle_timers_init (&blkp->throttle_timers,blk_get_aio_context (blk), - clock_type, + tg->clock_type, read_timer_cb, write_timer_cb, blk);
fsdev/qemu-fsdev-throttle.c +1 -1
@@ -86,7 +86,7 @@ void fsdev_throttle_init(FsThrottle *fst) fsdev_throttle_read_timer_cb, fsdev_throttle_write_timer_cb, fst); -throttle_config (&fst->ts, &fst->tt, &fst->cfg); +throttle_config (&fst->ts,QEMU_CLOCK_REALTIME , &fst->tt, &fst->cfg);qemu_co_queue_init (&fst->throttled_reqs[0 ]);qemu_co_queue_init (&fst->throttled_reqs[1 ]); }
include/qemu/throttle.h +1 -0
@@ -139,6 +139,7 @@ bool throttle_enabled(ThrottleConfig *cfg);bool throttle_is_valid (ThrottleConfig *cfg,Error **errp);void throttle_config (ThrottleState *ts, +QEMUClockType clock_type,ThrottleTimers *tt,ThrottleConfig *cfg);
tests/test-throttle.c +2 -2
@@ -228,7 +228,7 @@ static void test_config_functions(void) read_timer_cb, write_timer_cb, &ts);/* structure reset by throttle_init previous_leak should be null */ g_assert (!ts.previous_leak); -throttle_config (&ts, &tt, &orig_cfg); +throttle_config (&ts,QEMU_CLOCK_VIRTUAL , &tt, &orig_cfg);/* has previous leak been initialized by throttle_config ? */ g_assert (ts.previous_leak);
@@ -486,7 +486,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */throttle_init (&ts);throttle_timers_init (&tt, ctx,QEMU_CLOCK_VIRTUAL , read_timer_cb, write_timer_cb, &ts); -throttle_config (&ts, &tt, &cfg); +throttle_config (&ts,QEMU_CLOCK_VIRTUAL , &tt, &cfg);/* account a read */ throttle_account (&ts, false, size);
util/throttle.c +3 -1
@@ -399,10 +399,12 @@ static void throttle_cancel_timer(QEMUTimer *timer)/* Used to configure the throttle * * @ts: the throttle state we are working on +* @clock_type: the group's clock_type * @tt: the throttle timers we use in this aio context * @cfg: the config to set */ void throttle_config (ThrottleState *ts, +QEMUClockType clock_type,ThrottleTimers *tt,ThrottleConfig *cfg) {
@@ -414,7 +416,7 @@ void throttle_config(ThrottleState *ts,throttle_fix_bucket (&ts->cfg.buckets[i]); } - ts->previous_leak =qemu_clock_get_ns (tt->clock_type); + ts->previous_leak =qemu_clock_get_ns (clock_type);for (i =0 ; i <2 ; i++) {throttle_cancel_timer (tt->timers[i]);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] block: add clock_type field to ThrottleGroup
Quoted 5 lines · Manos Pitsidianakis
Clock type in throttling is currently inferred by the ThrottleTimer's clock type even though it is a per-ThrottleGroup property; it doesn't make sense to have different clock types in the same group. Moving this to a field in ThrottleGroup can simplify some of the throttle functions.
Quoted 8 lines
Signed-off-by Manos Pitsidianakis <[email protected]>--- block/throttle-groups.c | 20 ++++++++++---------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 1 + tests/test-throttle.c | 4 ++-- util/throttle.c | 4 +++- 5 files changed, 17 insertions(+), 14 deletions(-)
PATCH 2/2 block: remove timer canceling in throttle_config()
In reply to Manos Pitsidianakisthrottle_config() cancels the timers of the calling BlockBackend. This doesn't make sense because other BlockBackends in the group remain untouched. There's no need to cancel the timers in the one specific BlockBackend so let's not do that. Throttled requests will run as scheduled and future requests will follow the new configuration. This also allows a throttle group's configuration to be changed even when it has no members.
--- block/throttle-groups.c | 10 +--------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 1 - tests/test-throttle.c | 4 ++-- util/throttle.c | 14 -------------- 5 files changed, 4 insertions(+), 27 deletions(-)
block/throttle-groups.c +1 -9
@@ -426,18 +426,10 @@ void throttle_group_restart_blk(BlockBackend *blk)void throttle_group_config (BlockBackend *blk,ThrottleConfig *cfg) {BlockBackendPublic *blkp =blk_get_public (blk); -ThrottleTimers *tt = &blkp->throttle_timers;ThrottleState *ts = blkp->throttle_state;ThrottleGroup *tg =container_of (ts, ThrottleGroup, ts);qemu_mutex_lock (&tg->lock); -/* throttle_config() cancels the timers */ -if (timer_pending (tt->timers[0 ])) { - tg->any_timer_armed[0 ] = false; - } -if (timer_pending (tt->timers[1 ])) { - tg->any_timer_armed[1 ] = false; - } -throttle_config (ts, tg->clock_type, tt, cfg); +throttle_config (ts, tg->clock_type, cfg);qemu_mutex_unlock (&tg->lock);throttle_group_restart_blk (blk);
fsdev/qemu-fsdev-throttle.c +1 -1
@@ -86,7 +86,7 @@ void fsdev_throttle_init(FsThrottle *fst) fsdev_throttle_read_timer_cb, fsdev_throttle_write_timer_cb, fst); -throttle_config (&fst->ts,QEMU_CLOCK_REALTIME , &fst->tt, &fst->cfg); +throttle_config (&fst->ts,QEMU_CLOCK_REALTIME , &fst->cfg);qemu_co_queue_init (&fst->throttled_reqs[0 ]);qemu_co_queue_init (&fst->throttled_reqs[1 ]); }
include/qemu/throttle.h +0 -1
@@ -140,7 +140,6 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp);void throttle_config (ThrottleState *ts,QEMUClockType clock_type, -ThrottleTimers *tt,ThrottleConfig *cfg);void throttle_get_config (ThrottleState *ts,ThrottleConfig *cfg);
tests/test-throttle.c +2 -2
@@ -228,7 +228,7 @@ static void test_config_functions(void) read_timer_cb, write_timer_cb, &ts);/* structure reset by throttle_init previous_leak should be null */ g_assert (!ts.previous_leak); -throttle_config (&ts,QEMU_CLOCK_VIRTUAL , &tt, &orig_cfg); +throttle_config (&ts,QEMU_CLOCK_VIRTUAL , &orig_cfg);/* has previous leak been initialized by throttle_config ? */ g_assert (ts.previous_leak);
@@ -486,7 +486,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */throttle_init (&ts);throttle_timers_init (&tt, ctx,QEMU_CLOCK_VIRTUAL , read_timer_cb, write_timer_cb, &ts); -throttle_config (&ts,QEMU_CLOCK_VIRTUAL , &tt, &cfg); +throttle_config (&ts,QEMU_CLOCK_VIRTUAL , &cfg);/* account a read */ throttle_account (&ts, false, size);
util/throttle.c +0 -14
@@ -388,24 +388,14 @@ static void throttle_unfix_bucket(LeakyBucket *bkt) } } -/* take care of canceling a timer */ -static void throttle_cancel_timer (QEMUTimer *timer) -{ -assert (timer !=NULL ); - -timer_del (timer); -} -/* Used to configure the throttle * * @ts: the throttle state we are working on * @clock_type: the group's clock_type -* @tt: the throttle timers we use in this aio context * @cfg: the config to set */ void throttle_config (ThrottleState *ts,QEMUClockType clock_type, -ThrottleTimers *tt,ThrottleConfig *cfg) {int i;
@@ -417,10 +407,6 @@ void throttle_config(ThrottleState *ts, } ts->previous_leak =qemu_clock_get_ns (clock_type); - -for (i =0 ; i <2 ; i++) { -throttle_cancel_timer (tt->timers[i]); - } }/* used to get config
Signature · 1 line
2.11.0
Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] block: remove timer canceling in throttle_config()
Quoted 8 lines · Manos Pitsidianakis
throttle_config()cancels the timers of the calling BlockBackend. This doesn't make sense because other BlockBackends in the group remain untouched. There's no need to cancel the timers in the one specific BlockBackend so let's not do that. Throttled requests will run as scheduled and future requests will follow the new configuration. This also allows a throttle group's configuration to be changed even when it has no members.
Quoted 8 lines
Signed-off-by Manos Pitsidianakis <[email protected]>--- block/throttle-groups.c | 10 +--------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 1 - tests/test-throttle.c | 4 ++-- util/throttle.c | 14 -------------- 5 files changed, 4 insertions(+), 27 deletions(-)
Kevin Wolf
AppliedAm 02.07.2017 um 12:06 hat Manos Pitsidianakis geschrieben:
Quoted 2 lines
Since in the future ThrottleGroup configuration will be done even if it has no members, we need to separate the two.
Thanks, applied to the block branch.
Kevin