From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dor Laor Subject: Re: [PATCH 4/6] virtio network driver for QEMU (v2) Date: Sun, 11 Nov 2007 19:31:23 +0200 Message-ID: <47373C6B.7090102@qumranet.com> References: <11947512401155-git-send-email-aliguori@us.ibm.com> <11947512454030-git-send-email-aliguori@us.ibm.com> Reply-To: dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, Avi Kivity To: Anthony Liguori Return-path: In-Reply-To: <11947512454030-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org Anthony Liguori wrote: > This patch implements a very naive virtio network device backend in QEMU. > Even with this simple implementation, it get's about 3x the throughput of > rtl8139. Of course, there's a whole lot of room for optimization to eliminate > the unnecessary copying and support more advanced features. > > To use a virtio network device, simply specific '-net nic,model=virtio' > > Signed-off-by: Anthony Liguori > [snip] > +/* TX */ > +static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq) > +{ > + VirtIONet *n = to_virtio_net(vdev); > + VirtQueueElement elem; > + > + while (virtqueue_pop(vq, &elem)) { > + int i; > + size_t len = 0; > + > + /* ignore the header for now */ > + for (i = 1; i < elem.out_num; i++) { > + qemu_send_packet(n->vc, elem.out_sg[i].iov_base, > + elem.out_sg[i].iov_len); > + len += elem.out_sg[i].iov_len; > + } > + > + virtqueue_push(vq, &elem, sizeof(struct virtio_net_hdr) + len); > + virtio_notify(&n->vdev, vq); > + } > +} > Get the notify out of the while please. Regardless of above, at the moment you copy the receive packets into virtio sg's. I had a did an incomplete job of adding vectored read to qemu. What's your opinion about it? Maybe using qemu's pending dma functions? Regards & cheers, Dor. > + > +VirtIODevice *virtio_net_init(PCIBus *bus, uint16_t vendor, uint16_t device, > + NICInfo *nd, int devfn) > +{ > + VirtIONet *n; > + > + n = (VirtIONet *)virtio_init_pci(bus, "virtio-net", vendor, device, > + vendor, VIRTIO_ID_NET, > + 6, sizeof(VirtIONet)); > + > + n->vdev.update_config = virtio_net_update_config; > + n->vdev.get_features = virtio_net_get_features; > + n->rx_vq = virtio_add_queue(&n->vdev, virtio_net_handle_rx); > + n->tx_vq = virtio_add_queue(&n->vdev, virtio_net_handle_tx); > + n->can_receive = 0; > + memcpy(n->mac, nd->macaddr, 6); > + n->vc = qemu_new_vlan_client(nd->vlan, virtio_net_receive, > + virtio_net_can_receive, n); > + > + return &n->vdev; > +} > diff --git a/qemu/vl.h b/qemu/vl.h > index 7b5cc8d..4f26fbb 100644 > --- a/qemu/vl.h > +++ b/qemu/vl.h > @@ -1401,6 +1401,9 @@ VirtIODevice *virtio_blk_init(PCIBus *bus, uint16_t vendor, uint16_t device, > > VirtIODevice *virtio_9p_init(PCIBus *bus, uint16_t vendor, uint16_t device); > > +VirtIODevice *virtio_net_init(PCIBus *bus, uint16_t vendor, uint16_t device, > + NICInfo *nd, int devfn); > + > /* buf = NULL means polling */ > typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out, > const uint8_t *buf, int len); > > ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/