From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 6E87C1D7 for ; Fri, 5 Jan 2018 19:01:24 +0100 (CET) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jan 2018 10:01:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,319,1511856000"; d="scan'208";a="7541660" Received: from debian-xvivbkq.sh.intel.com ([10.67.104.226]) by fmsmga007.fm.intel.com with ESMTP; 05 Jan 2018 10:01:22 -0800 Date: Sat, 6 Jan 2018 02:00:55 +0800 From: Tiwei Bie To: Xiao Wang Cc: dev@dpdk.org, yliu@fridaylinux.org, stephen@networkplumber.org Message-ID: <20180105180055.iqqd4km2m33jbuwc@debian-xvivbkq.sh.intel.com> References: <1515081578-30649-3-git-send-email-xiao.w.wang@intel.com> <1515170817-136539-1-git-send-email-xiao.w.wang@intel.com> <1515170817-136539-3-git-send-email-xiao.w.wang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1515170817-136539-3-git-send-email-xiao.w.wang@intel.com> User-Agent: NeoMutt/20170609 (1.8.3) Subject: Re: [dpdk-dev] [PATCH v5 2/3] net/virtio: add packet injection method X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jan 2018 18:01:24 -0000 On Fri, Jan 05, 2018 at 08:46:56AM -0800, Xiao Wang wrote: [...] > +/* > + * Recover hw state to let worker thread continue. > + */ > +void > +virtio_dev_resume(struct rte_eth_dev *dev) > +{ > + struct virtio_hw *hw = dev->data->dev_private; > + > + hw->started = 1; > + rte_spinlock_unlock(&hw->state_lock); > +} > + > +int > +virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **buf, int count) > +{ It would be better to name `buf` as tx_pkts and name `count` as nb_pkts. It would be better to add some comments to highlight that the device needs to be paused before calling this function in driver. > + struct virtio_hw *hw = dev->data->dev_private; > + struct virtnet_tx *txvq = dev->data->tx_queues[0]; > + int ret; [...] > diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h > index 2039bc5..4a2a2f0 100644 > --- a/drivers/net/virtio/virtio_ethdev.h > +++ b/drivers/net/virtio/virtio_ethdev.h > @@ -37,6 +37,7 @@ > #include > > #include "virtio_pci.h" > +#include "virtio_rxtx.h" It's not necessary to include this header file. > > #define SPEED_10 10 > #define SPEED_100 100 > @@ -121,4 +122,9 @@ uint16_t virtio_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts, > > void virtio_interrupt_handler(void *param); > > +int virtio_dev_pause(struct rte_eth_dev *dev); > +void virtio_dev_resume(struct rte_eth_dev *dev); > +int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **buf, > + int count); Ditto. > + [...] > diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c > index 6a24fde..bbf5aaf 100644 > --- a/drivers/net/virtio/virtio_rxtx.c > +++ b/drivers/net/virtio/virtio_rxtx.c > @@ -1017,7 +1017,7 @@ > uint16_t nb_used, nb_tx = 0; > int error; > > - if (unlikely(hw->started == 0)) > + if (unlikely(hw->started == 0) && tx_pkts != hw->inject_buf) Why not just put all the condition checks in unlikely()? If (hw->started == 0) is "unlikely", then (hw->started == 0 && tx_pkts != hw->inject_buf) would be more "unlikely". > return nb_tx; > > if (unlikely(nb_pkts < 1)) > diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c > index b5bc1c4..d81d162 100644 > --- a/drivers/net/virtio/virtio_rxtx_simple.c > +++ b/drivers/net/virtio/virtio_rxtx_simple.c > @@ -99,7 +99,7 @@ int __attribute__((cold)) > uint16_t desc_idx_max = (vq->vq_nentries >> 1) - 1; > uint16_t nb_tx = 0; > > - if (unlikely(hw->started == 0)) > + if (unlikely(hw->started == 0) && tx_pkts != hw->inject_buf) Ditto. Thanks, Tiwei