From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C3B9920F for ; Mon, 22 May 2017 11:19:28 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2017 02:19:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,377,1491289200"; d="scan'208";a="90152178" Received: from irsmsx105.ger.corp.intel.com ([163.33.3.28]) by orsmga002.jf.intel.com with ESMTP; 22 May 2017 02:19:21 -0700 Received: from irsmsx156.ger.corp.intel.com (10.108.20.68) by irsmsx105.ger.corp.intel.com (163.33.3.28) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 22 May 2017 10:19:20 +0100 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.12]) by IRSMSX156.ger.corp.intel.com ([169.254.3.246]) with mapi id 14.03.0319.002; Mon, 22 May 2017 10:19:20 +0100 From: "Ananyev, Konstantin" To: "Hu, Jiayu" , "dev@dpdk.org" CC: "Wiles, Keith" , "yuanhan.liu@linux.intel.com" Thread-Topic: [PATCH v3 1/3] lib: add Generic Receive Offload API framework Thread-Index: AQHSvNIioTj7qilZNEunAvoVQTYKUKIAL6+A Date: Mon, 22 May 2017 09:19:19 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772583FAF8C27@IRSMSX109.ger.corp.intel.com> References: <1491309106-94264-1-git-send-email-jiayu.hu@intel.com> <1493021398-115955-1-git-send-email-jiayu.hu@intel.com> <1493021398-115955-2-git-send-email-jiayu.hu@intel.com> In-Reply-To: <1493021398-115955-2-git-send-email-jiayu.hu@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3 1/3] lib: add Generic Receive Offload API framework 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, 22 May 2017 09:19:29 -0000 Hi Jiayu, My comments/questions below. Konstantin >=20 > For applications, DPDK GRO provides three external functions to > enable/disable GRO: > - rte_gro_init: initialize GRO environment; > - rte_gro_enable: enable GRO for a given port; > - rte_gro_disable: disable GRO for a given port. > Before using GRO, applications should explicitly call rte_gro_init to > initizalize GRO environment. After that, applications can call > rte_gro_enable to enable GRO and call rte_gro_disable to disable GRO for > specific ports. I think this is too restrictive and wouldn't meet various user's needs. User might want to: - enable/disable GRO for particular RX queue - or even setup different GRO types for different RX queues, i.e, - GRO over IPV4/TCP for queue 0, and GRO over IPV6/TCP for queue 1= , etc. - For various reasons, user might prefer not to use RX callbacks for variou= s reasons, But invoke gro() manually at somepoint in his code. - Many users would like to control size (number of flows/items per flow), max allowed packet size, max timeout, etc., for different GRO tables. - User would need a way to flush all or only timeout packets from particula= r GRO tables. So I think that API needs to extended to become be much more fine-grained. Something like that: struct rte_gro_tbl_param { int32_t socket_id; size_t max_flows; size_t max_items_per_flow; size_t max_pkt_size; uint64_t packet_timeout_cycles; ... }; struct rte_gro_tbl; strct rte_gro_tbl *rte_gro_tbl_create(const struct rte_gro_tbl_param *param= ); void rte_gro_tbl_destroy(struct rte_gro_tbl *tbl); /* * process packets, might store some packets inside the GRO table, * returns number of filled entries in pkt[] */ uint32_t rte_gro_tbl_process(struct rte_gro_tbl *tbl, struct rte_mbuf *pkt[= ], uint32_t num); /* * retirieves up to num timeouted packets from the table. */ uint32_t rtre_gro_tbl_timeout(struct rte_gro_tbl *tbl, uint64_t tmt, struct= rte_mbuf *pkt[], uint32_t num); And if you like to keep them as helper functions: int rte_gro_port_enable(uint8_t port, struct rte_gro_tbl_param *param); void rte_gro_port_disable(uint8_t port); Though from my perspective, it is out of scope of that library, and I'd leave it to the upper layer to decide which callbacks and in what order have to be installed on particular port.=20 .... > diff --git a/lib/librte_gro/rte_gro.c b/lib/librte_gro/rte_gro.c > new file mode 100644 > index 0000000..996b382 > --- /dev/null > +++ b/lib/librte_gro/rte_gro.c > @@ -0,0 +1,219 @@ > +#include > +#include > +#include > +#include > +#include > + > +#include "rte_gro.h" > +#include "rte_gro_common.h" > + > +gro_reassemble_fn reassemble_functions[GRO_TYPE_MAX_NB] =3D {NULL}; > +gro_tbl_create_fn tbl_create_functions[GRO_TYPE_MAX_NB] =3D {NULL}; Why not to initialize these arrays properly at building time (here)? > + > +struct rte_gro_status *gro_status; > + > +/** > + * Internal function. It creates one hashing table for all > + * DPDK-supported GRO types, and all of them are stored in an object > + * of struct rte_gro_tbl. > + * > + * @param name > + * Name for GRO lookup table > + * @param nb_entries > + * Element number of each hashing table > + * @param socket_id > + * socket id > + * @param gro_tbl > + * gro_tbl points to a rte_gro_tbl object, which will be initalized > + * inside rte_gro_tbl_setup. > + * @return > + * If create successfully, return a positive value; if not, return > + * a negative value. > + */ > +static int > +rte_gro_tbl_setup(char *name, uint32_t nb_entries, > + uint16_t socket_id, struct rte_gro_tbl *gro_tbl) > +{ > + gro_tbl_create_fn create_tbl_fn; > + const uint32_t len =3D strlen(name) + 10; > + char tbl_name[len]; > + int i; > + > + for (i =3D 0; i < GRO_SUPPORT_TYPE_NB; i++) { > + sprintf(tbl_name, "%s_%u", name, i); > + create_tbl_fn =3D tbl_create_functions[i]; > + if (create_tbl_fn && (create_tbl_fn(name, > + nb_entries, > + socket_id, > + &(gro_tbl-> > + lkp_tbls[i].hash_tbl)) > + < 0)) { Shouldn't you destroy already created tables here? > + return -1; > + } > + gro_tbl->lkp_tbls[i].gro_type =3D i; > + } > + return 1; > +} > + > +/** > + * Internal function. It frees all the hashing tables stored in > + * the given struct rte_gro_tbl object. > + */ > +static void > +rte_gro_tbl_destroy(struct rte_gro_tbl *gro_tbl) > +{ > + int i; > + > + if (gro_tbl =3D=3D NULL) > + return; > + for (i =3D 0; i < GRO_SUPPORT_TYPE_NB; i++) { > + rte_hash_free(gro_tbl->lkp_tbls[i].hash_tbl); > + gro_tbl->lkp_tbls[i].hash_tbl =3D NULL; > + gro_tbl->lkp_tbls[i].gro_type =3D GRO_EMPTY_TYPE; > + } > +} > + > +/** > + * Internal function. It performs all supported GRO types on inputted > + * packets. For example, if current DPDK GRO supports TCP/IPv4 and > + * TCP/IPv6 GRO, this functions just reassembles TCP/IPv4 and TCP/IPv6 > + * packets. Packets of unsupported GRO types won't be processed. For > + * ethernet devices, which want to support GRO, this function is used to > + * registered as RX callback for all queues. > + * > + * @param pkts > + * Packets to reassemble. > + * @param nb_pkts > + * The number of packets to reassemble. > + * @param gro_tbl > + * pointer points to an object of struct rte_gro_tbl, which has been > + * initialized by rte_gro_tbl_setup. > + * @return > + * Packet number after GRO. If reassemble successfully, the value is > + * less than nb_pkts; if not, the value is equal to nb_pkts. If the > + * parameters are invalid, return 0. > + */ > +static uint16_t > +rte_gro_reassemble_burst(uint8_t port __rte_unused, > + uint16_t queue __rte_unused, > + struct rte_mbuf **pkts, > + uint16_t nb_pkts, > + uint16_t max_pkts __rte_unused, > + void *gro_tbl) > +{ > + if ((gro_tbl =3D=3D NULL) || (pkts =3D=3D NULL)) { > + printf("invalid parameters for GRO.\n"); > + return 0; > + } > + uint16_t nb_after_gro =3D nb_pkts; Here and everywhere - please move variable definitions to the top of the bl= ock. > + > + return nb_after_gro; > +} > + > +void > +rte_gro_init(void) > +{ > + uint8_t nb_port, i; > + uint16_t nb_queue; > + struct rte_eth_dev_info dev_info; > + > + /* if init already, return immediately */ > + if (gro_status) { > + printf("repeatly init GRO environment\n"); > + return; > + } > + > + gro_status =3D (struct rte_gro_status *)rte_zmalloc( > + NULL, > + sizeof(struct rte_gro_status), > + 0); > + > + nb_port =3D rte_eth_dev_count(); Number of ports and number of configured queues per port can change dynamic= ally. In fact, I don't think we need that function and global gro_status at all. To add/delete RX callback for particular port/queue - you can just scan ove= r exisiting callbacks Searching for particular cb_func and cb_arg values.=20 > + gro_status->ports =3D (struct gro_port_status *)rte_zmalloc( > + NULL, > + nb_port * sizeof(struct gro_port_status), > + 0); > + gro_status->nb_port =3D nb_port; > + > + for (i =3D 0; i < nb_port; i++) { > + rte_eth_dev_info_get(i, &dev_info); > + nb_queue =3D dev_info.nb_rx_queues; > + gro_status->ports[i].gro_tbls =3D > + (struct rte_gro_tbl **)rte_zmalloc( > + NULL, > + nb_queue * sizeof(struct rte_gro_tbl *), > + 0); > + gro_status->ports[i].gro_cbs =3D > + (struct rte_eth_rxtx_callback **) > + rte_zmalloc( > + NULL, > + nb_queue * > + sizeof(struct rte_eth_rxtx_callback *), > + 0); > + } > +} > + > +} .... > diff --git a/lib/librte_gro/rte_gro_common.h b/lib/librte_gro/rte_gro_com= mon.h .... > + > +typedef int (*gro_tbl_create_fn)( > + char *name, > + uint32_t nb_entries, > + uint16_t socket_id, > + struct rte_hash **hash_tbl); > + If you have create_fn, then you'll probably need a destroy_fn too. Second thing why always assume that particular GRO implementation would always use rte_hash to store it's data? Probably better hide that inside something neutral, like 'struct gro_data;'= or so.=20 > +typedef int32_t (*gro_reassemble_fn)( > + struct rte_hash *hash_tbl, > + struct gro_item_list *item_list); > +#endif > diff --git a/mk/rte.app.mk b/mk/rte.app.mk > index b5215c0..8956821 100644 > --- a/mk/rte.app.mk > +++ b/mk/rte.app.mk > @@ -98,6 +98,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_RING) +=3D -lrte_= ring > _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) +=3D -lrte_eal > _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE) +=3D -lrte_cmdline > _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER) +=3D -lrte_reorder > +_LDLIBS-$(CONFIG_RTE_LIBRTE_GRO) +=3D -lrte_gro >=20 > ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y) > _LDLIBS-$(CONFIG_RTE_LIBRTE_KNI) +=3D -lrte_kni > -- > 2.7.4