#include "qapi/error.h"
#include "qemu/throttle.h"
#include "qemu/error-report.h"
+#include "qemu/main-loop.h"
+#include "qemu/module.h"
#include "block/throttle-groups.h"
#include "sysemu/block-backend.h"
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)
{
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);
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]);
}
}
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);
/* 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);
{
/* 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 */
BucketType index;
int i;
+ throttle_config_init(&cfg);
+
for (i = 0; i < 3; i++) {
BucketType index = to_test[is_ops][i];
cfg.buckets[index].avg = avg;
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);
return false;
}
- throttle_timers_destroy(&tt);
+ throttle_timers_destroy(tt);
return true;
}
ThrottleGroupMember *tgm1, *tgm2, *tgm3;
/* No actual I/O is performed on these devices */
- blk1 = blk_new(0, BLK_PERM_ALL);
- blk2 = blk_new(0, BLK_PERM_ALL);
- blk3 = blk_new(0, BLK_PERM_ALL);
+ blk1 = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
+ blk2 = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
+ blk3 = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
blkp1 = blk_get_public(blk1);
blkp2 = blk_get_public(blk2);
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);
qemu_init_main_loop(&error_fatal);
ctx = qemu_get_aio_context();
bdrv_init();
+ module_call_init(MODULE_INIT_QOM);
do {} while (g_main_context_iteration(NULL, false));