From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH v6 09/17] virtio: add minimal support for virtqueues Date: Fri, 11 Jul 2014 11:32:20 +0200 Message-ID: <53BFAF24.2050900@redhat.com> References: <1405066787-5793-1-git-send-email-drjones@redhat.com> <1405066787-5793-10-git-send-email-drjones@redhat.com> <53BFAD00.4000700@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: christoffer.dall@linaro.org To: Andrew Jones , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Return-path: Received: from mail-ie0-f175.google.com ([209.85.223.175]:55951 "EHLO mail-ie0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752135AbaGKJcZ (ORCPT ); Fri, 11 Jul 2014 05:32:25 -0400 Received: by mail-ie0-f175.google.com with SMTP id x19so681936ier.34 for ; Fri, 11 Jul 2014 02:32:24 -0700 (PDT) In-Reply-To: <53BFAD00.4000700@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Il 11/07/2014 11:23, Paolo Bonzini ha scritto: > >> +static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, >> + unsigned index, >> + void (*callback)(struct virtqueue *vq), >> + const char *name) >> +{ >> + struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); >> + struct vring_virtqueue *vq; >> + void *queue; >> + unsigned num = VIRTIO_MMIO_QUEUE_NUM_MIN; >> + >> + vq = alloc(sizeof(*vq)); > > You can move the allocation of vq to vm_find_vqs (interleaving alloc and > alloc_aligned causes some fragmentation), allocating a single block > instead of one per vq. ... or even use static storage for the "struct virtqueue". You can just merge "struct vring_virtqueue" and "struct virtqueue", as the idea of other virtqueue transport never materialized. Then: +static struct virtqueue in_vq; +static struct virtqueue out_vq; + void chr_testdev_init(void) { const char *io_names[] = { "input", "output" }; - struct virtqueue *vqs[2]; + struct virtqueue *vqs[2] = { &in_vq, &out_vq }; int ret; vcon = virtio_bind(VIRTIO_ID_CONSOLE); if (vcon == NULL) { printf("%s: %s: can't find a virtio-console\n", __func__, TESTDEV_NAME); return; } ret = vcon->config->find_vqs(vcon, 2, vqs, NULL, io_names); if (ret < 0) { printf("%s: %s: can't init virtqueues\n", __func__, TESTDEV_NAME); vcon = NULL; return; } - in_vq = vqs[0]; - out_vq = vqs[1]; } Paolo