[v2,3/3] net/pcap: support pcap files and ifaces mix
Checks
Commit Message
Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Signed-off-by: ido goshen <ido@cgstowernetworks.com>
---
drivers/net/pcap/rte_eth_pcap.c | 82 +++++++++++++++++++++++++----------------
1 file changed, 50 insertions(+), 32 deletions(-)
Comments
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@intel.com>
> Sent: Thursday, June 21, 2018 3:51 PM
> To: Ido Goshen <Ido@cgstowernetworks.com>
> Cc: dev@dpdk.org
> Subject: Re: [PATCH v2 3/3] net/pcap: support pcap files and ifaces mix
>
> On 6/21/2018 1:24 PM, ido goshen wrote:
> > Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> >
> > Signed-off-by: ido goshen <ido@cgstowernetworks.com>
>
> <...>
>
> > +static uint16_t
> > +eth_pcap_tx_mux(void *queue, struct rte_mbuf **bufs, uint16_t
> > +nb_pkts) {
> > + struct pcap_tx_queue *tx_queue = queue;
> > + if (tx_queue->dumper)
> > + return eth_pcap_tx_dumper(queue, bufs, nb_pkts);
> > + else
> > + return eth_pcap_tx(queue, bufs, nb_pkts); }
> > +
> > /*
> > * pcap_open_live wrapper function
> > */
> > @@ -773,6 +783,31 @@ struct pmd_devargs {
> > return open_iface(key, value, extra_args); }
> >
> > +static int
> > +open_pcap_rx_mux(const char *key, const char *value, void
> > +*extra_args) {
> > + struct pmd_devargs *pcaps = extra_args;
>
> Do we need this assignment? Why not pass extra_args directly?
[idog] Correct, it can be passed directly
other option is to leave the assignment here and pass strong type to the internal open_rx_pcap/iface
instead of passing it as void*
Any preference?
>
> > +
> > + if (strcmp(key, ETH_PCAP_RX_PCAP_ARG) == 0)
> > + return open_rx_pcap(key, value, pcaps);
> > + if (strcmp(key, ETH_PCAP_RX_IFACE_ARG) == 0)
> > + return open_rx_iface(key, value, pcaps);
> > + return 0;
> > +}
> > +
> > +static int
> > +open_pcap_tx_mux(const char *key, const char *value, void
> > +*extra_args) {
> > + struct pmd_devargs *dumpers = extra_args;
>
> Do we need this assignment? Why not pass extra_args directly?
>
> > +
> > + if (strcmp(key, ETH_PCAP_TX_PCAP_ARG) == 0)
> > + return open_tx_pcap(key, value, dumpers);
> > + if (strcmp(key, ETH_PCAP_TX_IFACE_ARG) == 0)
> > + return open_tx_iface(key, value, dumpers);
> > + return 0;
> > +}
> > +
> > +
> > static struct rte_vdev_driver pmd_pcap_drv;
> >
> > static int
> > @@ -873,8 +908,7 @@ struct pmd_devargs { eth_from_pcaps(struct
> > rte_vdev_device *vdev,
> > struct pmd_devargs *rx_queues, const unsigned int
> nb_rx_queues,
> > struct pmd_devargs *tx_queues, const unsigned int
> nb_tx_queues,
> > - struct rte_kvargs *kvlist, int single_iface,
> > - unsigned int using_dumpers)
> > + struct rte_kvargs *kvlist, int single_iface)
> > {
> > struct pmd_internals *internals = NULL;
> > struct rte_eth_dev *eth_dev = NULL;
> > @@ -891,10 +925,7 @@ struct pmd_devargs {
> >
> > eth_dev->rx_pkt_burst = eth_pcap_rx;
> >
> > - if (using_dumpers)
> > - eth_dev->tx_pkt_burst = eth_pcap_tx_dumper;
> > - else
> > - eth_dev->tx_pkt_burst = eth_pcap_tx;
> > + eth_dev->tx_pkt_burst = eth_pcap_tx_mux;
>
> We shouldn't introduce an extra check in data path. Instead of checking "if
> (tx_queue->dumper)" for _each_ packet, we should check it here once and
> assign proper burst function.
[idog] I don't see how it can be avoided
rte_eth_dev has only single tx_pkt_burst
but now we suggest to support 2 different queue types in a single device
each type requires different end functionality pcap_dump or pcap_sendpkt
btw - it's only once per burst
On 6/22/2018 8:15 AM, Ido Goshen wrote:
>
>
>> -----Original Message-----
>> From: Ferruh Yigit <ferruh.yigit@intel.com>
>> Sent: Thursday, June 21, 2018 3:51 PM
>> To: Ido Goshen <Ido@cgstowernetworks.com>
>> Cc: dev@dpdk.org
>> Subject: Re: [PATCH v2 3/3] net/pcap: support pcap files and ifaces mix
>>
>> On 6/21/2018 1:24 PM, ido goshen wrote:
>>> Suggested-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>>
>>> Signed-off-by: ido goshen <ido@cgstowernetworks.com>
>>
>> <...>
>>
>>> +static uint16_t
>>> +eth_pcap_tx_mux(void *queue, struct rte_mbuf **bufs, uint16_t
>>> +nb_pkts) {
>>> + struct pcap_tx_queue *tx_queue = queue;
>>> + if (tx_queue->dumper)
>>> + return eth_pcap_tx_dumper(queue, bufs, nb_pkts);
>>> + else
>>> + return eth_pcap_tx(queue, bufs, nb_pkts); }
>>> +
>>> /*
>>> * pcap_open_live wrapper function
>>> */
>>> @@ -773,6 +783,31 @@ struct pmd_devargs {
>>> return open_iface(key, value, extra_args); }
>>>
>>> +static int
>>> +open_pcap_rx_mux(const char *key, const char *value, void
>>> +*extra_args) {
>>> + struct pmd_devargs *pcaps = extra_args;
>>
>> Do we need this assignment? Why not pass extra_args directly?
>
> [idog] Correct, it can be passed directly
> other option is to leave the assignment here and pass strong type to the internal open_rx_pcap/iface
> instead of passing it as void*
> Any preference?
>
>>
>>> +
>>> + if (strcmp(key, ETH_PCAP_RX_PCAP_ARG) == 0)
>>> + return open_rx_pcap(key, value, pcaps);
>>> + if (strcmp(key, ETH_PCAP_RX_IFACE_ARG) == 0)
>>> + return open_rx_iface(key, value, pcaps);
>>> + return 0;
>>> +}
>>> +
>>> +static int
>>> +open_pcap_tx_mux(const char *key, const char *value, void
>>> +*extra_args) {
>>> + struct pmd_devargs *dumpers = extra_args;
>>
>> Do we need this assignment? Why not pass extra_args directly?
>>
>>> +
>>> + if (strcmp(key, ETH_PCAP_TX_PCAP_ARG) == 0)
>>> + return open_tx_pcap(key, value, dumpers);
>>> + if (strcmp(key, ETH_PCAP_TX_IFACE_ARG) == 0)
>>> + return open_tx_iface(key, value, dumpers);
>>> + return 0;
>>> +}
>>> +
>>> +
>>> static struct rte_vdev_driver pmd_pcap_drv;
>>>
>>> static int
>>> @@ -873,8 +908,7 @@ struct pmd_devargs { eth_from_pcaps(struct
>>> rte_vdev_device *vdev,
>>> struct pmd_devargs *rx_queues, const unsigned int
>> nb_rx_queues,
>>> struct pmd_devargs *tx_queues, const unsigned int
>> nb_tx_queues,
>>> - struct rte_kvargs *kvlist, int single_iface,
>>> - unsigned int using_dumpers)
>>> + struct rte_kvargs *kvlist, int single_iface)
>>> {
>>> struct pmd_internals *internals = NULL;
>>> struct rte_eth_dev *eth_dev = NULL;
>>> @@ -891,10 +925,7 @@ struct pmd_devargs {
>>>
>>> eth_dev->rx_pkt_burst = eth_pcap_rx;
>>>
>>> - if (using_dumpers)
>>> - eth_dev->tx_pkt_burst = eth_pcap_tx_dumper;
>>> - else
>>> - eth_dev->tx_pkt_burst = eth_pcap_tx;
>>> + eth_dev->tx_pkt_burst = eth_pcap_tx_mux;
>>
>> We shouldn't introduce an extra check in data path. Instead of checking "if
>> (tx_queue->dumper)" for _each_ packet, we should check it here once and
>> assign proper burst function.
>
> [idog] I don't see how it can be avoided
> rte_eth_dev has only single tx_pkt_burst
> but now we suggest to support 2 different queue types in a single device
> each type requires different end functionality pcap_dump or pcap_sendpkt
> btw - it's only once per burst
Right, we can't avoid.
This change is removing a limitation in the PMD but with a side effect, I missed
side effect part.
I am for rejecting the patch until this feature explicitly requested for a
practical usecase, to be sure we are not introducing the side effect a feature
that is not really needed.
Thanks for your effort.
@@ -232,7 +232,7 @@ struct pmd_devargs {
/*
* Callback to handle writing packets to a pcap file.
*/
-static uint16_t
+static inline uint16_t
eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
unsigned int i;
@@ -293,7 +293,7 @@ struct pmd_devargs {
/*
* Callback to handle sending packets through a real NIC.
*/
-static uint16_t
+static inline uint16_t
eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
unsigned int i;
@@ -343,6 +343,16 @@ struct pmd_devargs {
return num_tx;
}
+static uint16_t
+eth_pcap_tx_mux(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
+{
+ struct pcap_tx_queue *tx_queue = queue;
+ if (tx_queue->dumper)
+ return eth_pcap_tx_dumper(queue, bufs, nb_pkts);
+ else
+ return eth_pcap_tx(queue, bufs, nb_pkts);
+}
+
/*
* pcap_open_live wrapper function
*/
@@ -773,6 +783,31 @@ struct pmd_devargs {
return open_iface(key, value, extra_args);
}
+static int
+open_pcap_rx_mux(const char *key, const char *value, void *extra_args)
+{
+ struct pmd_devargs *pcaps = extra_args;
+
+ if (strcmp(key, ETH_PCAP_RX_PCAP_ARG) == 0)
+ return open_rx_pcap(key, value, pcaps);
+ if (strcmp(key, ETH_PCAP_RX_IFACE_ARG) == 0)
+ return open_rx_iface(key, value, pcaps);
+ return 0;
+}
+
+static int
+open_pcap_tx_mux(const char *key, const char *value, void *extra_args)
+{
+ struct pmd_devargs *dumpers = extra_args;
+
+ if (strcmp(key, ETH_PCAP_TX_PCAP_ARG) == 0)
+ return open_tx_pcap(key, value, dumpers);
+ if (strcmp(key, ETH_PCAP_TX_IFACE_ARG) == 0)
+ return open_tx_iface(key, value, dumpers);
+ return 0;
+}
+
+
static struct rte_vdev_driver pmd_pcap_drv;
static int
@@ -873,8 +908,7 @@ struct pmd_devargs {
eth_from_pcaps(struct rte_vdev_device *vdev,
struct pmd_devargs *rx_queues, const unsigned int nb_rx_queues,
struct pmd_devargs *tx_queues, const unsigned int nb_tx_queues,
- struct rte_kvargs *kvlist, int single_iface,
- unsigned int using_dumpers)
+ struct rte_kvargs *kvlist, int single_iface)
{
struct pmd_internals *internals = NULL;
struct rte_eth_dev *eth_dev = NULL;
@@ -891,10 +925,7 @@ struct pmd_devargs {
eth_dev->rx_pkt_burst = eth_pcap_rx;
- if (using_dumpers)
- eth_dev->tx_pkt_burst = eth_pcap_tx_dumper;
- else
- eth_dev->tx_pkt_burst = eth_pcap_tx;
+ eth_dev->tx_pkt_burst = eth_pcap_tx_mux;
rte_eth_dev_probing_finish(eth_dev);
return 0;
@@ -904,7 +935,6 @@ struct pmd_devargs {
pmd_pcap_probe(struct rte_vdev_device *dev)
{
const char *name;
- unsigned int is_rx_pcap = 0, is_tx_pcap = 0;
struct rte_kvargs *kvlist;
struct pmd_devargs pcaps = {0};
struct pmd_devargs dumpers = {0};
@@ -958,42 +988,30 @@ struct pmd_devargs {
}
/*
- * We check whether we want to open a RX stream from a real NIC or a
- * pcap file
+ * Open RX streams for pcap files and real NICs
+ * Need to be parsed together for the queues to maintain
+ * the input args order
*/
- is_rx_pcap = rte_kvargs_count(kvlist, ETH_PCAP_RX_PCAP_ARG) ? 1 : 0;
pcaps.num_of_queue = 0;
-
- if (is_rx_pcap)
- ret = rte_kvargs_process(kvlist, ETH_PCAP_RX_PCAP_ARG,
- &open_rx_pcap, &pcaps);
- else
- ret = rte_kvargs_process(kvlist, ETH_PCAP_RX_IFACE_ARG,
- &open_rx_iface, &pcaps);
-
+ ret = rte_kvargs_process(kvlist, NULL,
+ &open_pcap_rx_mux, &pcaps);
if (ret < 0)
goto free_kvlist;
/*
- * We check whether we want to open a TX stream to a real NIC or a
- * pcap file
+ * Open TX streams for pcap files and real NICs
+ * Need to be parsed together for the queues to maintain
+ * the input args order
*/
- is_tx_pcap = rte_kvargs_count(kvlist, ETH_PCAP_TX_PCAP_ARG) ? 1 : 0;
dumpers.num_of_queue = 0;
-
- if (is_tx_pcap)
- ret = rte_kvargs_process(kvlist, ETH_PCAP_TX_PCAP_ARG,
- &open_tx_pcap, &dumpers);
- else
- ret = rte_kvargs_process(kvlist, ETH_PCAP_TX_IFACE_ARG,
- &open_tx_iface, &dumpers);
-
+ ret = rte_kvargs_process(kvlist, NULL,
+ &open_pcap_tx_mux, &dumpers);
if (ret < 0)
goto free_kvlist;
create_eth:
ret = eth_from_pcaps(dev, &pcaps, pcaps.num_of_queue, &dumpers,
- dumpers.num_of_queue, kvlist, single_iface, is_tx_pcap);
+ dumpers.num_of_queue, kvlist, single_iface);
free_kvlist:
rte_kvargs_free(kvlist);