public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Asias He <asias@redhat.com>, kvm-devel <kvm@vger.kernel.org>
Subject: [PATCH 1/2] vhost: Reduce vhost_work_flush() wakeup latency
Date: Wed, 14 Aug 2013 09:02:32 +0200	[thread overview]
Message-ID: <520B2B88.6020307@acm.org> (raw)
In-Reply-To: <520B2B47.9040002@acm.org>

If the TIF_NEED_RESCHED task flag is set, wake up any vhost_work_flush()
waiters before rescheduling instead of after rescheduling.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Asias He <asias@redhat.com>
---
 drivers/vhost/vhost.c |   42 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index e58cf00..e7ffc10 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -201,47 +201,43 @@ static void vhost_vq_reset(struct vhost_dev *dev,
 static int vhost_worker(void *data)
 {
 	struct vhost_dev *dev = data;
-	struct vhost_work *work = NULL;
-	unsigned uninitialized_var(seq);
+	struct vhost_work *work;
+	unsigned seq;
 	mm_segment_t oldfs = get_fs();
 
 	set_fs(USER_DS);
 	use_mm(dev->mm);
 
-	for (;;) {
+	spin_lock_irq(&dev->work_lock);
+	while (!kthread_should_stop()) {
 		/* mb paired w/ kthread_stop */
 		set_current_state(TASK_INTERRUPTIBLE);
-
-		spin_lock_irq(&dev->work_lock);
-		if (work) {
-			work->done_seq = seq;
-			if (work->flushing)
-				wake_up_all(&work->done);
-		}
-
-		if (kthread_should_stop()) {
-			spin_unlock_irq(&dev->work_lock);
-			__set_current_state(TASK_RUNNING);
-			break;
-		}
 		if (!list_empty(&dev->work_list)) {
 			work = list_first_entry(&dev->work_list,
 						struct vhost_work, node);
 			list_del_init(&work->node);
 			seq = work->queue_seq;
-		} else
-			work = NULL;
-		spin_unlock_irq(&dev->work_lock);
+			spin_unlock_irq(&dev->work_lock);
 
-		if (work) {
 			__set_current_state(TASK_RUNNING);
 			work->fn(work);
-			if (need_resched())
-				schedule();
-		} else
+
+			spin_lock_irq(&dev->work_lock);
+			work->done_seq = seq;
+			if (work->flushing)
+				wake_up_all(&work->done);
+		}
+		if (list_empty(&dev->work_list) || need_resched()) {
+			spin_unlock_irq(&dev->work_lock);
+
 			schedule();
 
+			spin_lock_irq(&dev->work_lock);
+		}
 	}
+	spin_unlock_irq(&dev->work_lock);
+
+	__set_current_state(TASK_RUNNING);
 	unuse_mm(dev->mm);
 	set_fs(oldfs);
 	return 0;
-- 
1.7.10.4


  reply	other threads:[~2013-08-14  7:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14  7:01 [PATCH 0/2] vhost_worker fixes Bart Van Assche
2013-08-14  7:02 ` Bart Van Assche [this message]
2013-08-14 11:37   ` [PATCH 1/2] vhost: Reduce vhost_work_flush() wakeup latency Michael S. Tsirkin
2013-08-14 15:22     ` Bart Van Assche
2013-08-14 17:58       ` Michael S. Tsirkin
2013-08-15  1:30         ` Asias He
2013-08-15  6:13           ` Bart Van Assche
2013-08-15  7:35             ` Michael S. Tsirkin
2013-08-14  7:03 ` [PATCH 2/2] vhost: Avoid that vhost_work_flush() returns early Bart Van Assche
2013-08-14 11:46   ` Michael S. Tsirkin
2013-08-14 15:19     ` Bart Van Assche
2013-08-14 11:39 ` [PATCH 0/2] vhost_worker fixes Michael S. Tsirkin

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=520B2B88.6020307@acm.org \
    --to=bvanassche@acm.org \
    --cc=asias@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@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