From: Stefan Hajnoczi <stefanha@gmail.com>
To: Alberto Garcia <berto@igalia.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 4/6] throttle: Add throttle group support
Date: Tue, 24 Mar 2015 16:31:45 +0000 [thread overview]
Message-ID: <20150324163145.GH1493@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <bfb885fd48da3e13a60ef962f0e0a7cbbd757480.1426000801.git.berto@igalia.com>
[-- Attachment #1: Type: text/plain, Size: 2585 bytes --]
On Tue, Mar 10, 2015 at 05:30:48PM +0200, Alberto Garcia wrote:
> +/* Return the next BlockDriverState in the round-robin sequence with
> + * pending I/O requests.
> + *
> + * @bs: the current BlockDriverState
> + * @is_write: the type of operation (read/write)
> + * @ret: the next BlockDriverState with pending requests, or bs
> + * if there is none.
> + */
> +static BlockDriverState *next_throttle_token(BlockDriverState *bs,
> + bool is_write)
> +{
> + ThrottleGroup *tg = container_of(bs->throttle_state, ThrottleGroup, ts);
> + BlockDriverState *token, *start;
> +
> + start = token = tg->tokens[is_write];
> +
> + /* get next bs round in round robin style */
> + token = throttle_group_next_bs(token);
> + while (token != start &&
> + qemu_co_queue_empty(&token->throttled_reqs[is_write])) {
It's not safe to access bs->throttled_reqs[]. There are many of other
places that access bs->throttled_reqs[] without holding tg->lock (e.g.
block.c).
throttled_reqs needs to be protected by tg->lock in order for this to
work.
> +/* 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.
> + *
> + * @bs: the current BlockDriverState
> + * @bytes: the number of bytes for this I/O
> + * @is_write: the type of operation (read/write)
> + */
> +void throttle_group_io_limits_intercept(BlockDriverState *bs,
> + unsigned int bytes,
> + bool is_write)
This function must be called from coroutine context because it uses
qemu_co_queue_wait() and may yield. Please mark the function with
coroutine_fn (see include/block/coroutine.h). This serves as
documentation.
> +{
> + bool must_wait;
> + BlockDriverState *token;
> +
> + ThrottleGroup *tg = container_of(bs->throttle_state, ThrottleGroup, ts);
> + qemu_mutex_lock(&tg->lock);
> +
> + /* First we check if this I/O has to be throttled. */
> + token = next_throttle_token(bs, is_write);
> + must_wait = throttle_group_schedule_timer(token, is_write);
> +
> + /* Wait if there's a timer set or queued requests of this type */
> + if (must_wait || !qemu_co_queue_empty(&bs->throttled_reqs[is_write])) {
> + qemu_mutex_unlock(&tg->lock);
> + qemu_co_queue_wait(&bs->throttled_reqs[is_write]);
Here bs->throttled_reqs[] is used without holding tg->lock. It can race
with token->throttled_reqs[] users.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-03-24 16:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-10 15:30 [Qemu-devel] [PATCH v3 0/6] Block Throttle Group Support Alberto Garcia
2015-03-10 15:30 ` [Qemu-devel] [PATCH 1/6] throttle: Extract timers from ThrottleState into a separate structure Alberto Garcia
2015-03-24 15:03 ` Stefan Hajnoczi
2015-03-10 15:30 ` [Qemu-devel] [PATCH 2/6] throttle: Add throttle group infrastructure Alberto Garcia
2015-03-24 15:03 ` Stefan Hajnoczi
2015-03-24 15:33 ` Alberto Garcia
2015-03-25 12:01 ` Stefan Hajnoczi
2015-03-25 12:14 ` Alberto Garcia
2015-03-10 15:30 ` [Qemu-devel] [PATCH 3/6] throttle: Add throttle group infrastructure tests Alberto Garcia
2015-03-24 15:15 ` Stefan Hajnoczi
2015-03-10 15:30 ` [Qemu-devel] [PATCH 4/6] throttle: Add throttle group support Alberto Garcia
2015-03-24 16:03 ` Stefan Hajnoczi
2015-03-24 16:31 ` Stefan Hajnoczi [this message]
2015-03-24 17:48 ` Alberto Garcia
2015-03-25 12:03 ` Stefan Hajnoczi
2015-03-10 15:30 ` [Qemu-devel] [PATCH 5/6] throttle: add the name of the ThrottleGroup to BlockDeviceInfo Alberto Garcia
2015-03-10 15:30 ` [Qemu-devel] [PATCH 6/6] throttle: Update throttle infrastructure copyright Alberto Garcia
2015-03-24 16:32 ` [Qemu-devel] [PATCH v3 0/6] Block Throttle Group Support Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150324163145.GH1493@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=berto@igalia.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).