From patchwork Sat May 7 02:34:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 763942 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 p472ZsTw001288 for ; Sat, 7 May 2011 02:35:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754771Ab1EGCfw (ORCPT ); Fri, 6 May 2011 22:35:52 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:59119 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754067Ab1EGCfv (ORCPT ); Fri, 6 May 2011 22:35:51 -0400 Received: by pvg12 with SMTP id 12so1666222pvg.19 for ; Fri, 06 May 2011 19:35:51 -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; bh=pC9lQr3uEXTn+P0XEDIZMYNJsWLeWH07+J4hgQXzpuA=; b=p8norZllNWrLWChc74serMnryYGraovp/8ryafsOmq/Z4jz8u3yiEit0244+PvOgOl ErKO/ZCaBpMfwjXpttjNj7brd7SKK3Q7SOoqQ/yWIAJP4fzF9LSObKwZ0iFkYcTW+GYN QAFynH9NrvOCAWc168FIGQoGHaNUhcZSFnB2Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=soqbC8ZnTr4EIiwsCE0dhwjEx8qt14YnYfjeH1bR1sMM+Mc/slUTOz4r1BflcHBjzb WVCb14x/932B4yeVXpUjHbIBsvojw84yksqgsUZ6f5zqlmcYsHqo4WAccGyOMpBD8GIu g0j5k3+EqcSxrW+Xk6tMaaga6hLxbSCNnJtsk= Received: by 10.68.62.6 with SMTP id u6mr5596491pbr.408.1304735750960; Fri, 06 May 2011 19:35:50 -0700 (PDT) Received: from localhost.localdomain ([202.112.128.133]) by mx.google.com with ESMTPS id d9sm2519443pba.16.2011.05.06.19.35.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 06 May 2011 19:35:49 -0700 (PDT) From: Asias He To: Pekka Enberg , Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi Cc: kvm@vger.kernel.org, Asias He Subject: [PATCH 1/2] kvm tools: Respect ISR status in virtio header Date: Sat, 7 May 2011 10:34:19 +0800 Message-Id: <1304735660-10844-1-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.4.4 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]); Sat, 07 May 2011 02:35:55 +0000 (UTC) Inject IRQ to guest only when ISR status is low which means guest has read ISR status and device has cleared this bit as the side effect of this reading. This reduces a lot of unnecessary IRQ inject from device to guest. Netpef test shows this patch changes: the host to guest bandwidth from 2866.27 Mbps (cpu 33.96%) to 5548.87 Mbps (cpu 53.87%), the guest to host bandwitdth form 1408.86 Mbps (cpu 99.9%) to 1301.29 Mbps (cpu 99.9%). The bottleneck of the guest to host bandwidth is guest cpu power. Signed-off-by: Asias He --- tools/kvm/include/kvm/virtio.h | 5 +++++ tools/kvm/virtio/core.c | 8 ++++++++ tools/kvm/virtio/net.c | 12 ++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h index e8df8eb..7f92dea 100644 --- a/tools/kvm/include/kvm/virtio.h +++ b/tools/kvm/include/kvm/virtio.h @@ -8,6 +8,9 @@ #include "kvm/kvm.h" +#define VIRTIO_IRQ_LOW 0 +#define VIRTIO_IRQ_HIGH 1 + struct virt_queue { struct vring vring; u32 pfn; @@ -37,4 +40,6 @@ struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm); +void virt_queue__trigger_irq(struct virt_queue *vq, int irq, u8 *isr, struct kvm *kvm); + #endif /* KVM__VIRTIO_H */ diff --git a/tools/kvm/virtio/core.c b/tools/kvm/virtio/core.c index 18d2c41..0734984 100644 --- a/tools/kvm/virtio/core.c +++ b/tools/kvm/virtio/core.c @@ -57,3 +57,11 @@ u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, return head; } + +void virt_queue__trigger_irq(struct virt_queue *vq, int irq, u8 *isr, struct kvm *kvm) +{ + if (*isr == VIRTIO_IRQ_LOW) { + *isr = VIRTIO_IRQ_HIGH; + kvm__irq_line(kvm, irq, VIRTIO_IRQ_HIGH); + } +} diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index df69ab3..0189f7d 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -35,6 +35,7 @@ struct net_device { u32 guest_features; u16 config_vector; u8 status; + u8 isr; u16 queue_selector; pthread_t io_rx_thread; @@ -88,8 +89,9 @@ static void *virtio_net_rx_thread(void *p) head = virt_queue__get_iov(vq, iov, &out, &in, self); len = readv(net_device.tap_fd, iov, in); virt_queue__set_used_elem(vq, head, len); + /* We should interrupt guest right now, otherwise latency is huge. */ - kvm__irq_line(self, VIRTIO_NET_IRQ, 1); + virt_queue__trigger_irq(vq, VIRTIO_NET_IRQ, &net_device.isr, self); } } @@ -123,7 +125,8 @@ static void *virtio_net_tx_thread(void *p) virt_queue__set_used_elem(vq, head, len); } - kvm__irq_line(self, VIRTIO_NET_IRQ, 1); + virt_queue__trigger_irq(vq, VIRTIO_NET_IRQ, &net_device.isr, self); + } pthread_exit(NULL); @@ -175,8 +178,9 @@ static bool virtio_net_pci_io_in(struct kvm *self, u16 port, void *data, int siz ioport__write8(data, net_device.status); break; case VIRTIO_PCI_ISR: - ioport__write8(data, 0x1); - kvm__irq_line(self, VIRTIO_NET_IRQ, 0); + ioport__write8(data, net_device.isr); + kvm__irq_line(self, VIRTIO_NET_IRQ, VIRTIO_IRQ_LOW); + net_device.isr = VIRTIO_IRQ_LOW; break; case VIRTIO_MSI_CONFIG_VECTOR: ioport__write16(data, net_device.config_vector);