mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
block: add aio_context field in ThrottleGroupMember
timer_cb() needs to know about the current Aio context of the throttle request that is woken up. In order to make ThrottleGroupMember backend agnostic, this information is stored in an aio_context field instead of accessing it from BlockBackend. Reviewed-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
022cdc9f40
commit
c61791fc23
4 changed files with 69 additions and 54 deletions
|
@ -24,8 +24,9 @@
|
|||
static AioContext *ctx;
|
||||
static LeakyBucket bkt;
|
||||
static ThrottleConfig cfg;
|
||||
static ThrottleGroupMember tgm;
|
||||
static ThrottleState ts;
|
||||
static ThrottleTimers tt;
|
||||
static ThrottleTimers *tt;
|
||||
|
||||
/* useful function */
|
||||
static bool double_cmp(double x, double y)
|
||||
|
@ -153,19 +154,21 @@ static void test_init(void)
|
|||
{
|
||||
int i;
|
||||
|
||||
tt = &tgm.throttle_timers;
|
||||
|
||||
/* fill the structures with crap */
|
||||
memset(&ts, 1, sizeof(ts));
|
||||
memset(&tt, 1, sizeof(tt));
|
||||
memset(tt, 1, sizeof(*tt));
|
||||
|
||||
/* init structures */
|
||||
throttle_init(&ts);
|
||||
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
read_timer_cb, write_timer_cb, &ts);
|
||||
|
||||
/* check initialized fields */
|
||||
g_assert(tt.clock_type == QEMU_CLOCK_VIRTUAL);
|
||||
g_assert(tt.timers[0]);
|
||||
g_assert(tt.timers[1]);
|
||||
g_assert(tt->clock_type == QEMU_CLOCK_VIRTUAL);
|
||||
g_assert(tt->timers[0]);
|
||||
g_assert(tt->timers[1]);
|
||||
|
||||
/* check other fields where cleared */
|
||||
g_assert(!ts.previous_leak);
|
||||
|
@ -176,18 +179,18 @@ static void test_init(void)
|
|||
g_assert(!ts.cfg.buckets[i].level);
|
||||
}
|
||||
|
||||
throttle_timers_destroy(&tt);
|
||||
throttle_timers_destroy(tt);
|
||||
}
|
||||
|
||||
static void test_destroy(void)
|
||||
{
|
||||
int i;
|
||||
throttle_init(&ts);
|
||||
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
read_timer_cb, write_timer_cb, &ts);
|
||||
throttle_timers_destroy(&tt);
|
||||
throttle_timers_destroy(tt);
|
||||
for (i = 0; i < 2; i++) {
|
||||
g_assert(!tt.timers[i]);
|
||||
g_assert(!tt->timers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,7 +227,7 @@ static void test_config_functions(void)
|
|||
orig_cfg.op_size = 1;
|
||||
|
||||
throttle_init(&ts);
|
||||
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
read_timer_cb, write_timer_cb, &ts);
|
||||
/* structure reset by throttle_init previous_leak should be null */
|
||||
g_assert(!ts.previous_leak);
|
||||
|
@ -236,7 +239,7 @@ static void test_config_functions(void)
|
|||
/* get back the fixed configuration */
|
||||
throttle_get_config(&ts, &final_cfg);
|
||||
|
||||
throttle_timers_destroy(&tt);
|
||||
throttle_timers_destroy(tt);
|
||||
|
||||
g_assert(final_cfg.buckets[THROTTLE_BPS_TOTAL].avg == 153);
|
||||
g_assert(final_cfg.buckets[THROTTLE_BPS_READ].avg == 56);
|
||||
|
@ -494,45 +497,45 @@ static void test_have_timer(void)
|
|||
{
|
||||
/* zero structures */
|
||||
memset(&ts, 0, sizeof(ts));
|
||||
memset(&tt, 0, sizeof(tt));
|
||||
memset(tt, 0, sizeof(*tt));
|
||||
|
||||
/* no timer set should return false */
|
||||
g_assert(!throttle_timers_are_initialized(&tt));
|
||||
g_assert(!throttle_timers_are_initialized(tt));
|
||||
|
||||
/* init structures */
|
||||
throttle_init(&ts);
|
||||
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
read_timer_cb, write_timer_cb, &ts);
|
||||
|
||||
/* timer set by init should return true */
|
||||
g_assert(throttle_timers_are_initialized(&tt));
|
||||
g_assert(throttle_timers_are_initialized(tt));
|
||||
|
||||
throttle_timers_destroy(&tt);
|
||||
throttle_timers_destroy(tt);
|
||||
}
|
||||
|
||||
static void test_detach_attach(void)
|
||||
{
|
||||
/* zero structures */
|
||||
memset(&ts, 0, sizeof(ts));
|
||||
memset(&tt, 0, sizeof(tt));
|
||||
memset(tt, 0, sizeof(*tt));
|
||||
|
||||
/* init the structure */
|
||||
throttle_init(&ts);
|
||||
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
read_timer_cb, write_timer_cb, &ts);
|
||||
|
||||
/* timer set by init should return true */
|
||||
g_assert(throttle_timers_are_initialized(&tt));
|
||||
g_assert(throttle_timers_are_initialized(tt));
|
||||
|
||||
/* timer should no longer exist after detaching */
|
||||
throttle_timers_detach_aio_context(&tt);
|
||||
g_assert(!throttle_timers_are_initialized(&tt));
|
||||
throttle_timers_detach_aio_context(tt);
|
||||
g_assert(!throttle_timers_are_initialized(tt));
|
||||
|
||||
/* timer should exist again after attaching */
|
||||
throttle_timers_attach_aio_context(&tt, ctx);
|
||||
g_assert(throttle_timers_are_initialized(&tt));
|
||||
throttle_timers_attach_aio_context(tt, ctx);
|
||||
g_assert(throttle_timers_are_initialized(tt));
|
||||
|
||||
throttle_timers_destroy(&tt);
|
||||
throttle_timers_destroy(tt);
|
||||
}
|
||||
|
||||
static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
|
||||
|
@ -561,7 +564,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
|
|||
cfg.op_size = op_size;
|
||||
|
||||
throttle_init(&ts);
|
||||
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL,
|
||||
read_timer_cb, write_timer_cb, &ts);
|
||||
throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &cfg);
|
||||
|
||||
|
@ -588,7 +591,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
|
|||
return false;
|
||||
}
|
||||
|
||||
throttle_timers_destroy(&tt);
|
||||
throttle_timers_destroy(tt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -688,9 +691,9 @@ static void test_groups(void)
|
|||
g_assert(tgm2->throttle_state == NULL);
|
||||
g_assert(tgm3->throttle_state == NULL);
|
||||
|
||||
throttle_group_register_tgm(tgm1, "bar");
|
||||
throttle_group_register_tgm(tgm2, "foo");
|
||||
throttle_group_register_tgm(tgm3, "bar");
|
||||
throttle_group_register_tgm(tgm1, "bar", blk_get_aio_context(blk1));
|
||||
throttle_group_register_tgm(tgm2, "foo", blk_get_aio_context(blk2));
|
||||
throttle_group_register_tgm(tgm3, "bar", blk_get_aio_context(blk3));
|
||||
|
||||
g_assert(tgm1->throttle_state != NULL);
|
||||
g_assert(tgm2->throttle_state != NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue