[dpdk-dev] [RFC][PATCH 1/3] examples/vhost: Add vswitch (generic switch) framework
On 9/2/2016 7:47 PM, Maxime Coquelin wrote: > > Hi Pankaj, > > Sorry for the late review. Hi Maxime, No problem :) Thanks for the review, and it came just in time. I am almost done with testing the patchset for intel (with vmdq) and i was about to send the next version tomorrow. Now that i've your review and views, i will incorporte them and send the tested patchset soon. Thanks again for your time and effort for review. > > On 08/27/2016 06:26 PM, Pankaj Chauhan wrote: >> Indroduce support for a generic framework for handling of switching >> between > s/Indroduce/Introduce/ >> physical and virtio devices. The vswitch framework introduces the >> following >> concept: > Shouldn't you use vhost term instead of virtio? Agreed, i will use vhost in next version >> >> 1. vswitch_dev: Vswitch device is a logical switch which can have >> Phsyical and > s/Phsyical/physical/ >> virtio devices. The devices are operated/used using standard DPDK API for >> devices. > Maybe mention that today, we don't use PMD API for vhost devices but > use directly the vhost library API? Agreed, will do it. >> >> 2. vswitch_port: Any physical or virtio device that is added to >> vswitch. The >> port can have it's own tx/rx functions for doing data transfer, which >> are exposed > s/it's/its/ sorry for typo, will fix it. >> to the framework using generic function pointers >> (vs_port->do_tx/do_rx). This way >> the generic code can do tx/rx without understanding the type of device >> (Physical or >> virtio). > Very good. >> >> 3. vswitch_ops: The ops is set of function pointers which are used to >> do operations >> like learning, unlearning, add/delete port, lookup_and_forward. The >> user of vswitch >> framework (vhost/main.[c,h])uses these function pointers to perform >> above mentioned >> operations, thus it remains agnostic of the underlying implmentation. > s/implmentation/implementation/ Typo again my bad!, will fix it > > >> >> Different switching logics can implement their vswitch_device and >> vswitch_ops, and >> register with the framework. This framework makes vhost-switch >> application scalable >> in terms of: >> >> 1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h] >> 2. Number of ports. >> 3. Policies of selecting ports for rx and tx. >> >> Signed-off-by: Pankaj Chauhan >> --- >> examples/vhost/Makefile | 2 +- >> examples/vhost/vswitch_common.c | 467 >> >> examples/vhost/vswitch_common.h | 175 +++ >> 3 files changed, 643 insertions(+), 1 deletion(-) >> create mode 100644 examples/vhost/vswitch_common.c >> create mode 100644 examples/vhost/vswitch_common.h >> >> diff --git a/examples/vhost/Makefile b/examples/vhost/Makefile >> index e95c68a..458d166 100644 >> --- a/examples/vhost/Makefile >> +++ b/examples/vhost/Makefile >> @@ -48,7 +48,7 @@ else >> APP = vhost-switch >> >> # all source are stored in SRCS-y >> -SRCS-y := main.c >> +SRCS-y := main.c vswitch_common.c >> >> CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 >> CFLAGS += $(WERROR_FLAGS) >> diff --git a/examples/vhost/vswitch_common.c >> b/examples/vhost/vswitch_common.c >> new file mode 100644 >> index 000..f0e07f2 >> --- /dev/null >> +++ b/examples/vhost/vswitch_common.c >> @@ -0,0 +1,467 @@ >> +/*- >> + * BSD LICENSE >> + * >> + * Copyright(c) 2016 Freescale Semiconductor. All rights reserved. >> + * All rights reserved. >> + * >> + * Redistribution and use in source and binary forms, with or without >> + * modification, are permitted provided that the following conditions >> + * are met: >> + * >> + * * Redistributions of source code must retain the above copyright >> + * notice, this list of conditions and the following disclaimer. >> + * * Redistributions in binary form must reproduce the above >> copyright >> + * notice, this list of conditions and the following disclaimer in >> + * the documentation and/or other materials provided with the >> + * distribution. >> + * * Neither the name of Freescale Semiconductor nor the names of >> its >> + * contributors may be used to endorse or promote products derived >> + * from this software without specific prior written permission. >> + * >> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >> + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >> + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND >> FITNESS FOR >> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE >> COPYRIGHT >> + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, >> INCIDENTAL, >> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF >> USE, >> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >> ON ANY >> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >> + * (INCLUDING
[dpdk-dev] [RFC][PATCH 1/3] examples/vhost: Add vswitch (generic switch) framework
Hi Pankaj, Sorry for the late review. On 08/27/2016 06:26 PM, Pankaj Chauhan wrote: > Indroduce support for a generic framework for handling of switching between s/Indroduce/Introduce/ > physical and virtio devices. The vswitch framework introduces the following > concept: Shouldn't you use vhost term instead of virtio? > > 1. vswitch_dev: Vswitch device is a logical switch which can have Phsyical and s/Phsyical/physical/ > virtio devices. The devices are operated/used using standard DPDK API for > devices. Maybe mention that today, we don't use PMD API for vhost devices but use directly the vhost library API? > > 2. vswitch_port: Any physical or virtio device that is added to vswitch. The > port can have it's own tx/rx functions for doing data transfer, which are > exposed s/it's/its/ > to the framework using generic function pointers (vs_port->do_tx/do_rx). This > way > the generic code can do tx/rx without understanding the type of device > (Physical or > virtio). Very good. > > 3. vswitch_ops: The ops is set of function pointers which are used to do > operations > like learning, unlearning, add/delete port, lookup_and_forward. The user of > vswitch > framework (vhost/main.[c,h])uses these function pointers to perform above > mentioned > operations, thus it remains agnostic of the underlying implmentation. s/implmentation/implementation/ > > Different switching logics can implement their vswitch_device and > vswitch_ops, and > register with the framework. This framework makes vhost-switch application > scalable > in terms of: > > 1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h] > 2. Number of ports. > 3. Policies of selecting ports for rx and tx. > > Signed-off-by: Pankaj Chauhan > --- > examples/vhost/Makefile | 2 +- > examples/vhost/vswitch_common.c | 467 > > examples/vhost/vswitch_common.h | 175 +++ > 3 files changed, 643 insertions(+), 1 deletion(-) > create mode 100644 examples/vhost/vswitch_common.c > create mode 100644 examples/vhost/vswitch_common.h > > diff --git a/examples/vhost/Makefile b/examples/vhost/Makefile > index e95c68a..458d166 100644 > --- a/examples/vhost/Makefile > +++ b/examples/vhost/Makefile > @@ -48,7 +48,7 @@ else > APP = vhost-switch > > # all source are stored in SRCS-y > -SRCS-y := main.c > +SRCS-y := main.c vswitch_common.c > > CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 > CFLAGS += $(WERROR_FLAGS) > diff --git a/examples/vhost/vswitch_common.c b/examples/vhost/vswitch_common.c > new file mode 100644 > index 000..f0e07f2 > --- /dev/null > +++ b/examples/vhost/vswitch_common.c > @@ -0,0 +1,467 @@ > +/*- > + * BSD LICENSE > + * > + * Copyright(c) 2016 Freescale Semiconductor. All rights reserved. > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Freescale Semiconductor nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include "vswitch_common.h" > + > +/* Meta data for vswitch. Since this is going to be used in this file only it > + * is defined here instead of in a header file. > + */ > +struct vs_mdata { > + rte_spinlock_t lock; > + int vswitch_dev_count; > + LIST_HEAD(, vswitch_dev) vswitch_head; Since this is only used in this
[dpdk-dev] [RFC][PATCH 1/3] examples/vhost: Add vswitch (generic switch) framework
Indroduce support for a generic framework for handling of switching between physical and virtio devices. The vswitch framework introduces the following concept: 1. vswitch_dev: Vswitch device is a logical switch which can have Phsyical and virtio devices. The devices are operated/used using standard DPDK API for devices. 2. vswitch_port: Any physical or virtio device that is added to vswitch. The port can have it's own tx/rx functions for doing data transfer, which are exposed to the framework using generic function pointers (vs_port->do_tx/do_rx). This way the generic code can do tx/rx without understanding the type of device (Physical or virtio). 3. vswitch_ops: The ops is set of function pointers which are used to do operations like learning, unlearning, add/delete port, lookup_and_forward. The user of vswitch framework (vhost/main.[c,h])uses these function pointers to perform above mentioned operations, thus it remains agnostic of the underlying implmentation. Different switching logics can implement their vswitch_device and vswitch_ops, and register with the framework. This framework makes vhost-switch application scalable in terms of: 1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h] 2. Number of ports. 3. Policies of selecting ports for rx and tx. Signed-off-by: Pankaj Chauhan --- examples/vhost/Makefile | 2 +- examples/vhost/vswitch_common.c | 467 examples/vhost/vswitch_common.h | 175 +++ 3 files changed, 643 insertions(+), 1 deletion(-) create mode 100644 examples/vhost/vswitch_common.c create mode 100644 examples/vhost/vswitch_common.h diff --git a/examples/vhost/Makefile b/examples/vhost/Makefile index e95c68a..458d166 100644 --- a/examples/vhost/Makefile +++ b/examples/vhost/Makefile @@ -48,7 +48,7 @@ else APP = vhost-switch # all source are stored in SRCS-y -SRCS-y := main.c +SRCS-y := main.c vswitch_common.c CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 CFLAGS += $(WERROR_FLAGS) diff --git a/examples/vhost/vswitch_common.c b/examples/vhost/vswitch_common.c new file mode 100644 index 000..f0e07f2 --- /dev/null +++ b/examples/vhost/vswitch_common.c @@ -0,0 +1,467 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2016 Freescale Semiconductor. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Freescale Semiconductor nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "vswitch_common.h" + +/* Meta data for vswitch. Since this is going to be used in this file only it + * is defined here instead of in a header file. + */ +struct vs_mdata { + rte_spinlock_t lock; + int vswitch_dev_count; + LIST_HEAD(, vswitch_dev) vswitch_head; +}; + +static struct vs_mdata *vs_mdata_g; + +static uint16_t vs_do_tx_phys_port(struct vswitch_port *port, uint16_t tx_q, + __attribute__((unused))struct rte_mempool *mbuf_pool, + struct rte_mbuf **pkts, uint16_t pkt_count) +{ + return rte_eth_tx_burst(port->port_id, tx_q, pkts, pkt_count); +} + + +static uint16_t vs_do_tx_virtio_port(struct vswitch_port *port, uint16_t tx_q, + __attribute__((unused)) struct rte_mempool *mbuf_pool, + struct rte_mbuf **pkts, uint16_t pkt_count) +{ +