[dpdk-dev] [PATCH v3 1/3] lib: add Generic Receive Offload API framework

Ananyev, Konstantin konstantin.ananyev at intel.com
Mon May 22 11:19:19 CEST 2017


Hi Jiayu,
My comments/questions below.
Konstantin

> 
> 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 various 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 particular 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;
   <desired GRO types (IPV4_TCP | IPV6_TCP, ...)>
  <probably type specific params>
  ...
};

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. 

....

> 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 <rte_ethdev.h>
> +#include <rte_mbuf.h>
> +#include <rte_hash.h>
> +#include <stdint.h>
> +#include <rte_malloc.h>
> +
> +#include "rte_gro.h"
> +#include "rte_gro_common.h"
> +
> +gro_reassemble_fn reassemble_functions[GRO_TYPE_MAX_NB] = {NULL};
> +gro_tbl_create_fn tbl_create_functions[GRO_TYPE_MAX_NB] = {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 = strlen(name) + 10;
> +	char tbl_name[len];
> +	int i;
> +
> +	for (i = 0; i < GRO_SUPPORT_TYPE_NB; i++) {
> +		sprintf(tbl_name, "%s_%u", name, i);
> +		create_tbl_fn = 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 = 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 == NULL)
> +		return;
> +	for (i = 0; i < GRO_SUPPORT_TYPE_NB; i++) {
> +		rte_hash_free(gro_tbl->lkp_tbls[i].hash_tbl);
> +		gro_tbl->lkp_tbls[i].hash_tbl = NULL;
> +		gro_tbl->lkp_tbls[i].gro_type = 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 == NULL) || (pkts == NULL)) {
> +		printf("invalid parameters for GRO.\n");
> +		return 0;
> +	}
> +	uint16_t nb_after_gro = nb_pkts;

Here and everywhere - please move variable definitions to the top of the block.

> +
> +	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 = (struct rte_gro_status *)rte_zmalloc(
> +			NULL,
> +			sizeof(struct rte_gro_status),
> +			0);
> +
> +	nb_port = rte_eth_dev_count();

Number of ports and number of configured queues per port can change dynamically.
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 over exisiting callbacks
Searching for particular cb_func and cb_arg values. 

> +	gro_status->ports = (struct gro_port_status *)rte_zmalloc(
> +			NULL,
> +			nb_port * sizeof(struct gro_port_status),
> +			0);
> +	gro_status->nb_port = nb_port;
> +
> +	for (i = 0; i < nb_port; i++) {
> +		rte_eth_dev_info_get(i, &dev_info);
> +		nb_queue = dev_info.nb_rx_queues;
> +		gro_status->ports[i].gro_tbls =
> +			(struct rte_gro_tbl **)rte_zmalloc(
> +					NULL,
> +					nb_queue * sizeof(struct rte_gro_tbl *),
> +					0);
> +		gro_status->ports[i].gro_cbs =
> +			(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_common.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. 

> +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)           += -lrte_ring
>  _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL)            += -lrte_eal
>  _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE)        += -lrte_cmdline
>  _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER)        += -lrte_reorder
> +_LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)        	+= -lrte_gro
> 
>  ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
>  _LDLIBS-$(CONFIG_RTE_LIBRTE_KNI)            += -lrte_kni
> --
> 2.7.4



More information about the dev mailing list