kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com,
	prasadjoshi124@gmail.com, kvm@vger.kernel.org,
	Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 5/6] kvm tools: Use threadpool for virtio-console.
Date: Thu, 28 Apr 2011 16:40:44 +0300	[thread overview]
Message-ID: <1303998045-22932-5-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1303998045-22932-1-git-send-email-levinsasha928@gmail.com>

This is very similar to the change done in virtio-net.

Notice that one signal here comes from outside the module (actual terminal) while the other one is generated by the virtio module.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/virtio-console.c |   40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/virtio-console.c b/tools/kvm/virtio-console.c
index f11ce4e..e66d198 100644
--- a/tools/kvm/virtio-console.c
+++ b/tools/kvm/virtio-console.c
@@ -8,6 +8,7 @@
 #include "kvm/mutex.h"
 #include "kvm/kvm.h"
 #include "kvm/pci.h"
+#include "kvm/threadpool.h"
 
 #include <linux/virtio_console.h>
 #include <linux/virtio_ring.h>
@@ -41,6 +42,8 @@ struct console_device {
 	uint16_t			config_vector;
 	uint8_t				status;
 	uint16_t			queue_selector;
+
+	void			*jobs[VIRTIO_CONSOLE_NUM_QUEUES];
 };
 
 static struct console_device console_device = {
@@ -58,7 +61,7 @@ static struct console_device console_device = {
 /*
  * Interrupts are injected for hvc0 only.
  */
-void virtio_console__inject_interrupt(struct kvm *self)
+static void virtio_console__inject_interrupt_callback(struct kvm *self, void *param)
 {
 	struct iovec iov[VIRTIO_CONSOLE_QUEUE_SIZE];
 	struct virt_queue *vq;
@@ -68,7 +71,7 @@ void virtio_console__inject_interrupt(struct kvm *self)
 
 	mutex_lock(&console_device.mutex);
 
-	vq = &console_device.vqs[VIRTIO_CONSOLE_RX_QUEUE];
+	vq = param;
 
 	if (term_readable(CONSOLE_VIRTIO) && virt_queue__available(vq)) {
 		head = virt_queue__get_iov(vq, iov, &out, &in, self);
@@ -80,6 +83,11 @@ void virtio_console__inject_interrupt(struct kvm *self)
 	mutex_unlock(&console_device.mutex);
 }
 
+void virtio_console__inject_interrupt(struct kvm *self)
+{
+	thread_pool__signal_work(console_device.jobs[VIRTIO_CONSOLE_RX_QUEUE]);
+}
+
 static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long offset, int size, uint32_t count)
 {
 	uint8_t *config_space = (uint8_t *) &console_device.console_config;
@@ -138,7 +146,7 @@ static bool virtio_console_pci_io_in(struct kvm *self, uint16_t port, void *data
 	return ret;
 }
 
-static void virtio_console_handle_callback(struct kvm *self, uint16_t queue_index)
+static void virtio_console_handle_callback(struct kvm *self, void *param)
 {
 	struct iovec iov[VIRTIO_CONSOLE_QUEUE_SIZE];
 	struct virt_queue *vq;
@@ -146,18 +154,15 @@ static void virtio_console_handle_callback(struct kvm *self, uint16_t queue_inde
 	uint16_t head;
 	uint32_t len;
 
-	vq = &console_device.vqs[queue_index];
-
-	if (queue_index == VIRTIO_CONSOLE_TX_QUEUE) {
+	vq = param;
 
-		while (virt_queue__available(vq)) {
-			head = virt_queue__get_iov(vq, iov, &out, &in, self);
-			len = term_putc_iov(CONSOLE_VIRTIO, iov, out);
-			virt_queue__set_used_elem(vq, head, len);
-		}
-
-		kvm__irq_line(self, VIRTIO_CONSOLE_IRQ, 1);
+	while (virt_queue__available(vq)) {
+		head = virt_queue__get_iov(vq, iov, &out, &in, self);
+		len = term_putc_iov(CONSOLE_VIRTIO, iov, out);
+		virt_queue__set_used_elem(vq, head, len);
 	}
+
+	kvm__irq_line(self, VIRTIO_CONSOLE_IRQ, 1);
 }
 
 static bool virtio_console_pci_io_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
@@ -183,6 +188,13 @@ static bool virtio_console_pci_io_out(struct kvm *self, uint16_t port, void *dat
 
 		vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, 4096);
 
+		if (console_device.queue_selector == VIRTIO_CONSOLE_TX_QUEUE)
+			console_device.jobs[console_device.queue_selector] =
+				thread_pool__add_jobtype(self, virtio_console_handle_callback, queue);
+		else if (console_device.queue_selector == VIRTIO_CONSOLE_RX_QUEUE)
+			console_device.jobs[console_device.queue_selector] =
+				thread_pool__add_jobtype(self, virtio_console__inject_interrupt_callback, queue);
+
 		break;
 	}
 	case VIRTIO_PCI_QUEUE_SEL:
@@ -191,7 +203,7 @@ static bool virtio_console_pci_io_out(struct kvm *self, uint16_t port, void *dat
 	case VIRTIO_PCI_QUEUE_NOTIFY: {
 		uint16_t queue_index;
 		queue_index	= ioport__read16(data);
-		virtio_console_handle_callback(self, queue_index);
+		thread_pool__signal_work(console_device.jobs[queue_index]);
 		break;
 	}
 	case VIRTIO_PCI_STATUS:
-- 
1.7.5.rc3


  parent reply	other threads:[~2011-04-28 13:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-28 13:40 [PATCH 1/6] kvm tools: Prevent duplicate definitions of ALIGN Sasha Levin
2011-04-28 13:40 ` [PATCH 2/6] kvm tools: Add kernel headers required for using list Sasha Levin
2011-04-28 13:40 ` [PATCH 3/6] kvm tools: Introduce generic IO threadpool Sasha Levin
2011-04-29  7:08   ` Asias He
     [not found]     ` <4DBA653A.90700@cs.helsinki.fi>
     [not found]       ` <1304064977.10069.15.camel@lappy>
2011-04-29 11:12         ` Sasha Levin
2011-04-28 13:40 ` [PATCH 4/6] kvm tools: Use threadpool for virtio-blk Sasha Levin
2011-04-28 13:40 ` Sasha Levin [this message]
2011-04-28 13:40 ` [PATCH 6/6] kvm tools: Use threadpool for virtio-net Sasha Levin

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=1303998045-22932-5-git-send-email-levinsasha928@gmail.com \
    --to=levinsasha928@gmail.com \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.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).