Received: from eggs.gnu.org ([2001:4830:134:3::10]:34541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xbl7z-000424-5u for qemu-devel@nongnu.org; Wed, 08 Oct 2014 02:53:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xbl7u-0005bv-1y for qemu-devel@nongnu.org; Wed, 08 Oct 2014 02:53:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xbl7t-0005bq-RC for qemu-devel@nongnu.org; Wed, 08 Oct 2014 02:53:34 -0400 Date: Wed, 8 Oct 2014 14:53:38 +0800 From: Fam Zheng Message-ID: <20141008065338.GD15829@fam-t430.nay.redhat.com> References: <1412688279-8312-1-git-send-email-benoit.canet@nodalink.com> <1412688279-8312-8-git-send-email-benoit.canet@nodalink.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1412688279-8312-8-git-send-email-benoit.canet@nodalink.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v1 7/8] throttle: Add throttle group support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Beno=EEt?= Canet Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Tue, 10/07 15:24, Beno=EEt Canet wrote: > The throttle group support use a cooperative round robin scheduling alg= orithm. >=20 > The principle of the algorithm are simple: s/principle/principles/ > - Each BDS of the group is used as a token in a circular way. > - The active BDS compute if a wait must be done and arm the right timer. > - If a wait must be done the token timer will be armed so the token wil= l become > the next active BDS. >=20 > Signed-off-by: Benoit Canet > --- > block.c | 191 ++++++++++++++++++++++++++++++++++++++= ++------ > block/qapi.c | 7 +- > block/throttle-groups.c | 2 +- > blockdev.c | 19 ++++- > hmp.c | 4 +- > include/block/block.h | 3 +- > include/block/block_int.h | 9 ++- > qapi/block-core.json | 5 +- > qemu-options.hx | 1 + > qmp-commands.hx | 3 +- > 10 files changed, 209 insertions(+), 35 deletions(-) >=20 > diff --git a/block.c b/block.c > index 527ea48..e7e5607 100644 > --- a/block.c > +++ b/block.c > @@ -36,6 +36,7 @@ > #include "qmp-commands.h" > #include "qemu/timer.h" > #include "qapi-event.h" > +#include "block/throttle-groups.h" > =20 > #ifdef CONFIG_BSD > #include > @@ -129,7 +130,9 @@ void bdrv_set_io_limits(BlockDriverState *bs, > { > int i; > =20 > - throttle_config(&bs->throttle_state, &bs->throttle_timers, cfg); > + throttle_group_lock(bs->throttle_state); > + throttle_config(bs->throttle_state, &bs->throttle_timers, cfg); > + throttle_group_unlock(bs->throttle_state); > =20 > for (i =3D 0; i < 2; i++) { > qemu_co_enter_next(&bs->throttled_reqs[i]); > @@ -156,34 +159,99 @@ static bool bdrv_start_throttled_reqs(BlockDriver= State *bs) > return drained; > } > =20 > +static void bdrv_throttle_group_add(BlockDriverState *bs) > +{ > + int i; > + BlockDriverState *token; > + > + for (i =3D 0; i < 2; i++) { > + /* Get the BlockDriverState having the round robin token */ > + token =3D throttle_group_token(bs->throttle_state, i); > + > + /* If the ThrottleGroup is new set the current BlockDriverStat= e as > + * token > + */ > + if (!token) { > + throttle_group_set_token(bs->throttle_state, bs, i); > + } > + > + } > + > + throttle_group_register_bs(bs->throttle_state, bs); > +} > + > +static void bdrv_throttle_group_remove(BlockDriverState *bs) > +{ > + BlockDriverState *token; > + int i; > + > + for (i =3D 0; i < 2; i++) { > + /* Get the BlockDriverState having the round robin token */ > + token =3D throttle_group_token(bs->throttle_state, i); > + /* if this bs is the current token set the next bs as token */ > + if (token =3D=3D bs) { > + token =3D throttle_group_next_bs(token); > + /* take care of the case where bs is the only bs of the gr= oup */ > + if (token =3D=3D bs) { > + token =3D NULL; > + } > + throttle_group_set_token(bs->throttle_state, token, i); > + } > + } > + > + /* remove the current bs from the list */ > + QLIST_REMOVE(bs, round_robin); > +} > + > void bdrv_io_limits_disable(BlockDriverState *bs) > { > + > + throttle_group_lock(bs->throttle_state); > bs->io_limits_enabled =3D false; > + throttle_group_unlock(bs->throttle_state); > =20 > bdrv_start_throttled_reqs(bs); > =20 > + throttle_group_lock(bs->throttle_state); > + bdrv_throttle_group_remove(bs); > + throttle_group_unlock(bs->throttle_state); > + > + throttle_group_unref(bs->throttle_state); > + bs->throttle_state =3D NULL; > + > throttle_timers_destroy(&bs->throttle_timers); > } > =20 > static void bdrv_throttle_read_timer_cb(void *opaque) > { > BlockDriverState *bs =3D opaque; > - throttle_timer_fired(&bs->throttle_state, false); > + > + throttle_group_lock(bs->throttle_state); > + throttle_timer_fired(bs->throttle_state, false); > + throttle_group_unlock(bs->throttle_state); > + > qemu_co_enter_next(&bs->throttled_reqs[0]); > } > =20 > static void bdrv_throttle_write_timer_cb(void *opaque) > { > BlockDriverState *bs =3D opaque; > - throttle_timer_fired(&bs->throttle_state, true); > + > + throttle_group_lock(bs->throttle_state); > + throttle_timer_fired(bs->throttle_state, true); > + throttle_group_unlock(bs->throttle_state); > + > qemu_co_enter_next(&bs->throttled_reqs[1]); > } > =20 > /* should be called before bdrv_set_io_limits if a limit is set */ > -void bdrv_io_limits_enable(BlockDriverState *bs) > +void bdrv_io_limits_enable(BlockDriverState *bs, const char *group) Does this mean that after this series, all the throttle_states must be contained inside its own throttle group? If so, we could embed ThrottleGr= oup fields in ThrottleState. It's weird when a function called throttle_group_compare takes a paramete= r of ThrottleState pointer, and cast it back to ThrottleGroup with container_o= f. Fam