From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 093D2A0A0F; Fri, 16 Apr 2021 11:41:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E5658141C38; Fri, 16 Apr 2021 11:41:10 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 1E3E6141B83 for ; Fri, 16 Apr 2021 11:41:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566069; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MK/4kVmIQ2zxdpXpKBV6FP0BhPHuW67xW6tgXsn4JwU=; b=ZhbAIr1yNfcs028beVeMzkfeRWpoVGZuUhdKYb7+83IorxbRIXUzRxbQMAfFsozNmWmIgL mtWVcPmCiwkGjA2s2Y0PETMFI77XaYNx6vSV6WiLmdIN4YfcvQy+ysHTDMvMNnQOP/Zxtj RP+sp4/LBoZCU4bm+lr3+axeNO/9mHs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-114-esRlVLqHOqS29h2HLUTYmQ-1; Fri, 16 Apr 2021 05:41:08 -0400 X-MC-Unique: esRlVLqHOqS29h2HLUTYmQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BBFA19251A0; Fri, 16 Apr 2021 09:41:07 +0000 (UTC) Received: from [10.36.110.28] (unknown [10.36.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D446060C0F; Fri, 16 Apr 2021 09:41:02 +0000 (UTC) To: Balazs Nemeth , David Marchand Cc: dev , "Xia, Chenbo" References: From: Maxime Coquelin Message-ID: <9d476397-a97c-3c9b-275e-48ecd157dba8@redhat.com> Date: Fri, 16 Apr 2021 11:41:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH v3] vhost: allocate and free packets in bulk X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Balazs, On 4/16/21 11:12 AM, Balazs Nemeth wrote: > Hi David, > > I was also thinking about using the same idea for tx split so that > virtio_dev_pktmbuf_alloc can be removed completely. I don't have those > patches yet. However, I can make virtio_dev_pktmbuf_alloc use > virtio_dev_pktmbuf_prep for this patch that addresses the packed > version and submit other patches for tx split later. Would that work for > now? I think so. That would be great to have the same for split ring, but more rework may be necessary than for packed ring. So I'm fine if the split ring part is done after this release. Thanks, Maxime > Regards, > Balazs  > > On Fri, Apr 16, 2021 at 11:05 AM David Marchand > > wrote: > > On Fri, Apr 16, 2021 at 10:18 AM Balazs Nemeth > wrote: > > > > Move allocation out further and perform all allocation in bulk. > The same > > goes for freeing packets. In the process, also rename > > virtio_dev_pktmbuf_alloc to virtio_dev_pktmbuf_prep. This > > function now receives an already allocated mbuf pointer. > > > > Signed-off-by: Balazs Nemeth > > > The title should indicate we are only touching the tx packed path. > > What about tx split? > If it is too complex to rework, this can wait. > > > > --- > >  lib/librte_vhost/virtio_net.c | 58 > +++++++++++++++++++++++------------ > >  1 file changed, 38 insertions(+), 20 deletions(-) > > > > diff --git a/lib/librte_vhost/virtio_net.c > b/lib/librte_vhost/virtio_net.c > > index ff39878609..d6d5636e0f 100644 > > --- a/lib/librte_vhost/virtio_net.c > > +++ b/lib/librte_vhost/virtio_net.c > > @@ -2168,6 +2168,24 @@ virtio_dev_pktmbuf_alloc(struct virtio_net > *dev, struct rte_mempool *mp, > >         return NULL; > >  } > > > > +static __rte_always_inline int > > +virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt, > > +                        uint32_t data_len) > > +{ > > +       if (rte_pktmbuf_tailroom(pkt) >= data_len) > > +               return 0; > > + > > +       /* attach an external buffer if supported */ > > +       if (dev->extbuf && !virtio_dev_extbuf_alloc(pkt, data_len)) > > +               return 0; > > + > > +       /* check if chained buffers are allowed */ > > +       if (!dev->linearbuf) > > +               return 0; > > + > > +       return -1; > > +} > > + > > If virtio_dev_pktmbuf_alloc() uses this new helper, we avoid > duplicating the logic. > > > >  static __rte_noinline uint16_t > >  virtio_dev_tx_split(struct virtio_net *dev, struct > vhost_virtqueue *vq, > >         struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, > uint16_t count) > > [snip] > > > @@ -2429,7 +2440,7 @@ static __rte_always_inline int > >  virtio_dev_tx_single_packed(struct virtio_net *dev, > >                             struct vhost_virtqueue *vq, > >                             struct rte_mempool *mbuf_pool, > > -                           struct rte_mbuf **pkts) > > +                           struct rte_mbuf *pkts) > >  { > > > >         uint16_t buf_id, desc_count = 0; > > @@ -2462,26 +2473,33 @@ virtio_dev_tx_packed(struct virtio_net *dev, > >         uint32_t pkt_idx = 0; > >         uint32_t remained = count; > > > > +       if (rte_pktmbuf_alloc_bulk(mbuf_pool, pkts, count)) > > +               return 0; > > + > >         do { > >                 rte_prefetch0(&vq->desc_packed[vq->last_avail_idx]); > > > >                 if (remained >= PACKED_BATCH_SIZE) { > > -                       if (!virtio_dev_tx_batch_packed(dev, vq, > mbuf_pool, > > +                       if (!virtio_dev_tx_batch_packed(dev, vq, > >                                                        >  &pkts[pkt_idx])) { > >                                 pkt_idx += PACKED_BATCH_SIZE; > >                                 remained -= PACKED_BATCH_SIZE; > > + > > No need for the extra line. > > > >                                 continue; > >                         } > >                 } > > > >                 if (virtio_dev_tx_single_packed(dev, vq, mbuf_pool, > > -                                               &pkts[pkt_idx])) > > +                                               pkts[pkt_idx])) > >                         break; > >                 pkt_idx++; > >                 remained--; > > > >         } while (remained); > > > > +       if (pkt_idx != count) > > +               rte_pktmbuf_free_bulk(&pkts[pkt_idx], count - > pkt_idx); > > + > >         if (vq->shadow_used_idx) { > >                 do_data_copy_dequeue(vq); > > > > With those comments addressed, > Reviewed-by: David Marchand > > > Thanks Balazs! > > > -- > David Marchand >