From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id E1EC35954 for ; Thu, 25 Aug 2016 05:37:59 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 24 Aug 2016 20:37:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,573,1464678000"; d="scan'208";a="753197099" Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.67.162]) by FMSMGA003.fm.intel.com with ESMTP; 24 Aug 2016 20:37:57 -0700 Date: Thu, 25 Aug 2016 11:48:00 +0800 From: Yuanhan Liu To: Zhihong Wang Cc: dev@dpdk.org, maxime.coquelin@redhat.com Message-ID: <20160825034800.GW30752@yliu-dev.sh.intel.com> References: <1471585430-125925-1-git-send-email-zhihong.wang@intel.com> <1471585430-125925-5-git-send-email-zhihong.wang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1471585430-125925-5-git-send-email-zhihong.wang@intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH v3 4/5] vhost: batch update used ring 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: Thu, 25 Aug 2016 03:38:00 -0000 On Fri, Aug 19, 2016 at 01:43:49AM -0400, Zhihong Wang wrote: > This patch enables batch update of the used ring for better efficiency. > > Signed-off-by: Zhihong Wang ... > diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c > index 1785695..87d09fa 100644 > --- a/lib/librte_vhost/virtio-net.c > +++ b/lib/librte_vhost/virtio-net.c > @@ -152,10 +152,14 @@ cleanup_device(struct virtio_net *dev, int destroy) > static void > free_device(struct virtio_net *dev) > { > + struct vhost_virtqueue *vq; > uint32_t i; > > - for (i = 0; i < dev->virt_qp_nb; i++) > - rte_free(dev->virtqueue[i * VIRTIO_QNUM]); > + for (i = 0; i < dev->virt_qp_nb; i++) { > + vq = dev->virtqueue[i * VIRTIO_QNUM]; > + rte_free(vq->shadow_used_ring); > + rte_free(vq); > + } > rte_free(dev); > } > @@ -418,13 +422,18 @@ int > vhost_set_vring_num(int vid, struct vhost_vring_state *state) > { > struct virtio_net *dev; > + struct vhost_virtqueue *vq; > > dev = get_device(vid); > if (dev == NULL) > return -1; > > /* State->index refers to the queue index. The txq is 1, rxq is 0. */ > - dev->virtqueue[state->index]->size = state->num; > + vq = dev->virtqueue[state->index]; > + vq->size = state->num; > + vq->shadow_used_ring = rte_malloc("", > + vq->size * sizeof(struct vring_used_elem), > + RTE_CACHE_LINE_SIZE); Few notes here: - I think the typical way to not specific a string type is using NULL, but not "". - You should check the return value of rte_malloc: it could fail. - Note that free_device() is invoked only when the vhost-user connection is broken (say the guest is halt). However, vhost_set_vring_num() could be invoked many times for a connection, say when you restart testpmd many times. This would lead to memory leak. The right way is to free it on get_vring_base(). --yliu