From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0073.outbound.protection.outlook.com [104.47.40.73]) by dpdk.org (Postfix) with ESMTP id 682DFF91B for ; Mon, 19 Dec 2016 18:52:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cpluK8wj2m1Op2sQjWtPmPokuPMMXrJ2pVCKiXHpk98=; b=EJRP7Kqmk0qLQzNUiLvRUMTNmmGsAQd4rCgrrFZj/uJk1nx0YmVniszy/jdnCla2L/qnzXk8w65c9Ln1BvvTwOqbPynbkQ/YWw81taWlHn+3n/NN2ic7zTa/vldpy3ZJl2LRkwnRT+a++B+0VXFBX5OH1xACA/sV50pc1gQeANc= Received: from BY2PR05MB2359.namprd05.prod.outlook.com (10.166.113.11) by BY2PR05MB2359.namprd05.prod.outlook.com (10.166.113.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.5; Mon, 19 Dec 2016 17:52:49 +0000 Received: from BY2PR05MB2359.namprd05.prod.outlook.com ([10.166.113.11]) by BY2PR05MB2359.namprd05.prod.outlook.com ([10.166.113.11]) with mapi id 15.01.0803.010; Mon, 19 Dec 2016 17:52:49 +0000 From: Yong Wang To: Ferruh Yigit , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v4] net/kni: add KNI PMD Thread-Index: AQHSSzVTxslxUr1Mx0irHfhqQAZ8/qEEy9mwgALj2gCAACBukIABcMYAgAZlkyA= Date: Mon, 19 Dec 2016 17:52:49 +0000 Message-ID: References: <20161010131946.13303-1-ferruh.yigit@intel.com> <20161130181228.25380-1-ferruh.yigit@intel.com> <479e706e-4d7e-53d1-e140-5c26f001c2c5@intel.com> In-Reply-To: <479e706e-4d7e-53d1-e140-5c26f001c2c5@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=yongwang@vmware.com; x-originating-ip: [208.91.1.34] x-ms-office365-filtering-correlation-id: c54873c9-8045-46f8-8317-08d42837d8e8 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BY2PR05MB2359; x-microsoft-exchange-diagnostics: 1; BY2PR05MB2359; 7:UOG4TAwft6nQOqr2c0NYhCoVwqqGICpchDo5VH72a/K1PeNtbYNoGxTmeTF+f8myacJliszmXOjKl4LAiImUxzXUSmUpiCohrvcvi5vYYlqD7jfIPaR3qdyZmbPlJy5n5eKDAqNUcoKAh2Lr39by18DGwSBWlN11s293k5s7DnRiPSnJMEEF8WnSVRt1xKJ/BExD8Nvi/0eg4t1hqsMEQY//DHPUPkgfT8VRpo1jcyOLn7QvzuHAwx9v6iri2kjrferj0V1UsNApJiwDhwjkXJNhGB0K/BtlLCsTfXhzaib9kYEFryihLxEEmUEhHlYTYb2uUcYUwtkTf6yMKlx2YhBdH2dTUVQw3Oy+gNrwGIyjmewM7DwnbWgWGocnQQBhzCZ8iFwT98lUWYFswtQcGiWbR5soKMRZvw7/746X0zyzuOzDdodKNp5+49ioaP7TFBnLLKlvJtLpgwsWeoRQpA==; 20:pSCYZ+QGvbj5/jdMjDZQUL8/VaSroLMsDKdC2HIfDS1IJEM23hJiA+ypC5wZ8/6JJCAFr7sWbFEB7Jr9oE7TrWSVnDZEM2KZmDu3c3RQUfeFSMwLNdNItD26hc5zgQagKD1PM/B9032iw2m5M9J0l18WJvEjtEu/mmMXm+TRW5s= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(61668805478150)(278428928389397)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(20161123558021)(6072148); SRVR:BY2PR05MB2359; BCL:0; PCL:0; RULEID:; SRVR:BY2PR05MB2359; x-forefront-prvs: 01613DFDC8 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39450400003)(199003)(189002)(377454003)(24454002)(13464003)(2501003)(7696004)(86362001)(122556002)(2900100001)(3280700002)(33656002)(92566002)(81156014)(8936002)(66066001)(2950100002)(81166006)(5660300001)(102836003)(9686002)(3660700001)(50986999)(76176999)(189998001)(54356999)(3846002)(6116002)(101416001)(8676002)(6506006)(77096006)(107886002)(2906002)(6436002)(38730400001)(5001770100001)(97736004)(25786008)(106356001)(99286002)(106116001)(305945005)(7736002)(74316002)(76576001)(93886004)(68736007)(229853002)(105586002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR05MB2359; H:BY2PR05MB2359.namprd05.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2016 17:52:49.0348 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR05MB2359 Subject: Re: [dpdk-dev] [PATCH v4] net/kni: add KNI PMD 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: Mon, 19 Dec 2016 17:52:52 -0000 > -----Original Message----- > From: Ferruh Yigit [mailto:ferruh.yigit@intel.com] > Sent: Thursday, December 15, 2016 7:56 AM > To: Yong Wang ; dev@dpdk.org > Subject: Re: [dpdk-dev] [PATCH v4] net/kni: add KNI PMD >=20 > On 12/14/2016 7:25 PM, Yong Wang wrote: > >> -----Original Message----- > >> From: Ferruh Yigit [mailto:ferruh.yigit@intel.com] > >> Sent: Wednesday, December 14, 2016 8:00 AM > >> To: Yong Wang ; dev@dpdk.org > >> Subject: Re: [dpdk-dev] [PATCH v4] net/kni: add KNI PMD > >> > >> On 12/12/2016 9:59 PM, Yong Wang wrote: > >>>> -----Original Message----- > >>>> From: Ferruh Yigit [mailto:ferruh.yigit@intel.com] > >>>> Sent: Wednesday, November 30, 2016 10:12 AM > >>>> To: dev@dpdk.org > >>>> Cc: Ferruh Yigit ; Yong Wang > >>>> > >>>> Subject: [PATCH v4] net/kni: add KNI PMD > >>>> > >>>> Add KNI PMD which wraps librte_kni for ease of use. > >>>> > >>>> KNI PMD can be used as any regular PMD to send / receive packets to > the > >>>> Linux networking stack. > >>>> > >>>> Signed-off-by: Ferruh Yigit > >>>> --- > >>>> > >>>> v4: > >>>> * allow only single queue > >>>> * use driver.name as name > >>>> > >>>> v3: > >>>> * rebase on top of latest master > >>>> > >>>> v2: > >>>> * updated driver name eth_kni -> net_kni > >>>> --- > >>>> config/common_base | 1 + > >>>> config/common_linuxapp | 1 + > >>>> drivers/net/Makefile | 1 + > >>>> drivers/net/kni/Makefile | 63 +++++ > >>>> drivers/net/kni/rte_eth_kni.c | 462 > >>>> ++++++++++++++++++++++++++++++++ > >>>> drivers/net/kni/rte_pmd_kni_version.map | 4 + > >>>> mk/rte.app.mk | 10 +- > >>>> 7 files changed, 537 insertions(+), 5 deletions(-) > >>>> create mode 100644 drivers/net/kni/Makefile > >>>> create mode 100644 drivers/net/kni/rte_eth_kni.c > >>>> create mode 100644 drivers/net/kni/rte_pmd_kni_version.map > >>>> > >>>> diff --git a/config/common_base b/config/common_base > >>>> index 4bff83a..3385879 100644 > >>>> --- a/config/common_base > >>>> +++ b/config/common_base > >>>> @@ -543,6 +543,7 @@ CONFIG_RTE_PIPELINE_STATS_COLLECT=3Dn > >>>> # Compile librte_kni > >>>> # > >>>> CONFIG_RTE_LIBRTE_KNI=3Dn > >>>> +CONFIG_RTE_LIBRTE_PMD_KNI=3Dn > >>>> CONFIG_RTE_KNI_KMOD=3Dn > >>>> CONFIG_RTE_KNI_PREEMPT_DEFAULT=3Dy > >>>> CONFIG_RTE_KNI_VHOST=3Dn > >>>> diff --git a/config/common_linuxapp b/config/common_linuxapp > >>>> index 2483dfa..2ecd510 100644 > >>>> --- a/config/common_linuxapp > >>>> +++ b/config/common_linuxapp > >>>> @@ -39,6 +39,7 @@ CONFIG_RTE_EAL_IGB_UIO=3Dy > >>>> CONFIG_RTE_EAL_VFIO=3Dy > >>>> CONFIG_RTE_KNI_KMOD=3Dy > >>>> CONFIG_RTE_LIBRTE_KNI=3Dy > >>>> +CONFIG_RTE_LIBRTE_PMD_KNI=3Dy > >>>> CONFIG_RTE_LIBRTE_VHOST=3Dy > >>>> CONFIG_RTE_LIBRTE_PMD_VHOST=3Dy > >>>> CONFIG_RTE_LIBRTE_PMD_AF_PACKET=3Dy > >>>> diff --git a/drivers/net/Makefile b/drivers/net/Makefile > >>>> index bc93230..c4771cd 100644 > >>>> --- a/drivers/net/Makefile > >>>> +++ b/drivers/net/Makefile > >>>> @@ -41,6 +41,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_ENIC_PMD) +=3D enic > >>>> DIRS-$(CONFIG_RTE_LIBRTE_FM10K_PMD) +=3D fm10k > >>>> DIRS-$(CONFIG_RTE_LIBRTE_I40E_PMD) +=3D i40e > >>>> DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) +=3D ixgbe > >>>> +DIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D kni > >>>> DIRS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) +=3D mlx4 > >>>> DIRS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) +=3D mlx5 > >>>> DIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) +=3D mpipe > >>>> diff --git a/drivers/net/kni/Makefile b/drivers/net/kni/Makefile > >>>> new file mode 100644 > >>>> index 0000000..0b7cf91 > >>>> --- /dev/null > >>>> +++ b/drivers/net/kni/Makefile > >>>> @@ -0,0 +1,63 @@ > >>>> +# BSD LICENSE > >>>> +# > >>>> +# Copyright(c) 2016 Intel Corporation. All rights reserved. > >>>> +# > >>>> +# Redistribution and use in source and binary forms, with or with= out > >>>> +# modification, are permitted provided that the following conditi= ons > >>>> +# are met: > >>>> +# > >>>> +# * Redistributions of source code must retain the above copyri= ght > >>>> +# notice, this list of conditions and the following disclaime= r. > >>>> +# * Redistributions in binary form must reproduce the above > copyright > >>>> +# notice, this list of conditions and the following disclaime= r in > >>>> +# the documentation and/or other materials provided with the > >>>> +# distribution. > >>>> +# * Neither the name of Intel Corporation nor the names of its > >>>> +# contributors may be used to endorse or promote products > derived > >>>> +# from this software without specific prior written permissio= n. > >>>> +# > >>>> +# 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 $(RTE_SDK)/mk/rte.vars.mk > >>>> + > >>>> +# > >>>> +# library name > >>>> +# > >>>> +LIB =3D librte_pmd_kni.a > >>>> + > >>>> +CFLAGS +=3D -O3 > >>>> +CFLAGS +=3D $(WERROR_FLAGS) > >>>> +LDLIBS +=3D -lpthread > >>>> + > >>>> +EXPORT_MAP :=3D rte_pmd_kni_version.map > >>>> + > >>>> +LIBABIVER :=3D 1 > >>>> + > >>>> +# > >>>> +# all source are stored in SRCS-y > >>>> +# > >>>> +SRCS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D rte_eth_kni.c > >>>> + > >>>> +# > >>>> +# Export include files > >>>> +# > >>>> +SYMLINK-y-include +=3D > >>>> + > >>>> +# this lib depends upon: > >>>> +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_eal > >>>> +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_ether > >>>> +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_kni > >>>> +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_mbuf > >>>> +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_KNI) +=3D lib/librte_mempool > >>>> + > >>>> +include $(RTE_SDK)/mk/rte.lib.mk > >>>> diff --git a/drivers/net/kni/rte_eth_kni.c > b/drivers/net/kni/rte_eth_kni.c > >>>> new file mode 100644 > >>>> index 0000000..6c4df96 > >>>> --- /dev/null > >>>> +++ b/drivers/net/kni/rte_eth_kni.c > >>>> @@ -0,0 +1,462 @@ > >>>> +/*- > >>>> + * BSD LICENSE > >>>> + * > >>>> + * Copyright(c) 2016 Intel Corporation. All rights reserved. > >>>> + * All rights reserved. > >>>> + * > >>>> + * Redistribution and use in source and binary forms, with or wit= hout > >>>> + * modification, are permitted provided that the following condit= ions > >>>> + * are met: > >>>> + * > >>>> + * * Redistributions of source code must retain the above copyr= ight > >>>> + * notice, this list of conditions and the following disclaim= er. > >>>> + * * Redistributions in binary form must reproduce the above > copyright > >>>> + * notice, this list of conditions and the following disclaim= er in > >>>> + * the documentation and/or other materials provided with the > >>>> + * distribution. > >>>> + * * Neither the name of Intel Corporation nor the names of its > >>>> + * contributors may be used to endorse or promote products > derived > >>>> + * from this software without specific prior written permissi= on. > >>>> + * > >>>> + * 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 > >>>> + > >>>> +/* Only single queue supported */ > >>>> +#define KNI_MAX_QUEUE_PER_PORT 1 > >>>> + > >>>> +#define MAX_PACKET_SZ 2048 > >>>> +#define MAX_KNI_PORTS 8 > >>>> + > >>>> +struct pmd_queue_stats { > >>>> + uint64_t pkts; > >>>> + uint64_t bytes; > >>>> + uint64_t err_pkts; > >>>> +}; > >>>> + > >>>> +struct pmd_queue { > >>>> + struct pmd_internals *internals; > >>>> + struct rte_mempool *mb_pool; > >>>> + > >>>> + struct pmd_queue_stats rx; > >>>> + struct pmd_queue_stats tx; > >>>> +}; > >>>> + > >>>> +struct pmd_internals { > >>>> + struct rte_kni *kni; > >>>> + int is_kni_started; > >>>> + > >>>> + pthread_t thread; > >>>> + int stop_thread; > >>>> + > >>>> + struct pmd_queue rx_queues[KNI_MAX_QUEUE_PER_PORT]; > >>>> + struct pmd_queue tx_queues[KNI_MAX_QUEUE_PER_PORT]; > >>>> +}; > >>>> + > >>>> +static struct ether_addr eth_addr; > >>>> +static struct rte_eth_link pmd_link =3D { > >>>> + .link_speed =3D ETH_SPEED_NUM_10G, > >>>> + .link_duplex =3D ETH_LINK_FULL_DUPLEX, > >>>> + .link_status =3D 0 > >>>> +}; > >>>> +static int is_kni_initialized; > >>>> + > >>>> +static uint16_t > >>>> +eth_kni_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) > >>>> +{ > >>>> + struct pmd_queue *kni_q =3D q; > >>>> + struct rte_kni *kni =3D kni_q->internals->kni; > >>>> + uint16_t nb_pkts; > >>>> + > >>>> + nb_pkts =3D rte_kni_rx_burst(kni, bufs, nb_bufs); > >>>> + > >>>> + kni_q->rx.pkts +=3D nb_pkts; > >>>> + kni_q->rx.err_pkts +=3D nb_bufs - nb_pkts; > >>>> + > >>>> + return nb_pkts; > >>>> +} > >>>> + > >>>> +static uint16_t > >>>> +eth_kni_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) > >>>> +{ > >>>> + struct pmd_queue *kni_q =3D q; > >>>> + struct rte_kni *kni =3D kni_q->internals->kni; > >>>> + uint16_t nb_pkts; > >>>> + > >>>> + nb_pkts =3D rte_kni_tx_burst(kni, bufs, nb_bufs); > >>>> + > >>>> + kni_q->tx.pkts +=3D nb_pkts; > >>>> + kni_q->tx.err_pkts +=3D nb_bufs - nb_pkts; > >>>> + > >>>> + return nb_pkts; > >>>> +} > >>>> + > >>>> +static void * > >>>> +kni_handle_request(void *param) > >>>> +{ > >>>> + struct pmd_internals *internals =3D param; > >>>> +#define MS 1000 > >>>> + > >>>> + while (!internals->stop_thread) { > >>>> + rte_kni_handle_request(internals->kni); > >>>> + usleep(500 * MS); > >>>> + } > >>>> + > >>>> + return param; > >>>> +} > >>>> + > >>> > >>> Do we really need a thread to handle request by default? I know there > are > >> apps that handle request their own way and having a separate thread > could > >> add synchronization problems. Can we at least add an option to disabl= e > this? > >> > >> I didn't think about there can be a use case that requires own request > >> handling. > >> > >> But, kni requests should be handled to make kni interface run properly= , > >> and to handle interface "kni" handler (internals->kni) required, which > >> this PMD doesn't expose. > >> > >> So, just disabling this thread won't work on its own. > > > > I understand that and what I am asking is a way to at least disable thi= s > without having to make code changes for applications that have their own > way of handling KNI request and the callback mentioned below sounds good > to me. I am fine with adding this capability with this commit or in a se= parate > commit after you have this commit checked in. >=20 > I don't mind adding in new version, only I am trying to understand it. >=20 > Normally what it does is calling KNI library rte_kni_handle_request() > API periodically on KNI handler. What an app may be doing own its way, > other than tweaking the period? It's the context that calls into rte_kni_handle_request() that I am referri= ng to. For applications that already handle this in their own thread or in= the pmd thread, they don't need the extra thread created here. It's not a= big deal as they can just change the behavior by modifying the source code= but I think it's reasonable to opt out of this default thread without maki= ng any source code changes to kni pmd.