qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, famz@redhat.com, kwolf@redhat.com, berto@igalia.com
Subject: [Qemu-devel] [PATCH 02/11] throttle-groups: restart throttled requests from coroutine context
Date: Fri, 15 Apr 2016 13:31:57 +0200	[thread overview]
Message-ID: <1460719926-12950-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1460719926-12950-1-git-send-email-pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/throttle-groups.c | 69 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 20 deletions(-)

diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index 1938e90..53e910e 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -264,8 +264,7 @@ static void schedule_next_request(BlockDriverState *bs, bool is_write)
     /* If it doesn't have to wait, queue it for immediate execution */
     if (!must_wait) {
         /* Give preference to requests from the current bs */
-        if (qemu_in_coroutine() &&
-            qemu_co_queue_next(&bs->throttled_reqs[is_write])) {
+        if (qemu_co_queue_next(&bs->throttled_reqs[is_write])) {
             token = bs;
         } else {
             ThrottleTimers *tt = &token->throttle_timers;
@@ -317,15 +316,54 @@ void coroutine_fn throttle_group_co_io_limits_intercept(BlockDriverState *bs,
     qemu_mutex_unlock(&tg->lock);
 }
 
-void throttle_group_restart_bs(BlockDriverState *bs)
-{
-    int i;
+typedef struct RestartData RestartData;
+struct RestartData {
+    BlockDriverState *bs;
+    bool single;
+    bool is_write;
+};
 
-    for (i = 0; i < 2; i++) {
-        while (qemu_co_enter_next(&bs->throttled_reqs[i])) {
-            ;
+static void throttle_group_restart_queue_entry(void *opaque)
+{
+    RestartData *data = opaque;
+    BlockDriverState *bs = data->bs;
+    bool single = data->single;
+    bool is_write = data->is_write;
+    unsigned count = 0;
+
+    g_free(data);
+    while (qemu_co_queue_next(&bs->throttled_reqs[is_write])) {
+        count++;
+        if (single) {
+            break;
         }
     }
+
+    if (count == 0) {
+        ThrottleGroup *tg = container_of(bs->throttle_state, ThrottleGroup, ts);
+
+        qemu_mutex_lock(&tg->lock);
+        schedule_next_request(bs, is_write);
+        qemu_mutex_unlock(&tg->lock);
+    }
+}
+
+static void throttle_group_restart_queue(BlockDriverState *bs, bool single,
+                                         bool is_write)
+{
+    RestartData *data = g_new(RestartData, 1);
+
+    data->bs = bs;
+    data->single = single;
+    data->is_write = is_write;
+    qemu_coroutine_enter(qemu_coroutine_create(throttle_group_restart_queue_entry),
+                         &data);
+}
+
+void throttle_group_restart_bs(BlockDriverState *bs)
+{
+    throttle_group_restart_queue(bs, false, 0);
+    throttle_group_restart_queue(bs, false, 1);
 }
 
 /* Update the throttle configuration for a particular group. Similar
@@ -351,8 +389,8 @@ void throttle_group_config(BlockDriverState *bs, ThrottleConfig *cfg)
     throttle_config(ts, tt, cfg);
     qemu_mutex_unlock(&tg->lock);
 
-    qemu_co_enter_next(&bs->throttled_reqs[0]);
-    qemu_co_enter_next(&bs->throttled_reqs[1]);
+    throttle_group_restart_queue(bs, true, 0);
+    throttle_group_restart_queue(bs, true, 1);
 }
 
 /* Get the throttle configuration from a particular group. Similar to
@@ -381,7 +419,6 @@ static void timer_cb(BlockDriverState *bs, bool is_write)
 {
     ThrottleState *ts = bs->throttle_state;
     ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
-    bool empty_queue;
 
     /* The timer has just been fired, so we can update the flag */
     qemu_mutex_lock(&tg->lock);
@@ -390,16 +427,8 @@ static void timer_cb(BlockDriverState *bs, bool is_write)
 
     /* Run the request that was waiting for this timer */
     aio_context_acquire(bdrv_get_aio_context(bs));
-    empty_queue = !qemu_co_enter_next(&bs->throttled_reqs[is_write]);
+    throttle_group_restart_queue(bs, true, is_write);
     aio_context_release(bdrv_get_aio_context(bs));
-
-    /* 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(bs, is_write);
-        qemu_mutex_unlock(&tg->lock);
-    }
 }
 
 static void read_timer_cb(void *opaque)
-- 
2.5.5

  parent reply	other threads:[~2016-04-15 11:32 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-15 11:31 [Qemu-devel] [RFC PATCH resend 00/11] Make CoMutex/CoQueue/CoRwlock thread-safe Paolo Bonzini
2016-04-15 11:31 ` [Qemu-devel] [PATCH 01/11] coroutine: use QSIMPLEQ instead of QTAILQ Paolo Bonzini
2016-04-19 13:45   ` Stefan Hajnoczi
2016-04-15 11:31 ` Paolo Bonzini [this message]
2016-04-19 13:49   ` [Qemu-devel] [PATCH 02/11] throttle-groups: restart throttled requests from coroutine context Stefan Hajnoczi
2016-04-15 11:31 ` [Qemu-devel] [PATCH 03/11] coroutine: delete qemu_co_enter_next Paolo Bonzini
2016-04-19 13:49   ` Stefan Hajnoczi
2016-04-15 11:31 ` [Qemu-devel] [PATCH 04/11] aio: introduce aio_co_schedule Paolo Bonzini
2016-04-19 14:31   ` Stefan Hajnoczi
2016-05-17 14:57     ` Paolo Bonzini
2016-05-26 19:19       ` Stefan Hajnoczi
2016-04-29  5:11   ` Fam Zheng
2016-05-17 14:38     ` Paolo Bonzini
2016-04-15 11:32 ` [Qemu-devel] [PATCH 05/11] coroutine-lock: reschedule coroutine on the AioContext it was running on Paolo Bonzini
2016-04-15 11:32 ` [Qemu-devel] [PATCH 06/11] coroutine-lock: make CoMutex thread-safe Paolo Bonzini
2016-04-29  6:26   ` Fam Zheng
2016-05-17 15:34     ` Paolo Bonzini
2016-04-15 11:32 ` [Qemu-devel] [PATCH 07/11] coroutine-lock: add limited spinning to CoMutex Paolo Bonzini
2016-04-15 11:32 ` [Qemu-devel] [PATCH 08/11] test-aio-multithread: add performance comparison with thread-based mutexes Paolo Bonzini
2016-04-29  6:52   ` Fam Zheng
2016-05-12 16:49     ` Paolo Bonzini
2016-04-15 11:32 ` [Qemu-devel] [PATCH 09/11] coroutine-lock: place CoMutex before CoQueue in header Paolo Bonzini
2016-04-15 11:32 ` [Qemu-devel] [PATCH 10/11] coroutine-lock: add mutex argument to CoQueue APIs Paolo Bonzini
2016-04-15 11:32 ` [Qemu-devel] [PATCH 11/11] coroutine-lock: make CoRwlock thread-safe and fair Paolo Bonzini
2016-04-26 10:54 ` [Qemu-devel] [RFC PATCH resend 00/11] Make CoMutex/CoQueue/CoRwlock thread-safe Stefan Hajnoczi
2016-04-27 15:42   ` Stefan Hajnoczi
2016-05-17 15:34   ` Paolo Bonzini

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=1460719926-12950-3-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=berto@igalia.com \
    --cc=famz@redhat.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).