From patchwork Thu Apr 28 13:40:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 739301 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3SDfLea008534 for ; Thu, 28 Apr 2011 13:41:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932715Ab1D1NlP (ORCPT ); Thu, 28 Apr 2011 09:41:15 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:52574 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758293Ab1D1NlM (ORCPT ); Thu, 28 Apr 2011 09:41:12 -0400 Received: by mail-bw0-f46.google.com with SMTP id 15so2302490bwz.19 for ; Thu, 28 Apr 2011 06:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=X+8joROGVnT+UtXa7F4WOwvCwLfRTEBQtURrfTa3AVA=; b=c2YEmBIXpxfE4gj3gNp38WNHkyFjEYWjMn4abDpzDj+DOozUfau2g7bolMWQ4rtSHh otgrsb9AafEaYDPy3FvB1BROkTIl82Eu03K1u3f61rtol9AcIh81nVi33/bl4RPaBStK PVfsqtHE61pMj2vB2BGAWjd6/ALhyiIADqupY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=EOJPY/aJDPulYm7d3we6tWjYRg9v1e1AJpoXxXNhFmXi0D+xAorpgL40YqZh/Dp6jt OAxzd3OEA74YakmGRHH+7sBBzYabXOdloIewst4G9UMOve1apXkCcjuLG3pcWdSJASxb mODhHRFFxTVEErYnqWUdZwecVqcy2weKQcf7A= Received: by 10.204.8.141 with SMTP id h13mr3448700bkh.64.1303998071976; Thu, 28 Apr 2011 06:41:11 -0700 (PDT) Received: from localhost.localdomain ([188.120.129.206]) by mx.google.com with ESMTPS id w3sm1033795bkt.17.2011.04.28.06.41.09 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Apr 2011 06:41:11 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 5/6] kvm tools: Use threadpool for virtio-console. Date: Thu, 28 Apr 2011 16:40:44 +0300 Message-Id: <1303998045-22932-5-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1303998045-22932-1-git-send-email-levinsasha928@gmail.com> References: <1303998045-22932-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 28 Apr 2011 13:41:21 +0000 (UTC) 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 --- 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 #include @@ -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: