From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by dpdk.org (Postfix) with ESMTP id 3CD9FCE7 for ; Mon, 20 Jul 2015 20:40:38 +0200 (CEST) Received: by pdbnt7 with SMTP id nt7so34672326pdb.0 for ; Mon, 20 Jul 2015 11:40:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dbtaHaRwdFbKYxtZchCg4aLe+7wXXAdHTx1GuRcrrbQ=; b=HyMJQ2jhdDPPN+WRz3kw7i9+RaYeu1trQhYGOywiLi2vhWPSeCUtIKuy9H15xE34M2 xFRAo2GKgCWSoood87nqP1pIAFuf9sLE8cb2b8vCaaxqbg1tlYrfPXA9MU2of8DYBqpb gHONv9XsQTZwSGt+2QHYkURz7rKEJbKuXQOwmAOZGcMXY10Sa3xrYQtIdQtrq4pJPIHq 1PRILjygSXlOIyDKMWyyUGz+ZXdV6XOvaxFCOzU3whs9o+65soCBpEfMrSBZX34dVgUb VKDh75ebym/OYaBM34DlAqoOKZcW/6NkQBLESXC5vVd8M/7bH23MdguAsOyhkTzoSSMp PPdw== X-Gm-Message-State: ALoCoQnPonuov2W+BBkpISdQH2OiXrJ/RToSt49lCx42RAvYBEXFQTigHAg8wYooDB65bMMaEqiK X-Received: by 10.70.131.4 with SMTP id oi4mr62952751pdb.122.1437417637567; Mon, 20 Jul 2015 11:40:37 -0700 (PDT) Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by smtp.gmail.com with ESMTPSA id j4sm23105650pdg.64.2015.07.20.11.40.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Jul 2015 11:40:36 -0700 (PDT) From: Stephen Hemminger To: changchun.ouyang@intel.com Date: Mon, 20 Jul 2015 11:40:45 -0700 Message-Id: <1437417646-11221-2-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437417646-11221-1-git-send-email-stephen@networkplumber.org> References: <1437417646-11221-1-git-send-email-stephen@networkplumber.org> Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH v2 1/2] virtio: fix queue size and number of descriptors X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jul 2015 18:40:39 -0000 The virtual queue ring size and the number of slots actually usable are separate parameters. In the most common environment (QEMU) the virtual queue ring size is 256, but some environments the ring maybe much larger. The ring size comes from the host and the driver must use the actual size passed. The number of descriptors can be either zero to use the whole available ring, or some value smaller. This is used to limit the number of mbufs allocated for the receive ring. If more descriptors are requested than available the size is silently truncated. Note: the ring size (from host) must be a power of two, but the number of descriptors used can be any size from 1 to the size of the virtual ring. Reported-by: Ouyang Changchun Signed-off-by: Stephen Hemminger --- drivers/net/virtio/virtio_ethdev.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 9ca9bb2..d460d89 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -276,8 +276,6 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, */ vq_size = VIRTIO_READ_REG_2(hw, VIRTIO_PCI_QUEUE_NUM); PMD_INIT_LOG(DEBUG, "vq_size: %d nb_desc:%d", vq_size, nb_desc); - if (nb_desc == 0) - nb_desc = vq_size; if (vq_size == 0) { PMD_INIT_LOG(ERR, "%s: virtqueue does not exist", __func__); return -EINVAL; @@ -288,16 +286,6 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, return -EINVAL; } - if (nb_desc < vq_size) { - if (!rte_is_power_of_2(nb_desc)) { - PMD_INIT_LOG(ERR, - "nb_desc(%u) size is not powerof 2", - nb_desc); - return -EINVAL; - } - vq_size = nb_desc; - } - if (queue_type == VTNET_RQ) { snprintf(vq_name, sizeof(vq_name), "port%d_rvq%d", dev->data->port_id, queue_idx); @@ -325,7 +313,10 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, vq->queue_id = queue_idx; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; - vq->vq_free_cnt = vq_size; + + if (nb_desc == 0 || nb_desc > vq_size) + nb_desc = vq_size; + vq->vq_free_cnt = nb_desc; /* * Reserve a memzone for vring elements -- 2.1.4