From nobody Thu Nov 6 06:44:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497143845038364.89377203879246; Sat, 10 Jun 2017 18:17:25 -0700 (PDT) Received: from localhost ([::1]:60730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJrVL-00011U-Ic for importer@patchew.org; Sat, 10 Jun 2017 21:17:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJrTf-0000BN-LY for qemu-devel@nongnu.org; Sat, 10 Jun 2017 21:15:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJrTa-00036g-Hg for qemu-devel@nongnu.org; Sat, 10 Jun 2017 21:15:39 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:21477) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJrTR-00035B-Ha; Sat, 10 Jun 2017 21:15:26 -0400 Received: from mail.ntua.gr (ppp141255063244.access.hol.gr [141.255.63.244]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v5B1EjRT016037 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Jun 2017 04:14:45 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host ppp141255063244.access.hol.gr [141.255.63.244] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Sun, 11 Jun 2017 04:14:26 +0300 Message-Id: <20170611011427.6713-2-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170611011427.6713-1-el13635@mail.ntua.gr> References: <20170611011427.6713-1-el13635@mail.ntua.gr> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH RFC v2 1/2] block: move ThrottleGroup membership to ThrottleGroupMember X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit gathers ThrottleGroup membership details from BlockBackendPublic into ThrottleGroupMember and refactors existing code to use the structure. Signed-off-by: Manos Pitsidianakis --- block/block-backend.c | 75 ++++++---- block/qapi.c | 8 +- block/throttle-groups.c | 305 +++++++++++++++++-------------------= ---- blockdev.c | 4 +- include/block/throttle-groups.h | 15 +- include/qemu/throttle.h | 64 +++++++++ include/sysemu/block-backend.h | 22 +-- tests/test-throttle.c | 53 +++---- util/throttle.c | 5 + 9 files changed, 293 insertions(+), 258 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index f3a60081a7..1d6b35c34d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -209,6 +209,7 @@ static const BdrvChildRole child_root =3D { BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm) { BlockBackend *blk; + BlockBackendPublic *blkp; =20 blk =3D g_new0(BlockBackend, 1); blk->refcnt =3D 1; @@ -216,8 +217,9 @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_pe= rm) blk->shared_perm =3D shared_perm; blk_set_enable_write_cache(blk, true); =20 - qemu_co_queue_init(&blk->public.throttled_reqs[0]); - qemu_co_queue_init(&blk->public.throttled_reqs[1]); + blkp =3D blk_get_public(blk); + qemu_co_queue_init(&blkp->throttle_group_member.throttled_reqs[0]); + qemu_co_queue_init(&blkp->throttle_group_member.throttled_reqs[1]); =20 notifier_list_init(&blk->remove_bs_notifiers); notifier_list_init(&blk->insert_bs_notifiers); @@ -284,7 +286,7 @@ static void blk_delete(BlockBackend *blk) assert(!blk->refcnt); assert(!blk->name); assert(!blk->dev); - if (blk->public.throttle_state) { + if (blk_get_public(blk)->throttle_group_member.throttle_state) { blk_io_limits_disable(blk); } if (blk->root) { @@ -596,8 +598,10 @@ BlockBackend *blk_by_public(BlockBackendPublic *public) void blk_remove_bs(BlockBackend *blk) { notifier_list_notify(&blk->remove_bs_notifiers, blk); - if (blk->public.throttle_state) { - throttle_timers_detach_aio_context(&blk->public.throttle_timers); + BlockBackendPublic *blkp =3D blk_get_public(blk); + if (blkp->throttle_group_member.throttle_state) { + ThrottleTimers *tt =3D &blkp->throttle_group_member.throttle_timer= s; + throttle_timers_detach_aio_context(tt); } =20 blk_update_root_state(blk); @@ -619,9 +623,10 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState = *bs, Error **errp) bdrv_ref(bs); =20 notifier_list_notify(&blk->insert_bs_notifiers, blk); - if (blk->public.throttle_state) { + if (blk_get_public(blk)->throttle_group_member.throttle_state) { throttle_timers_attach_aio_context( - &blk->public.throttle_timers, bdrv_get_aio_context(bs)); + &blk_get_public(blk)->throttle_group_member.throttle_timers, + bdrv_get_aio_context(bs)); } =20 return 0; @@ -972,6 +977,7 @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int64= _t offset, { int ret; BlockDriverState *bs =3D blk_bs(blk); + BlockBackendPublic *blkp; =20 trace_blk_co_preadv(blk, bs, offset, bytes, flags); =20 @@ -981,10 +987,12 @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int= 64_t offset, } =20 bdrv_inc_in_flight(bs); + blkp =3D blk_get_public(blk); =20 /* throttling disk I/O */ - if (blk->public.throttle_state) { - throttle_group_co_io_limits_intercept(blk, bytes, false); + if (blkp->throttle_group_member.throttle_state) { + throttle_group_co_io_limits_intercept(&blkp->throttle_group_member, + bytes, false); } =20 ret =3D bdrv_co_preadv(blk->root, offset, bytes, qiov, flags); @@ -998,6 +1006,7 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, int= 64_t offset, { int ret; BlockDriverState *bs =3D blk_bs(blk); + BlockBackendPublic *blkp; =20 trace_blk_co_pwritev(blk, bs, offset, bytes, flags); =20 @@ -1007,10 +1016,11 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, = int64_t offset, } =20 bdrv_inc_in_flight(bs); - + blkp =3D blk_get_public(blk); /* throttling disk I/O */ - if (blk->public.throttle_state) { - throttle_group_co_io_limits_intercept(blk, bytes, true); + if (blkp->throttle_group_member.throttle_state) { + throttle_group_co_io_limits_intercept(&blkp->throttle_group_member, + bytes, true); } =20 if (!blk->enable_write_cache) { @@ -1681,13 +1691,15 @@ void blk_set_aio_context(BlockBackend *blk, AioCont= ext *new_context) BlockDriverState *bs =3D blk_bs(blk); =20 if (bs) { - if (blk->public.throttle_state) { - throttle_timers_detach_aio_context(&blk->public.throttle_timer= s); + BlockBackendPublic *blkp =3D blk_get_public(blk); + if (blkp->throttle_group_member.throttle_state) { + ThrottleTimers *tt =3D &blkp->throttle_group_member.throttle_t= imers; + throttle_timers_detach_aio_context(tt); } bdrv_set_aio_context(bs, new_context); - if (blk->public.throttle_state) { - throttle_timers_attach_aio_context(&blk->public.throttle_timer= s, - new_context); + if (blkp->throttle_group_member.throttle_state) { + ThrottleTimers *tt =3D &blkp->throttle_group_member.throttle_t= imers; + throttle_timers_attach_aio_context(tt, new_context); } } } @@ -1905,33 +1917,39 @@ int blk_commit_all(void) /* throttling disk I/O limits */ void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg) { - throttle_group_config(blk, cfg); + throttle_group_config(&blk_get_public(blk)->throttle_group_member, cfg= ); } =20 void blk_io_limits_disable(BlockBackend *blk) { - assert(blk->public.throttle_state); + assert(blk_get_public(blk)->throttle_group_member.throttle_state); bdrv_drained_begin(blk_bs(blk)); - throttle_group_unregister_blk(blk); + throttle_group_unregister_tgm(&blk_get_public(blk)->throttle_group_mem= ber); bdrv_drained_end(blk_bs(blk)); } =20 /* should be called before blk_set_io_limits if a limit is set */ void blk_io_limits_enable(BlockBackend *blk, const char *group) { - assert(!blk->public.throttle_state); - throttle_group_register_blk(blk, group); + BlockBackendPublic *blkp =3D blk_get_public(blk); + + assert(!blkp->throttle_group_member.throttle_state); + + blkp->throttle_group_member.aio_context =3D blk_get_aio_context(blk); + throttle_group_register_tgm(&blkp->throttle_group_member, group); } =20 void blk_io_limits_update_group(BlockBackend *blk, const char *group) { + BlockBackendPublic *blkp =3D blk_get_public(blk); /* this BB is not part of any group */ - if (!blk->public.throttle_state) { + if (!blkp->throttle_group_member.throttle_state) { return; } =20 /* this BB is a part of the same group than the one we want */ - if (!g_strcmp0(throttle_group_get_name(blk), group)) { + if (!g_strcmp0(throttle_group_get_name(&blkp->throttle_group_member), + group)) { return; } =20 @@ -1953,8 +1971,9 @@ static void blk_root_drained_begin(BdrvChild *child) /* Note that blk->root may not be accessible here yet if we are just * attaching to a BlockDriverState that is drained. Use child instead.= */ =20 - if (blk->public.io_limits_disabled++ =3D=3D 0) { - throttle_group_restart_blk(blk); + if (blk_get_public(blk)->throttle_group_member.io_limits_disabled++ = =3D=3D 0) { + BlockBackendPublic *blkp =3D blk_get_public(blk); + throttle_group_restart_tgm(&blkp->throttle_group_member); } } =20 @@ -1963,8 +1982,8 @@ static void blk_root_drained_end(BdrvChild *child) BlockBackend *blk =3D child->opaque; assert(blk->quiesce_counter); =20 - assert(blk->public.io_limits_disabled); - --blk->public.io_limits_disabled; + assert(blk_get_public(blk)->throttle_group_member.io_limits_disabled); + --blk_get_public(blk)->throttle_group_member.io_limits_disabled; =20 if (--blk->quiesce_counter =3D=3D 0) { if (blk->dev_ops && blk->dev_ops->drained_end) { diff --git a/block/qapi.c b/block/qapi.c index a40922ea26..d7fc1345df 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -67,10 +67,11 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *b= lk, info->backing_file_depth =3D bdrv_get_backing_file_depth(bs); info->detect_zeroes =3D bs->detect_zeroes; =20 - if (blk && blk_get_public(blk)->throttle_state) { + if (blk && blk_get_public(blk)->throttle_group_member.throttle_state) { ThrottleConfig cfg; + BlockBackendPublic *blkp =3D blk_get_public(blk); =20 - throttle_group_get_config(blk, &cfg); + throttle_group_get_config(&blkp->throttle_group_member, &cfg); =20 info->bps =3D cfg.buckets[THROTTLE_BPS_TOTAL].avg; info->bps_rd =3D cfg.buckets[THROTTLE_BPS_READ].avg; @@ -118,7 +119,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *b= lk, info->iops_size =3D cfg.op_size; =20 info->has_group =3D true; - info->group =3D g_strdup(throttle_group_get_name(blk)); + info->group =3D + g_strdup(throttle_group_get_name(&blkp->throttle_group_member)= ); } =20 info->write_threshold =3D bdrv_write_threshold_get(bs); diff --git a/block/throttle-groups.c b/block/throttle-groups.c index b73e7a800b..d8bf990ccb 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -29,43 +29,6 @@ #include "qemu/thread.h" #include "sysemu/qtest.h" =20 -/* The ThrottleGroup structure (with its ThrottleState) is shared - * among different BlockBackends and it's independent from - * AioContext, so in order to use it from different threads it needs - * its own locking. - * - * This locking is however handled internally in this file, so it's - * transparent to outside users. - * - * The whole ThrottleGroup structure is private and invisible to - * outside users, that only use it through its ThrottleState. - * - * In addition to the ThrottleGroup structure, BlockBackendPublic has - * fields that need to be accessed by other members of the group and - * therefore also need to be protected by this lock. Once a - * BlockBackend is registered in a group those fields can be accessed - * by other threads any time. - * - * Again, all this is handled internally and is mostly transparent to - * the outside. The 'throttle_timers' field however has an additional - * constraint because it may be temporarily invalid (see for example - * bdrv_set_aio_context()). Therefore in this file a thread will - * access some other BlockBackend's timers only after verifying that - * that BlockBackend has throttled requests in the queue. - */ -typedef struct ThrottleGroup { - char *name; /* This is constant during the lifetime of the group */ - - QemuMutex lock; /* This lock protects the following four fields */ - ThrottleState ts; - QLIST_HEAD(, BlockBackendPublic) head; - BlockBackend *tokens[2]; - bool any_timer_armed[2]; - - /* These two are protected by the global throttle_groups_lock */ - unsigned refcount; - QTAILQ_ENTRY(ThrottleGroup) list; -} ThrottleGroup; =20 static QemuMutex throttle_groups_lock; static QTAILQ_HEAD(, ThrottleGroup) throttle_groups =3D @@ -133,114 +96,113 @@ void throttle_group_unref(ThrottleState *ts) qemu_mutex_unlock(&throttle_groups_lock); } =20 -/* Get the name from a BlockBackend's ThrottleGroup. The name (and the poi= nter) +/* Get the name from a ThrottleGroupMember's group. The name (and the poin= ter) * is guaranteed to remain constant during the lifetime of the group. * - * @blk: a BlockBackend that is member of a throttling group + * @tgm: a ThrottleGroupMember * @ret: the name of the group. */ -const char *throttle_group_get_name(BlockBackend *blk) +const char *throttle_group_get_name(ThrottleGroupMember *tgm) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); + ThrottleState *ts =3D tgm->throttle_state; + ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); return tg->name; } =20 -/* Return the next BlockBackend in the round-robin sequence, simulating a - * circular list. +/* Return the next ThrottleGroupMember in the round-robin sequence, simula= ting + * a circular list. * * This assumes that tg->lock is held. * - * @blk: the current BlockBackend - * @ret: the next BlockBackend in the sequence + * @tgm: the current ThrottleGroupMember + * @ret: the next ThrottleGroupMember in the sequence */ -static BlockBackend *throttle_group_next_blk(BlockBackend *blk) +static ThrottleGroupMember *throttle_group_next_tgm(ThrottleGroupMember *t= gm) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleState *ts =3D blkp->throttle_state; + ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); - BlockBackendPublic *next =3D QLIST_NEXT(blkp, round_robin); + ThrottleGroupMember *next =3D QLIST_NEXT(tgm, round_robin); =20 if (!next) { next =3D QLIST_FIRST(&tg->head); } =20 - return blk_by_public(next); + return next; } =20 /* - * Return whether a BlockBackend has pending requests. + * Return whether a ThrottleGroupMember has pending requests. * * This assumes that tg->lock is held. * - * @blk: the BlockBackend - * @is_write: the type of operation (read/write) - * @ret: whether the BlockBackend has pending requests. + * @tgm: the ThrottleGroupMember + * @is_write: the type of operation (read/write) + * @ret: whether the ThrottleGroupMember has pending requests. */ -static inline bool blk_has_pending_reqs(BlockBackend *blk, +static inline bool tgm_has_pending_reqs(ThrottleGroupMember *tgm, bool is_write) { - const BlockBackendPublic *blkp =3D blk_get_public(blk); - return blkp->pending_reqs[is_write]; + return tgm->pending_reqs[is_write]; } =20 -/* Return the next BlockBackend in the round-robin sequence with pending I= /O - * requests. +/* Return the next ThrottleGroupMember in the round-robin sequence with pe= nding + * I/O requests. * * This assumes that tg->lock is held. * - * @blk: the current BlockBackend + * @tgm: the current ThrottleGroupMember * @is_write: the type of operation (read/write) - * @ret: the next BlockBackend with pending requests, or blk if ther= e is - * none. + * @ret: the next ThrottleGroupMember with pending requests, or tgm = if + * there is none. */ -static BlockBackend *next_throttle_token(BlockBackend *blk, bool is_write) +static ThrottleGroupMember *next_throttle_token(ThrottleGroupMember *tgm, + bool is_write) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); - BlockBackend *token, *start; + ThrottleState *ts =3D tgm->throttle_state; + ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); + ThrottleGroupMember *token, *start; =20 start =3D token =3D tg->tokens[is_write]; =20 /* get next bs round in round robin style */ - token =3D throttle_group_next_blk(token); - while (token !=3D start && !blk_has_pending_reqs(token, is_write)) { - token =3D throttle_group_next_blk(token); + token =3D throttle_group_next_tgm(token); + while (token !=3D start && !tgm_has_pending_reqs(token, is_write)) { + token =3D throttle_group_next_tgm(token); } =20 /* If no IO are queued for scheduling on the next round robin token - * then decide the token is the current bs because chances are - * the current bs get the current request queued. + * then decide the token is the current TGM because chances are + * the current TGM get the current request queued. */ - if (token =3D=3D start && !blk_has_pending_reqs(token, is_write)) { - token =3D blk; + if (token =3D=3D start && !tgm_has_pending_reqs(token, is_write)) { + token =3D tgm; } =20 - /* Either we return the original BB, or one with pending requests */ - assert(token =3D=3D blk || blk_has_pending_reqs(token, is_write)); + /* Either we return the original TGM, or one with pending requests */ + assert(token =3D=3D tgm || tgm_has_pending_reqs(token, is_write)); =20 return token; } =20 -/* Check if the next I/O request for a BlockBackend needs to be throttled = or - * not. If there's no timer set in this group, set one and update the token - * accordingly. +/* Check if the next I/O request for a ThrottleGroupMember needs to be + * throttled or not. If there's no timer set in this group, set one and up= date + * the token accordingly. * * This assumes that tg->lock is held. * - * @blk: the current BlockBackend + * @tgm: the current ThrottleGroupMember * @is_write: the type of operation (read/write) * @ret: whether the I/O request needs to be throttled or not */ -static bool throttle_group_schedule_timer(BlockBackend *blk, bool is_write) +static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm, + bool is_write) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleState *ts =3D blkp->throttle_state; - ThrottleTimers *tt =3D &blkp->throttle_timers; + ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); + ThrottleTimers *tt =3D &tgm->throttle_timers; bool must_wait; =20 - if (blkp->io_limits_disabled) { + if (tgm->io_limits_disabled) { return false; } =20 @@ -251,9 +213,9 @@ static bool throttle_group_schedule_timer(BlockBackend = *blk, bool is_write) =20 must_wait =3D throttle_schedule_timer(ts, tt, is_write); =20 - /* If a timer just got armed, set blk as the current token */ + /* If a timer just got armed, set tgm as the current token */ if (must_wait) { - tg->tokens[is_write] =3D blk; + tg->tokens[is_write] =3D tgm; tg->any_timer_armed[is_write] =3D true; } =20 @@ -264,19 +226,19 @@ static bool throttle_group_schedule_timer(BlockBacken= d *blk, bool is_write) * * This assumes that tg->lock is held. * - * @blk: the current BlockBackend + * @tgm: the current ThrottleGroupMember * @is_write: the type of operation (read/write) */ -static void schedule_next_request(BlockBackend *blk, bool is_write) +static void schedule_next_request(ThrottleGroupMember *tgm, bool is_write) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); + ThrottleState *ts =3D tgm->throttle_state; + ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); bool must_wait; - BlockBackend *token; + ThrottleGroupMember *token; =20 /* Check if there's any pending request to schedule next */ - token =3D next_throttle_token(blk, is_write); - if (!blk_has_pending_reqs(token, is_write)) { + token =3D next_throttle_token(tgm, is_write); + if (!tgm_has_pending_reqs(token, is_write)) { return; } =20 @@ -285,12 +247,12 @@ static void schedule_next_request(BlockBackend *blk, = bool is_write) =20 /* If it doesn't have to wait, queue it for immediate execution */ if (!must_wait) { - /* Give preference to requests from the current blk */ + /* Give preference to requests from the current tgm */ if (qemu_in_coroutine() && - qemu_co_queue_next(&blkp->throttled_reqs[is_write])) { - token =3D blk; + qemu_co_queue_next(&tgm->throttled_reqs[is_write])) { + token =3D tgm; } else { - ThrottleTimers *tt =3D &blk_get_public(token)->throttle_timers; + ThrottleTimers *tt =3D &token->throttle_timers; int64_t now =3D qemu_clock_get_ns(tt->clock_type); timer_mod(tt->timers[is_write], now + 1); tg->any_timer_armed[is_write] =3D true; @@ -299,71 +261,66 @@ static void schedule_next_request(BlockBackend *blk, = bool is_write) } } =20 -/* Check if an I/O request needs to be throttled, wait and set a timer - * if necessary, and schedule the next request using a round robin - * algorithm. +/* Check if an I/O request needs to be throttled, wait and set a timer if + * necessary, and schedule the next request using a round robin algorithm. * - * @blk: the current BlockBackend + * @tgm: the current ThrottleGroupMember * @bytes: the number of bytes for this I/O * @is_write: the type of operation (read/write) */ -void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk, +void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMembe= r *tgm, unsigned int bytes, bool is_write) { bool must_wait; - BlockBackend *token; - - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); + ThrottleGroupMember *token; + ThrottleState *ts =3D tgm->throttle_state; + ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); qemu_mutex_lock(&tg->lock); =20 /* First we check if this I/O has to be throttled. */ - token =3D next_throttle_token(blk, is_write); + token =3D next_throttle_token(tgm, is_write); must_wait =3D throttle_group_schedule_timer(token, is_write); =20 /* Wait if there's a timer set or queued requests of this type */ - if (must_wait || blkp->pending_reqs[is_write]) { - blkp->pending_reqs[is_write]++; + if (must_wait || tgm->pending_reqs[is_write]) { + tgm->pending_reqs[is_write]++; qemu_mutex_unlock(&tg->lock); - qemu_co_queue_wait(&blkp->throttled_reqs[is_write], NULL); + qemu_co_queue_wait(&tgm->throttled_reqs[is_write], NULL); qemu_mutex_lock(&tg->lock); - blkp->pending_reqs[is_write]--; + tgm->pending_reqs[is_write]--; } =20 /* The I/O will be executed, so do the accounting */ - throttle_account(blkp->throttle_state, is_write, bytes); + throttle_account(tgm->throttle_state, is_write, bytes); =20 /* Schedule the next request */ - schedule_next_request(blk, is_write); + schedule_next_request(tgm, is_write); =20 qemu_mutex_unlock(&tg->lock); } =20 -void throttle_group_restart_blk(BlockBackend *blk) +void throttle_group_restart_tgm(ThrottleGroupMember *tgm) { - BlockBackendPublic *blkp =3D blk_get_public(blk); int i; =20 for (i =3D 0; i < 2; i++) { - while (qemu_co_enter_next(&blkp->throttled_reqs[i])) { + while (qemu_co_enter_next(&tgm->throttled_reqs[i])) { ; } } } =20 -/* Update the throttle configuration for a particular group. Similar - * to throttle_config(), but guarantees atomicity within the - * throttling group. +/* Update the throttle configuration for a particular group. Similar to + * throttle_config(), but guarantees atomicity within the throttling group. * - * @blk: a BlockBackend that is a member of the group - * @cfg: the configuration to set + * @tgm: a ThrottleGroupMember that is a member of the group + * @cfg: the configuration to set */ -void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg) +void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleTimers *tt =3D &blkp->throttle_timers; - ThrottleState *ts =3D blkp->throttle_state; + ThrottleTimers *tt =3D &tgm->throttle_timers; + ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); qemu_mutex_lock(&tg->lock); /* throttle_config() cancels the timers */ @@ -376,37 +333,34 @@ void throttle_group_config(BlockBackend *blk, Throttl= eConfig *cfg) throttle_config(ts, tt, cfg); qemu_mutex_unlock(&tg->lock); =20 - qemu_co_enter_next(&blkp->throttled_reqs[0]); - qemu_co_enter_next(&blkp->throttled_reqs[1]); + qemu_co_enter_next(&tgm->throttled_reqs[0]); + qemu_co_enter_next(&tgm->throttled_reqs[1]); } =20 /* Get the throttle configuration from a particular group. Similar to - * throttle_get_config(), but guarantees atomicity within the - * throttling group. + * throttle_get_config(), but guarantees atomicity within the throttling g= roup. * - * @blk: a BlockBackend that is a member of the group - * @cfg: the configuration will be written here + * @tgm: a ThrottleGroupMember that is a member of the group + * @cfg: the configuration will be written here */ -void throttle_group_get_config(BlockBackend *blk, ThrottleConfig *cfg) +void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *c= fg) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleState *ts =3D blkp->throttle_state; + ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); qemu_mutex_lock(&tg->lock); throttle_get_config(ts, cfg); qemu_mutex_unlock(&tg->lock); } =20 -/* ThrottleTimers callback. This wakes up a request that was waiting - * because it had been throttled. +/* ThrottleTimers callback. This wakes up a request that was waiting becau= se it + * had been throttled. * - * @blk: the BlockBackend whose request had been throttled + * @tgm: the ThrottleGroupMember whose request had been throttled * @is_write: the type of operation (read/write) */ -static void timer_cb(BlockBackend *blk, bool is_write) +static void timer_cb(ThrottleGroupMember *tgm, bool is_write) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleState *ts =3D blkp->throttle_state; + ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); bool empty_queue; =20 @@ -416,15 +370,15 @@ static void timer_cb(BlockBackend *blk, bool is_write) qemu_mutex_unlock(&tg->lock); =20 /* Run the request that was waiting for this timer */ - aio_context_acquire(blk_get_aio_context(blk)); - empty_queue =3D !qemu_co_enter_next(&blkp->throttled_reqs[is_write]); - aio_context_release(blk_get_aio_context(blk)); + aio_context_acquire(tgm->aio_context); + empty_queue =3D !qemu_co_enter_next(&tgm->throttled_reqs[is_write]); + aio_context_release(tgm->aio_context); =20 /* If the request queue was empty then we have to take care of * scheduling the next one */ if (empty_queue) { qemu_mutex_lock(&tg->lock); - schedule_next_request(blk, is_write); + schedule_next_request(tgm, is_write); qemu_mutex_unlock(&tg->lock); } } @@ -439,17 +393,17 @@ static void write_timer_cb(void *opaque) timer_cb(opaque, true); } =20 -/* Register a BlockBackend in the throttling group, also initializing its - * timers and updating its throttle_state pointer to point to it. If a +/* Register a ThrottleGroupMember from the throttling group, also initiali= zing + * its timers and updating its throttle_state pointer to point to it. If a * throttling group with that name does not exist yet, it will be created. * - * @blk: the BlockBackend to insert + * @tgm: the ThrottleGroupMember to insert * @groupname: the name of the group */ -void throttle_group_register_blk(BlockBackend *blk, const char *groupname) +void throttle_group_register_tgm(ThrottleGroupMember *tgm, + const char *groupname) { int i; - BlockBackendPublic *blkp =3D blk_get_public(blk); ThrottleState *ts =3D throttle_group_incref(groupname); ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); int clock_type =3D QEMU_CLOCK_REALTIME; @@ -459,67 +413,68 @@ void throttle_group_register_blk(BlockBackend *blk, c= onst char *groupname) clock_type =3D QEMU_CLOCK_VIRTUAL; } =20 - blkp->throttle_state =3D ts; + tgm->throttle_state =3D ts; =20 qemu_mutex_lock(&tg->lock); - /* If the ThrottleGroup is new set this BlockBackend as the token */ + /* If the ThrottleGroup is new set this ThrottleGroupMember as the tok= en */ for (i =3D 0; i < 2; i++) { if (!tg->tokens[i]) { - tg->tokens[i] =3D blk; + tg->tokens[i] =3D tgm; } } =20 - QLIST_INSERT_HEAD(&tg->head, blkp, round_robin); + QLIST_INSERT_HEAD(&tg->head, tgm, round_robin); =20 - throttle_timers_init(&blkp->throttle_timers, - blk_get_aio_context(blk), + throttle_timers_init(&tgm->throttle_timers, + tgm->aio_context, clock_type, read_timer_cb, write_timer_cb, - blk); + tgm); =20 qemu_mutex_unlock(&tg->lock); } =20 -/* Unregister a BlockBackend from its group, removing it from the list, +/* Unregister a ThrottleGroupMember from its group, removing it from the l= ist, * destroying the timers and setting the throttle_state pointer to NULL. * - * The BlockBackend must not have pending throttled requests, so the calle= r has - * to drain them first. + * The ThrottleGroupMember must not have pending throttled requests, so the + * caller has to drain them first. * * The group will be destroyed if it's empty after this operation. * - * @blk: the BlockBackend to remove + * @tgm the ThrottleGroupMember to remove */ -void throttle_group_unregister_blk(BlockBackend *blk) +void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) { - BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); + ThrottleState *ts =3D tgm->throttle_state; + ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); + ThrottleGroupMember *token; int i; =20 - assert(blkp->pending_reqs[0] =3D=3D 0 && blkp->pending_reqs[1] =3D=3D = 0); - assert(qemu_co_queue_empty(&blkp->throttled_reqs[0])); - assert(qemu_co_queue_empty(&blkp->throttled_reqs[1])); + assert(tgm->pending_reqs[0] =3D=3D 0 && tgm->pending_reqs[1] =3D=3D 0); + assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); + assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); =20 qemu_mutex_lock(&tg->lock); for (i =3D 0; i < 2; i++) { - if (tg->tokens[i] =3D=3D blk) { - BlockBackend *token =3D throttle_group_next_blk(blk); - /* Take care of the case where this is the last blk in the gro= up */ - if (token =3D=3D blk) { + if (tg->tokens[i] =3D=3D tgm) { + token =3D throttle_group_next_tgm(tgm); + /* Take care of the case where this is the last tgm in the gro= up */ + if (token =3D=3D tgm) { token =3D NULL; } tg->tokens[i] =3D token; } } =20 - /* remove the current blk from the list */ - QLIST_REMOVE(blkp, round_robin); - throttle_timers_destroy(&blkp->throttle_timers); + /* remove the current tgm from the list */ + QLIST_REMOVE(tgm, round_robin); + throttle_timers_destroy(&tgm->throttle_timers); qemu_mutex_unlock(&tg->lock); =20 throttle_group_unref(&tg->ts); - blkp->throttle_state =3D NULL; + tgm->throttle_state =3D NULL; } =20 static void throttle_groups_init(void) diff --git a/blockdev.c b/blockdev.c index c63f4e82c7..ad8cec8008 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2706,7 +2706,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, = Error **errp) if (throttle_enabled(&cfg)) { /* Enable I/O limits if they're not enabled yet, otherwise * just update the throttling group. */ - if (!blk_get_public(blk)->throttle_state) { + if (!blk_get_public(blk)->throttle_group_member.throttle_state) { blk_io_limits_enable(blk, arg->has_group ? arg->group : arg->has_device ? arg->device : @@ -2716,7 +2716,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, = Error **errp) } /* Set the new throttling configuration */ blk_set_io_limits(blk, &cfg); - } else if (blk_get_public(blk)->throttle_state) { + } else if (blk_get_public(blk)->throttle_group_member.throttle_state) { /* If all throttling settings are set to 0, disable I/O limits */ blk_io_limits_disable(blk); } diff --git a/include/block/throttle-groups.h b/include/block/throttle-group= s.h index d983d34074..487b2da461 100644 --- a/include/block/throttle-groups.h +++ b/include/block/throttle-groups.h @@ -28,19 +28,20 @@ #include "qemu/throttle.h" #include "block/block_int.h" =20 -const char *throttle_group_get_name(BlockBackend *blk); +const char *throttle_group_get_name(ThrottleGroupMember *tgm); =20 ThrottleState *throttle_group_incref(const char *name); void throttle_group_unref(ThrottleState *ts); =20 -void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg); -void throttle_group_get_config(BlockBackend *blk, ThrottleConfig *cfg); +void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg); +void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *c= fg); =20 -void throttle_group_register_blk(BlockBackend *blk, const char *groupname); -void throttle_group_unregister_blk(BlockBackend *blk); -void throttle_group_restart_blk(BlockBackend *blk); +void throttle_group_register_tgm(ThrottleGroupMember *tgm, + const char *groupname); +void throttle_group_unregister_tgm(ThrottleGroupMember *tgm); +void throttle_group_restart_tgm(ThrottleGroupMember *tgm); =20 -void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk, +void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMembe= r *tgm, unsigned int bytes, bool is_write); =20 diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 9109657609..8b67fbfdfb 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -27,6 +27,9 @@ =20 #include "qemu-common.h" #include "qemu/timer.h" +#include "qemu/queue.h" +#include "qemu/thread.h" +#include "qemu/coroutine.h" =20 #define THROTTLE_VALUE_MAX 1000000000000000LL =20 @@ -153,4 +156,65 @@ bool throttle_schedule_timer(ThrottleState *ts, =20 void throttle_account(ThrottleState *ts, bool is_write, uint64_t size); =20 +/* The ThrottleGroup structure (with its ThrottleState) is shared among + * different ThrottleGroupMembers and it's independent from AioContext, so= in + * order to use it from different threads it needs its own locking. + * + * This locking is however handled internally in block/throttle-groups.c so + * it's transparent to outside users. + * + * The whole ThrottleGroup structure is private and invisible to outside u= sers, + * that only use it through its ThrottleState. + * + * In addition to the ThrottleGroup structure, ThrottleGroupMember has fie= lds + * that need to be accessed by other members of the group and therefore al= so + * need to be protected by this lock. Once a ThrottleGroupMember is regist= ered + * in a group those fields can be accessed by other threads any time. + * + * Again, all this is handled internally in block/throttle-groups.c and is + * mostly transparent to the outside. The 'throttle_timers' field however = has + * an additional constraint because it may be temporarily invalid (see for + * example bdrv_set_aio_context()). Therefore block/throttle-groups.c will + * access some other ThrottleGroupMember's timers only after verifying that + * ThrottleGroupMember has throttled requests in the queue. + */ + +typedef struct ThrottleGroup { + char *name; /* This is constant during the lifetime of the group */ + + QemuMutex lock; /* This lock protects the following four fields */ + ThrottleState ts; + QLIST_HEAD(, ThrottleGroupMember) head; + struct ThrottleGroupMember *tokens[2]; + bool any_timer_armed[2]; + + /* These two are protected by the global throttle_groups_lock */ + unsigned refcount; + QTAILQ_ENTRY(ThrottleGroup) list; +} ThrottleGroup; + +/* The ThrottleGroupMember structure indicates membership in a ThrottleGro= up + * and holds related data. + */ + +typedef struct ThrottleGroupMember { + AioContext *aio_context; + /* I/O throttling has its own locking, but also some fields are + * protected by the AioContext lock. + */ + + /* Protected by AioContext lock. */ + CoQueue throttled_reqs[2]; + + /* Nonzero if the I/O limits are currently being ignored; generally + * it is zero. */ + unsigned int io_limits_disabled; + + ThrottleState *throttle_state; + ThrottleTimers throttle_timers; + unsigned pending_reqs[2]; + QLIST_ENTRY(ThrottleGroupMember) round_robin; + +} ThrottleGroupMember; + #endif diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 840ad6134c..4fec907b7f 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -70,26 +70,10 @@ typedef struct BlockDevOps { =20 /* This struct is embedded in (the private) BlockBackend struct and contai= ns * fields that must be public. This is in particular for QLIST_ENTRY() and - * friends so that BlockBackends can be kept in lists outside block-backen= d.c */ + * friends so that BlockBackends can be kept in lists outside block-backen= d.c + * */ typedef struct BlockBackendPublic { - /* I/O throttling has its own locking, but also some fields are - * protected by the AioContext lock. - */ - - /* Protected by AioContext lock. */ - CoQueue throttled_reqs[2]; - - /* Nonzero if the I/O limits are currently being ignored; generally - * it is zero. */ - unsigned int io_limits_disabled; - - /* The following fields are protected by the ThrottleGroup lock. - * See the ThrottleGroup documentation for details. - * throttle_state tells us if I/O limits are configured. */ - ThrottleState *throttle_state; - ThrottleTimers throttle_timers; - unsigned pending_reqs[2]; - QLIST_ENTRY(BlockBackendPublic) round_robin; + ThrottleGroupMember throttle_group_member; } BlockBackendPublic; =20 BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm); diff --git a/tests/test-throttle.c b/tests/test-throttle.c index a9201b1fea..0f95da2592 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -592,6 +592,7 @@ static void test_groups(void) ThrottleConfig cfg1, cfg2; BlockBackend *blk1, *blk2, *blk3; BlockBackendPublic *blkp1, *blkp2, *blkp3; + ThrottleGroupMember *tgm1, *tgm2, *tgm3; =20 /* No actual I/O is performed on these devices */ blk1 =3D blk_new(0, BLK_PERM_ALL); @@ -602,21 +603,25 @@ static void test_groups(void) blkp2 =3D blk_get_public(blk2); blkp3 =3D blk_get_public(blk3); =20 - g_assert(blkp1->throttle_state =3D=3D NULL); - g_assert(blkp2->throttle_state =3D=3D NULL); - g_assert(blkp3->throttle_state =3D=3D NULL); + tgm1 =3D &blkp1->throttle_group_member; + tgm2 =3D &blkp2->throttle_group_member; + tgm3 =3D &blkp3->throttle_group_member; =20 - throttle_group_register_blk(blk1, "bar"); - throttle_group_register_blk(blk2, "foo"); - throttle_group_register_blk(blk3, "bar"); + g_assert(tgm1->throttle_state =3D=3D NULL); + g_assert(tgm2->throttle_state =3D=3D NULL); + g_assert(tgm3->throttle_state =3D=3D NULL); =20 - g_assert(blkp1->throttle_state !=3D NULL); - g_assert(blkp2->throttle_state !=3D NULL); - g_assert(blkp3->throttle_state !=3D NULL); + throttle_group_register_tgm(tgm1, "bar"); + throttle_group_register_tgm(tgm2, "foo"); + throttle_group_register_tgm(tgm3, "bar"); =20 - g_assert(!strcmp(throttle_group_get_name(blk1), "bar")); - g_assert(!strcmp(throttle_group_get_name(blk2), "foo")); - g_assert(blkp1->throttle_state =3D=3D blkp3->throttle_state); + g_assert(tgm1->throttle_state !=3D NULL); + g_assert(tgm2->throttle_state !=3D NULL); + g_assert(tgm3->throttle_state !=3D NULL); + + g_assert(!strcmp(throttle_group_get_name(tgm1), "bar")); + g_assert(!strcmp(throttle_group_get_name(tgm2), "foo")); + g_assert(tgm1->throttle_state =3D=3D tgm3->throttle_state); =20 /* Setting the config of a group member affects the whole group */ throttle_config_init(&cfg1); @@ -624,29 +629,29 @@ static void test_groups(void) cfg1.buckets[THROTTLE_BPS_WRITE].avg =3D 285000; cfg1.buckets[THROTTLE_OPS_READ].avg =3D 20000; cfg1.buckets[THROTTLE_OPS_WRITE].avg =3D 12000; - throttle_group_config(blk1, &cfg1); + throttle_group_config(tgm1, &cfg1); =20 - throttle_group_get_config(blk1, &cfg1); - throttle_group_get_config(blk3, &cfg2); + throttle_group_get_config(tgm1, &cfg1); + throttle_group_get_config(tgm3, &cfg2); g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1))); =20 cfg2.buckets[THROTTLE_BPS_READ].avg =3D 4547; cfg2.buckets[THROTTLE_BPS_WRITE].avg =3D 1349; cfg2.buckets[THROTTLE_OPS_READ].avg =3D 123; cfg2.buckets[THROTTLE_OPS_WRITE].avg =3D 86; - throttle_group_config(blk3, &cfg1); + throttle_group_config(tgm3, &cfg1); =20 - throttle_group_get_config(blk1, &cfg1); - throttle_group_get_config(blk3, &cfg2); + throttle_group_get_config(tgm1, &cfg1); + throttle_group_get_config(tgm3, &cfg2); g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1))); =20 - throttle_group_unregister_blk(blk1); - throttle_group_unregister_blk(blk2); - throttle_group_unregister_blk(blk3); + throttle_group_unregister_tgm(tgm1); + throttle_group_unregister_tgm(tgm2); + throttle_group_unregister_tgm(tgm3); =20 - g_assert(blkp1->throttle_state =3D=3D NULL); - g_assert(blkp2->throttle_state =3D=3D NULL); - g_assert(blkp3->throttle_state =3D=3D NULL); + g_assert(tgm1->throttle_state =3D=3D NULL); + g_assert(tgm2->throttle_state =3D=3D NULL); + g_assert(tgm3->throttle_state =3D=3D NULL); } =20 int main(int argc, char **argv) diff --git a/util/throttle.c b/util/throttle.c index 3570ed25fc..ec1fe73dbd 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -185,6 +185,9 @@ static bool throttle_compute_timer(ThrottleState *ts, void throttle_timers_attach_aio_context(ThrottleTimers *tt, AioContext *new_context) { + ThrottleGroupMember *tgm =3D container_of(tt, ThrottleGroupMember, thr= ottle_timers); + tgm->aio_context =3D new_context; + tt->timers[0] =3D aio_timer_new(new_context, tt->clock_type, SCALE_NS, tt->read_timer_cb, tt->timer_opaque); tt->timers[1] =3D aio_timer_new(new_context, tt->clock_type, SCALE_NS, @@ -241,6 +244,8 @@ static void throttle_timer_destroy(QEMUTimer **timer) /* Remove timers from event loop */ void throttle_timers_detach_aio_context(ThrottleTimers *tt) { + ThrottleGroupMember *tgm =3D container_of(tt, ThrottleGroupMember, thr= ottle_timers); + tgm->aio_context =3D NULL; int i; =20 for (i =3D 0; i < 2; i++) { --=20 2.11.0 From nobody Thu Nov 6 06:44:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149714392601625.2255189459363; Sat, 10 Jun 2017 18:18:46 -0700 (PDT) Received: from localhost ([::1]:60733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJrWe-0002MG-KN for importer@patchew.org; Sat, 10 Jun 2017 21:18:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJrTb-0000AA-8g for qemu-devel@nongnu.org; Sat, 10 Jun 2017 21:15:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJrTY-00036U-R3 for qemu-devel@nongnu.org; Sat, 10 Jun 2017 21:15:35 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:21485) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJrTS-00035g-Nq; Sat, 10 Jun 2017 21:15:27 -0400 Received: from mail.ntua.gr (ppp141255063244.access.hol.gr [141.255.63.244]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v5B1EqvM016114 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Jun 2017 04:14:52 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host ppp141255063244.access.hol.gr [141.255.63.244] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Sun, 11 Jun 2017 04:14:27 +0300 Message-Id: <20170611011427.6713-3-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170611011427.6713-1-el13635@mail.ntua.gr> References: <20170611011427.6713-1-el13635@mail.ntua.gr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by smtp1.ntua.gr id v5B1EqvM016114 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH RFC v2 2/2] block: add throttle block filter driver X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" block/throttle.c uses existing I/O throttle infrastructure inside a block filter driver. I/O operations are intercepted in the filter's read/write coroutines, and referred to block/throttle-groups.c The driver can be used with the command -drive driver=3Dthrottle,file.filename=3Dfoo.qcow2,iops-total=3D... The configuration flags and semantics are identical to the hardcoded throttling ones. Signed-off-by: Manos Pitsidianakis --- block/Makefile.objs | 1 + block/throttle-groups.c | 16 +- block/throttle.c | 364 ++++++++++++++++++++++++++++++++++++= ++++ include/block/throttle-groups.h | 6 +- include/qemu/throttle-options.h | 60 ++++--- 5 files changed, 419 insertions(+), 28 deletions(-) create mode 100644 block/throttle.c diff --git a/block/Makefile.objs b/block/Makefile.objs index ea955302c8..bb811a4d01 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -25,6 +25,7 @@ block-obj-y +=3D accounting.o dirty-bitmap.o block-obj-y +=3D write-threshold.o block-obj-y +=3D backup.o block-obj-$(CONFIG_REPLICATION) +=3D replication.o +block-obj-y +=3D throttle.o =20 block-obj-y +=3D crypto.o =20 diff --git a/block/throttle-groups.c b/block/throttle-groups.c index d8bf990ccb..9008b73cc9 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -29,11 +29,11 @@ #include "qemu/thread.h" #include "sysemu/qtest.h" =20 - -static QemuMutex throttle_groups_lock; -static QTAILQ_HEAD(, ThrottleGroup) throttle_groups =3D +QemuMutex throttle_groups_lock; +QTAILQ_HEAD(throttle_groups_head, ThrottleGroup) throttle_groups =3D QTAILQ_HEAD_INITIALIZER(throttle_groups); =20 + /* Increments the reference count of a ThrottleGroup given its name. * * If no ThrottleGroup is found with the given name a new one is @@ -117,7 +117,7 @@ const char *throttle_group_get_name(ThrottleGroupMember= *tgm) * @tgm: the current ThrottleGroupMember * @ret: the next ThrottleGroupMember in the sequence */ -static ThrottleGroupMember *throttle_group_next_tgm(ThrottleGroupMember *t= gm) +ThrottleGroupMember *throttle_group_next_tgm(ThrottleGroupMember *tgm) { ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); @@ -229,7 +229,7 @@ static bool throttle_group_schedule_timer(ThrottleGroup= Member *tgm, * @tgm: the current ThrottleGroupMember * @is_write: the type of operation (read/write) */ -static void schedule_next_request(ThrottleGroupMember *tgm, bool is_write) +void schedule_next_request(ThrottleGroupMember *tgm, bool is_write) { ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); @@ -358,7 +358,7 @@ void throttle_group_get_config(ThrottleGroupMember *tgm= , ThrottleConfig *cfg) * @tgm: the ThrottleGroupMember whose request had been throttled * @is_write: the type of operation (read/write) */ -static void timer_cb(ThrottleGroupMember *tgm, bool is_write) +void timer_cb(ThrottleGroupMember *tgm, bool is_write) { ThrottleState *ts =3D tgm->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); @@ -383,12 +383,12 @@ static void timer_cb(ThrottleGroupMember *tgm, bool i= s_write) } } =20 -static void read_timer_cb(void *opaque) +void read_timer_cb(void *opaque) { timer_cb(opaque, false); } =20 -static void write_timer_cb(void *opaque) +void write_timer_cb(void *opaque) { timer_cb(opaque, true); } diff --git a/block/throttle.c b/block/throttle.c new file mode 100644 index 0000000000..6be5d3de59 --- /dev/null +++ b/block/throttle.c @@ -0,0 +1,364 @@ +/* + * QEMU block throttling filter driver infrastructure + * + * Copyright (C) Nodalink, EURL. 2014 + * Copyright (C) Igalia, S.L. 2015 + * + * Authors: + * Beno=C3=AEt Canet + * Alberto Garcia + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "block/throttle-groups.h" +#include "qemu/throttle-options.h" +#include "qapi/error.h" + + +static QemuOptsList throttle_opts =3D { + .name =3D "throttle", + .head =3D QTAILQ_HEAD_INITIALIZER(throttle_opts.head), + .desc =3D { + { + .name =3D QEMU_OPT_IOPS_TOTAL, + .type =3D QEMU_OPT_NUMBER, + .help =3D "limit total I/O operations per second", + },{ + .name =3D QEMU_OPT_IOPS_READ, + .type =3D QEMU_OPT_NUMBER, + .help =3D "limit read operations per second", + },{ + .name =3D QEMU_OPT_IOPS_WRITE, + .type =3D QEMU_OPT_NUMBER, + .help =3D "limit write operations per second", + },{ + .name =3D QEMU_OPT_BPS_TOTAL, + .type =3D QEMU_OPT_NUMBER, + .help =3D "limit total bytes per second", + },{ + .name =3D QEMU_OPT_BPS_READ, + .type =3D QEMU_OPT_NUMBER, + .help =3D "limit read bytes per second", + },{ + .name =3D QEMU_OPT_BPS_WRITE, + .type =3D QEMU_OPT_NUMBER, + .help =3D "limit write bytes per second", + },{ + .name =3D QEMU_OPT_IOPS_TOTAL_MAX, + .type =3D QEMU_OPT_NUMBER, + .help =3D "I/O operations burst", + },{ + .name =3D QEMU_OPT_IOPS_READ_MAX, + .type =3D QEMU_OPT_NUMBER, + .help =3D "I/O operations read burst", + },{ + .name =3D QEMU_OPT_IOPS_WRITE_MAX, + .type =3D QEMU_OPT_NUMBER, + .help =3D "I/O operations write burst", + },{ + .name =3D QEMU_OPT_BPS_TOTAL_MAX, + .type =3D QEMU_OPT_NUMBER, + .help =3D "total bytes burst", + },{ + .name =3D QEMU_OPT_BPS_READ_MAX, + .type =3D QEMU_OPT_NUMBER, + .help =3D "total bytes read burst", + },{ + .name =3D QEMU_OPT_BPS_WRITE_MAX, + .type =3D QEMU_OPT_NUMBER, + .help =3D "total bytes write burst", + },{ + .name =3D QEMU_OPT_IOPS_TOTAL_MAX_LENGTH, + .type =3D QEMU_OPT_NUMBER, + .help =3D "length of the iopstotalmax burst period, in seconds= ", + },{ + .name =3D QEMU_OPT_IOPS_READ_MAX_LENGTH, + .type =3D QEMU_OPT_NUMBER, + .help =3D "length of the iopsreadmax burst period, in seconds", + },{ + .name =3D QEMU_OPT_IOPS_WRITE_MAX_LENGTH, + .type =3D QEMU_OPT_NUMBER, + .help =3D "length of the iopswritemax burst period, in seconds= ", + },{ + .name =3D QEMU_OPT_BPS_TOTAL_MAX_LENGTH, + .type =3D QEMU_OPT_NUMBER, + .help =3D "length of the bpstotalmax burst period, in seconds", + },{ + .name =3D QEMU_OPT_BPS_READ_MAX_LENGTH, + .type =3D QEMU_OPT_NUMBER, + .help =3D "length of the bpsreadmax burst period, in seconds", + },{ + .name =3D QEMU_OPT_BPS_WRITE_MAX_LENGTH, + .type =3D QEMU_OPT_NUMBER, + .help =3D "length of the bpswritemax burst period, in seconds", + },{ + .name =3D QEMU_OPT_IOPS_SIZE, + .type =3D QEMU_OPT_NUMBER, + .help =3D "when limiting by iops max size of an I/O in bytes", + }, + { + .name =3D QEMU_OPT_THROTTLE_GROUP_NAME, + .type =3D QEMU_OPT_STRING, + .help =3D "throttle group name", + }, + { /* end of list */ } + }, +}; + +static int throttle_open(BlockDriverState *bs, QDict *options, + int flags, Error **errp) +{ + int ret =3D 0; + ThrottleGroupMember *tgm =3D bs->opaque; + Error *local_err =3D NULL; + QemuOpts *opts =3D NULL; + const char *group_name =3D NULL; + + bs->file =3D bdrv_open_child(NULL, options, "file", + bs, &child_file, false, &local_= err); + + if (local_err) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + return ret; + } + + qdict_flatten(options); + opts =3D qemu_opts_create(&throttle_opts, NULL, 0, &error_abort); + qemu_opts_absorb_qdict(opts, options, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto fin; + } + + group_name =3D qemu_opt_get(opts, QEMU_OPT_THROTTLE_GROUP_NAME); + if (!group_name) { + group_name =3D bdrv_get_device_or_node_name(bs); + if (!strlen(group_name)) { + error_setg(&local_err, + "A group name must be specified for this device."); + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto fin; + } + } + + tgm->aio_context =3D bdrv_get_aio_context(bs); + throttle_group_register_tgm(tgm, group_name); + ThrottleState *ts =3D tgm->throttle_state; + ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); + ThrottleConfig *throttle_cfg =3D &ts->cfg; + + + qemu_mutex_lock(&tg->lock); + if (qemu_opt_get(opts, QEMU_OPT_BPS_TOTAL)) { + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_TOTAL, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_READ)) { + throttle_cfg->buckets[THROTTLE_BPS_READ].avg =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_READ, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_WRITE)) { + throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_WRITE, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_TOTAL)) { + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_TOTAL, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_READ)) { + throttle_cfg->buckets[THROTTLE_OPS_READ].avg =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_READ, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_WRITE)) { + throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_WRITE, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_TOTAL_MAX)) { + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_TOTAL_MAX, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_READ_MAX)) { + throttle_cfg->buckets[THROTTLE_BPS_READ].max =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_READ_MAX, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_WRITE_MAX)) { + throttle_cfg->buckets[THROTTLE_BPS_WRITE].max =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_WRITE_MAX, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_TOTAL_MAX)) { + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_TOTAL_MAX, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_READ_MAX)) { + throttle_cfg->buckets[THROTTLE_OPS_READ].max =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_READ_MAX, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_WRITE_MAX)) { + throttle_cfg->buckets[THROTTLE_OPS_WRITE].max =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_WRITE_MAX, 0); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_TOTAL_MAX_LENGTH)) { + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_TOTAL_MAX_LENGTH, 1); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_READ_MAX_LENGTH)) { + throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_READ_MAX_LENGTH, 1); + } + if (qemu_opt_get(opts, QEMU_OPT_BPS_WRITE_MAX_LENGTH)) { + throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length =3D + qemu_opt_get_number(opts, QEMU_OPT_BPS_WRITE_MAX_LENGTH, 1); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_TOTAL_MAX_LENGTH)) { + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_TOTAL_MAX_LENGTH, 1); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_READ_MAX_LENGTH)) { + throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_READ_MAX_LENGTH, 1); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_WRITE_MAX_LENGTH)) { + throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_WRITE_MAX_LENGTH, 1); + } + if (qemu_opt_get(opts, QEMU_OPT_IOPS_SIZE)) { + throttle_cfg->op_size =3D + qemu_opt_get_number(opts, QEMU_OPT_IOPS_SIZE, 0); + } + + if (!throttle_is_valid(throttle_cfg, &local_err)) { + error_propagate(errp, local_err); + throttle_group_unregister_tgm(tgm); + ret =3D -EINVAL; + goto fin; + } + + qemu_mutex_unlock(&tg->lock); + + qemu_co_queue_init(&tgm->throttled_reqs[0]); + qemu_co_queue_init(&tgm->throttled_reqs[1]); + +fin: + qemu_opts_del(opts); + return ret; +} + +static void throttle_close(BlockDriverState *bs) +{ + ThrottleGroupMember *tgm =3D bs->opaque; + throttle_group_unregister_tgm(tgm); + return; +} + + +static int64_t throttle_getlength(BlockDriverState *bs) +{ + return bdrv_getlength(bs->file->bs); +} + + +static int coroutine_fn throttle_co_preadv(BlockDriverState *bs, uint64_t = offset, + uint64_t bytes, QEMUIOVector *= qiov, + int flags) +{ + + ThrottleGroupMember *tgm =3D bs->opaque; + throttle_group_co_io_limits_intercept(tgm, bytes, false); + + return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); +} + +static int coroutine_fn throttle_co_pwritev(BlockDriverState *bs, uint64_t= offset, + uint64_t bytes, QEMUIOVector *= qiov, + int flags) +{ + ThrottleGroupMember *tgm =3D bs->opaque; + throttle_group_co_io_limits_intercept(tgm, bytes, true); + + return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); +} + +static int coroutine_fn throttle_co_pwrite_zeroes(BlockDriverState *bs, + int64_t offset, int bytes, BdrvRequestFlags flags) +{ + ThrottleGroupMember *tgm =3D bs->opaque; + throttle_group_co_io_limits_intercept(tgm, bytes, true); + + return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); +} + +static int coroutine_fn throttle_co_pdiscard(BlockDriverState *bs, + int64_t offset, int bytes) +{ + ThrottleGroupMember *tgm =3D bs->opaque; + throttle_group_co_io_limits_intercept(tgm, bytes, true); + + return bdrv_co_pdiscard(bs->file->bs, offset, bytes); +} + +static int throttle_co_flush(BlockDriverState *bs) +{ + return bdrv_co_flush(bs->file->bs); +} + +static void throttle_detach_aio_context(BlockDriverState *bs) +{ + ThrottleGroupMember *tgm =3D bs->opaque; + throttle_timers_detach_aio_context(&tgm->throttle_timers); +} + +static void throttle_attach_aio_context(BlockDriverState *bs, + AioContext *new_context) +{ + ThrottleGroupMember *tgm =3D bs->opaque; + throttle_timers_attach_aio_context(&tgm->throttle_timers, new_context); +} +static BlockDriver bdrv_throttle =3D { + .format_name =3D "throttle", + .protocol_name =3D "throttle", + .instance_size =3D sizeof(ThrottleGroupMember), + + .bdrv_file_open =3D throttle_open, + .bdrv_close =3D throttle_close, + .bdrv_co_flush =3D throttle_co_flush, + + .bdrv_child_perm =3D bdrv_filter_default_perms, + + .bdrv_getlength =3D throttle_getlength, + + .bdrv_co_preadv =3D throttle_co_preadv, + .bdrv_co_pwritev =3D throttle_co_pwritev, + + .bdrv_co_pwrite_zeroes =3D throttle_co_pwrite_zeroes, + .bdrv_co_pdiscard =3D throttle_co_pdiscard, + + .bdrv_recurse_is_first_non_filter =3D bdrv_recurse_is_first_non_fi= lter, + + .bdrv_attach_aio_context =3D throttle_attach_aio_context, + .bdrv_detach_aio_context =3D throttle_detach_aio_context, + + .is_filter =3D true, +}; + +static void bdrv_throttle_init(void) +{ + bdrv_register(&bdrv_throttle); +} + +block_init(bdrv_throttle_init); diff --git a/include/block/throttle-groups.h b/include/block/throttle-group= s.h index 487b2da461..67b6c69fe4 100644 --- a/include/block/throttle-groups.h +++ b/include/block/throttle-groups.h @@ -44,5 +44,9 @@ void throttle_group_restart_tgm(ThrottleGroupMember *tgm); void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMembe= r *tgm, unsigned int bytes, bool is_write); - +ThrottleGroupMember *throttle_group_next_tgm(ThrottleGroupMember *tgm); +void schedule_next_request(struct ThrottleGroupMember *tgm, bool is_write); +void timer_cb(ThrottleGroupMember *tgm, bool is_write); +void read_timer_cb(void *opaque); +void write_timer_cb(void *opaque); #endif diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-option= s.h index 3133d1ca40..3528a8f4a2 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -10,81 +10,103 @@ #ifndef THROTTLE_OPTIONS_H #define THROTTLE_OPTIONS_H =20 +#define QEMU_OPT_IOPS_TOTAL "iops-total" +#define QEMU_OPT_IOPS_TOTAL_MAX "iops-total-max" +#define QEMU_OPT_IOPS_TOTAL_MAX_LENGTH "iops-total-max-length" +#define QEMU_OPT_IOPS_READ "iops-read" +#define QEMU_OPT_IOPS_READ_MAX "iops-read-max" +#define QEMU_OPT_IOPS_READ_MAX_LENGTH "iops-read-max-length" +#define QEMU_OPT_IOPS_WRITE "iops-write" +#define QEMU_OPT_IOPS_WRITE_MAX "iops-write-max" +#define QEMU_OPT_IOPS_WRITE_MAX_LENGTH "iops-write-max-length" +#define QEMU_OPT_BPS_TOTAL "bps-total" +#define QEMU_OPT_BPS_TOTAL_MAX "bps-total-max" +#define QEMU_OPT_BPS_TOTAL_MAX_LENGTH "bps-total-max-length" +#define QEMU_OPT_BPS_READ "bps-read" +#define QEMU_OPT_BPS_READ_MAX "bps-read-max" +#define QEMU_OPT_BPS_READ_MAX_LENGTH "bps-read-max-length" +#define QEMU_OPT_BPS_WRITE "bps-write" +#define QEMU_OPT_BPS_WRITE_MAX "bps-write-max" +#define QEMU_OPT_BPS_WRITE_MAX_LENGTH "bps-write-max-length" +#define QEMU_OPT_IOPS_SIZE "iops-size" +#define QEMU_OPT_THROTTLE_GROUP_NAME "throttle-group" + +#define THROTTLE_OPT_PREFIX "throttling." #define THROTTLE_OPTS \ { \ - .name =3D "throttling.iops-total",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "limit total I/O operations per second",\ },{ \ - .name =3D "throttling.iops-read",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "limit read operations per second",\ },{ \ - .name =3D "throttling.iops-write",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "limit write operations per second",\ },{ \ - .name =3D "throttling.bps-total",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "limit total bytes per second",\ },{ \ - .name =3D "throttling.bps-read",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "limit read bytes per second",\ },{ \ - .name =3D "throttling.bps-write",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "limit write bytes per second",\ },{ \ - .name =3D "throttling.iops-total-max",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "I/O operations burst",\ },{ \ - .name =3D "throttling.iops-read-max",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "I/O operations read burst",\ },{ \ - .name =3D "throttling.iops-write-max",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "I/O operations write burst",\ },{ \ - .name =3D "throttling.bps-total-max",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "total bytes burst",\ },{ \ - .name =3D "throttling.bps-read-max",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "total bytes read burst",\ },{ \ - .name =3D "throttling.bps-write-max",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "total bytes write burst",\ },{ \ - .name =3D "throttling.iops-total-max-length",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX_LENGTH,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "length of the iops-total-max burst period, in secon= ds",\ },{ \ - .name =3D "throttling.iops-read-max-length",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX_LENGTH,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "length of the iops-read-max burst period, in second= s",\ },{ \ - .name =3D "throttling.iops-write-max-length",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX_LENGTH,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "length of the iops-write-max burst period, in secon= ds",\ },{ \ - .name =3D "throttling.bps-total-max-length",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX_LENGTH,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "length of the bps-total-max burst period, in second= s",\ },{ \ - .name =3D "throttling.bps-read-max-length",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX_LENGTH,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "length of the bps-read-max burst period, in seconds= ",\ },{ \ - .name =3D "throttling.bps-write-max-length",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX_LENGTH,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "length of the bps-write-max burst period, in second= s",\ },{ \ - .name =3D "throttling.iops-size",\ + .name =3D THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_SIZE,\ .type =3D QEMU_OPT_NUMBER,\ .help =3D "when limiting by iops max size of an I/O in bytes",\ } --=20 2.11.0