add external mempool manager
Re: [PATCH v6 1/5] mempool: support external handler
In reply to David HuntHello David,
the rename s/handler/ops/ has a lot of residues. Sorry for that :). I tried to mark most of them. Otherwise, I couldn't see many more serious issues for now.
Just, note the s/pool/priv/ rename suggestion.
Quoted 120 lines · On Wed, 1 Jun 2016 17:19:54 +0100 David Hunt <[email protected]> wrote:
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_handler()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.v7 changes:
* Moved the flags handling fromrte_mempool_create_emptytorte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamedrte_mempool_handlertorte_mempool_ops
* Added a union for *pool and u64pool_idin structrte_mempoolv6 changes:
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed some review comments
* renamed put and get functions to enqueue and dequeue
* renamedrte_mempool_handlerstruct torte_mempool_handler_ops
* changed occurences ofrte_mempool_handler_opsto const, as they contain function pointers (security)
* added some extra commentsv5 changes: rebasing on top of 35 patch set mempool work.
Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>--- lib/librte_mempool/Makefile | 1 + lib/librte_mempool/rte_mempool.c | 71 ++++------ lib/librte_mempool/rte_mempool.h | 235 ++++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_handler.c | 141 +++++++++++++++++++ 4 files changed, 384 insertions(+), 64 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_handler.clib/librte_mempool/Makefile +1
-0@@ -42,6 +42,7 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_handler.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.hlib/librte_mempool/rte_mempool.c +2
-37@@ -148,7 +148,7 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, phys_addr_t physaddr)#endif /* enqueue in ring */ -rte_ring_sp_enqueue (mp->ring, obj); +rte_mempool_ops_enqueue_bulk (mp, &obj,1 ); }/* call obj_cb() for each mempool element */ @@ -303,40 +303,6 @@ rte_mempool_xmem_usage(__rte_unused void *vaddr, uint32_t elt_num,return (size_t )paddr_idx << pg_shift; } -/* create the internal ring */ -static int -rte_mempool_ring_create (struct rte_mempool *mp) -{ -int rg_flags =0 , ret; -char rg_name[RTE_RING_NAMESIZE ]; -struct rte_ring *r; - - ret =snprintf (rg_name,sizeof (rg_name), -RTE_MEMPOOL_MZ_FORMAT , mp->name); -if (ret <0 || ret >= (int )sizeof (rg_name)) -return -ENAMETOOLONG ; - -/* ring flags */ -if (mp->flags &MEMPOOL_F_SP_PUT ) - rg_flags |=RING_F_SP_ENQ ; -if (mp->flags &MEMPOOL_F_SC_GET ) - rg_flags |=RING_F_SC_DEQ ; - -/* Allocate the ring that will be used to store objects. -* Ring functions will return appropriate errors if we are -* running as a secondary process etc., so no checks made -* in this function for that condition. -*/ - r =rte_ring_create (rg_name,rte_align32pow2 (mp->size +1 ), - mp->socket_id, rg_flags); -if (r ==NULL ) -return -rte_errno; - - mp->ring = r; - mp->flags |=MEMPOOL_F_RING_CREATED ; -return 0 ; -} -/* free a memchunk allocated with rte_memzone_reserve() */ static void rte_mempool_memchunk_mz_free(__rte_unused struct rte_mempool_memhdr *memhdr,@@ -354,7 +320,7 @@ rte_mempool_free_memchunks(struct rte_mempool *mp)void *elt;while (!STAILQ_EMPTY (&mp->elt_list)) { -rte_ring_sc_dequeue (mp->ring, &elt); +rte_mempool_ops_dequeue_bulk (mp, &elt,1 ); (void )elt;STAILQ_REMOVE_HEAD (&mp->elt_list, next); mp->populated_size--;@@ -383,13 +349,16 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,unsigned i =0 ;size_t off;struct rte_mempool_memhdr *memhdr; -int ret;/* create the internal ring if not already done */
lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, · line 360
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +6
-3if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) { - ret =rte_mempool_ring_create (mp); -if (ret <0 ) -return ret; + rte_errno =0 ; + mp->pool =rte_mempool_ops_alloc (mp); +if (mp->pool ==NULL ) { +if (rte_errno ==0 ) +return -EINVAL ; +return -rte_errno;
Are you sure the rte_errno is a positive value?
Quoted 74 lines
lib/librte_mempool/rte_mempool.c +19
-4+ } }/* mempool is already populated */ @@ -703,7 +672,7 @@ rte_mempool_free(struct rte_mempool *mp)rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK );rte_mempool_free_memchunks (mp); -rte_ring_free (mp->ring); +rte_mempool_ops_free (mp);rte_memzone_free (mp->mz); }@@ -815,6 +784,20 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,RTE_PTR_ADD (mp,MEMPOOL_HEADER_SIZE (mp,0 )); te->data = mp; + +/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the handler table. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_handler (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_handler (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_handler (mp,"ring_mp_sc" ); +else +rte_mempool_set_handler (mp,"ring_mp_mc" ); +rte_rwlock_write_lock (RTE_EAL_TAILQ_RWLOCK );TAILQ_INSERT_TAIL (mempool_list, te, next);rte_rwlock_write_unlock (RTE_EAL_TAILQ_RWLOCK );@@ -930,7 +913,7 @@ rte_mempool_count(const struct rte_mempool *mp)unsigned count;unsigned lcore_id; - count =rte_ring_count (mp->ring); + count =rte_mempool_ops_get_count (mp);if (mp->cache_size ==0 )return count;@@ -1123,7 +1106,7 @@ rte_mempool_dump(FILE *f, struct rte_mempool *mp)fprintf (f,"mempool <%s>@%p\n" , mp->name, mp);fprintf (f," flags=%x\n" , mp->flags); -fprintf (f," ring=<%s>@%p\n" , mp->ring->name, mp->ring); +fprintf (f," pool=%p\n" , mp->pool);fprintf (f," phys_addr=0x%" PRIx64"\n" , mp->mz->phys_addr);fprintf (f," nb_mem_chunks=%u\n" , mp->nb_mem_chunks);fprintf (f," size=%" PRIu32"\n" , mp->size);@@ -1144,7 +1127,7 @@ rte_mempool_dump(FILE *f, struct rte_mempool *mp) } cache_count =rte_mempool_dump_cache (f, mp); - common_count =rte_ring_count (mp->ring); + common_count =rte_mempool_ops_get_count (mp);if ((cache_count + common_count) > mp->size) common_count = mp->size - cache_count;fprintf (f," common_pool_count=%u\n" , common_count);lib/librte_mempool/rte_mempool.h +1
-0@@ -67,6 +67,7 @@#include <inttypes.h> #include <sys/queue.h> +#include <rte_spinlock.h> #include <rte_log.h> #include <rte_debug.h> #include <rte_lcore.h>
lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 209
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +2
-0@@ -204,9 +205,13 @@ struct rte_mempool_memhdr {struct rte_mempool {char name[RTE_MEMPOOL_NAMESIZE ];/**< Name of mempool. */ struct rte_ring *ring;/**< Ring to store objects. */ +union { +void *pool;/**< Ring or pool to store objects */
What about calling this pdata or priv? I think, it can improve some doc comments. Describing a "pool" may refer to both the rte_mempool itself or to the mp->pool pointer. The "priv" would help to understand the code a bit.
Then the rte_mempool_alloc_t can be called rte_mempool_priv_alloc_t. Or something similar. It's than clear enough, what the function should do...
lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 210
Quoted 1 line
lib/librte_mempool/rte_mempool.h +1
-0+uint64_t *pool_id;/**< External mempool identifier */
Why is pool_id a pointer? Is it a typo? I've understood it should be 64b wide from the discussion (Olivier, Jerin, David):
| >>> something like below,
| >>> union {
| >>> void *pool;
| >>> uint64_t val;
| >>> uint8_t extra_mem[16] // available free bytes in fast path cache line
| >>>
| >>> }
| >>
| >> Something for the future, perhaps? Will the 8-bits in the flags suffice for
| >> now?
| >
| > OK. But simple anonymous union for same type should be OK add now? Not
| > much change I believe, If its difficult then postpone it
| >
| > union {
| > void *pool;
| > uint64_t val;
| > }
|
| I'm ok with the simple union with (void *) and (uint64_t).
| Maybe "val" should be replaced by something more appropriate.
| Is "pool_id" a better name?Quoted 9 lines
lib/librte_mempool/rte_mempool.h +2
-1+ };const struct rte_memzone *mz;/**< Memzone where pool is allocated */ int flags;/**< Flags of the mempool. */ -int socket_id;/**< Socket id passed at mempool creation. */ +int socket_id;/**< Socket id passed at create */ uint32_t size;/**< Max size of the mempool. */ uint32_t cache_size;/**< Size of per-lcore local cache. */ uint32_t cache_flushthresh;
lib/librte_mempool/rte_mempool.h struct rte_mempool { · line 226
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +2
-0@@ -217,6 +222,14 @@ struct rte_mempool {uint32_t trailer_size;/**< Size of trailer (after elt). */ unsigned private_data_size;/**< Size of private data. */ +/** +* Index into rte_mempool_handler_table array of mempool handler ops
s/rte_mempool_handler_table/rte_mempool_ops_table/
lib/librte_mempool/rte_mempool.h struct rte_mempool { · line 232
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +6
-0+* structs, which contain callback function pointers. +* We're using an index here rather than pointers to the callbacks +* to facilitate any secondary processes that may want to use +* this mempool. +*/ +int32_t handler_idx;
s/handler_idx/ops_idx/
What about ops_index? Not a big deal...
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 344
Quoted 11 lines
lib/librte_mempool/rte_mempool.h +4
-0struct rte_mempool_cache *local_cache;/**< Per-lcore local cache */ @@ -325,6 +338,199 @@ void rte_mempool_check_cookies(const struct rte_mempool *mp,#define __mempool_check_cookies (mp, obj_table_const, n, free) do {} while(0)#endif /* RTE_LIBRTE_MEMPOOL_DEBUG */ +#define RTE_MEMPOOL_HANDLER_NAMESIZE 32/**< Max length of handler name. */ + +/** +* typedef for allocating the external pool.
What about:
function prototype to provide an implementation specific data
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 347
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+* The handler's alloc function does whatever it needs to do to grab memory +* for this handler, and sets the *pool opaque pointer in the rte_mempool +* struct. In the default handler, *pool points to a ring,in other handlers,
What about:
The function should provide a memory heap representation or another private data used for allocation by the rte_mempool_ops. E.g. the default ops provides an instance of the rte_ring for this purpose.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 349
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+* it will mostlikely point to a different type of data structure. +* It will be transparent to the application programmer.
I'd add something like this:
The function should not touch the given *mp instance.
...because it's goal is NOT to set the mp->pool, this is done by the rte_mempool_populate_phys - the caller of this rte_mempool_ops_alloc.
This is why I've suggested to pass the rte_mempool as const in the v5. Is there any reason to modify the rte_mempool contents by the implementation? I think, we just need to read the flags, socket_id, etc.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 353
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+*/ +typedef void *(*rte_mempool_alloc_t )(struct rte_mempool *mp); + +/** Free the external pool opaque data (that pointed to by *pool) */
What about:
/** Free the opaque private data stored in the mp->pool pointer. */
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 359
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +6
-0+typedef void (*rte_mempool_free_t )(void *p); + +/** +* Put an object in the external pool. +* The *p pointer is the opaque data for a given mempool handler (ring, +* array, linked list, etc)
The obj_table is not documented. Is it really a table? I'd called an array instead.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 361
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+*/ +typedef int (*rte_mempool_put_t )(void *p,void *const *obj_table,unsigned n);
unsigned int
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 364
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** Get an object from the external pool. */ +typedef int (*rte_mempool_get_t )(void *p,void **obj_table,unsigned n);
unsigned int
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 366
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+ +/** Return the number of available objects in the external pool. */
Is the number of available objects or the total number of all objects (so probably a constant value)?
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 367
Quoted 1 line
lib/librte_mempool/rte_mempool.h +1
-0+typedef unsigned (*rte_mempool_get_count )(void *p);
Should it be const void *p?
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 369
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+ +/** Structure defining a mempool handler. */
What about:
/** Structure defining mempool operations. */
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 371
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+struct rte_mempool_ops { +char name[RTE_MEMPOOL_HANDLER_NAMESIZE ];/**< Name of mempool handler */
s/RTE_MEMPOOL_HANDLER_NAMESIZE/RTE_MEMPOOL_OPS_NAMESIZE/
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 372
Quoted 1 line
lib/librte_mempool/rte_mempool.h +1
-0+rte_mempool_alloc_t alloc;/**< Allocate the external pool. */
What about:
Allocate the private data for this rte_mempool_ops.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 379
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+rte_mempool_free_t free;/**< Free the external pool. */ +rte_mempool_put_t put;/**< Put an object. */ +rte_mempool_get_t get;/**< Get an object. */ +rte_mempool_get_count get_count;/**< Get the number of available objs. */ +} __rte_cache_aligned; + +#define RTE_MEMPOOL_MAX_HANDLER_IDX 16/**< Max registered handlers */
s/RTE_MEMPOOL_MAX_HANDLER_IDX/RTE_MEMPOOL_MAX_OPS_IDX/
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 390
Quoted 11 lines
lib/librte_mempool/rte_mempool.h +11
-0+ +/** +* Structure storing the table of registered handlers, each of which contain +* the function pointers for the mempool handler functions. +* Each process has it's own storage for this handler struct aray so that +* the mempools can be shared across primary and secondary processes. +* The indices used to access the array are valid across processes, whereas +* any function pointers stored directly in the mempool struct would not be. +* This results in us simply having "handler_idx" in the mempool struct. +*/ +struct rte_mempool_handler_table {
s/rte_mempool_handler_table/rte_mempool_ops_table/
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 392
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+rte_spinlock_t sl;/**< Spinlock for add/delete. */ +uint32_t num_handlers;/**< Number of handlers in the table. */
s/num_handlers/num_ops/
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 396
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+/** +* Storage for all possible handlers. +*/ +struct rte_mempool_ops handler_ops[RTE_MEMPOOL_MAX_HANDLER_IDX ];
s/handler_ops/ops/
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 400
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+} __rte_cache_aligned; + +/** Array of registered handlers */ +extern struct rte_mempool_handler_table rte_mempool_handler_table;
s/rte_mempool_handler_table/rte_mempool_ops_table/
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 412
Quoted 12 lines
lib/librte_mempool/rte_mempool.h +12
-0+ +/** +* @internal Get the mempool handler from its index. +* +* @param handler_idx +* The index of the handler in the handler table. It must be a valid +* index: (0 <= idx < num_handlers). +* @return +* The pointer to the handler in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_handler_get (int handler_idx)
rte_mempool_ops_get(int ops_idx)
Quoted 23 lines
lib/librte_mempool/rte_mempool.h +23
-0+{ +return &rte_mempool_handler_table.handler_ops[handler_idx]; +} + +/** +* @internal wrapper for external mempool manager alloc callback. +* +* @param mp +* Pointer to the memory pool. +* @return +* The opaque pointer to the external pool. +*/ +void * +rte_mempool_ops_alloc (struct rte_mempool *mp); + +/** +* @internal wrapper for external mempool manager get callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 445
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* Number of objects to get. +* @return +* - 0: Success; got n objects. +* - <0: Error; code of handler get function. +*/ +static inline int +rte_mempool_ops_dequeue_bulk (struct rte_mempool *mp, +void **obj_table,unsigned n) +{ +struct rte_mempool_ops *handler;
*ops
Quoted 13 lines
lib/librte_mempool/rte_mempool.h +13
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +return handler->get (mp->pool, obj_table, n); +} + +/** +* @internal wrapper for external mempool manager put callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 468
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* Number of objects to put. +* @return +* - 0: Success; n objects supplied. +* - <0: Error; code of handler put function. +*/ +static inline int +rte_mempool_ops_enqueue_bulk (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct rte_mempool_ops *handler;
*ops
Quoted 29 lines
lib/librte_mempool/rte_mempool.h +29
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +return handler->put (mp->pool, obj_table, n); +} + +/** +* @internal wrapper for external mempool manager get_count callback. +* +* @param mp +* Pointer to the memory pool. +* @return +* The number of available objects in the external pool. +*/ +unsigned +rte_mempool_ops_get_count (const struct rte_mempool *mp); + +/** +* @internal wrapper for external mempool manager free callback. +* +* @param mp +* Pointer to the memory pool. +*/ +void +rte_mempool_ops_free (struct rte_mempool *mp); + +/** +* Set the handler of a mempool +* +* This can only be done on a mempool that is not populated, i.e. just after
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 507
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* a call to rte_mempool_create_empty(). +* +* @param mp +* Pointer to the memory pool. +* @param name +* Name of the handler. +* @return +* - 0: Sucess; the new handler is configured. +* - EINVAL - Invalid handler name provided +* - EEXIST - mempool already has a handler assigned
They are returned as -EINVAL and -EEXIST.
IMHO, using "-" here is counter-intuitive:
- EINVAL
does it mean a positive with "-" or negative value?
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 510
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+*/ +int +rte_mempool_set_handler (struct rte_mempool *mp,const char *name);
rte_mempool_set_ops
What about rte_mempool_set_ops_byname? Not a big deal...
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 513
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** +* Register an external pool handler.
Register mempool operations
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 520
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+* +* @param h +* Pointer to the external pool handler +* @return +* - >=0: Sucess; return the index of the handler in the table. +* - EINVAL - missing callbacks while registering handler +* - ENOSPC - the maximum number of handlers has been reached
- -EINVAL
- -ENOSPC
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 522
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+*/ +int rte_mempool_handler_register (const struct rte_mempool_ops *h);
rte_mempool_ops_register
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 525
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** +* Macro to statically register an external pool handler.
What about adding:
Note that the rte_mempool_ops_register fails silently here when more then RTE_MEMPOOL_MAX_OPS_IDX is registered.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 527
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+*/ +#define MEMPOOL_REGISTER_HANDLER (h)
MEMPOOL_REGISTER_OPS
\
Quoted 42 lines
lib/librte_mempool/rte_mempool.h +10
-13+ void mp_hdlr_init_##h(void); \ + void __attribute__((constructor, used)) mp_hdlr_init_##h(void) \ + { \ + rte_mempool_handler_register(&h); \ + } +/** * An object callback function for mempool. * @@ -774,7 +980,7 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table, cache->len += n;if (cache->len >= flushthresh) { -rte_ring_mp_enqueue_bulk (mp->ring, &cache->objs[cache_size], +rte_mempool_ops_enqueue_bulk (mp, &cache->objs[cache_size], cache->len - cache_size); cache->len = cache_size; }@@ -785,19 +991,10 @@ ring_enqueue:/* push remaining objects in ring */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG -if (is_mp) { -if (rte_ring_mp_enqueue_bulk (mp->ring, obj_table, n) <0 ) -rte_panic ("cannot put objects in mempool\n" ); - } -else { -if (rte_ring_sp_enqueue_bulk (mp->ring, obj_table, n) <0 ) -rte_panic ("cannot put objects in mempool\n" ); - } +if (rte_mempool_ops_enqueue_bulk (mp, obj_table, n) <0 ) +rte_panic ("cannot put objects in mempool\n" );#else -if (is_mp) -rte_ring_mp_enqueue_bulk (mp->ring, obj_table, n); -else -rte_ring_sp_enqueue_bulk (mp->ring, obj_table, n); +rte_mempool_ops_enqueue_bulk (mp, obj_table, n);#endif }
lib/librte_mempool/rte_mempool.h rte_mempool_put(struct rte_mempool *mp, void *obj) · line 1122
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +1
-1@@ -922,7 +1119,7 @@ rte_mempool_put(struct rte_mempool *mp, void *obj)*/ static inline int __attribute__((always_inline))__mempool_get_bulk (struct rte_mempool *mp,void **obj_table, -unsigned n,int is_mc) + unsigned n, __rte_unused int is_mc)
unsigned int
lib/librte_mempool/rte_mempool_handler.c
Quoted 30 lines
lib/librte_mempool/rte_mempool.h +3
-5{int ret;struct rte_mempool_cache *cache;@@ -945,7 +1142,8 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table,uint32_t req = n + (cache_size - cache->len);/* How many do we require i.e. number to fill the cache + the request */ - ret =rte_ring_mc_dequeue_bulk (mp->ring, &cache->objs[cache->len], req); + ret =rte_mempool_ops_dequeue_bulk (mp, + &cache->objs[cache->len], req);if (unlikely (ret <0 )) {/* * In the offchance that we are buffer constrained, @@ -972,10 +1170,7 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table, ring_dequeue:/* get remaining objects from ring */ -if (is_mc) - ret =rte_ring_mc_dequeue_bulk (mp->ring, obj_table, n); -else - ret =rte_ring_sc_dequeue_bulk (mp->ring, obj_table, n); + ret =rte_mempool_ops_dequeue_bulk (mp, obj_table, n);if (ret <0 )__MEMPOOL_STAT_ADD (mp, get_fail, n);lib/librte_mempool/rte_mempool_handler.c new file +0
-0
rte_mempool_ops.c
Quoted 32 lines
lib/librte_mempool/rte_mempool_handler.c new file +31
-0@@ -0,0 +1,141 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2016 Intel Corporation. All rights reserved. +* Copyright(c) 2016 6WIND S.A. +* 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 Intel Corporation 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
lib/librte_mempool/rte_mempool_handler.c line 41
Quoted 10 lines
lib/librte_mempool/rte_mempool_handler.c new file +10
-0+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <stdio.h> +#include <string.h> + +#include <rte_mempool.h> + +/* indirect jump table to support external memory pools */ +struct rte_mempool_handler_table rte_mempool_handler_table = {
rte_mempool_ops_table
lib/librte_mempool/rte_mempool_handler.c line 43
Quoted 2 lines
lib/librte_mempool/rte_mempool_handler.c new file +2
-0+ .sl = RTE_SPINLOCK_INITIALIZER , + .num_handlers =0
num_ops
lib/librte_mempool/rte_mempool_handler.c line 50
Quoted 7 lines
lib/librte_mempool/rte_mempool_handler.c new file +7
-0+}; + +/* add a new handler in rte_mempool_handler_table, return its index */ +int +rte_mempool_handler_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *handler;
*ops
lib/librte_mempool/rte_mempool_handler.c line 51
Quoted 1 line
lib/librte_mempool/rte_mempool_handler.c new file +1
-0+int16_t handler_idx;
ops_idx
Quoted 26 lines
lib/librte_mempool/rte_mempool_handler.c new file +26
-0+ +rte_spinlock_lock (&rte_mempool_handler_table.sl); + +if (rte_mempool_handler_table.num_handlers >= +RTE_MEMPOOL_MAX_HANDLER_IDX ) { +rte_spinlock_unlock (&rte_mempool_handler_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool handlers exceeded\n" ); +return -ENOSPC ; + } + +if (h->put ==NULL || h->get ==NULL || h->get_count ==NULL ) { +rte_spinlock_unlock (&rte_mempool_handler_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Missing callback while registering mempool handler\n" ); +return -EINVAL ; + } + + handler_idx = rte_mempool_handler_table.num_handlers++; + handler = &rte_mempool_handler_table.handler_ops[handler_idx]; +snprintf (handler->name,sizeof (handler->name),"%s" , h->name); + handler->alloc = h->alloc; + handler->put = h->put; + handler->get = h->get; + handler->get_count = h->get_count; +
lib/librte_mempool/rte_mempool_handler.c line 87
Quoted 10 lines
lib/librte_mempool/rte_mempool_handler.c new file +10
-0+rte_spinlock_unlock (&rte_mempool_handler_table.sl); + +return handler_idx; +} + +/* wrapper to allocate an external pool handler */ +void * +rte_mempool_ops_alloc (struct rte_mempool *mp) +{ +struct rte_mempool_ops *handler;
*ops
lib/librte_mempool/rte_mempool_handler.c line 99
Quoted 12 lines
lib/librte_mempool/rte_mempool_handler.c new file +12
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +if (handler->alloc ==NULL ) +return NULL ; +return handler->alloc (mp); +} + +/* wrapper to free an external pool handler */ +void +rte_mempool_ops_free (struct rte_mempool *mp) +{ +struct rte_mempool_ops *handler;
*ops
lib/librte_mempool/rte_mempool_handler.c line 111
Quoted 12 lines
lib/librte_mempool/rte_mempool_handler.c new file +12
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +if (handler->free ==NULL ) +return ; +return handler->free (mp); +} + +/* wrapper to get available objects in an external pool handler */ +unsigned int +rte_mempool_ops_get_count (const struct rte_mempool *mp) +{ +struct rte_mempool_ops *handler;
*ops
lib/librte_mempool/rte_mempool_handler.c line 121
Quoted 10 lines
lib/librte_mempool/rte_mempool_handler.c new file +10
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +return handler->get_count (mp->pool); +} + +/* sets a handler previously registered by rte_mempool_handler_register */ +int +rte_mempool_set_handler (struct rte_mempool *mp,const char *name) +{ +struct rte_mempool_ops *handler =NULL ;
*ops
Quoted 10 lines
lib/librte_mempool/rte_mempool_handler.c new file +10
-0+unsigned i; + +/* too late, the mempool is already populated */ +if (mp->flags &MEMPOOL_F_RING_CREATED ) +return -EEXIST ; + +for (i =0 ; i < rte_mempool_handler_table.num_handlers; i++) { +if (!strcmp (name, + rte_mempool_handler_table.handler_ops[i].name)) { + handler = &rte_mempool_handler_table.handler_ops[i];
lib/librte_mempool/rte_mempool_handler.c line 141
Quoted 10 lines
lib/librte_mempool/rte_mempool_handler.c new file +10
-0+break ; + } + } + +if (handler ==NULL ) +return -EINVAL ; + + mp->handler_idx = i; +return 0 ; +}
Regards
Jan
Re: [PATCH v6 1/5] mempool: support external handler
Quoted 4 lines · Jan Viktorin
Hello David,
the rename s/handler/ops/ has a lot of residues. Sorry for that :). I tried to mark most of them. Otherwise, I couldn't see many more serious issues for now.
Ah, I had assumed that we were just talking about the rte_mempool_handler_ops structure, not a global replace of 'handler' with 'ops'. It does make sense to change it to ops, so we don't have two words describing the same entity. I'll change to ops.
Just, note the s/pool/priv/ rename suggestion.
I prefer your suggestion of pdata rather than priv, how about "pool_data"?
Again, thanks for the comprehensive review.
Regards,
Dave.
[...]
Re: [PATCH v6 1/5] mempool: support external handler
In reply to Jan ViktorinQuoted 19 lines · Jan Viktorin
mp->populated_size--;
lib/librte_mempool/rte_mempool.c +6
-4@@ -383,13 +349,16 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,unsigned i =0 ;size_t off;struct rte_mempool_memhdr *memhdr; -int ret;/* create the internal ring if not already done */ if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) { - ret =rte_mempool_ring_create (mp); -if (ret <0 ) -return ret; + rte_errno =0 ; + mp->pool =rte_mempool_ops_alloc (mp); +if (mp->pool ==NULL ) { +if (rte_errno ==0 ) +return -EINVAL ; +return -rte_errno;
Quoted 1 line
Are you sure the
rte_errnois a positive value?
If the user returns EINVAL, or similar, we want to return negative, as per the rest of DPDK.
Quoted 10 lines
lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 209
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +2
-0@@ -204,9 +205,13 @@ struct rte_mempool_memhdr {struct rte_mempool {char name[RTE_MEMPOOL_NAMESIZE ];/**< Name of mempool. */ struct rte_ring *ring;/**< Ring to store objects. */ +union { +void *pool;/**< Ring or pool to store objects */ What about calling this pdata or priv? I think, it can improve some doc comments. Describing a "pool" may refer to both the
rte_mempoolitself or to themp->poolpointer. The "priv" would help to understand the code a bit.
Quoted 2 lines
Then the
rte_mempool_alloc_tcan be calledrte_mempool_priv_alloc_t. Or something similar. It's than clear enough, what the function should do...
I'd lean towards pdata or maybe pool_data. Not sure about the function name change though, the function does return a pool_data pointer, which we put into mp->pool_data.
Quoted 3 lines
lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 210
Quoted 1 line
lib/librte_mempool/rte_mempool.h +1
-0+uint64_t *pool_id;/**< External mempool identifier */ Why is
pool_ida pointer? Is it a typo? I've understood it should be 64b wide from the discussion (Olivier, Jerin, David):
Yes, typo.
Quoted 6 lines
uint32_ttrailer_size; /**< Size of trailer (after elt). */unsigned
private_data_size; /**< Size of private data. */lib/librte_mempool/rte_mempool.h +2
-0+/** +* Index into rte_mempool_handler_table array of mempool handler ops s/rte_mempool_handler_table/rte_mempool_ops_table/
Done.
Quoted 9 lines
lib/librte_mempool/rte_mempool.h struct rte_mempool { · line 232
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +6
-0+* structs, which contain callback function pointers. +* We're using an index here rather than pointers to the callbacks +* to facilitate any secondary processes that may want to use +* this mempool. +*/ +int32_t handler_idx;s/handler_idx/ops_idx/
What about
ops_index? Not a big deal...
I agree ops_index is better. Changed.
Quoted 24 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 344
Quoted 11 lines
lib/librte_mempool/rte_mempool.h +4
-0struct rte_mempool_cache *local_cache;/**< Per-lcore local cache */ @@ -325,6 +338,199 @@ void rte_mempool_check_cookies(const struct rte_mempool *mp,#define __mempool_check_cookies (mp, obj_table_const, n, free) do {} while(0)#endif /* RTE_LIBRTE_MEMPOOL_DEBUG */ +#define RTE_MEMPOOL_HANDLER_NAMESIZE 32/**< Max length of handler name. */ + +/** +* typedef for allocating the external pool. What about:
function prototype to provide an implementation specific data
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 347
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+* The handler's alloc function does whatever it needs to do to grab memory +* for this handler, and sets the *pool opaque pointer in the rte_mempool +* struct. In the default handler, *pool points to a ring,in other handlers, What about:
The function should provide a memory heap representation or another private data used for allocation by the
rte_mempool_ops. E.g. the default ops provides an instance of therte_ringfor this purpose.
Quoted 5 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 349
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+* it will mostlikely point to a different type of data structure. +* It will be transparent to the application programmer. I'd add something like this:
The function should not touch the given *mp instance.
Agreed. Reworked somewhat.
Quoted 6 lines
...because it's goal is NOT to set the
mp->pool, this is done by therte_mempool_populate_phys- the caller of thisrte_mempool_ops_alloc.This is why I've suggested to pass the
rte_mempoolas const in the v5. Is there any reason to modify therte_mempoolcontents by the implementation? I think, we just need to read the flags,socket_id, etc.
Yes, I agree it should be const. Changed.
Quoted 7 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 353
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+*/ +typedef void *(*rte_mempool_alloc_t )(struct rte_mempool *mp); + +/** Free the external pool opaque data (that pointed to by *pool) */ What about:
/** Free the opaque private data stored in the
mp->poolpointer. */
I've merged the two versions of the comment:
/** Free the opaque private data pointed to by mp->pool_data pointer */
Quoted 7 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 359
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +6
-0+typedef void (*rte_mempool_free_t )(void *p); + +/** +* Put an object in the external pool. +* The *p pointer is the opaque data for a given mempool handler (ring, +* array, linked list, etc) The
obj_tableis not documented. Is it really a table? I'd called an array instead.
You're probably right, but it's always been called obj_table, and I'm not sure this patchset is the place to change it. Maybe a follow up patch?
Quoted 3 lines
Review void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 361
Quoted 2 lines
(quoted diff) +2
-0+ */ +typedef int (*rte_mempool_put_t)(void *p, void * const *obj_table, unsigned n);unsigned int
Done
Quoted 5 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 364
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** Get an object from the external pool. */ +typedef int (*rte_mempool_get_t )(void *p,void **obj_table,unsigned n);unsigned int
Done
Quoted 5 lines
Review void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 366
Quoted 3 lines
(quoted diff) +2
-0+ +/** Return the number of available objects in the external pool. */Is the number of available objects or the total number of all objects (so probably a constant value)?
It's intended to be the umber of available objects
Quoted 3 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 367
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +1
-0+typedef unsigned (*rte_mempool_get_count )(void *p);Should it be const void *p?
Yes, it could be. Changed.
Quoted 6 lines
Review void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 369
Quoted 3 lines
(quoted diff) +2
-0+ +/** Structure defining a mempool handler. */What about:
/** Structure defining mempool operations. */
Changed.
Quoted 3 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 371
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+struct rte_mempool_ops { +char name[RTE_MEMPOOL_HANDLER_NAMESIZE ];/**< Name of mempool handler */ s/RTE_MEMPOOL_HANDLER_NAMESIZE/RTE_MEMPOOL_OPS_NAMESIZE/
Done
Quoted 4 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 372
Quoted 1 line
lib/librte_mempool/rte_mempool.h +1
-0+rte_mempool_alloc_t alloc;/**< Allocate the external pool. */ What about:
Allocate the private data for this
rte_mempool_ops.
Changed to /**< Allocate private data */
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 379
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+rte_mempool_free_t free;/**< Free the external pool. */ +rte_mempool_put_t put;/**< Put an object. */ +rte_mempool_get_t get;/**< Get an object. */ +rte_mempool_get_count get_count;/**< Get the number of available objs. */ +} __rte_cache_aligned; + +#define RTE_MEMPOOL_MAX_HANDLER_IDX 16/**< Max registered handlers */ s/RTE_MEMPOOL_MAX_HANDLER_IDX/RTE_MEMPOOL_MAX_OPS_IDX/
Changed
Quoted 4 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+ +/** +* Structure storing the table of registered handlers, each of which contain +* the function pointers for the mempool handler functions.
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 390
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+* Each process has it's own storage for this handler struct aray so that +* the mempools can be shared across primary and secondary processes. +* The indices used to access the array are valid across processes, whereas +* any function pointers stored directly in the mempool struct would not be. +* This results in us simply having "handler_idx" in the mempool struct. +*/ +struct rte_mempool_handler_table {s/rte_mempool_handler_table/rte_mempool_ops_table/
Done
Quoted 3 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 392
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+rte_spinlock_t sl;/**< Spinlock for add/delete. */ +uint32_t num_handlers;/**< Number of handlers in the table. */ s/num_handlers/num_ops/
Done
Quoted 5 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 396
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+/** +* Storage for all possible handlers. +*/ +struct rte_mempool_ops handler_ops[RTE_MEMPOOL_MAX_HANDLER_IDX ];s/handler_ops/ops/
Done
Quoted 5 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 400
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+} __rte_cache_aligned; + +/** Array of registered handlers */ +extern struct rte_mempool_handler_table rte_mempool_handler_table;s/rte_mempool_handler_table/rte_mempool_ops_table/
Done
Quoted 5 lines
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +5
-0+ +/** +* @internal Get the mempool handler from its index. +* +* @param handler_idx
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 412
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+* The index of the handler in the handler table. It must be a valid +* index: (0 <= idx < num_handlers). +* @return +* The pointer to the handler in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_handler_get (int handler_idx)
rte_mempool_ops_get(int ops_idx)
Done
Quoted 26 lines
Quoted 26 lines
lib/librte_mempool/rte_mempool.h +26
-0+{ +return &rte_mempool_handler_table.handler_ops[handler_idx]; +} + +/** +* @internal wrapper for external mempool manager alloc callback. +* +* @param mp +* Pointer to the memory pool. +* @return +* The opaque pointer to the external pool. +*/ +void * +rte_mempool_ops_alloc (struct rte_mempool *mp); + +/** +* @internal wrapper for external mempool manager get callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n +* Number of objects to get. +* @return +* - 0: Success; got n objects.
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 445
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+* - <0: Error; code of handler get function. +*/ +static inline int +rte_mempool_ops_dequeue_bulk (struct rte_mempool *mp, +void **obj_table,unsigned n) +{ +struct rte_mempool_ops *handler;*ops
Done
Quoted 16 lines
Quoted 16 lines
lib/librte_mempool/rte_mempool.h +16
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +return handler->get (mp->pool, obj_table, n); +} + +/** +* @internal wrapper for external mempool manager put callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n +* Number of objects to put. +* @return +* - 0: Success; n objects supplied.
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 468
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+* - <0: Error; code of handler put function. +*/ +static inline int +rte_mempool_ops_enqueue_bulk (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct rte_mempool_ops *handler;*ops
Done
Quoted 11 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 507
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+* @return +* - 0: Sucess; the new handler is configured. +* - EINVAL - Invalid handler name provided +* - EEXIST - mempool already has a handler assigned They are returned as
-EINVALand-EEXIST.IMHO, using "-" here is counter-intuitive:
- EINVAL
does it mean a positive with "-" or negative value?
EINVAL is positive, so it's returning negative. Common usage in DPDK, afaics.
Quoted 6 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 510
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+*/ +int +rte_mempool_set_handler (struct rte_mempool *mp,const char *name);
rte_mempool_set_opsWhat about
rte_mempool_set_ops_byname? Not a big deal...
I agree. rte_mempool_set_ops_byname
Quoted 4 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 513
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** +* Register an external pool handler. Register mempool operations
Done
Quoted 9 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 520
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+* +* @param h +* Pointer to the external pool handler +* @return +* - >=0: Sucess; return the index of the handler in the table. +* - EINVAL - missing callbacks while registering handler +* - ENOSPC - the maximum number of handlers has been reached -
-EINVAL
--ENOSPC
:)
Quoted 3 lines
Review void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 487
Quoted 2 lines
(quoted diff) +2
-0+ */ +int rte_mempool_handler_register(const struct rte_mempool_ops *h);
rte_mempool_ops_register
Done
Quoted 7 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 525
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** +* Macro to statically register an external pool handler. What about adding:
Note that the
rte_mempool_ops_registerfails silently here when more thenRTE_MEMPOOL_MAX_OPS_IDXis registered.
Done
Quoted 3 lines
Review void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 492
Quoted 2 lines
(quoted diff) +2
-0+ */ +#define MEMPOOL_REGISTER_HANDLER(h)
MEMPOOL_REGISTER_OPS
Done
Quoted 42 lines
\Quoted 41 lines
lib/librte_mempool/rte_mempool.h +10
-13+ void mp_hdlr_init_##h(void); \ + void __attribute__((constructor, used)) mp_hdlr_init_##h(void) \ + { \ + rte_mempool_handler_register(&h); \ + } +/** * An object callback function for mempool. * @@ -774,7 +980,7 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table, cache->len += n;if (cache->len >= flushthresh) { -rte_ring_mp_enqueue_bulk (mp->ring, &cache->objs[cache_size], +rte_mempool_ops_enqueue_bulk (mp, &cache->objs[cache_size], cache->len - cache_size); cache->len = cache_size; }@@ -785,19 +991,10 @@ ring_enqueue:/* push remaining objects in ring */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG -if (is_mp) { -if (rte_ring_mp_enqueue_bulk (mp->ring, obj_table, n) <0 ) -rte_panic ("cannot put objects in mempool\n" ); - } -else { -if (rte_ring_sp_enqueue_bulk (mp->ring, obj_table, n) <0 ) -rte_panic ("cannot put objects in mempool\n" ); - } +if (rte_mempool_ops_enqueue_bulk (mp, obj_table, n) <0 ) +rte_panic ("cannot put objects in mempool\n" );#else -if (is_mp) -rte_ring_mp_enqueue_bulk (mp->ring, obj_table, n); -else -rte_ring_sp_enqueue_bulk (mp->ring, obj_table, n); +rte_mempool_ops_enqueue_bulk (mp, obj_table, n);#endif }
Quoted 7 lines
lib/librte_mempool/rte_mempool.h rte_mempool_put(struct rte_mempool *mp, void *obj) · line 1122
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +1
-1@@ -922,7 +1119,7 @@ rte_mempool_put(struct rte_mempool *mp, void *obj)*/ static inline int __attribute__((always_inline))__mempool_get_bulk (struct rte_mempool *mp,void **obj_table, -unsigned n,int is_mc) + unsigned n, __rte_unused int is_mc)unsigned int
Done
Quoted 23 lines
Quoted 23 lines
lib/librte_mempool/rte_mempool.h +3
-5{int ret;struct rte_mempool_cache *cache;@@ -945,7 +1142,8 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table,uint32_t req = n + (cache_size - cache->len);/* How many do we require i.e. number to fill the cache + the request */ - ret =rte_ring_mc_dequeue_bulk (mp->ring, &cache->objs[cache->len], req); + ret =rte_mempool_ops_dequeue_bulk (mp, + &cache->objs[cache->len], req);if (unlikely (ret <0 )) {/* * In the offchance that we are buffer constrained, @@ -972,10 +1170,7 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table, ring_dequeue:/* get remaining objects from ring */ -if (is_mc) - ret =rte_ring_mc_dequeue_bulk (mp->ring, obj_table, n); -else - ret =rte_ring_sc_dequeue_bulk (mp->ring, obj_table, n); + ret =rte_mempool_ops_dequeue_bulk (mp, obj_table, n);
Quoted 8 lines
lib/librte_mempool/rte_mempool_handler.c
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +0
-0if (ret <0 )__MEMPOOL_STAT_ADD (mp, get_fail, n);lib/librte_mempool/rte_mempool_handler.c new file +0
-0
rte_mempool_ops.c
Done.
Quoted 36 lines
Quoted 36 lines
lib/librte_mempool/rte_mempool_handler.c new file +34
-0@@ -0,0 +1,141 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2016 Intel Corporation. All rights reserved. +* Copyright(c) 2016 6WIND S.A. +* 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 Intel Corporation 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. +*/ +
Quoted 8 lines
lib/librte_mempool/rte_mempool_handler.c line 41
Quoted 7 lines
lib/librte_mempool/rte_mempool_handler.c new file +7
-0+#include <stdio.h> +#include <string.h> + +#include <rte_mempool.h> + +/* indirect jump table to support external memory pools */ +struct rte_mempool_handler_table rte_mempool_handler_table = {
rte_mempool_ops_table
Done
Quoted 3 lines
lib/librte_mempool/rte_mempool_handler.c line 43
Quoted 2 lines
lib/librte_mempool/rte_mempool_handler.c new file +2
-0+ .sl = RTE_SPINLOCK_INITIALIZER , + .num_handlers =0
num_ops
Done
Quoted 8 lines
lib/librte_mempool/rte_mempool_handler.c line 50
Quoted 7 lines
lib/librte_mempool/rte_mempool_handler.c new file +7
-0+}; + +/* add a new handler in rte_mempool_handler_table, return its index */ +int +rte_mempool_handler_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *handler;*ops
Done
Quoted 2 lines
lib/librte_mempool/rte_mempool_handler.c line 51
Quoted 1 line
lib/librte_mempool/rte_mempool_handler.c new file +1
-0+int16_t handler_idx;
ops_idx
Done
Quoted 29 lines
Quoted 29 lines
lib/librte_mempool/rte_mempool_handler.c new file +29
-0+ +rte_spinlock_lock (&rte_mempool_handler_table.sl); + +if (rte_mempool_handler_table.num_handlers >= +RTE_MEMPOOL_MAX_HANDLER_IDX ) { +rte_spinlock_unlock (&rte_mempool_handler_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool handlers exceeded\n" ); +return -ENOSPC ; + } + +if (h->put ==NULL || h->get ==NULL || h->get_count ==NULL ) { +rte_spinlock_unlock (&rte_mempool_handler_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Missing callback while registering mempool handler\n" ); +return -EINVAL ; + } + + handler_idx = rte_mempool_handler_table.num_handlers++; + handler = &rte_mempool_handler_table.handler_ops[handler_idx]; +snprintf (handler->name,sizeof (handler->name),"%s" , h->name); + handler->alloc = h->alloc; + handler->put = h->put; + handler->get = h->get; + handler->get_count = h->get_count; + +rte_spinlock_unlock (&rte_mempool_handler_table.sl); + +return handler_idx;
Quoted 8 lines
lib/librte_mempool/rte_mempool_handler.c line 87
Quoted 7 lines
lib/librte_mempool/rte_mempool_handler.c new file +7
-0+} + +/* wrapper to allocate an external pool handler */ +void * +rte_mempool_ops_alloc (struct rte_mempool *mp) +{ +struct rte_mempool_ops *handler;*ops
Done
Quoted 5 lines
Quoted 5 lines
lib/librte_mempool/rte_mempool_handler.c new file +5
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +if (handler->alloc ==NULL ) +return NULL ; +return handler->alloc (mp);
Quoted 8 lines
lib/librte_mempool/rte_mempool_handler.c line 99
Quoted 7 lines
lib/librte_mempool/rte_mempool_handler.c new file +7
-0+} + +/* wrapper to free an external pool handler */ +void +rte_mempool_ops_free (struct rte_mempool *mp) +{ +struct rte_mempool_ops *handler;*ops
Done
Quoted 5 lines
Quoted 5 lines
lib/librte_mempool/rte_mempool_handler.c new file +5
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +if (handler->free ==NULL ) +return ; +return handler->free (mp);
Quoted 8 lines
lib/librte_mempool/rte_mempool_handler.c line 111
Quoted 7 lines
lib/librte_mempool/rte_mempool_handler.c new file +7
-0+} + +/* wrapper to get available objects in an external pool handler */ +unsigned int +rte_mempool_ops_get_count (const struct rte_mempool *mp) +{ +struct rte_mempool_ops *handler;*ops
Done
Quoted 11 lines
lib/librte_mempool/rte_mempool_handler.c line 121
Quoted 10 lines
lib/librte_mempool/rte_mempool_handler.c new file +10
-0+ + handler =rte_mempool_handler_get (mp->handler_idx); +return handler->get_count (mp->pool); +} + +/* sets a handler previously registered by rte_mempool_handler_register */ +int +rte_mempool_set_handler (struct rte_mempool *mp,const char *name) +{ +struct rte_mempool_ops *handler =NULL ;*ops
Done
Quoted 14 lines
Quoted 14 lines
lib/librte_mempool/rte_mempool_handler.c new file +14
-0+unsigned i; + +/* too late, the mempool is already populated */ +if (mp->flags &MEMPOOL_F_RING_CREATED ) +return -EEXIST ; + +for (i =0 ; i < rte_mempool_handler_table.num_handlers; i++) { +if (!strcmp (name, + rte_mempool_handler_table.handler_ops[i].name)) { + handler = &rte_mempool_handler_table.handler_ops[i]; +break ; + } + } +
Quoted 8 lines
lib/librte_mempool/rte_mempool_handler.c line 141
Quoted 6 lines
lib/librte_mempool/rte_mempool_handler.c new file +6
-0+if (handler ==NULL ) +return -EINVAL ; + + mp->handler_idx = i; +return 0 ; +}Regards
Jan
Thanks,
Dave.
Re: [PATCH v6 1/5] mempool: support external handler
Quoted 9 lines · David
Quoted 8 lines · Jan Viktorin
mp->populated_size--;
lib/librte_mempool/rte_mempool.c +0
-1@@ -383,13 +349,16 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,unsigned i =0 ;size_t off;struct rte_mempool_memhdr *memhdr; -int ret;
Quoted 15 lines
Quoted 11 lines
lib/librte_mempool/rte_mempool.c +6
-3/* create the internal ring if not already done */ if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) { - ret =rte_mempool_ring_create (mp); -if (ret <0 ) -return ret; + rte_errno =0 ; + mp->pool =rte_mempool_ops_alloc (mp); +if (mp->pool ==NULL ) { +if (rte_errno ==0 ) +return -EINVAL ; +return -rte_errno;Quoted 1 line
Are you sure the
rte_errnois a positive value?If the user returns EINVAL, or similar, we want to return negative, as per the rest of DPDK.
Oh, yes... you're right.
Quoted 11 lines
Quoted 11 lines
lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 209
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +2
-0@@ -204,9 +205,13 @@ struct rte_mempool_memhdr {struct rte_mempool {char name[RTE_MEMPOOL_NAMESIZE ];/**< Name of mempool. */ struct rte_ring *ring;/**< Ring to store objects. */ +union { +void *pool;/**< Ring or pool to store objects */ What about calling this pdata or priv? I think, it can improve some doc comments. Describing a "pool" may refer to both the
rte_mempoolitself or to themp->poolpointer. The "priv" would help to understand the code a bit.
Quoted 7 lines
Quoted 2 lines
Then the
rte_mempool_alloc_tcan be calledrte_mempool_priv_alloc_t. Or something similar. It's than clear enough, what the function should do...I'd lean towards pdata or maybe
pool_data. Not sure about the function name change though,
the function does return apool_datapointer, which we put intomp->pool_data.
Yes. But from the name of the function, it is difficult to understand what is its purpose.
Quoted 5 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 210
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +1
-0+uint64_t *pool_id;/**< External mempool identifier */ Why is
pool_ida pointer? Is it a typo? I've understood it should be 64b wide from the discussion (Olivier, Jerin, David):
[...]
Quoted 9 lines
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 359
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +6
-0+typedef void (*rte_mempool_free_t )(void *p); + +/** +* Put an object in the external pool. +* The *p pointer is the opaque data for a given mempool handler (ring, +* array, linked list, etc) The
obj_tableis not documented. Is it really a table? I'd called an array instead.
Quoted 3 lines
You're probably right, but it's always been called
obj_table, and I'm not sure
this patchset is the place to change it. Maybe a follow up patch?
In that case, it's OK.
Quoted 10 lines
Quoted 4 lines
Quoted 3 lines
+ */
+typedef int (*rte_mempool_put_t)(void *p, void * const*obj_table, unsigned n);unsigned int
Done
Quoted 5 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 364
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** Get an object from the external pool. */ +typedef int (*rte_mempool_get_t )(void *p,void **obj_table,unsigned n);unsigned int
Quoted 8 lines
Done
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +/** Return the number of available objects in the external pool. */Is the number of available objects or the total number of all objects (so probably a constant value)?
It's intended to be the umber of available objects
OK, forget it.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
+typedef unsigned (*rte_mempool_get_count)(void *p);
Should it be const void *p?
Yes, it could be. Changed.
Quoted 1 line
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
+ * @return
+ * - 0: Sucess; the new handler is configured. + * - EINVAL - Invalid handler name provided + * - EEXIST - mempool already has a handler assignedThey are returned as
-EINVALand-EEXIST.
Quoted 8 lines
Quoted 5 lines
IMHO, using "-" here is counter-intuitive:
- EINVAL
does it mean a positive with "-" or negative value?
EINVAL is positive, so it's returning negative. Common usage in DPDK, afaics.
Yes, of course. But it is not so clear from the doc. I've already wrote a code checking the positive error codes. That was because of no "minus sign" in the doc. So, my code was wrong and it took me a while to find out the reason... I supposed, the positive value was intentional. Finally, I had to lookup the source code (the calling path) to verify...
Quoted 25 lines
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 510
Quoted 5 lines
+ */
lib/librte_mempool/rte_mempool.h +2
-0+int +rte_mempool_set_handler (struct rte_mempool *mp,const char *name);
rte_mempool_set_opsWhat about
rte_mempool_set_ops_byname? Not a big deal...I agree.
rte_mempool_set_ops_bynameQuoted 4 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 513
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** +* Register an external pool handler. Register mempool operations
Done
Quoted 7 lines
Quoted 7 lines
+ *
+ * @param h
+ * Pointer to the external pool handler
+ * @return+ * - >=0: Sucess; return the index of the handler in the table. + * - EINVAL - missing callbacks while registering handler + * - ENOSPC - the maximum number of handlers has been reached
Quoted 4 lines
Quoted 2 lines
-
-EINVAL
--ENOSPC:)
Similar as above... If it's a DPDK standard to write it like this, then I am OK with that.
Quoted 1 line
[...]
Signature · 4 lines
Jan Viktorin E-mail: [email protected] System Architect Web: www.RehiveTech.com RehiveTech Brno, Czech Republic
PATCH v6 2/5 mempool: remove rte_ring from rte_mempool struct
In reply to David HuntNow that we're moving to an external mempoool handler, which uses a void *pool as a pointer to the pool data, remove the unneeded ring pointer from the mempool struct.
--- app/test/test_mempool_perf.c | 1 - lib/librte_mempool/rte_mempool.h | 1 - 2 files changed, 2 deletions(-)
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
lib/librte_mempool/rte_mempool.h +0 -1
@@ -204,7 +204,6 @@ struct rte_mempool_memhdr {*/ struct rte_mempool {char name[RTE_MEMPOOL_NAMESIZE ];/**< Name of mempool. */ -struct rte_ring *ring;/**< Ring to store objects. */ union {void *pool;/**< Ring or pool to store objects */ uint64_t *pool_id;/**< External mempool identifier */
Signature · 1 line
2.5.5
PATCH v6 3/5 mempool: add default external mempool handler
In reply to David HuntThe first patch in this series added the framework for an external mempool manager. This patch in the series adds a set of default handlers based on rte_ring.
v6 changes: split out into a separate patch for easier review.
--- lib/librte_mempool/Makefile | 1 + lib/librte_mempool/rte_mempool.h | 2 + lib/librte_mempool/rte_mempool_default.c | 153 +++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 lib/librte_mempool/rte_mempool_default.c
lib/librte_mempool/Makefile +1 -0
@@ -43,6 +43,7 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_handler.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_default.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.h +2 -0
@@ -410,6 +410,8 @@ extern struct rte_mempool_handler_table rte_mempool_handler_table;static inline struct rte_mempool_ops *rte_mempool_handler_get (int handler_idx) { +RTE_VERIFY (handler_idx <RTE_MEMPOOL_MAX_HANDLER_IDX ); +return &rte_mempool_handler_table.handler_ops[handler_idx]; }
lib/librte_mempool/rte_mempool_default.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH v6 4/5 app/test: test external mempool handler
In reply to David HuntUse a minimal custom mempool external handler and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)
app/test/test_mempool.c +114 -0
@@ -83,6 +83,97 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static void * +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return NULL ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; +return cm; +} + +static void +custom_mempool_free (void *p) +{ +rte_free (p); +} + +static int +custom_mempool_put (void *p,void *const *obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)p; +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_get (void *p,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)p; +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (void *p) +{ +struct custom_mempool *cm = (struct custom_mempool *)p; + +return cm->count; +} + +static struct rte_mempool_ops mempool_handler_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .put = custom_mempool_put, + .get = custom_mempool_get, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_HANDLER (mempool_handler_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -477,6 +568,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +597,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_handler (mp_ext,"custom_handler" ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +658,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
PATCH v6 5/5 mbuf: get default mempool handler from configuration
In reply to David HuntBy default, the mempool handler used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_HANDLER.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_HANDLER="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_handler (mp, +RTE_MBUF_DEFAULT_MEMPOOL_HANDLER ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
v7 cover mempool: add external mempool manager
In reply to David HuntHere's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 19/5/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_HANDLER macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops to create a new mempool
using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new 'create' function, providing the mempool ops struct name to point the mempool to the relevant mempool manager callback structure.
The old 'create' function can still be called by legacy programs, and will internally work out the mempool handle based on the flags provided (single producer, single consumer, etc). By default handles are created internally to implement the built-in DPDK mempool manager and mempool types.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. put - puts an object back into the mempool once an application has
finished with it
3. get - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time a get/put/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
intrte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.put = common_ring_sp_put,
.get = common_ring_mc_get,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (4):
mempool: support external mempool operations
mempool: remove rte_ring from rte_mempool struct
mempool: add default external mempool ops
mbuf: allow apps to change default mempool ops
Olivier Matz (1):
app/test: test external mempool manager
PATCH v7 1/5 mempool: support external mempool operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_handler() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
--- lib/librte_mempool/Makefile | 1 + lib/librte_mempool/rte_mempool.c | 71 ++++------- lib/librte_mempool/rte_mempool.h | 240 ++++++++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_ops.c | 141 ++++++++++++++++++++ 4 files changed, 389 insertions(+), 64 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_ops.c
lib/librte_mempool/Makefile +1 -0
@@ -42,6 +42,7 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +27 -44
128 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +220 -20
297 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
2.5.5
v7 cover mempool: add external mempool manager
Since the cover letter seems to have gone missing, sending it again:
Here's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 19/5/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments,
duplicating
the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is
required
as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool
tests,
avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached
operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_HANDLER macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops to create a new mempool
using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon()
functions
which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new 'create' function, providing the mempool ops struct name to point the mempool to the relevant mempool manager callback structure.
The old 'create' function can still be called by legacy programs, and will internally work out the mempool handle based on the flags provided (single producer, single consumer, etc). By default handles are created internally to implement the built-in DPDK mempool manager and mempool types.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto
a ring
2. put - puts an object back into the mempool once an
application has
finished with it
3. get - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time a get/put/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
intrte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.put = common_ring_sp_put,
.get = common_ring_mc_get,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (4):
mempool: support external mempool operations
mempool: remove rte_ring from rte_mempool struct
mempool: add default external mempool ops
mbuf: allow apps to change default mempool ops
Olivier Matz (1):
app/test: test external mempool manager
Re: [PATCH v7 1/5] mempool: support external mempool operations
In reply to David HuntOn Thu, Jun 02, 2016 at 02:27:19PM +0100, David Hunt wrote:
[snip]
lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, · line 354
Quoted 2 lines
lib/librte_mempool/rte_mempool.c +0
-0/* create the internal ring if not already done */ if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) {
|> 1) May be RING can be replaced with some other higher abstraction name |> for the internal MEMPOOL_F_RING_CREATED flag | |Agreed. I'll change to MEMPOOL_F_POOL_CREATED, since we're already |changing the *ring |element of the mempool struct to *pool
Looks like you have missed the above review comment?
[snip]
Quoted 4 lines
static inline struct
rte_mempool_ops*rte_mempool_ops_get(int ops_index)return &rte_mempool_ops_table.ops[ops_index];
|> 2) Considering "get" and "put" are the fast-path callbacks for
|> pool-manger, Is it possible to avoid the extra overhead of the
|> following
|> _load_ and additional cache line on each call,
|> rte_mempool_handler_table.handler[handler_idx]
|>
|> I understand it is for multiprocess support but I am thing can we
|> introduce something like ethernet API support for multiprocess and
|> resolve "put" and "get" functions pointer on init and store in
|> struct mempool. Some thinking like
|>
|> file: drivers/net/ixgbe/ixgbe_ethdev.c
|> search for if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
|
|I'll look at this one before posting the next version of the patch
|(soon). :)Have you checked the above comment, if it difficult then postpone it. But IMO it will reduce few cycles in fast-path and reduce the cache usage in fast path
[snip]
Quoted 12 lines
lib/librte_mempool/rte_mempool.h +12
-0+ +/** +* @internal wrapper for external mempool manager put callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n +* Number of objects to put. +* @return +* - 0: Success; n objects supplied.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 474
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* - <0: Error; code of put function. +*/ +static inline int +rte_mempool_ops_enqueue_bulk (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->put (mp->pool_data, obj_table, n);
Pass by value of "pool_data", On 32 bit systems, casting back to pool_id will be an issue as void* on 32 bit is 4B. IMO, May be can use uint64_t to pass by value and typecast to void* to fix it.
Jerin
Re: [PATCH v7 1/5] mempool: support external mempool operations
Quoted 6 lines · Jerin Jacob
On Thu, Jun 02, 2016 at 02:27:19PM +0100, David Hunt wrote:
[snip]
Quoted 2 lines
/* create the internal ring if not already done */ if ((
mp->flags&MEMPOOL_F_RING_CREATED) == 0) {
Quoted 8 lines
|> 1) May be RING can be replaced with some other higher abstraction name |> for the internal MEMPOOL_F_RING_CREATED flag | |Agreed. I'll change to MEMPOOL_F_POOL_CREATED, since we're already |changing the *ring |element of the mempool struct to *poolLooks like you have missed the above review comment?
Ah, yes, I'll address in the next patch.
I've to remove some 'const's in the alloc functions anyway
which I introduced in the last revision, which I shouldn't have. Future handlers (including the stack hander) will need to set the pool_data in the alloc.
Quoted 24 lines
[snip]
Quoted 4 lines
static inline struct
rte_mempool_ops*rte_mempool_ops_get(int ops_index)return &rte_mempool_ops_table.ops[ops_index];
|> 2) Considering "get" and "put" are the fast-path callbacks for |> pool-manger, Is it possible to avoid the extra overhead of the |> following |> _load_ and additional cache line on each call, |> rte_mempool_handler_table.handler[handler_idx] |> |> I understand it is for multiprocess support but I am thing can we |> introduce something like ethernet API support for multiprocess and |> resolve "put" and "get" functions pointer on init and store in |> struct mempool. Some thinking like |> |> file: drivers/net/ixgbe/ixgbe_ethdev.c |> search for if (rte_eal_process_type() != RTE_PROC_PRIMARY) { | |I'll look at this one before posting the next version of the patch |(soon). :)
Quoted 5 lines
Have you checked the above comment, if it difficult then postpone it. But IMO it will reduce few cycles in fast-path and reduce the cache usage in fast path
[snip]
I looked at it, but I'd need to do some more digging into it to see how it can be done properly. I'm not seeing any performance drop at the moment, and it may be a good way to improve further down the line. Is it OK to postpone?
Quoted 17 lines
Quoted 17 lines
lib/librte_mempool/rte_mempool.h +17
-0+ +/** +* @internal wrapper for external mempool manager put callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n +* Number of objects to put. +* @return +* - 0: Success; n objects supplied. +* - <0: Error; code of put function. +*/ +static inline int +rte_mempool_ops_enqueue_bulk (struct rte_mempool *mp,void *const *obj_table, +unsigned n)
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 474
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +5
-0+{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->put (mp->pool_data, obj_table, n);Pass by value of "
pool_data", On 32 bit systems, casting back topool_idwill be an issue as void* on 32 bit is 4B. IMO, May be can useuint64_tto pass by value and typecast to void* to fix it.
OK. I see the problem. I'll see 4 callbacks that need to change, free, get, put and get_count. So the callbacks will be:
typedef void *(*rte_mempool_alloc_t)(struct rte_mempool *mp);
typedef void (*rte_mempool_free_t)(uint64_t p);
typedef int (*rte_mempool_put_t)(uint64_t p, void * const *obj_table, unsigned int n); typedef int (*rte_mempool_get_t)(uint64_t p, void **obj_table, unsigned int n); typedef unsigned (*rte_mempool_get_count)(uint64_t p);
Regards,
Dave.
Re: [PATCH v7 1/5] mempool: support external mempool operations
Quoted 26 lines · David
Quoted 26 lines
Quoted 5 lines
static inline struct
rte_mempool_ops*rte_mempool_ops_get(int ops_index)return &rte_mempool_ops_table.ops[ops_index];
|> 2) Considering "get" and "put" are the fast-path callbacks for |> pool-manger, Is it possible to avoid the extra overhead of the |> following |> _load_ and additional cache line on each call, |> rte_mempool_handler_table.handler[handler_idx] |> |> I understand it is for multiprocess support but I am thing can we |> introduce something like ethernet API support for multiprocess and |> resolve "put" and "get" functions pointer on init and store in |> struct mempool. Some thinking like |> |> file: drivers/net/ixgbe/ixgbe_ethdev.c |> search for if (rte_eal_process_type() != RTE_PROC_PRIMARY) { | |I'll look at this one before posting the next version of the patch |(soon). :)Have you checked the above comment, if it difficult then postpone it. But IMO it will reduce few cycles in fast-path and reduce the cache usage in fast path
Quoted 6 lines
Quoted 1 line
[snip]
I looked at it, but I'd need to do some more digging into it to see how it can be
done properly. I'm not seeing any performance drop at the moment, and it may be a good way to improve further down the line. Is it OK to postpone?
I am OK for fixing it later. Performance issue should come in the use cases where mempool "local cache" gets overflows and "get" and "put." function pointers being used. Like crypto and ethdev, fast path function pointers can accommodate in the main structure itself rather than one more indirection.
Jerin
Re: [PATCH v7 1/5] mempool: support external mempool operations
In reply to Hunt, DavidQuoted 29 lines · David
Quoted 19 lines · Jerin Jacob
Quoted 18 lines · David Hunt
lib/librte_mempool/rte_mempool.h +15
-0+/** +* @internal wrapper for external mempool manager put callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n +* Number of objects to put. +* @return +* - 0: Success; n objects supplied. +* - <0: Error; code of put function. +*/ +static inline int +rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const
*obj_table,lib/librte_mempool/rte_mempool.h +2
-0+ unsigned n) +{Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 474
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->put (mp->pool_data, obj_table, n);Pass by value of "
pool_data", On 32 bit systems, casting back topool_idwill
be an issue as void* on 32 bit is 4B. IMO, May be can useuint64_tto pass by value and typecast to void* to fix it.
Quoted 10 lines
OK. I see the problem. I'll see 4 callbacks that need to change, free, get, put and
get_count.
So the callbacks will be:
typedef void *(*rte_mempool_alloc_t)(structrte_mempool*mp); typedef void (*rte_mempool_free_t)(uint64_t p);
typedef int (*rte_mempool_put_t)(uint64_t p, void * const*obj_table, unsigned int n);
typedef int (*rte_mempool_get_t)(uint64_t p, void **obj_table, unsigned int n);
typedef unsigned (*rte_mempool_get_count)(uint64_t p);
I don't quite like the uint64_t argument (I exepect that most handlers will use a pointer, and they will have to do a cast). What about giving a (struct rte_mempool *) instead? The handler function would then select between void * or uint64_t without a cast.
In that case, maybe the prototype of alloc should be:
typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
It would directly set mp->pool_data and return 0 or -errno.
By the way, I found a strange thing:
Quoted 1 line
typedef void (*rte_mempool_free_t)(void *p);
[...]
Quoted 11 lines
void
rte_mempool_ops_free(struct rte_mempool *mp)
{
structrte_mempool_ops*ops;ops =
rte_mempool_ops_get(mp->ops_index);
if (ops->free== NULL)
return;
returnops->free(mp);
}
Seems that the free cb expects mp->pool_data, but mp is passed.
Another alternative to the "uint64_t or ptr" question would be to use a uintptr_t instead of a uint64_t. This is won't be possible if it need to be a 64 bits value even on 32 bits architectures. We could then keep the argument as pointer, and cast it to uintptr_t if needed.
Regards,
Olivier
Re: [PATCH v7 1/5] mempool: support external mempool operations
Hello,
sorry for top-posting. I vote for passing rte_mempool instead of void *. This is what I've already pointed at, a kind of type-safety... Passing uint64_t just hides the problem. Another way is to name the union and pass it as eg. union rte_mempool_priv * to the callbacks.
Jan Viktorin
RehiveTech
Sent from a mobile device
Původní zpráva
Od: Olivier MATZ
Odesláno: pátek, 3. června 2016 13:08
Komu: Hunt, David; Jerin Jacob
Kopie: [email protected]; [email protected]
Předmět: Re: [PATCH v7 1/5] mempool: support external mempool operations
Quoted 29 lines · David
Quoted 19 lines · Jerin Jacob
Quoted 18 lines · David Hunt
lib/librte_mempool/rte_mempool.h +15
-0+/** +* @internal wrapper for external mempool manager put callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n +* Number of objects to put. +* @return +* - 0: Success; n objects supplied. +* - <0: Error; code of put function. +*/ +static inline int +rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const
*obj_table,
+ unsigned n)
+{Quoted 8 lines
Quoted 4 lines
+ struct
rte_mempool_ops*ops;
+
+ ops =rte_mempool_ops_get(mp->ops_index);
+ returnops->put(mp->pool_data, obj_table, n);Pass by value of "
pool_data", On 32 bit systems, casting back topool_idwill
be an issue as void* on 32 bit is 4B. IMO, May be can useuint64_tto pass by value and typecast to void* to fix it.
Quoted 10 lines
OK. I see the problem. I'll see 4 callbacks that need to change, free, get, put and
get_count.
So the callbacks will be:
typedef void *(*rte_mempool_alloc_t)(structrte_mempool*mp); typedef void (*rte_mempool_free_t)(uint64_t p);
typedef int (*rte_mempool_put_t)(uint64_t p, void * const*obj_table, unsigned int n);
typedef int (*rte_mempool_get_t)(uint64_t p, void **obj_table, unsigned int n);
typedef unsigned (*rte_mempool_get_count)(uint64_t p);
I don't quite like the uint64_t argument (I exepect that most handlers will use a pointer, and they will have to do a cast). What about giving a (struct rte_mempool *) instead? The handler function would then select between void * or uint64_t without a cast.
In that case, maybe the prototype of alloc should be:
typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
It would directly set mp->pool_data and return 0 or -errno.
By the way, I found a strange thing:
Quoted 1 line
typedef void (*rte_mempool_free_t)(void *p);
[...]
Quoted 11 lines
void
rte_mempool_ops_free(struct rte_mempool *mp)
{
structrte_mempool_ops*ops;ops =
rte_mempool_ops_get(mp->ops_index);
if (ops->free== NULL)
return;
returnops->free(mp);
}
Seems that the free cb expects mp->pool_data, but mp is passed.
Another alternative to the "uint64_t or ptr" question would be to use a uintptr_t instead of a uint64_t. This is won't be possible if it need to be a 64 bits value even on 32 bits architectures. We could then keep the argument as pointer, and cast it to uintptr_t if needed.
Regards,
Olivier
Re: [PATCH v7 1/5] mempool: support external mempool operations
In reply to Olivier MATZQuoted 46 lines · Olivier MATZ
Quoted 28 lines · David
Quoted 19 lines · Jerin Jacob
Quoted 18 lines · David Hunt
lib/librte_mempool/rte_mempool.h +15
-0+/** +* @internal wrapper for external mempool manager put callback. +* +* @param mp +* Pointer to the memory pool. +* @param obj_table +* Pointer to a table of void * pointers (objects). +* @param n +* Number of objects to put. +* @return +* - 0: Success; n objects supplied. +* - <0: Error; code of put function. +*/ +static inline int +rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const
*obj_table,lib/librte_mempool/rte_mempool.h +2
-0+ unsigned n) +{Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 474
Quoted 4 lines
lib/librte_mempool/rte_mempool.h +4
-0+struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->put (mp->pool_data, obj_table, n);Pass by value of "
pool_data", On 32 bit systems, casting back topool_idwill
be an issue as void* on 32 bit is 4B. IMO, May be can useuint64_tto pass by value and typecast to void* to fix it.Quoted 10 lines
OK. I see the problem. I'll see 4 callbacks that need to change, free, get, put and
get_count.
So the callbacks will be:
typedef void *(*rte_mempool_alloc_t)(structrte_mempool*mp); typedef void (*rte_mempool_free_t)(uint64_t p);
typedef int (*rte_mempool_put_t)(uint64_t p, void * const*obj_table, unsigned int n);
typedef int (*rte_mempool_get_t)(uint64_t p, void **obj_table, unsigned int n);
typedef unsigned (*rte_mempool_get_count)(uint64_t p);I don't quite like the
uint64_targument (I exepect that most handlers will use a pointer, and they will have to do a cast). What about giving a (structrte_mempool*) instead? The handler function would then select between void * oruint64_twithout a cast.
In that case, maybe the prototype of alloc should be:
Quoted 3 lines
typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);It would directly set
mp->pool_dataand return 0 or -errno.
I would tend to agree. The uint64 didn't sit well with me :) I would prefer the rte_mempool*
Quoted 3 lines
By the way, I found a strange thing:
Quoted 1 line
typedef void (*rte_mempool_free_t)(void *p);
Yes, I spotted that earler, will be fixed in next version
Quoted 7 lines
[...]
Quoted 5 lines
void
rte_mempool_ops_free(struct rte_mempool *mp)
{
structrte_mempool_ops*ops;
Quoted 7 lines
Quoted 6 lines
ops =
rte_mempool_ops_get(mp->ops_index);
if (ops->free== NULL)
return;
returnops->free(mp);
}Seems that the free cb expects
mp->pool_data, but mp is passed.
Working in it.
Quoted 6 lines
Another alternative to the "
uint64_tor ptr" question would be to use auintptr_tinstead of auint64_t. This is won't be possible if it need to be a 64 bits value even on 32 bits architectures. We could then keep the argument as pointer, and cast it touintptr_tif needed.
I had assumed that the requirement was for 64 bits even on 32 bit OS's. I've implemented the double cast of the u64 to uintptr_t to struct pointer done to avoid compiler warnings on 32-bit but I really prefer the solution of passing the rte_mempool pointer instead. I'll change to *mp.
Regards,
Dave.
Re: [PATCH v7 1/5] mempool: support external mempool operations
In reply to David HuntHi,
Some comments below.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 352
Quoted 12 lines · David Hunt
lib/librte_mempool/rte_mempool.h +10
-0+/** +* prototype for implementation specific data provisioning function +* The function should provide the implementation specific memory for +* for use by the other mempool ops functions in a given mempool ops struct. +* E.g. the default ops provides an instance of the rte_ring for this purpose. +* it will mostlikely point to a different type of data structure, and +* will be transparent to the application programmer. +* The function should also not touch the given *mp instance. +*/ +typedef void *(*rte_mempool_alloc_t )(const struct rte_mempool *mp);
nit: about doxygen comments, it's better to have a one-line description, then a blank line, then the full description. While there, please also check the uppercase at the beginning and the dot when relevant.
Quoted 4 lines
+/**
+ * Structure storing the table of registered ops structs, each of which contain
+ * the function pointers for the mempool ops functions.
+ * Each process has it's own storage for this ops struct aray so that
it's -> its
aray -> array
Quoted 24 lines
+ * the mempools can be shared across primary and secondary processes.
+ * The indices used to access the array are valid across processes, whereas
+ * any function pointers stored directly in the mempool struct would not be.
+ * This results in us simply having "ops_index" in the mempool struct.
+ */lib/librte_mempool/rte_mempool.h +19
-0+struct rte_mempool_ops_table { +rte_spinlock_t sl;/**< Spinlock for add/delete. */ +uint32_t num_ops;/**< Number of used ops structs in the table. */ +/** +* Storage for all possible ops structs. +*/ +struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX ]; +} __rte_cache_aligned; + +/** Array of registered ops structs */ +extern struct rte_mempool_ops_table rte_mempool_ops_table; + +/** +* @internal Get the mempool ops struct from its index. +* +* @param ops_index +* The index of the ops struct in the ops struct table. It must be a valid +* index: (0 <= idx < num_ops). +* @return
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 421
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* The pointer to the ops struct in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_ops_get (int ops_index) +{ +return &rte_mempool_ops_table.ops[ops_index]; +} + +/** +* @internal wrapper for external mempool manager alloc callback.
wrapper for mempool_ops alloc callback
?
(same for other functions)
lib/librte_mempool/rte_mempool.h rte_mempool_put(struct rte_mempool *mp, void *obj) · line 1130
Quoted 9 lines
lib/librte_mempool/rte_mempool.h +1
-1@@ -922,7 +1124,7 @@ rte_mempool_put(struct rte_mempool *mp, void *obj)*/ static inline int __attribute__((always_inline))__mempool_get_bulk (struct rte_mempool *mp,void **obj_table, -unsigned n,int is_mc) +unsigned int n,int is_mc) {int ret;struct rte_mempool_cache *cache;
Despite "unsigned" is not conform to current checkpatch policy, I don't think it should be modified in this patch.
Quoted 5 lines
lib/librte_mempool/rte_mempool_ops.c new file +2
-0+ +#include <rte_mempool.h>
lib/librte_mempool/rte_mempool_ops.c line 48
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+ +/* indirect jump table to support external memory pools */ +struct rte_mempool_ops_table rte_mempool_ops_table = { + .sl =RTE_SPINLOCK_INITIALIZER , + .num_ops =0 +}; + +/* add a new ops struct in rte_mempool_ops_table, return its index */ +int +rte_mempool_ops_register (const struct rte_mempool_ops *h)
nit: "h" should be "ops" :)
Quoted 14 lines
lib/librte_mempool/rte_mempool_ops.c new file +14
-0+{ +struct rte_mempool_ops *ops; +int16_t ops_index; + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + +if (rte_mempool_ops_table.num_ops >= +RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool ops structs exceeded\n" ); +return -ENOSPC ; + } +
lib/librte_mempool/rte_mempool_ops.c line 72
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+if (h->put ==NULL || h->get ==NULL || h->get_count ==NULL ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Missing callback while registering mempool ops\n" ); +return -EINVAL ; + } + + ops_index = rte_mempool_ops_table.num_ops++; + ops = &rte_mempool_ops_table.ops[ops_index]; +snprintf (ops->name,sizeof (ops->name),"%s" , h->name);
I think we should check for truncation here, as it was done in:85cf00791cca ("mem: avoid memzone/mempool/ring name truncation") (this should be done before the num_ops++)
Regards,
Olivier
PATCH v7 2/5 mempool: remove rte_ring from rte_mempool struct
In reply to David HuntNow that we're moving to an external mempoool handler, which uses a void *pool_data as a pointer to the pool data, remove the unneeded ring pointer from the mempool struct.
--- app/test/test_mempool_perf.c | 1 - lib/librte_mempool/rte_mempool.h | 1 - 2 files changed, 2 deletions(-)
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
lib/librte_mempool/rte_mempool.h +0 -1
@@ -204,7 +204,6 @@ struct rte_mempool_memhdr {*/ struct rte_mempool {char name[RTE_MEMPOOL_NAMESIZE ];/**< Name of mempool. */ -struct rte_ring *ring;/**< Ring to store objects. */ union {void *pool_data;/**< Ring or pool to store objects */ uint64_t pool_id;/**< External mempool identifier */
Signature · 1 line
2.5.5
Re: [PATCH v7 2/5] mempool: remove rte_ring from rte_mempool struct
Quoted 28 lines · David Hunt
Now that we're moving to an external mempoool handler, which uses a void
*pool_dataas a pointer to the pool data, remove the unneeded ring pointer from the mempool struct.Signed-off-by David Hunt <[email protected]>--- app/test/test_mempool_perf.c | 1 - lib/librte_mempool/rte_mempool.h | 1 - 2 files changed, 2 deletions(-)app/test/test_mempool_perf.c +0
-1@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }lib/librte_mempool/rte_mempool.h +0
-0
lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 209
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +0
-1@@ -204,7 +204,6 @@ struct rte_mempool_memhdr {*/ struct rte_mempool {char name[RTE_MEMPOOL_NAMESIZE ];/**< Name of mempool. */ -struct rte_ring *ring;/**< Ring to store objects. */ union {void *pool_data;/**< Ring or pool to store objects */ uint64_t pool_id;/**< External mempool identifier */
Sorry if I missed it in previous discussions, but I don't really see the point of having this in a separate commit, as the goal of the previous commit is to replace the ring by configurable ops.
Moreover, after applying only the previous commit, the call to rte_ring_dump(stdout, mp->ring) would probably crash sine ring is NULL.
I think this comment also applies to the next commit. Splitting between functionalities is good, but in this case I think the 3 commits are linked together, and it should not break compilation or tests to facilitate the git bisect.
Regards,
Olivier
Re: [PATCH v7 2/5] mempool: remove rte_ring from rte_mempool struct
Quoted 45 lines · Olivier MATZ
Quoted 28 lines · David Hunt
Now that we're moving to an external mempoool handler, which uses a void
*pool_dataas a pointer to the pool data, remove the unneeded ring pointer from the mempool struct.Signed-off-by David Hunt <[email protected]>--- app/test/test_mempool_perf.c | 1 - lib/librte_mempool/rte_mempool.h | 1 - 2 files changed, 2 deletions(-)app/test/test_mempool_perf.c +0
-1@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }lib/librte_mempool/rte_mempool.h +0
-0lib/librte_mempool/rte_mempool.h struct rte_mempool_memhdr { · line 209
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +0
-1@@ -204,7 +204,6 @@ struct rte_mempool_memhdr {*/ struct rte_mempool {char name[RTE_MEMPOOL_NAMESIZE ];/**< Name of mempool. */ -struct rte_ring *ring;/**< Ring to store objects. */ union {void *pool_data;/**< Ring or pool to store objects */ uint64_t pool_id;/**< External mempool identifier */ Sorry if I missed it in previous discussions, but I don't really see the point of having this in a separate commit, as the goal of the previous commit is to replace the ring by configurable ops.
Moreover, after applying only the previous commit, the call to
rte_ring_dump(stdout, mp->ring)would probably crash sine ring is NULL.
Quoted 8 lines
I think this comment also applies to the next commit. Splitting between functionalities is good, but in this case I think the 3 commits are linked together, and it should not break compilation or tests to facilitate the git bisect.
Regards,
Olivier
Yes. Originally there was a lot of discussion to split out the bigger patch, which I did, and it was easier to review, but I think that now we're (very) close to final revision, I can merge those three back into one.
Thanks,
Dave.
PATCH v7 3/5 mempool: add default external mempool ops
In reply to David HuntThe first patch in this series added the framework for an external mempool manager. This patch in the series adds a set of default ops (functioni callbacks) based on rte_ring.
--- lib/librte_mempool/Makefile | 1 + lib/librte_mempool/rte_mempool.h | 2 + lib/librte_mempool/rte_mempool_default.c | 153 +++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 lib/librte_mempool/rte_mempool_default.c
lib/librte_mempool/Makefile +1 -0
@@ -43,6 +43,7 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_default.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.h +2 -0
@@ -413,6 +413,8 @@ extern struct rte_mempool_ops_table rte_mempool_ops_table;static inline struct rte_mempool_ops *rte_mempool_ops_get (int ops_index) { +RTE_VERIFY (ops_index <RTE_MEMPOOL_MAX_OPS_IDX ); +return &rte_mempool_ops_table.ops[ops_index]; }
lib/librte_mempool/rte_mempool_default.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH v7 4/5 app/test: test external mempool manager
In reply to David HuntUse a minimal custom mempool external ops and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)
app/test/test_mempool.c +114 -0
@@ -83,6 +83,97 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static void * +custom_mempool_alloc (const struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return NULL ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; +return cm; +} + +static void +custom_mempool_free (void *p) +{ +rte_free (p); +} + +static int +custom_mempool_put (void *p,void *const *obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)p; +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_get (void *p,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)p; +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (void *p) +{ +struct custom_mempool *cm = (struct custom_mempool *)p; + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .put = custom_mempool_put, + .get = custom_mempool_get, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -477,6 +568,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +597,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +658,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
PATCH v7 5/5 mbuf: allow apps to change default mempool ops
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
Re: [PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Quoted 1 line
[PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Should the title be fixed?
I don't feel this allows application to change the default ops.
Re: [PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Quoted 3 lines · Olivier MATZ
Quoted 1 line
[PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Should the title be fixed?
I don't feel this allows application to change the default ops.
Allow _user_ to change default mempool ops, I think.
Re: [PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Quoted 8 lines · David
Quoted 3 lines · Olivier MATZ
Quoted 1 line
[PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Should the title be fixed?
I don't feel this allows application to change the default ops.Allow _user_ to change default mempool ops, I think.
make default mempool ops configurable at build
?
Re: [PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Quoted 10 lines · Olivier Matz
Quoted 6 lines · David
Quoted 3 lines · Olivier MATZ
Quoted 1 line
[PATCH v7 5/5] mbuf: allow apps to change default mempool ops
Should the title be fixed?
I don't feel this allows application to change the default ops.Allow _user_ to change default mempool ops, I think.
make default mempool ops configurable at build
?
Yup :)
v8 cover mempool: add external mempool manager
In reply to David HuntHere's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 19/5/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_HANDLER macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops to create a new mempool
using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new 'create' function, providing the mempool ops struct name to point the mempool to the relevant mempool manager callback structure.
The old 'create' function can still be called by legacy programs, and will internally work out the mempool handle based on the flags provided (single producer, single consumer, etc). By default handles are created internally to implement the built-in DPDK mempool manager and mempool types.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. put - puts an object back into the mempool once an application has
finished with it
3. get - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time a get/put/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
intrte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.put = common_ring_sp_put,
.get = common_ring_mc_get,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support external mempool operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test external mempool manager
PATCH v8 1/3 mempool: support external mempool operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_handler() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 73 ++++----- lib/librte_mempool/rte_mempool.h | 247 ++++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_default.c | 157 ++++++++++++++++++++ lib/librte_mempool/rte_mempool_ops.c | 149 +++++++++++++++++++ 6 files changed, 562 insertions(+), 67 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_default.c create mode 100644 lib/librte_mempool/rte_mempool_ops.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_default.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +28 -45
129 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +226 -21
304 lines not on this page · raw message
lib/librte_mempool/rte_mempool_default.c new file +157 -0
157 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.5.5
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi,
This is more of a question/clarification than a comment. (And I have taken only some snippets from original mail to keep it cleaner)
<snip>
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);
<snip>
<snip>
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to David HuntHi,
(Apologies for overly-eager email sent on this thread earlier. Will be more careful in future).
This is more of a question/clarification than a comment. (And I have taken only some snippets from original mail to keep it cleaner)
<snip>
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);
<snip>
Quoted 1 line
From the above what I understand is that multiple packet pool handlers can be created.
I have a use-case where application has multiple pools but only the packet pool is hardware backed. Using the hardware for general buffer requirements would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based on the flags below.
<snip>
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +
Is there any way I can achieve the above use case of multiple pools which can be selected by an application - something like a run-time toggle/flag?
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi Shreyansh,
Quoted 13 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be more careful in future).
This is more of a question/clarification than a comment. (And I have taken only some snippets from original mail to keep it cleaner)
<snip>
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
Quoted 4 lines
From the above what I understand is that multiple packet pool handlers can be created.
I have a use-case where application has multiple pools but only the packet pool is hardware backed. Using the hardware for general buffer requirements would prove costly.
From what I understand from the patch, selection of the pool is based on the flags below.
The flags are only used to select one of the default handlers for backward compatibility through the rte_mempool_create call. If you wish to use a mempool handler that is not one of the defaults, (i.e. a new hardware handler), you would use the rte_create_mempool_empty followed by the rte_mempool_set_ops_byname call.
So, for the external handlers, you create and empty mempool, then set the operations (ops) for that particular mempool.
Quoted 16 lines
<snip>
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +Is there any way I can achieve the above use case of multiple pools which can be selected by an application - something like a run-time toggle/flag?
Quoted 2 lines
-
Shreyansh
Yes, you can create multiple pools, some using the default handlers, and some using external handlers. There is an example of this in the autotests (app/test/test_mempool.c). This test creates multiple mempools, of which one is a custom malloc based mempool handler. The test puts and gets mbufs to/from each mempool all in the same application.
Regards,
Dave.
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 36 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be more
careful in future).
Quoted 2 lines
This is more of a question/clarification than a comment. (And I have taken
only some snippets from original mail to keep it cleaner)
Quoted 9 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool handlers can
be created.
Quoted 2 lines
I have a use-case where application has multiple pools but only the packet
pool is hardware backed. Using the hardware for general buffer requirements would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based on
the flags below.
Quoted 10 lines
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.
I am concerned about the existing applications (for example, l3fwd).
Explicit calls to 'rte_create_mempool_empty->rte_mempool_set_ops_byname' model would require modifications to these applications.
Ideally, without any modifications, these applications should be able to use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.
If I go by your suggestions, what I understand is, doing the above without modification to applications would be equivalent to:
struct rte_mempool_ops custom_hw_allocator = {...}
thereafter, in config/common_base:
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"
calls to rte_pktmbuf_pool_create would use the new allocator.
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:
rte_pktmbuf_pool_create
\- rte_mempool_create_empty
| \- rte_mempool_set_ops_byname(..ring_mp_mc..)
|
`- rte_mempool_set_ops_byname
(...RTE_MBUF_DEFAULT_MEMPOOL_OPS..)
/* Override default 'ring_mp_mc' of
* rte_mempool_create */2. Through generic mempool create API rte_mempool_create
\- rte_mempool_create_empty
(passing pktmbuf and pool constructors)
I found various instances in example applications where rte_mempool_create() is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.
In (2) control path, RTE_MBUF_DEFAULT_MEMPOOLS_OPS wouldn't be able to replace custom handler operations for packet buffer allocations.
Quoted 4 lines
From a performance point-of-view, Applications should be able to select between packet pools and non-packet pools.
Quoted 1 line
<snip>
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
lib/librte_mempool/rte_mempool.c +5
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET ))Quoted 8 lines
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 8 lines
lib/librte_mempool/rte_mempool.c +8
-0+rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); + else if (flags & MEMPOOL_F_SP_PUT) + rte_mempool_set_ops_byname(mp, "ring_sp_mc"); + else if (flags & MEMPOOL_F_SC_GET) + rte_mempool_set_ops_byname(mp, "ring_mp_sc"); + else + rte_mempool_set_ops_byname(mp, "ring_mp_mc"); +
My suggestion is to have an additional flag, 'MEMPOOL_F_PKT_ALLOC', which, if specified, would:
...
#define MEMPOOL_F_SC_GET 0x0008
#define MEMPOOL_F_PKT_ALLOC 0x0010
...
in rte_mempool_create_empty:
... after checking the other MEMPOOL_F_* flags...
if (flags & MEMPOOL_F_PKT_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)
And removing the redundant call to rte_mempool_set_ops_byname() in rte_pktmbuf_create_pool().
Thereafter, rte_pktmbuf_pool_create can be changed to:
...
mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0);
+ sizeof(struct rte_pktmbuf_pool_private), socket_id,
+ MEMPOOL_F_PKT_ALLOC);
if (mp == NULL)
return NULL;Quoted 6 lines
Quoted 1 line
Is there any way I can achieve the above use case of multiple pools which
can be selected by an application - something like a run-time toggle/flag?
Quoted 3 lines
-
Shreyansh
Quoted 7 lines
Yes, you can create multiple pools, some using the default handlers, and some using external handlers.
There is an example of this in the autotests (app/test/test_mempool.c). This test creates multiple
mempools, of which one is a custom malloc based mempool handler. The test puts and gets mbufs
to/from each mempool all in the same application.
Thanks for the explanation.
Quoted 4 lines
Regards,
Dave.
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi Shreyansh,
Quoted 53 lines · Shreyansh Jain
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 33 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be more
careful in future).
Quoted 1 line
This is more of a question/clarification than a comment. (And I have taken
only some snippets from original mail to keep it cleaner)
Quoted 8 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool handlers can
be created.
Quoted 1 line
I have a use-case where application has multiple pools but only the packet
pool is hardware backed. Using the hardware for general buffer requirements would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based on
the flags below.
Quoted 10 lines
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.I am concerned about the existing applications (for example, l3fwd).
Explicit calls to 'rte_create_mempool_empty->rte_mempool_set_ops_byname' model would require modifications to these applications.
Ideally, without any modifications, these applications should be able to use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.If I go by your suggestions, what I understand is, doing the above without modification to applications would be equivalent to:
Quoted 7 lines
struct rte_mempool_ops custom_hw_allocator = {...}thereafter, in config/common_base:
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"calls to
rte_pktmbuf_pool_createwould use the new allocator.
Yes, correct. But only for calls to rte_pktmbuf_pool_create(). Calls to rte_mempool_create will continue to use the default handlers (ring based).
Quoted 18 lines
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:rte_pktmbuf_pool_create \- rte_mempool_create_empty | \- rte_mempool_set_ops_byname(..ring_mp_mc..) | `- rte_mempool_set_ops_byname (...RTE_MBUF_DEFAULT_MEMPOOL_OPS..) /* Override default 'ring_mp_mc' of * rte_mempool_create */2. Through generic mempool create API
rte_mempool_create
\-rte_mempool_create_empty
(passing pktmbuf and pool constructors)
Quoted 5 lines
I found various instances in example applications where
rte_mempool_create()is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.In (2) control path,
RTE_MBUF_DEFAULT_MEMPOOLS_OPSwouldn't be able to replace custom handler operations for packet buffer allocations.From a performance point-of-view, Applications should be able to select between packet pools and non-packet pools.
This is intended for backward compatibility, and API consistency. Any applications that use rte_mempool_create directly will continue to use the default mempool handlers. If the need to use a custeom hander, they will need to be modified to call the newer API, rte_mempool_create_empty and rte_mempool_set_ops_byname.
Quoted 33 lines
Quoted 14 lines
Quoted 14 lines
<snip>
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:...
#defineMEMPOOL_F_SC_GET0x0008
#defineMEMPOOL_F_PKT_ALLOC0x0010
...in
rte_mempool_create_empty:
... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:...
mp = rte_mempool_create_empty(name, n,elt_size,cache_size,
Review
Quoted 5 lines
(quoted diff) +2
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;
Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces the rte_mempool_set_ops_byname with a flag bit. However, I'm not sure we want to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1. rte_pktmbuf_pool_create()
2. rte_mempool_create_empty() with MEMPOOL_F_PKT_ALLOC set (which would use the configured custom handler)
3. rte_mempool_create_empty() with MEMPOOL_F_PKT_ALLOC __not__ set followed by a call to rte_mempool_set_ops_byname() (would allow several
different custom
handlers to be used in one application
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
Regards,
Dave.
Re: [PATCH v8 1/3] mempool: support external mempool operations
Quoted 151 lines · David
Hi Shreyansh,
Quoted 53 lines · Shreyansh Jain
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 33 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be more
careful in future).
Quoted 1 line
This is more of a question/clarification than a comment. (And I have taken
only some snippets from original mail to keep it cleaner)
Quoted 8 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool handlers can
be created.
Quoted 1 line
I have a use-case where application has multiple pools but only the packet
pool is hardware backed. Using the hardware for general buffer requirements would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based on
the flags below.
Quoted 10 lines
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.I am concerned about the existing applications (for example, l3fwd).
Explicit calls to 'rte_create_mempool_empty->rte_mempool_set_ops_byname' model would require modifications to these applications.
Ideally, without any modifications, these applications should be able to use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.If I go by your suggestions, what I understand is, doing the above without modification to applications would be equivalent to:
Quoted 7 lines
struct rte_mempool_ops custom_hw_allocator = {...}thereafter, in config/common_base:
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"calls to
rte_pktmbuf_pool_createwould use the new allocator.Yes, correct. But only for calls to
rte_pktmbuf_pool_create(). Calls torte_mempool_createwill continue to use the default handlers (ring based).Quoted 19 lines
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:rte_pktmbuf_pool_create \- rte_mempool_create_empty | \- rte_mempool_set_ops_byname(..ring_mp_mc..) | `- rte_mempool_set_ops_byname (...RTE_MBUF_DEFAULT_MEMPOOL_OPS..) /* Override default 'ring_mp_mc' of * rte_mempool_create */2. Through generic mempool create API
rte_mempool_create
\-rte_mempool_create_empty
(passing pktmbuf and pool constructors)
I found various instances in example applications whererte_mempool_create()is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.Quoted 3 lines
In (2) control path,
RTE_MBUF_DEFAULT_MEMPOOLS_OPSwouldn't be able to replace custom handler operations for packet buffer allocations.From a performance point-of-view, Applications should be able to select between packet pools and non-packet pools.
This is intended for backward compatibility, and API consistency. Any applications that use
rte_mempool_createdirectly will continue to use the default mempool handlers. If the need
to use a custeom hander, they will need to be modified to call the newer API,rte_mempool_create_emptyandrte_mempool_set_ops_byname.Quoted 33 lines
Quoted 14 lines
Quoted 14 lines
<snip>
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:...
#defineMEMPOOL_F_SC_GET0x0008
#defineMEMPOOL_F_PKT_ALLOC0x0010
...in
rte_mempool_create_empty:
... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:...
mp = rte_mempool_create_empty(name, n,elt_size,cache_size,Review
Quoted 5 lines
(quoted diff) +2
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want
to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different
custom
handlers to be used in one application
Quoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
As I mentioned earlier, My take is not to create the separate API's for external mempool handlers.In my view, It's same, just that sepreate mempool handler through function pointers.
To keep the backward compatibility, I think we can extend the flags in rte_mempool_create and have a single API external/internal pool creation(makes easy for existing applications too, add a just mempool flag command line argument to existing applications to choose the mempool handler)
Jerin
Quoted 5 lines
Regards,
Dave.
Re: [PATCH v8 1/3] mempool: support external mempool operations
Quoted 154 lines · Jerin Jacob
Quoted 148 lines · David
Hi Shreyansh,
Quoted 53 lines · Shreyansh Jain
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 33 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be more
careful in future).
Quoted 1 line
This is more of a question/clarification than a comment. (And I have taken
only some snippets from original mail to keep it cleaner)
Quoted 8 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool handlers can
be created.
Quoted 1 line
I have a use-case where application has multiple pools but only the packet
pool is hardware backed. Using the hardware for general buffer requirements would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based on
the flags below.
Quoted 10 lines
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.I am concerned about the existing applications (for example, l3fwd).
Explicit calls to 'rte_create_mempool_empty->rte_mempool_set_ops_byname' model would require modifications to these applications.
Ideally, without any modifications, these applications should be able to use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.If I go by your suggestions, what I understand is, doing the above without modification to applications would be equivalent to:
Quoted 7 lines
struct rte_mempool_ops custom_hw_allocator = {...}thereafter, in config/common_base:
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"calls to
rte_pktmbuf_pool_createwould use the new allocator.Yes, correct. But only for calls to
rte_pktmbuf_pool_create(). Calls torte_mempool_createwill continue to use the default handlers (ring based).Quoted 19 lines
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:rte_pktmbuf_pool_create \- rte_mempool_create_empty | \- rte_mempool_set_ops_byname(..ring_mp_mc..) | `- rte_mempool_set_ops_byname (...RTE_MBUF_DEFAULT_MEMPOOL_OPS..) /* Override default 'ring_mp_mc' of * rte_mempool_create */2. Through generic mempool create API
rte_mempool_create
\-rte_mempool_create_empty
(passing pktmbuf and pool constructors)
I found various instances in example applications whererte_mempool_create()is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.Quoted 3 lines
In (2) control path,
RTE_MBUF_DEFAULT_MEMPOOLS_OPSwouldn't be able to replace custom handler operations for packet buffer allocations.From a performance point-of-view, Applications should be able to select between packet pools and non-packet pools.
This is intended for backward compatibility, and API consistency. Any applications that use
rte_mempool_createdirectly will continue to use the default mempool handlers. If the need
to use a custeom hander, they will need to be modified to call the newer API,rte_mempool_create_emptyandrte_mempool_set_ops_byname.Quoted 33 lines
Quoted 14 lines
Quoted 14 lines
<snip>
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:...
#defineMEMPOOL_F_SC_GET0x0008
#defineMEMPOOL_F_PKT_ALLOC0x0010
...in
rte_mempool_create_empty:
... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:...
mp = rte_mempool_create_empty(name, n,elt_size,cache_size,Review
Quoted 5 lines
(quoted diff) +2
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want
to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different
custom
handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
As I mentioned earlier, My take is not to create the separate API's for external mempool handlers.In my view, It's same, just that sepreate mempool handler through function pointers.
Quoted 7 lines
To keep the backward compatibility, I think we can extend the flags in
rte_mempool_createand have a single API external/internal pool creation(makes easy for existing applications too, add a just mempool flag command line argument to existing applications to choose the mempool handler)Jerin
Would a good compromise be what Shreyansh is suggesting, adding just 1 bit into the flags to allow the rte_mempool_create use the mempool handler as defined in CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS?
That way we wouldn't have the complexity of the previously discussed proposed solution of parsing out the sections of the flags bits into bytes to get the handler index requested, and we wouldn't have to query by name to get the index of the handler we're interested in. It's just a simple "use the configured custom handler or not" bit.
This way, applications can set the bit to use the custom handler defined in the config, but still have the flexibility using the other new API calls to have several handlers in use in an application.
Regards,
David.
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to Jerin JacobHi Jerin,
Quoted 186 lines
-----Original Message-----
From: Jerin Jacob [mailto:[email protected]]
Sent: Thursday, June 09, 2016 4:02 PM
To: Hunt, David <[email protected]>
Cc: Shreyansh Jain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsQuoted 14 lines · David
Hi Shreyansh,
Quoted 11 lines · Shreyansh Jain
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 7 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support externalmempool
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
operations
Hi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will
be more
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
careful in future).
Quoted 1 line
This is more of a question/clarification than a comment. (And I have
taken
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
only some snippets from original mail to keep it cleaner)
Quoted 8 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool
handlers can
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
be created.
Quoted 1 line
I have a use-case where application has multiple pools but only the
packet
Quoted 1 line
Quoted 1 line
Quoted 1 line
pool is hardware backed. Using the hardware for general buffer
requirements
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is
based on
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
the flags below.
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.Quoted 2 lines
Quoted 2 lines
I am concerned about the existing applications (for example, l3fwd). Explicit calls to '
rte_create_mempool_empty->rte_mempool_set_ops_byname'model would require modifications to these applications.
Quoted 1 line
Quoted 1 line
Ideally, without any modifications, these applications should be able to
use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.
Quoted 2 lines
Quoted 2 lines
If I go by your suggestions, what I understand is, doing the above
without modification to applications would be equivalent to:
Quoted 29 lines
Quoted 8 lines
struct rte_mempool_ops custom_hw_allocator = {...}thereafter, in config/common_base:
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"calls to
rte_pktmbuf_pool_createwould use the new allocator.Yes, correct. But only for calls to
rte_pktmbuf_pool_create(). Calls torte_mempool_createwill continue to use the default handlers (ring based).Quoted 18 lines
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:rte_pktmbuf_pool_create \- rte_mempool_create_empty | \- rte_mempool_set_ops_byname(..ring_mp_mc..) | `- rte_mempool_set_ops_byname (...RTE_MBUF_DEFAULT_MEMPOOL_OPS..) /* Override default 'ring_mp_mc' of * rte_mempool_create */2. Through generic mempool create API
rte_mempool_create
\-rte_mempool_create_empty
(passing pktmbuf and pool constructors)
I found various instances in example applications where
rte_mempool_create()is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.Quoted 2 lines
Quoted 2 lines
In (2) control path,
RTE_MBUF_DEFAULT_MEMPOOLS_OPSwouldn't be able toreplace custom handler operations for packet buffer allocations.
Quoted 2 lines
Quoted 2 lines
From a performance point-of-view, Applications should be able to select
between packet pools and non-packet pools.
Quoted 10 lines
This is intended for backward compatibility, and API consistency. Any applications that use
rte_mempool_createdirectly will continue to use the default mempool handlers. If the need
to use a custeom hander, they will need to be modified to call the newer API,rte_mempool_create_emptyandrte_mempool_set_ops_byname.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
<snip>
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * Since we have 4 combinations of the SP/SC/MP/MC examine theflags to
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool.c +4
-0+* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" );Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 7 lines
lib/librte_mempool/rte_mempool.c +7
-0+else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC',which, if specified, would:
Quoted 6 lines
Quoted 6 lines
...
#defineMEMPOOL_F_SC_GET0x0008
#defineMEMPOOL_F_PKT_ALLOC0x0010
...Quoted 7 lines
Quoted 7 lines
in
rte_mempool_create_empty:
... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()in
rte_pktmbuf_create_pool().Quoted 11 lines
Review
Quoted 10 lines
Thereafter,
rte_pktmbuf_pool_createcan be changed to:...
mp = rte_mempool_create_empty(name, n,elt_size,cache_size,(quoted diff) +2
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Quoted 1 line
Yes, this would simplify somewhat the creation of a pktmbuf pool, in that
it
Quoted 13 lines
replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want
to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different
custom
handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
As I mentioned earlier, My take is not to create the separate API's for external mempool handlers.In my view, It's same, just that sepreate mempool handler through function pointers.
Quoted 5 lines
To keep the backward compatibility, I think we can extend the flags in
rte_mempool_createand have a single API external/internal pool creation(makes easy for existing applications too, add a just mempool flag command line argument to existing applications to choose the mempool handler)
May be I am interpreting it wrong, but, are you suggesting a single mempool handler for all buffer/packet needs of an application (passed as command line argument)? That would be inefficient especially for cases where pool is backed by a hardware. The application wouldn't want its generic buffers to consume hardware resource which would be better used for packets.
I was hoping that external mempool handler would help segregate such use-cases and allow applications to tap into accelerated packet processors.
Do correct me if I my understanding is wrong.
Quoted 8 lines
Jerin
Quoted 5 lines
Regards,
Dave.
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
Quoted 1 line · Shreyansh Jain
Hi Jerin,
Hi Shreyansh,
Quoted 22 lines
Quoted 22 lines
Quoted 2 lines
Yes, this would simplify somewhat the creation of a pktmbuf pool, in that
it
Quoted 13 lines
replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want
to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different
custom
handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
As I mentioned earlier, My take is not to create the separate API's for external mempool handlers.In my view, It's same, just that sepreate mempool handler through function pointers.
Quoted 8 lines
Quoted 5 lines
To keep the backward compatibility, I think we can extend the flags in
rte_mempool_createand have a single API external/internal pool creation(makes easy for existing applications too, add a just mempool flag command line argument to existing applications to choose the mempool handler)May be I am interpreting it wrong, but, are you suggesting a single mempool handler for all buffer/packet needs of an application (passed as command line argument)? That would be inefficient especially for cases where pool is backed by a hardware. The application wouldn't want its generic buffers to consume hardware resource which would be better used for packets.
It may vary from platform to platform or particular use case. For instance, the HW external pool manager for generic buffers may scale better than SW multi producers/multi-consumer implementation when the number of cores > N (as no locking involved in enqueue/dequeue(again it is depended on specific HW implementation))
I thought their no harm in selecting the external pool handlers in root level itself(rte_mempool_create) as by default it is SW MP/MC and it just an option to override if the application wants it.
Jerin
Quoted 16 lines
I was hoping that external mempool handler would help segregate such use-cases and allow applications to tap into accelerated packet processors.
Do correct me if I my understanding is wrong.
Quoted 8 lines
Jerin
Quoted 5 lines
Regards,
Dave.-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi Jerin,
Quoted 54 lines
-----Original Message-----
From: Jerin Jacob [mailto:[email protected]]
Sent: Thursday, June 09, 2016 6:01 PM
To: Shreyansh Jain <[email protected]>
Cc: Hunt, David <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsQuoted 1 line · Shreyansh Jain
Hi Jerin,
Hi Shreyansh,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Yes, this would simplify somewhat the creation of a pktmbuf pool, in
that
Quoted 3 lines
Quoted 3 lines
it
Quoted 2 lines
replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not surewe
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
want
to introduce a third method of creating a mempool to the developers. Ifwe
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__setfollowed
Quoted 1 line
Quoted 1 line
Quoted 1 line
by a call to
rte_mempool_set_ops_byname()(would allow severaldifferent
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
custom
handlers to be used in one applicationDoes anyone else have an opinion on this? Oliver, Jerin, Jan?
As I mentioned earlier, My take is not to create the separate API's for external mempool handlers.In my view, It's same, just that sepreate mempool handler through function pointers.
Quoted 7 lines
Quoted 5 lines
To keep the backward compatibility, I think we can extend the flags in
rte_mempool_createand have a single API external/internal pool creation(makes easy for existing applications too, add a just mempool flag command line argument to existing applications to choose the mempool handler)May be I am interpreting it wrong, but, are you suggesting a single mempool
handler for all buffer/packet needs of an application (passed as command line argument)?
Quoted 1 line
That would be inefficient especially for cases where pool is backed by a
hardware. The application wouldn't want its generic buffers to consume hardware resource which would be better used for packets.
Quoted 6 lines
It may vary from platform to platform or particular use case. For instance, the HW external pool manager for generic buffers may scale better than SW multi
producers/multi-consumer implementation when the number of cores > N (as no locking involved in enqueue/dequeue(again it is depended on specific HW implementation))
I agree with you that above cases would exist.
But, even in these cases I think it would be application's prerogative to decide whether it would like its buffers to be managed by a hardware allocator or SW [SM]p/[SM]c implementations. Probably, in this case the application would call the rte_mempool_*(PKT_POOL) for generic buffers as well (or maybe a dedicated buffer pool flag) - just as an example.
Quoted 4 lines
I thought their no harm in selecting the external pool handlers in root level
itself(rte_mempool_create)as by default it is SW MP/MC and it just an option to override if the application wants it.
It sounds fine if calls to rte_mempool_* can select an external handler *optionally* - but, if we pass it as command line, it would be binding (at least, semantically) for rte_pktmbuf_* calls as well. Isn't it?
[Probably, I am still unclear how it would remain 'optional' in command line case you suggested.]
Quoted 4 lines
Jerin
[...]
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to Jerin JacobQuoted 37 lines · Jerin Jacob
Quoted 1 line · Shreyansh Jain
Hi Jerin,
Hi Shreyansh,
Quoted 20 lines
Quoted 20 lines
Quoted 1 line
Yes, this would simplify somewhat the creation of a pktmbuf pool, in that
it
Quoted 13 lines
replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want
to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different
custom
handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
As I mentioned earlier, My take is not to create the separate API's for external mempool handlers.In my view, It's same, just that sepreate mempool handler through function pointers.
Quoted 7 lines
Quoted 5 lines
To keep the backward compatibility, I think we can extend the flags in
rte_mempool_createand have a single API external/internal pool creation(makes easy for existing applications too, add a just mempool flag command line argument to existing applications to choose the mempool handler)May be I am interpreting it wrong, but, are you suggesting a single mempool handler for all buffer/packet needs of an application (passed as command line argument)? That would be inefficient especially for cases where pool is backed by a hardware. The application wouldn't want its generic buffers to consume hardware resource which would be better used for packets.
It may vary from platform to platform or particular use case. For instance, the HW external pool manager for generic buffers may scale better than SW multi producers/multi-consumer implementation when the number of cores > N (as no locking involved in enqueue/dequeue(again it is depended on specific HW implementation))
Quoted 6 lines
I thought their no harm in selecting the external pool handlers in root level
itself(rte_mempool_create)as by default it is SW MP/MC and it just an option to override if the application wants it.Jerin
So, how about we go with the following, based on Shreyansh's suggestion:
1. Add in #define MEMPOOL_F_EMM_ALLOC 0x0010 (EMM for External Mempool Manager)
2. Check this bit in rte_mempool_create() just before the other bits are checked (by the way, the flags check has been moved to rte_mempool_create(), as per an earlier patchset, but was inadvertantly reverted)
/*
* First check to see if we use the config'd mempool hander.
* Then examine the combinations of SP/SC/MP/MC flags to
* set the correct index into the table of ops structs. */
if (flags & MEMPOOL_F_EMM_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)
else (flags & (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET))
rte_mempool_set_ops_byname(mp, "ring_sp_sc");
else if (flags & MEMPOOL_F_SP_PUT)
rte_mempool_set_ops_byname(mp, "ring_sp_mc");
else if (flags & MEMPOOL_F_SC_GET)
rte_mempool_set_ops_byname(mp, "ring_mp_sc");
else
rte_mempool_set_ops_byname(mp, "ring_mp_mc");
3. Modify rte_pktmbuf_pool_create to pass the bit to rte_mempool_create
- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC);
This will allow legacy apps to use one external handler ( as defined RTE_MBUF_DEFAULT_MEMPOOL_OPS) by adding the MEMPOOL_F_EMM_ALLOC bit to their flags in the call to rte_mempool_create().
Of course, if an app wants to use more than one external handler, they can call create_empty and set_ops_byname() for each mempool they create.
Regards,
Dave.
Re: [PATCH v8 1/3] mempool: support external mempool operations
Quoted 59 lines · David
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
As I mentioned earlier, My take is not to create the separate API's for external mempool handlers.In my view, It's same, just that sepreate mempool handler through function pointers.
Quoted 7 lines
Quoted 5 lines
To keep the backward compatibility, I think we can extend the flags in
rte_mempool_createand have a single API external/internal pool creation(makes easy for existing applications too, add a just mempool flag command line argument to existing applications to choose the mempool handler)May be I am interpreting it wrong, but, are you suggesting a single mempool handler for all buffer/packet needs of an application (passed as command line argument)? That would be inefficient especially for cases where pool is backed by a hardware. The application wouldn't want its generic buffers to consume hardware resource which would be better used for packets.
It may vary from platform to platform or particular use case. For instance, the HW external pool manager for generic buffers may scale better than SW multi producers/multi-consumer implementation when the number of cores > N (as no locking involved in enqueue/dequeue(again it is depended on specific HW implementation))
Quoted 6 lines
I thought their no harm in selecting the external pool handlers in root level
itself(rte_mempool_create)as by default it is SW MP/MC and it just an option to override if the application wants it.Jerin
So, how about we go with the following, based on Shreyansh's suggestion:
1. Add in #define
MEMPOOL_F_EMM_ALLOC0x0010(EMM for External Mempool Manager)2. Check this bit in
rte_mempool_create()just before the other bits are checked (by the way, the flags check has been moved torte_mempool_create(), as per an earlier patchset, but was inadvertantly reverted)/*
* First check to see if we use the config'd mempool hander.
* Then examine the combinations of SP/SC/MP/MC flags to
* set the correct index into the table of ops structs. */
if (flags &MEMPOOL_F_EMM_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)
else (flags & (MEMPOOL_F_SP_PUT|MEMPOOL_F_SC_GET))
rte_mempool_set_ops_byname(mp, "ring_sp_sc");
else if (flags &MEMPOOL_F_SP_PUT)
rte_mempool_set_ops_byname(mp, "ring_sp_mc");
else if (flags &MEMPOOL_F_SC_GET)
rte_mempool_set_ops_byname(mp, "ring_mp_sc");
else
rte_mempool_set_ops_byname(mp, "ring_mp_mc");3. Modify
rte_pktmbuf_pool_createto pass the bit torte_mempool_create(quoted diff) +2
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC);
Quoted 6 lines
This will allow legacy apps to use one external handler ( as defined
RTE_MBUF_DEFAULT_MEMPOOL_OPS) by adding theMEMPOOL_F_EMM_ALLOCbit to their flags in the call torte_mempool_create().Of course, if an app wants to use more than one external handler, they can call
create_emptyandset_ops_byname()for each mempool they create.
+1
Since rte_pktmbuf_pool_create does not take flag, I think this the only option left with for legacy apps.
Quoted 13 lines
Regards,
Dave.
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to Hunt, DavidHi David,
Quoted 77 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Thursday, June 09, 2016 3:10 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 19 lines · Shreyansh Jain
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 15 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be
more
Quoted 2 lines
Quoted 2 lines
careful in future).
Quoted 1 line
This is more of a question/clarification than a comment. (And I have
taken
Quoted 9 lines
Quoted 9 lines
only some snippets from original mail to keep it cleaner)
Quoted 8 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool handlers
can
Quoted 2 lines
Quoted 2 lines
be created.
Quoted 1 line
I have a use-case where application has multiple pools but only the
packet
Quoted 1 line
Quoted 1 line
pool is hardware backed. Using the hardware for general buffer
requirements
Quoted 2 lines
Quoted 2 lines
would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based
on
Quoted 12 lines
Quoted 12 lines
the flags below.
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.Quoted 2 lines
I am concerned about the existing applications (for example, l3fwd). Explicit calls to '
rte_create_mempool_empty->rte_mempool_set_ops_byname'model would require modifications to these applications.
Quoted 1 line
Ideally, without any modifications, these applications should be able to
use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.
Quoted 2 lines
If I go by your suggestions, what I understand is, doing the above without
modification to applications would be equivalent to:
Quoted 3 lines
struct rte_mempool_ops custom_hw_allocator = {...}
Quoted 8 lines
Quoted 5 lines
thereafter, in config/common_base:
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"calls to
rte_pktmbuf_pool_createwould use the new allocator.Yes, correct. But only for calls to
rte_pktmbuf_pool_create(). Calls torte_mempool_createwill continue to use the default handlers (ring based).
Agree with you.
But, some applications continue to use rte_mempool_create for allocating packet pools. Thus, even with a custom handler available (which, most probably, would be a hardware packet buffer handler), application would unintentionally end up not using it. Probably, such applications should be changed? (e.g. pipeline).
Quoted 28 lines
Quoted 13 lines
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:rte_pktmbuf_pool_create \- rte_mempool_create_empty | \- rte_mempool_set_ops_byname(..ring_mp_mc..) | `- rte_mempool_set_ops_byname (...RTE_MBUF_DEFAULT_MEMPOOL_OPS..) /* Override default 'ring_mp_mc' of * rte_mempool_create */Quoted 6 lines
2. Through generic mempool create API
rte_mempool_create
\-rte_mempool_create_empty
(passing pktmbuf and pool constructors)I found various instances in example applications where
rte_mempool_create()is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.Quoted 2 lines
In (2) control path,
RTE_MBUF_DEFAULT_MEMPOOLS_OPSwouldn't be able toreplace custom handler operations for packet buffer allocations.
Quoted 2 lines
From a performance point-of-view, Applications should be able to select
between packet pools and non-packet pools.
Quoted 7 lines
This is intended for backward compatibility, and API consistency. Any applications that use
rte_mempool_createdirectly will continue to use the default mempool handlers. If the need
to use a custeom hander, they will need to be modified to call the newer API,rte_mempool_create_emptyandrte_mempool_set_ops_byname.
My understanding was that applications should be oblivious of how their pools are managed, except that they do understand packet pools should be faster (or accelerated) than non-packet pools. (Of course, some applications may be designed to explicitly take advantage of an available handler through rte_mempool_create_empty=>rte_mempool_set_ops_byname calls.)
In that perspective, I was expecting that applications should be calling:
-> rte_pktmbuf_* for all packet relation operations
-> rte_mempool_* for non-packet or explicit hardware handlers
And leave rest of the mempool handler related magic to DPDK framework.
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
<snip>
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * Since we have 4 combinations of the SP/SC/MP/MC examine theflags to
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool.c +4
-0+* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" );Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 7 lines
lib/librte_mempool/rte_mempool.c +7
-0+else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which,
Quoted 1 line
if specified, would:
I read through some previous discussions and realized that something similar [1] had already been proposed earlier. I didn't want to hijack this thread with an old discussions - it was unintentional.
[1] http://article.gmane.org/gmane.comp.networking.dpdk.devel/39803
But, [1] would make the distinction of *type* of pool and its corresponding handler, whether default or external/custom, quite clear.
Quoted 39 lines
Quoted 6 lines
...
#defineMEMPOOL_F_SC_GET0x0008
#defineMEMPOOL_F_PKT_ALLOC0x0010
...Quoted 7 lines
in
rte_mempool_create_empty:
... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()in
rte_pktmbuf_create_pool().Review
Quoted 10 lines
Thereafter,
rte_pktmbuf_pool_createcan be changed to:...
mp = rte_mempool_create_empty(name, n,elt_size,cache_size,(quoted diff) +2
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want
to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several
different custom
handlers to be used in one application
Quoted 5 lines
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
Regards,
Dave.
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
Quoted 77 lines · Shreyansh Jain
Hi David,
Quoted 75 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Thursday, June 09, 2016 3:10 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 19 lines · Shreyansh Jain
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 15 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be
more
Quoted 2 lines
Quoted 2 lines
careful in future).
Quoted 1 line
This is more of a question/clarification than a comment. (And I have
taken
Quoted 9 lines
Quoted 9 lines
only some snippets from original mail to keep it cleaner)
Quoted 8 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool handlers
can
Quoted 2 lines
Quoted 2 lines
be created.
Quoted 1 line
I have a use-case where application has multiple pools but only the
packet
Quoted 1 line
Quoted 1 line
pool is hardware backed. Using the hardware for general buffer
requirements
Quoted 2 lines
Quoted 2 lines
would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based
on
Quoted 12 lines
Quoted 12 lines
the flags below.
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.Quoted 2 lines
I am concerned about the existing applications (for example, l3fwd). Explicit calls to '
rte_create_mempool_empty->rte_mempool_set_ops_byname'model would require modifications to these applications.
Quoted 7 lines
Ideally, without any modifications, these applications should be able to use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.
If I go by your suggestions, what I understand is, doing the above without modification to applications would be equivalent to:struct rte_mempool_ops custom_hw_allocator = {...}thereafter, in config/common_base:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"calls to
rte_pktmbuf_pool_createwould use the new allocator.Yes, correct. But only for calls to
rte_pktmbuf_pool_create(). Calls torte_mempool_createwill continue to use the default handlers (ring based).Agree with you.
But, some applications continue to userte_mempool_createfor allocating packet pools. Thus, even with a custom handler available (which, most probably, would be a hardware packet buffer handler), application would unintentionally end up not using it. Probably, such applications should be changed? (e.g. pipeline).
Yes, agreed. If those applications need to use external mempool handlers, then they should be changed. I would see that as outside the scope of this patchset.
Quoted 33 lines
Quoted 26 lines
Quoted 13 lines
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:rte_pktmbuf_pool_create \- rte_mempool_create_empty | \- rte_mempool_set_ops_byname(..ring_mp_mc..) | `- rte_mempool_set_ops_byname (...RTE_MBUF_DEFAULT_MEMPOOL_OPS..) /* Override default 'ring_mp_mc' of * rte_mempool_create */Quoted 6 lines
2. Through generic mempool create API
rte_mempool_create
\-rte_mempool_create_empty
(passing pktmbuf and pool constructors)I found various instances in example applications where
rte_mempool_create()is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.Quoted 1 line
In (2) control path,
RTE_MBUF_DEFAULT_MEMPOOLS_OPSwouldn't be able toreplace custom handler operations for packet buffer allocations.
Quoted 1 line
From a performance point-of-view, Applications should be able to select
between packet pools and non-packet pools.
Quoted 7 lines
This is intended for backward compatibility, and API consistency. Any applications that use
rte_mempool_createdirectly will continue to use the default mempool handlers. If the need
to use a custeom hander, they will need to be modified to call the newer API,rte_mempool_create_emptyandrte_mempool_set_ops_byname.
Quoted 8 lines
My understanding was that applications should be oblivious of how their pools are managed, except that they do understand packet pools should be faster (or accelerated) than non-packet pools. (Of course, some applications may be designed to explicitly take advantage of an available handler through rte_mempool_create_empty=>rte_mempool_set_ops_byname calls.)
In that perspective, I was expecting that applications should be calling:
-> rte_pktmbuf_* for all packet relation operations
-> rte_mempool_* for non-packet or explicit hardware handlersAnd leave rest of the mempool handler related magic to DPDK framework.
I think there is still some work on the applications side to know whether to use external or internal (default) handler for particular mempools.
I'll propose something based on the further comments on the other part of this thread based on feedback so far.
Regards,
Dave.
Quoted 18 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
<snip>
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * Since we have 4 combinations of the SP/SC/MP/MC examine theflags to
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 11 lines
lib/librte_mempool/rte_mempool.c +11
-0+* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which,
Quoted 7 lines
Quoted 1 line
if specified, would:
I read through some previous discussions and realized that something similar [1] had already been proposed earlier. I didn't want to hijack this thread with an old discussions - it was unintentional.
[1] http://article.gmane.org/gmane.comp.networking.dpdk.devel/39803
But, [1] would make the distinction of *type* of pool and its corresponding handler, whether default or external/custom, quite clear.
I can incorporate a bit in the flags (MEMPOOL_F_PKT_ALLOC) as you suggest, which would allow the rte_mempool_create calls to use a custom handler
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to Hunt, DavidQuoted 152 lines · David
Hi Shreyansh,
Quoted 53 lines · Shreyansh Jain
Hi David,
Thanks for explanation. I have some comments inline...
Quoted 33 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 2:56 PM
To: Shreyansh Jain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi Shreyansh,
Quoted 3 lines · Shreyansh Jain
Hi,
(Apologies for overly-eager email sent on this thread earlier. Will be more
careful in future).
Quoted 1 line
This is more of a question/clarification than a comment. (And I have taken
only some snippets from original mail to keep it cleaner)
Quoted 8 lines
<snip>
lib/librte_mempool/rte_mempool_default.c line 157
Quoted 4 lines
lib/librte_mempool/rte_mempool_default.c new file +4
-0+MEMPOOL_REGISTER_OPS (ops_mp_mc); +MEMPOOL_REGISTER_OPS (ops_sp_sc); +MEMPOOL_REGISTER_OPS (ops_mp_sc); +MEMPOOL_REGISTER_OPS (ops_sp_mc);<snip>
From the above what I understand is that multiple packet pool handlers can
be created.
Quoted 1 line
I have a use-case where application has multiple pools but only the packet
pool is hardware backed. Using the hardware for general buffer requirements would prove costly.
Quoted 1 line
From what I understand from the patch, selection of the pool is based on
the flags below.
Quoted 10 lines
The flags are only used to select one of the default handlers for backward compatibility through
therte_mempool_createcall. If you wish to use a mempool handler that is not one of the
defaults, (i.e. a new hardware handler), you would use therte_create_mempool_empty
followed by therte_mempool_set_ops_bynamecall.
So, for the external handlers, you create and empty mempool, then set the operations (ops)
for that particular mempool.I am concerned about the existing applications (for example, l3fwd).
Explicit calls to 'rte_create_mempool_empty->rte_mempool_set_ops_byname' model would require modifications to these applications.
Ideally, without any modifications, these applications should be able to use packet pools (backed by hardware) and buffer pools (backed by ring/others) - transparently.If I go by your suggestions, what I understand is, doing the above without modification to applications would be equivalent to:
Quoted 7 lines
struct rte_mempool_ops custom_hw_allocator = {...}thereafter, in config/common_base:
CONFIG_RTE_DEFAULT_MEMPOOL_OPS="custom_hw_allocator"calls to
rte_pktmbuf_pool_createwould use the new allocator.Yes, correct. But only for calls to
rte_pktmbuf_pool_create(). Calls torte_mempool_createwill continue to use the default handlers (ring based).Quoted 18 lines
But, another problem arises here.
There are two distinct paths for allocations of a memory pool:
1. A 'pkt' pool:rte_pktmbuf_pool_create \- rte_mempool_create_empty | \- rte_mempool_set_ops_byname(..ring_mp_mc..) | `- rte_mempool_set_ops_byname (...RTE_MBUF_DEFAULT_MEMPOOL_OPS..) /* Override default 'ring_mp_mc' of * rte_mempool_create */2. Through generic mempool create API
rte_mempool_create
\-rte_mempool_create_empty
(passing pktmbuf and pool constructors)Quoted 5 lines
I found various instances in example applications where
rte_mempool_create()is being called directly for packet pools - bypassing the more semantically correct call to rte_pktmbuf_* for packet pools.In (2) control path,
RTE_MBUF_DEFAULT_MEMPOOLS_OPSwouldn't be able to replace custom handler operations for packet buffer allocations.From a performance point-of-view, Applications should be able to select between packet pools and non-packet pools.
This is intended for backward compatibility, and API consistency. Any applications that use
rte_mempool_createdirectly will continue to use the default mempool handlers. If the need
to use a custeom hander, they will need to be modified to call the newer API,rte_mempool_create_emptyandrte_mempool_set_ops_byname.Quoted 33 lines
Quoted 14 lines
Quoted 14 lines
<snip>
lib/librte_mempool/rte_mempool.c rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, · line 800
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13
-0+/* +* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to +* set the correct index into the table of ops structs. +*/ +if (flags & (MEMPOOL_F_SP_PUT |MEMPOOL_F_SC_GET )) +rte_mempool_set_ops_byname (mp,"ring_sp_sc" ); +else if (flags &MEMPOOL_F_SP_PUT ) +rte_mempool_set_ops_byname (mp,"ring_sp_mc" ); +else if (flags &MEMPOOL_F_SC_GET ) +rte_mempool_set_ops_byname (mp,"ring_mp_sc" ); +else +rte_mempool_set_ops_byname (mp,"ring_mp_mc" ); +My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:...
#defineMEMPOOL_F_SC_GET0x0008
#defineMEMPOOL_F_PKT_ALLOC0x0010
...in
rte_mempool_create_empty:
... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)
rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:...
mp = rte_mempool_create_empty(name, n,elt_size,cache_size,Review
Quoted 5 lines
(quoted diff) +2
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, + MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces
therte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want
to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have:
1.rte_pktmbuf_pool_create()
2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler)
3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several
different custom
handlers to be used in one application
Quoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
I am quite careful about this topic as I don't feel to be very involved in all the use cases. My opinion is that the _new API_ should be able to cover all cases and the _old API_ should be backwards compatible, however, built on top of the _new API_.
I.e. I think, the flags MEMPOOL_F_SP_PUT, MEMPOOL_F_SC_GET (relicts of the old API) should be accepted by the old API ONLY. The rte_mempool_create_empty should not process them. Similarly for a potential MEMPOOL_F_PKT_ALLOC, I would not polute the rte_mempool_create_empty by this anymore.
In overall we would get exactly 2 approaches (and not more):
* using rte_mempool_create with flags calling the rte_mempool_create_empty and rte_mempool_set_ops_byname internally (so this layer can be marked as deprecated and removed in the future)
* using rte_mempool_create_empty + rte_mempool_set_ops_byname - allowing any customizations but with the necessity to change the applications (new preferred API)
So, the old applications can stay as they are (OK, with a possible new flag MEMPOOL_F_PKT_ALLOC) and the new one can do the same but you have to set the ops explicitly.
The more different ways of using those APIs we have, the greater hell we have to maintain.
Regards
Jan
Quoted 5 lines
Regards,
Dave.
Signature · 4 lines
Jan Viktorin E-mail: [email protected] System Architect Web: www.RehiveTech.com RehiveTech Brno, Czech Republic
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi,
Quoted 35 lines · Jan Viktorin
Quoted 33 lines
Quoted 20 lines
My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:... #define
MEMPOOL_F_SC_GET0x0008#defineMEMPOOL_F_PKT_ALLOC0x0010...in
rte_mempool_create_empty: ... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:... mp = rte_mempool_create_empty(name, n,
elt_size,cache_size,(quoted diff) +1
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, +Quoted 1 line
MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces the
rte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have: 1.rte_pktmbuf_pool_create()2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler) 3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different custom handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
Quoted 8 lines
I am quite careful about this topic as I don't feel to be very involved in all the use cases. My opinion is that the
_newAPI_should be able to cover all cases and the_oldAPI_should be backwards compatible, however, built on top of the_newAPI_.I.e. I think, the flags
MEMPOOL_F_SP_PUT,MEMPOOL_F_SC_GET(relicts of the old API) should be accepted by the old API ONLY. Therte_mempool_create_emptyshould not process them.
The rte_mempool_create_empty() function already processes these flags (SC_GET, SP_PUT) as of today.
Quoted 2 lines
Similarly for a potential
MEMPOOL_F_PKT_ALLOC, I would not polute therte_mempool_create_emptyby this anymore.
+1
I think we should stop adding flags. Flags are prefered for independent features. Here, what would be the behavior with MEMPOOL_F_PKT_ALLOC + MEMPOOL_F_SP_PUT?
Another reason to not add this flag is the rte_mempool library should not be aware of mbufs. The mbuf pools rely on mempools, but not the contrary.
Quoted 6 lines
In overall we would get exactly 2 approaches (and not more):
* using
rte_mempool_createwith flags calling therte_mempool_create_emptyandrte_mempool_set_ops_bynameinternally (so this layer can be marked as deprecated and removed in the future)
Agree. This was one of the objective of my mempool rework patchset:
provide a more flexible API, and avoid functions with 10 to 15 arguments.
Quoted 3 lines
* using
rte_mempool_create_empty+rte_mempool_set_ops_byname- allowing any customizations but with the necessity to change the applications (new preferred API)
Yes.
And if required, maybe a third API is possible in case of mbuf pools. Indeed, the applications are encouraged to use rte_pktmbuf_pool_create() to create a pool of mbuf instead of mempool API. If an application wants to select specific ops for it, we could add:
rte_pktmbuf_pool_create_<something>(..., name)
instead of using the mempool API.
I think this is what Shreyansh suggests when he says:
It sounds fine if calls to rte_mempool_* can select an external handler *optionally* - but, if we pass it as command line, it would be binding (at least, semantically) for rte_pktmbuf_* calls as well. Isn't it?
Quoted 6 lines
So, the old applications can stay as they are (OK, with a possible new flag
MEMPOOL_F_PKT_ALLOC) and the new one can do the same but you have to set the ops explicitly.The more different ways of using those APIs we have, the greater hell we have to maintain.
I'm really not in favor of a MEMPOOL_F_PKT_ALLOC flag in mempool api.
I think David's patch is already a good step forward. Let's do it step by step. Next step is maybe to update some applications (at least testpmd) to select a new pool handler dynamically.
Regards,
Olivier
Re: [PATCH v8 1/3] mempool: support external mempool operations
Quoted 43 lines · On Fri, 10 Jun 2016 09:29:44 +0200 Olivier Matz <[email protected]> wrote:
Hi,
Quoted 40 lines · Jan Viktorin
Quoted 33 lines
Quoted 20 lines
My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:... #define
MEMPOOL_F_SC_GET0x0008#defineMEMPOOL_F_PKT_ALLOC0x0010...in
rte_mempool_create_empty: ... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:... mp = rte_mempool_create_empty(name, n,
elt_size,cache_size,(quoted diff) +1
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, +Quoted 1 line
MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces the
rte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have: 1.rte_pktmbuf_pool_create()2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler) 3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different custom handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
I am quite careful about this topic as I don't feel to be very involved in all the use cases. My opinion is that the
_newAPI_should be able to cover all cases and the_oldAPI_should be backwards compatible, however, built on top of the_newAPI_.
Quoted 6 lines
Quoted 3 lines
I.e. I think, the flags
MEMPOOL_F_SP_PUT,MEMPOOL_F_SC_GET(relicts of the old API) should be accepted by the old API ONLY. Therte_mempool_create_emptyshould not process them.The
rte_mempool_create_empty()function already processes these flags (SC_GET,SP_PUT) as of today.
Yes, I consider it quite strange. When thinking more about the mempool API, I'd move the flags processing to the rte_mempool_create. Semantically, it makes more sense as the "empty" clearly describes that it is empty. But with the flags, it is not... What is the reason to have those flags there?
Quoted 9 lines
Quoted 3 lines
Similarly for a potential
MEMPOOL_F_PKT_ALLOC, I would not polute therte_mempool_create_emptyby this anymore.+1
I think we should stop adding flags. Flags are prefered for independent features. Here, what would be the behavior with
MEMPOOL_F_PKT_ALLOC+MEMPOOL_F_SP_PUT?
+1 :)
Quoted 8 lines
Another reason to not add this flag is the
rte_mempoollibrary should not be aware of mbufs. The mbuf pools rely on mempools, but not the contrary.Quoted 2 lines
In overall we would get exactly 2 approaches (and not more):
future)
Well, now I can see that I've just written the same thing but with my own words :).
Quoted 9 lines
Quoted 4 lines
* using
rte_mempool_createwith flags calling therte_mempool_create_emptyandrte_mempool_set_ops_bynameinternally (so this layer can be marked as deprecated and removed in theAgree. This was one of the objective of my mempool rework patchset:
provide a more flexible API, and avoid functions with 10 to 15 arguments.
Quoted 6 lines
Quoted 3 lines
* using
rte_mempool_create_empty+rte_mempool_set_ops_byname- allowing any customizations but with the necessity to change the applications (new preferred API)Yes.
And if required, maybe a third API is possible in case of mbuf pools.
I don't count this. It's an upper layer, but yes.
Quoted 5 lines
Indeed, the applications are encouraged to use
rte_pktmbuf_pool_create()to create a pool of mbuf instead of mempool API. If an application wants to select specific ops for it, we could add:rte_pktmbuf_pool_create_<something>(..., name)
Seems like a good idea.
Quoted 8 lines
instead of using the mempool API.
I think this is what Shreyansh suggests when he says:It sounds fine if calls to rte_mempool_* can select an external handler *optionally* - but, if we pass it as command line, it would be binding (at least, semantically) for rte_pktmbuf_* calls as well. Isn't it?
I think, the question here is whether the processing of such optional command line specification is up to the application or up the the DPDK core. If we leave it in applications, it's just a matter of API.
Quoted 9 lines
Quoted 7 lines
So, the old applications can stay as they are (OK, with a possible new flag
MEMPOOL_F_PKT_ALLOC) and the new one can do the same but you have to set the ops explicitly.The more different ways of using those APIs we have, the greater hell we have to maintain.
I'm really not in favor of a
MEMPOOL_F_PKT_ALLOCflag in mempool api.
Your arguments are valid, +1.
Quoted 4 lines
I think David's patch is already a good step forward. Let's do it step by step. Next step is maybe to update some applications (at least testpmd) to select a new pool handler dynamically.
We can probably make an API to process the command line by applications that configures a mempool automatically. So, it would be a oneliner or something like that. Like rte_mempool_create_from_devargs(...).
Jan
Quoted 3 lines
Regards,
Olivier
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi Jan,
Quoted 47 lines · Jan Viktorin
Quoted 44 lines · On Fri, 10 Jun 2016 09:29:44 +0200 Olivier Matz <[email protected]> wrote:
Hi,
Quoted 41 lines · Jan Viktorin
Quoted 32 lines
Quoted 20 lines
My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:... #define
MEMPOOL_F_SC_GET0x0008#defineMEMPOOL_F_PKT_ALLOC0x0010...in
rte_mempool_create_empty: ... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:... mp = rte_mempool_create_empty(name, n,
elt_size,cache_size,(quoted diff) +1
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, +Quoted 1 line
MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces the
rte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have: 1.rte_pktmbuf_pool_create()2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler) 3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different custom handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
I am quite careful about this topic as I don't feel to be very involved in all the use cases. My opinion is that the
_newAPI_should be able to cover all cases and the_oldAPI_should be backwards compatible, however, built on top of the_newAPI_.I.e. I think, the flags
MEMPOOL_F_SP_PUT,MEMPOOL_F_SC_GET(relicts of the old API) should be accepted by the old API ONLY. Therte_mempool_create_emptyshould not process them.
Quoted 6 lines
Quoted 2 lines
The
rte_mempool_create_empty()function already processes these flags (SC_GET,SP_PUT) as of today.Yes, I consider it quite strange. When thinking more about the mempool API, I'd move the flags processing to the
rte_mempool_create. Semantically, it makes more sense as the "empty" clearly describes that it is empty. But with the flags, it is not... What is the reason to have those flags there?
Yes, they should be in rte_mempool_create. There were in an earlier patch, but regressed. I'll have them in rte_mempool_create in the next patch.
[...]
Rgds,
Dave.
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to Olivier MatzHi all,
Quoted 90 lines · Olivier Matz
Hi,
Quoted 33 lines · Jan Viktorin
Quoted 32 lines
Quoted 20 lines
My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:... #define
MEMPOOL_F_SC_GET0x0008#defineMEMPOOL_F_PKT_ALLOC0x0010...in
rte_mempool_create_empty: ... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:... mp = rte_mempool_create_empty(name, n,
elt_size,cache_size,(quoted diff) +1
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, +Quoted 1 line
MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces the
rte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have: 1.rte_pktmbuf_pool_create()2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler) 3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different custom handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
Quoted 8 lines
I am quite careful about this topic as I don't feel to be very involved in all the use cases. My opinion is that the
_newAPI_should be able to cover all cases and the_oldAPI_should be backwards compatible, however, built on top of the_newAPI_.I.e. I think, the flags
MEMPOOL_F_SP_PUT,MEMPOOL_F_SC_GET(relicts of the old API) should be accepted by the old API ONLY. Therte_mempool_create_emptyshould not process them.The
rte_mempool_create_empty()function already processes these flags (SC_GET,SP_PUT) as of today.Quoted 2 lines
Similarly for a potential
MEMPOOL_F_PKT_ALLOC, I would not polute therte_mempool_create_emptyby this anymore.+1
I think we should stop adding flags. Flags are prefered for independent features. Here, what would be the behavior with
MEMPOOL_F_PKT_ALLOC+MEMPOOL_F_SP_PUT?Another reason to not add this flag is the
rte_mempoollibrary should not be aware of mbufs. The mbuf pools rely on mempools, but not the contrary.Quoted 6 lines
In overall we would get exactly 2 approaches (and not more):
* using
rte_mempool_createwith flags calling therte_mempool_create_emptyandrte_mempool_set_ops_bynameinternally (so this layer can be marked as deprecated and removed in the future)Agree. This was one of the objective of my mempool rework patchset:
provide a more flexible API, and avoid functions with 10 to 15 arguments.Quoted 3 lines
* using
rte_mempool_create_empty+rte_mempool_set_ops_byname- allowing any customizations but with the necessity to change the applications (new preferred API)Yes.
And if required, maybe a third API is possible in case of mbuf pools. Indeed, the applications are encouraged to userte_pktmbuf_pool_create()to create a pool of mbuf instead of mempool API. If an application wants to select specific ops for it, we could add:rte_pktmbuf_pool_create_<something>(..., name)instead of using the mempool API.
I think this is what Shreyansh suggests when he says:It sounds fine if calls to rte_mempool_* can select an external handler *optionally* - but, if we pass it as command line, it would be binding (at least, semantically) for rte_pktmbuf_* calls as well. Isn't it?
Quoted 7 lines
Quoted 6 lines
So, the old applications can stay as they are (OK, with a possible new flag
MEMPOOL_F_PKT_ALLOC) and the new one can do the same but you have to set the ops explicitly.The more different ways of using those APIs we have, the greater hell we have to maintain.
I'm really not in favor of a
MEMPOOL_F_PKT_ALLOCflag in mempool api.
I would tend to agree, even though yesterday I proposed making that change. However, thinking about it some more, I'm not totally happy with the MEMPOOL_F_PKT_ALLOC addition. It adds yet another method of creating a mempool, and I think that may introduce some confusion with some developers.
I also like the suggestion of rte_pktmbuf_pool_create_<something>(..., name) suggested above, I was thinking the same myself last night, and I would prefer that rather than adding the MEMPOOL_F_PKT_ALLOC flag. Developers can add that function into their apps as a wrapper to rte_mempool_create_empty->rte_mempool_set_ops_byname should the need to have more than one pktmbuf allocator. Otherwise they can use the one that makes use of the RTE_MBUF_DEFAULT_MEMPOOL_OPS config setting.
Quoted 6 lines
I think David's patch is already a good step forward. Let's do it step by step. Next step is maybe to update some applications (at least testpmd) to select a new pool handler dynamically.
Regards,
Olivier
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi David,
Quoted 15 lines
-----Original Message-----
From: Hunt, David [mailto:[email protected]]
Sent: Friday, June 10, 2016 3:05 PM
To: Olivier Matz <[email protected]>; Jan Viktorin <[email protected]>
Cc: Shreyansh Jain <[email protected]>; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi all,
Quoted 2 lines · Olivier Matz
Hi,
[...snip...]
Quoted 17 lines
Quoted 9 lines
Quoted 8 lines
So, the old applications can stay as they are (OK, with a possible new flag
MEMPOOL_F_PKT_ALLOC) and the new one can do the same but you have to set the ops explicitly.The more different ways of using those APIs we have, the greater hell we have to maintain.
I'm really not in favor of a
MEMPOOL_F_PKT_ALLOCflag in mempool api.I would tend to agree, even though yesterday I proposed making that change. However,
thinking about it some more, I'm not totally happy with theMEMPOOL_F_PKT_ALLOCaddition. It adds yet another method of creating a mempool,
and I think that may introduce some confusion with some developers.
Quoted 11 lines
I also like the suggestion of rte_pktmbuf_pool_create_<something>(..., name) suggested
above, I was thinking the same myself last night, and I would prefer that rather than adding theMEMPOOL_F_PKT_ALLOCflag. Developers can add that function into their apps as a wrapper
torte_mempool_create_empty->rte_mempool_set_ops_bynameshould the need to have
more than one pktmbuf allocator. Otherwise they can use the one that makes use of theRTE_MBUF_DEFAULT_MEMPOOL_OPSconfig setting.
+1
Quoted 8 lines
Quoted 8 lines
I think David's patch is already a good step forward. Let's do it step by step. Next step is maybe to update some applications (at least testpmd) to select a new pool handler dynamically.
Regards,
Olivier
Thanks.
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to Olivier MatzQuoted 50 lines · Olivier Matz
Hi,
Quoted 35 lines · Jan Viktorin
Quoted 33 lines
Quoted 20 lines
My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:... #define
MEMPOOL_F_SC_GET0x0008#defineMEMPOOL_F_PKT_ALLOC0x0010...in
rte_mempool_create_empty: ... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:... mp = rte_mempool_create_empty(name, n,
elt_size,cache_size,(quoted diff) +1
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, +Quoted 1 line
MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces the
rte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have: 1.rte_pktmbuf_pool_create()2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler) 3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different custom handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
Quoted 8 lines
I am quite careful about this topic as I don't feel to be very involved in all the use cases. My opinion is that the
_newAPI_should be able to cover all cases and the_oldAPI_should be backwards compatible, however, built on top of the_newAPI_.I.e. I think, the flags
MEMPOOL_F_SP_PUT,MEMPOOL_F_SC_GET(relicts of the old API) should be accepted by the old API ONLY. Therte_mempool_create_emptyshould not process them.The
rte_mempool_create_empty()function already processes these flags (SC_GET,SP_PUT) as of today.
Quoted 8 lines
Quoted 2 lines
Similarly for a potential
MEMPOOL_F_PKT_ALLOC, I would not polute therte_mempool_create_emptyby this anymore.+1
I think we should stop adding flags. Flags are prefered for independent features. Here, what would be the behavior with
MEMPOOL_F_PKT_ALLOC+MEMPOOL_F_SP_PUT?
+1
MEMPOOL_F_PKT_ALLOC introduced only for legacy application to make it work with external pool manager. If we are not taking that path(and expects applications to change) then IMO we can we have proper mempool create API to accommodate the external pool and deprecate rte_mempool_create/rte_mempool_xmem_create
like,
1) Remove 10 to 15 arguments pool create and make it as structure(more forward looking)
2) Remove flags
3) Have the same API for external and internal mempool create and differentiate through handler through "name". NULL can be default mempool handler(MPMC)
Quoted 5 lines
Another reason to not add this flag is the
rte_mempoollibrary should not be aware of mbufs. The mbuf pools rely on mempools, but not the contrary.
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to Olivier MatzHi Olivier,
Quoted 65 lines
-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Friday, June 10, 2016 1:00 PM
To: Jan Viktorin <[email protected]>; Hunt, David <[email protected]>
Cc: Shreyansh Jain <[email protected]>; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operationsHi,
Quoted 35 lines · Jan Viktorin
Quoted 33 lines
Quoted 20 lines
My suggestion is to have an additional flag, '
MEMPOOL_F_PKT_ALLOC', which, if specified, would:... #define
MEMPOOL_F_SC_GET0x0008#defineMEMPOOL_F_PKT_ALLOC0x0010...in
rte_mempool_create_empty: ... after checking the other MEMPOOL_F_* flags...if (flags &
MEMPOOL_F_PKT_ALLOC)rte_mempool_set_ops_byname(mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS)And removing the redundant call to
rte_mempool_set_ops_byname()inrte_pktmbuf_create_pool().Thereafter,
rte_pktmbuf_pool_createcan be changed to:... mp = rte_mempool_create_empty(name, n,
elt_size,cache_size,(quoted diff) +1
-1- sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, +Quoted 1 line
MEMPOOL_F_PKT_ALLOC); if (mp == NULL) return NULL;Yes, this would simplify somewhat the creation of a pktmbuf pool, in that it replaces the
rte_mempool_set_ops_bynamewith a flag bit. However, I'm not sure we want to introduce a third method of creating a mempool to the developers. If we introduced this, we would then have: 1.rte_pktmbuf_pool_create()2.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOCset (which would use the configured custom handler) 3.rte_mempool_create_empty()withMEMPOOL_F_PKT_ALLOC__not__set followed by a call torte_mempool_set_ops_byname()(would allow several different custom handlers to be used in one applicationQuoted 1 line
Does anyone else have an opinion on this? Oliver, Jerin, Jan?
Quoted 8 lines
I am quite careful about this topic as I don't feel to be very involved in all the use cases. My opinion is that the
_newAPI_should be able to cover all cases and the_oldAPI_should be backwards compatible, however, built on top of the_newAPI_.I.e. I think, the flags
MEMPOOL_F_SP_PUT,MEMPOOL_F_SC_GET(relicts of the old API) should be accepted by the old API ONLY. Therte_mempool_create_emptyshould not process them.The
rte_mempool_create_empty()function already processes these flags (SC_GET,SP_PUT) as of today.Quoted 2 lines
Similarly for a potential
MEMPOOL_F_PKT_ALLOC, I would not polute therte_mempool_create_emptyby this anymore.+1
Quoted 7 lines
I think we should stop adding flags. Flags are prefered for independent features. Here, what would be the behavior with
MEMPOOL_F_PKT_ALLOC+MEMPOOL_F_SP_PUT?Another reason to not add this flag is the
rte_mempoollibrary should not be aware of mbufs. The mbuf pools rely on mempools, but not the contrary.
Agree - mempool should be agnostic of the mbufs using it. But, mempool should be aware of the allocator it is using, in my opinion.
And, agree with your argument of "MEMPOOL_F_PKT_ALLOC + MEMPOOL_F_SP_PUT" - it is bad semantics.
Quoted 25 lines
Quoted 8 lines
In overall we would get exactly 2 approaches (and not more):
* using
rte_mempool_createwith flags calling therte_mempool_create_emptyandrte_mempool_set_ops_bynameinternally (so this layer can be marked as deprecated and removed in the future)Agree. This was one of the objective of my mempool rework patchset:
provide a more flexible API, and avoid functions with 10 to 15 arguments.Quoted 3 lines
* using
rte_mempool_create_empty+rte_mempool_set_ops_byname- allowing any customizations but with the necessity to change the applications (new preferred API)Yes.
And if required, maybe a third API is possible in case of mbuf pools. Indeed, the applications are encouraged to userte_pktmbuf_pool_create()to create a pool of mbuf instead of mempool API. If an application wants to select specific ops for it, we could add:rte_pktmbuf_pool_create_<something>(..., name)
Quoted 7 lines
instead of using the mempool API.
I think this is what Shreyansh suggests when he says:It sounds fine if calls to rte_mempool_* can select an external handler *optionally* - but, if we pass it as command line, it would be binding (at least, semantically) for rte_pktmbuf_* calls as well. Isn't it?
Er. I think I should clarify the context.
I was referring to the 'command-line-argument-for-selecting-external-mem-allocator' comment. I was just highlighting that probably it would cause conflict with the two APIs.
But, having said that, I agree with you about "...applications are encouraged to use rte_pktmbuf_pool_create() to create a pool of mbuf...".
Quoted 10 lines
Quoted 8 lines
So, the old applications can stay as they are (OK, with a possible new flag
MEMPOOL_F_PKT_ALLOC) and the new one can do the same but you have to set the ops explicitly.The more different ways of using those APIs we have, the greater hell we have to maintain.
I'm really not in favor of a
MEMPOOL_F_PKT_ALLOCflag in mempool api.
Agree. Flags are not pretty way of handling mutually exclusive features - they are not intuitive. Semantically cleaner API is better approach.
Quoted 4 lines
I think David's patch is already a good step forward. Let's do it step by step. Next step is maybe to update some applications (at least testpmd) to select a new pool handler dynamically.
Fair enough. We can slowly make changes to all applications to show 'best practice' of creating buffer or packet pools.
Quoted 3 lines
Regards,
Olivier
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to David HuntQuoted 9 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of David Hunt
Sent: Friday, June 03, 2016 8:28 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; David Hunt <[email protected]>
Subject: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operations
[...]
Quoted 18 lines
lib/librte_mempool/rte_mempool_ops.c new file +18
-0+int +rte_mempool_ops_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + +if (rte_mempool_ops_table.num_ops >= +RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool ops structs exceeded\n" ); +return -ENOSPC ; + } + +if (h->put ==NULL || h->get ==NULL || h->get_count ==NULL ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl);
lib/librte_mempool/rte_mempool_ops.c line 75
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+RTE_LOG (ERR ,MEMPOOL , +"Missing callback while registering mempool ops\n" ); +return -EINVAL ; + } + +if (strlen (h->name) >=sizeof (ops->name) -1 ) { +RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , + __func__, h->name); + rte_errno =EEXIST ; +return NULL ;
rte_mempool_ops_register has return type 'int'. Above should be 'return rte_errno;', or probably 'return -EEXIST;' itself.
Quoted 5 lines
lib/librte_mempool/rte_mempool_ops.c new file +5
-0+ } + + ops_index = rte_mempool_ops_table.num_ops++; + ops = &rte_mempool_ops_table.ops[ops_index]; +snprintf (ops->name,sizeof (ops->name),"%s" , h->name);
lib/librte_mempool/rte_mempool_ops.c line 90
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+ ops->alloc = h->alloc; + ops->put = h->put; + ops->get = h->get; + ops->get_count = h->get_count; + +rte_spinlock_unlock (&rte_mempool_ops_table.sl); + +return ops_index; +} +
[...]
-
Shreyansh
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to David HuntHi David,
Please find some comments below.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 351
Quoted 13 lines · David Hunt
lib/librte_mempool/rte_mempool.h +10
-0+/** +* Prototype for implementation specific data provisioning function. +* +* The function should provide the implementation specific memory for +* for use by the other mempool ops functions in a given mempool ops struct. +* E.g. the default ops provides an instance of the rte_ring for this purpose. +* it will mostlikely point to a different type of data structure, and +* will be transparent to the application programmer. +*/ +typedef void *(*rte_mempool_alloc_t )(struct rte_mempool *mp);
In http://dpdk.org/ml/archives/dev/2016-June/040233.html, I suggested to change the prototype to return an int (-errno) and directly set the set mp->pool_data (void *) or mp->pool_if (uint64_t). No cast would be required in this latter case.
By the way, there is a typo in the comment:
"mostlikely" -> "most likely"
lib/librte_mempool/rte_mempool_default.c line 110
Quoted 8 lines
lib/librte_mempool/rte_mempool_default.c new file +5
-0+static void +common_ring_free (struct rte_mempool *mp) +{ +rte_ring_free ((struct rte_ring *)mp->pool_data); +}
I don't think the cast is needed here.
(same in other functions)
Quoted 23 lines
lib/librte_mempool/rte_mempool_ops.c new file +20
-0+/* add a new ops struct in rte_mempool_ops_table, return its index */ +int +rte_mempool_ops_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + +if (rte_mempool_ops_table.num_ops >= +RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool ops structs exceeded\n" ); +return -ENOSPC ; + } + +if (h->put ==NULL || h->get ==NULL || h->get_count ==NULL ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); + RTE_LOG(ERR, MEMPOOL,
lib/librte_mempool/rte_mempool_ops.c line 76
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+ "Missing callback while registering mempool ops\n"); +return -EINVAL ; + } + +if (strlen (h->name) >=sizeof (ops->name) -1 ) { +RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , + __func__, h->name); + rte_errno =EEXIST ; +return NULL ; + }
This has already been noticed by Shreyansh, but in case of:
rte_mempool_ops.c:75:10: error: return makes integer from pointer without a cast [-Werror=int-conversion]
return NULL;
^lib/librte_mempool/rte_mempool_ops.c line 127
Quoted 3 lines
lib/librte_mempool/rte_mempool_ops.c new file +3
-0+/* sets mempool ops previously registered by rte_mempool_ops_register */ +int +rte_mempool_set_ops_byname (struct rte_mempool *mp,const char *name)
When I compile with shared libraries enabled, I get the following error:
librte_reorder.so: undefined reference to rte_mempool_ops_table' librte_mbuf.so: undefined reference to rte_mempool_set_ops_byname'
...
The new functions and global variables must be in rte_mempool_version.map. This was in v5
( http://dpdk.org/ml/archives/dev/2016-May/039365.html ) but was dropped in v6.
Regards,
Olivier
Re: [PATCH v8 1/3] mempool: support external mempool operations
Hi Olivier,
Quoted 6 lines · Olivier Matz
Hi David,
Please find some comments below.
On 06/03/2016 04:58 PM, David Hunt wrote:
Quoted 16 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 351
Quoted 12 lines
lib/librte_mempool/rte_mempool.h +10
-0+/** +* Prototype for implementation specific data provisioning function. +* +* The function should provide the implementation specific memory for +* for use by the other mempool ops functions in a given mempool ops struct. +* E.g. the default ops provides an instance of the rte_ring for this purpose. +* it will mostlikely point to a different type of data structure, and +* will be transparent to the application programmer. +*/ +typedef void *(*rte_mempool_alloc_t )(struct rte_mempool *mp);In http://dpdk.org/ml/archives/dev/2016-June/040233.html, I suggested to change the prototype to return an int (-errno) and directly set the set
mp->pool_data(void *) ormp->pool_if(uint64_t). No cast would be required in this latter case.
Done.
Quoted 2 lines
By the way, there is a typo in the comment:
"mostlikely" -> "most likely"
Fixed.
Quoted 9 lines
lib/librte_mempool/rte_mempool_default.c line 110
Quoted 7 lines
lib/librte_mempool/rte_mempool_default.c new file +5
-0+static void +common_ring_free (struct rte_mempool *mp) +{ +rte_ring_free ((struct rte_ring *)mp->pool_data); +}I don't think the cast is needed here.
(same in other functions)
Removed.
Quoted 35 lines
Quoted 23 lines
lib/librte_mempool/rte_mempool_ops.c new file +20
-0+/* add a new ops struct in rte_mempool_ops_table, return its index */ +int +rte_mempool_ops_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + +if (rte_mempool_ops_table.num_ops >= +RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool ops structs exceeded\n" ); +return -ENOSPC ; + } + +if (h->put ==NULL || h->get ==NULL || h->get_count ==NULL ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); + RTE_LOG(ERR, MEMPOOL,lib/librte_mempool/rte_mempool_ops.c line 76
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+ "Missing callback while registering mempool ops\n"); +return -EINVAL ; + } + +if (strlen (h->name) >=sizeof (ops->name) -1 ) { +RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , + __func__, h->name); + rte_errno =EEXIST ; +return NULL ; + }This has already been noticed by Shreyansh, but in case of:
Quoted 4 lines
rte_mempool_ops.c:75:10: error: return makes integer from pointer without a cast [-Werror=int-conversion]
return NULL; ^
Changed to return -EEXIST
Quoted 7 lines
lib/librte_mempool/rte_mempool_ops.c line 127
Quoted 4 lines
lib/librte_mempool/rte_mempool_ops.c new file +3
-0+/* sets mempool ops previously registered by rte_mempool_ops_register */ +int +rte_mempool_set_ops_byname (struct rte_mempool *mp,const char *name)When I compile with shared libraries enabled, I get the following error:
Quoted 8 lines
librte_reorder.so: undefined reference to
rte_mempool_ops_table' librte_mbuf.so: undefined reference torte_mempool_set_ops_byname'
...The new functions and global variables must be in rte_mempool_version.map. This was in v5
( http://dpdk.org/ml/archives/dev/2016-May/039365.html ) but was dropped in v6.
OK, Added.
Quoted 3 lines
Regards,
Olivier
Thanks,
David.
Re: [PATCH v8 1/3] mempool: support external mempool operations
In reply to David HuntHi David,
Sorry for multiple mails on a patch. I forgot a trivial comment in previous mail.
Quoted 9 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of David Hunt
Sent: Friday, June 03, 2016 8:28 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; David Hunt <[email protected]>
Subject: [dpdk-dev] [PATCH v8 1/3] mempool: support external mempool operations
[...]
Quoted 7 lines
lib/librte_mempool/rte_mempool_ops.c new file +7
-0+int +rte_mempool_ops_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; + +rte_spinlock_lock (&rte_mempool_ops_table.sl);
lib/librte_mempool/rte_mempool_ops.c line 64
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+ +if (rte_mempool_ops_table.num_ops >= +RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool ops structs exceeded\n" ); +return -ENOSPC ; + } + +if (h->put ==NULL || h->get ==NULL || h->get_count ==NULL ) {
I think 'h->alloc' should also be checked here.
Quoted 16 lines
lib/librte_mempool/rte_mempool_ops.c new file +16
-0+rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Missing callback while registering mempool ops\n" ); +return -EINVAL ; + } + +if (strlen (h->name) >=sizeof (ops->name) -1 ) { +RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , + __func__, h->name); + rte_errno =EEXIST ; +return NULL ; + } + + ops_index = rte_mempool_ops_table.num_ops++; + ops = &rte_mempool_ops_table.ops[ops_index]; +snprintf (ops->name,sizeof (ops->name),"%s" , h->name);
lib/librte_mempool/rte_mempool_ops.c line 90
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+ ops->alloc = h->alloc; + ops->put = h->put; + ops->get = h->get; + ops->get_count = h->get_count; + +rte_spinlock_unlock (&rte_mempool_ops_table.sl); + +return ops_index; +} +
[...]
-
Shreyansh
PATCH v8 2/3 app/test: test external mempool manager
In reply to David HuntUse a minimal custom mempool external ops and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)
app/test/test_mempool.c +114 -0
@@ -83,6 +83,97 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static void * +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return NULL ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; +return cm; +} + +static void +custom_mempool_free (struct rte_mempool *mp) +{ +rte_free ((void *)(mp->pool_data)); +} + +static int +custom_mempool_put (struct rte_mempool *mp,void *const *obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_get (struct rte_mempool *mp,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (const struct rte_mempool *mp) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .put = custom_mempool_put, + .get = custom_mempool_get, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -477,6 +568,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +597,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +658,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
PATCH v8 3/3 mbuf: make default mempool ops configurable at build
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
v9 cover mempool: add external mempool manager
In reply to David HuntHere's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 09/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v9 changes:
* added a check for NULL alloc in rte_mempool_ops_register
* rte_mempool_alloc_t now returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return -EEXIST in rte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check from rte_mempool_create_empty to rte_mempool_create
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_HANDLER macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops to create a new mempool
using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new 'create' function, providing the mempool ops struct name to point the mempool to the relevant mempool manager callback structure.
The old 'create' function can still be called by legacy programs, and will internally work out the mempool handle based on the flags provided (single producer, single consumer, etc). By default handles are created internally to implement the built-in DPDK mempool manager and mempool types.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. put - puts an object back into the mempool once an application has
finished with it
3. get - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time a get/put/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
intrte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.put = common_ring_sp_put,
.get = common_ring_mc_get,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support external mempool operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test external mempool manager
PATCH v9 1/3 mempool: support external mempool operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_handler() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 72 ++++----- lib/librte_mempool/rte_mempool.h | 248 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_default.c | 159 ++++++++++++++++++ lib/librte_mempool/rte_mempool_ops.c | 150 +++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 4 + 7 files changed, 570 insertions(+), 66 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_default.c create mode 100644 lib/librte_mempool/rte_mempool_ops.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_default.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +28 -44
132 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +227 -21
305 lines not on this page · raw message
lib/librte_mempool/rte_mempool_default.c new file +159 -0
159 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +150 -0
150 lines not on this page · raw message
lib/librte_mempool/rte_mempool_version.map +4 -0
@@ -19,6 +19,8 @@ DPDK_2.0 { DPDK_16.7 { global: + rte_mempool_ops_table; + rte_mempool_check_cookies; rte_mempool_obj_iter; rte_mempool_mem_iter;
@@ -29,6 +31,8 @@ DPDK_16.7 { rte_mempool_populate_default; rte_mempool_populate_anon; rte_mempool_free; + rte_mempool_set_ops_byname; + rte_mempool_ops_register; local: *; } DPDK_2.0;
Signature · 1 line
2.5.5
Re: [PATCH v9 1/3] mempool: support external mempool operations
Hi David,
Some comments below.
Quoted 24 lines · David Hunt
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_handler()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.This patch also adds a set of default ops (function callbacks) based on
rte_ring.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>...
lib/librte_mempool/rte_mempool.c +0
-3@@ -386,10 +352,14 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,int ret;/* create the internal ring if not already done */ -if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) { - ret =rte_mempool_ring_create (mp); -if (ret <0 )
lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, · line 363
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +8
-1-return ret; +if ((mp->flags &MEMPOOL_F_POOL_CREATED ) ==0 ) { + rte_errno =0 ; + ret =rte_mempool_ops_alloc (mp); +if (ret !=0 ) { +if (rte_errno ==0 ) +return -EINVAL ; +return -rte_errno; + } }
The rte_errno should be removed. Just return the error code from rte_mempool_ops_alloc() on failure.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 384
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+/** Structure defining mempool operations structure */ +struct rte_mempool_ops { +char name[RTE_MEMPOOL_OPS_NAMESIZE ];/**< Name of mempool ops struct */ +rte_mempool_alloc_t alloc;/**< Allocate private data */ +rte_mempool_free_t free;/**< Free the external pool. */ +rte_mempool_put_t put;/**< Put an object. */ +rte_mempool_get_t get;/**< Get an object. */ +rte_mempool_get_count get_count;/**< Get qty of available objs. */ +} __rte_cache_aligned; +
Sorry, I missed that in the previous reviews, but since the get/put functions have been renamed in dequeue/enqueue, I think the same change should also be done here.
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 351
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+/** +* Prototype for implementation specific data provisioning function. +* +* The function should provide the implementation specific memory for +* for use by the other mempool ops functions in a given mempool ops struct. +* E.g. the default ops provides an instance of the rte_ring for this purpose. +* it will most likely point to a different type of data structure, and +* will be transparent to the application programmer. +*/ +typedef int (*rte_mempool_alloc_t )(struct rte_mempool *mp);
A comment saying that this function should set mp->pool_data would be nice here, I think.
lib/librte_mempool/rte_mempool_ops.c line 102
Quoted 11 lines
lib/librte_mempool/rte_mempool_ops.c new file +11
-0+/* wrapper to allocate an external mempool's private (pool) data */ +int +rte_mempool_ops_alloc (struct rte_mempool *mp) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +if (ops->alloc ==NULL ) +return -ENOMEM ; +return ops->alloc (mp); +}
Now that we check that ops->alloc != NULL in the register function, I wonder if we should keep this test or not. Yes, it doesn't hurt, but for consistency with the other functions (get/put/get_count), we may remove it.
This would be a good thing because it would prevent any confusion with rte_mempool_ops_get(), which returns a pointer to the ops struct (and has nothing to do with ops->get()).
Regards,
Olivier
Re: [PATCH v9 1/3] mempool: support external mempool operations
Hi Olivier,
Quoted 24 lines · Olivier Matz
Hi David,
Some comments below.
Quoted 19 lines · David Hunt
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_handler()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.This patch also adds a set of default ops (function callbacks) based on
rte_ring.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>...
lib/librte_mempool/rte_mempool.c +0
-0@@ -386,10 +352,14 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,int ret;
Quoted 16 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool.c +0
-3/* create the internal ring if not already done */ -if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) { - ret =rte_mempool_ring_create (mp); -if (ret <0 )lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, · line 363
Quoted 10 lines
lib/librte_mempool/rte_mempool.c +8
-1-return ret; +if ((mp->flags &MEMPOOL_F_POOL_CREATED ) ==0 ) { + rte_errno =0 ; + ret =rte_mempool_ops_alloc (mp); +if (ret !=0 ) { +if (rte_errno ==0 ) +return -EINVAL ; +return -rte_errno; + } }The
rte_errnoshould be removed. Just return the error code fromrte_mempool_ops_alloc()on failure.
Done.
Quoted 5 lines
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +5
-0+/** Structure defining mempool operations structure */ +struct rte_mempool_ops { +char name[RTE_MEMPOOL_OPS_NAMESIZE ];/**< Name of mempool ops struct */ +rte_mempool_alloc_t alloc;/**< Allocate private data */ +rte_mempool_free_t free;/**< Free the external pool. */
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 384
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +5
-0+rte_mempool_put_t put;/**< Put an object. */ +rte_mempool_get_t get;/**< Get an object. */ +rte_mempool_get_count get_count;/**< Get qty of available objs. */ +} __rte_cache_aligned; +Sorry, I missed that in the previous reviews, but since the get/put functions have been renamed in dequeue/enqueue, I think the same change should also be done here.
Done. I also changed the common_ring_[sc|mc]_put and common_ring_[sc|mc]_get. I didn't go as far as changing the rte_mempool_put or rte_mempool_put_bulk calls, as they are used in several drivers and apps.
Quoted 13 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 351
Quoted 11 lines
lib/librte_mempool/rte_mempool.h +10
-0+/** +* Prototype for implementation specific data provisioning function. +* +* The function should provide the implementation specific memory for +* for use by the other mempool ops functions in a given mempool ops struct. +* E.g. the default ops provides an instance of the rte_ring for this purpose. +* it will most likely point to a different type of data structure, and +* will be transparent to the application programmer. +*/ +typedef int (*rte_mempool_alloc_t )(struct rte_mempool *mp);A comment saying that this function should set
mp->pool_datawould be nice here, I think.
Done
Quoted 16 lines
lib/librte_mempool/rte_mempool_ops.c line 102
Quoted 11 lines
lib/librte_mempool/rte_mempool_ops.c new file +11
-0+/* wrapper to allocate an external mempool's private (pool) data */ +int +rte_mempool_ops_alloc (struct rte_mempool *mp) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +if (ops->alloc ==NULL ) +return -ENOMEM ; +return ops->alloc (mp); +}Now that we check that
ops->alloc!= NULL in the register function, I wonder if we should keep this test or not. Yes, it doesn't hurt, but for consistency with the other functions (get/put/get_count), we may remove it.
Quoted 3 lines
This would be a good thing because it would prevent any confusion with
rte_mempool_ops_get(), which returns a pointer to the ops struct (and has nothing to do withops->get()).
Done.
Quoted 3 lines
Regards,
Olivier
Thanks,
Dave.
PATCH v9 2/3 app/test: test external mempool manager
In reply to David HuntUse a minimal custom mempool external ops and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+)
app/test/test_mempool.c +115 -0
@@ -83,6 +83,98 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static int +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return -ENOMEM ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; + mp->pool_data = cm; +return 0 ; +} + +static void +custom_mempool_free (struct rte_mempool *mp) +{ +rte_free ((void *)(mp->pool_data)); +} + +static int +custom_mempool_put (struct rte_mempool *mp,void *const *obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_get (struct rte_mempool *mp,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (const struct rte_mempool *mp) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .put = custom_mempool_put, + .get = custom_mempool_get, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -477,6 +569,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +598,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +659,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
PATCH v9 3/3 mbuf: make default mempool ops configurable at build
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
v10 cover mempool: add external mempool manager
In reply to David HuntHere's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 14/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v10 changes:
* changed the _put/_get op names to _enqueue/_dequeue to be consistent with the function names
* some rte_errno cleanup
* comment tweaks about when to set pool_data
* removed an un-needed check for ops->alloc == NULL
v9 changes:
* added a check for NULL alloc in rte_mempool_ops_register
* rte_mempool_alloc_t now returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return -EEXIST in rte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check from rte_mempool_create_empty to rte_mempool_create
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_HANDLER macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops to create a new mempool
using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new 'create' function, providing the mempool ops struct name to point the mempool to the relevant mempool manager callback structure.
The old 'create' function can still be called by legacy programs, and will internally work out the mempool handle based on the flags provided (single producer, single consumer, etc). By default handles are created internally to implement the built-in DPDK mempool manager and mempool types.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. enqueue - puts an object back into the mempool once an application has
finished with it
3. dequeue - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time an enqueue/dequeue/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
intrte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support external mempool operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test external mempool manager
PATCH v10 1/3 mempool: support external mempool operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_handler() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 66 +++----- lib/librte_mempool/rte_mempool.h | 249 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_default.c | 161 +++++++++++++++++++ lib/librte_mempool/rte_mempool_ops.c | 148 +++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 4 + 7 files changed, 566 insertions(+), 65 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_default.c create mode 100644 lib/librte_mempool/rte_mempool_ops.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_default.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +23 -43
126 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +228 -21
306 lines not on this page · raw message
lib/librte_mempool/rte_mempool_default.c new file +161 -0
161 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +148 -0
148 lines not on this page · raw message
lib/librte_mempool/rte_mempool_version.map +4 -0
@@ -19,6 +19,8 @@ DPDK_2.0 { DPDK_16.7 { global: + rte_mempool_ops_table; + rte_mempool_check_cookies; rte_mempool_obj_iter; rte_mempool_mem_iter;
@@ -29,6 +31,8 @@ DPDK_16.7 { rte_mempool_populate_default; rte_mempool_populate_anon; rte_mempool_free; + rte_mempool_set_ops_byname; + rte_mempool_ops_register; local: *; } DPDK_2.0;
Signature · 1 line
2.5.5
Re: [PATCH v10 1/3] mempool: support external mempool operations
Hi,
Quoted 18 lines
-----Original Message-----
From: David Hunt [mailto:[email protected]]
Sent: Tuesday, June 14, 2016 3:16 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shreyansh Jain <[email protected]>; David Hunt <[email protected]>
Subject: [PATCH v10 1/3] mempool: support external mempool operationsUntil now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_handler()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.
Quoted 5 lines
This patch also adds a set of default ops (function callbacks) based on
rte_ring.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>
Re: [PATCH v10 1/3] mempool: support external mempool operations
In reply to David HuntHi David,
2016-06-14 10:46, David Hunt:
Quoted 9 lines
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_handler()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.
Quoted 5 lines
This patch also adds a set of default ops (function callbacks) based on
rte_ring.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>
Glad to see we are close to have this feature integrated.
I've just looked into few details before pushing.
One of them are the comments. In mempool they were all ended by a dot. Please check the new comments.
The doc/guides/rel_notes/deprecation.rst must be updated to remove the deprecation notice in this patch.
Isn't there some explanations to add indoc/guides/prog_guide/mempool_lib.rst?
Isn't there a better name than "default" for the default implementation? I don't think the filename rte_mempool_default.c is meaningful.
Quoted 5 lines
+/**
+ * Register mempool operations
+ *
+ * @param h
+ * Pointer to and ops structure to register
The parameter name and its description are not correct.
Quoted 6 lines
+ * @return
+ * - >=0: Success; return the index of the ops struct in the table. + * - -EINVAL - some missing callbacks while registering ops struct + * - -ENOSPC - the maximum number of ops structs has been reached+ */
+intrte_mempool_ops_register(const struct rte_mempool_ops *ops);
You can check the doc with doxygen:
make doc-api-html
lib/librte_mempool/rte_mempool_version.map DPDK_2.0 { · line 23
Quoted 8 lines
lib/librte_mempool/rte_mempool_version.map +2
-0@@ -19,6 +19,8 @@ DPDK_2.0 { DPDK_16.7 { global: + rte_mempool_ops_table; +
Why this empty line?
lib/librte_mempool/rte_mempool_version.map DPDK_16.7 { · line 35
Quoted 9 lines
lib/librte_mempool/rte_mempool_version.map +2
-0rte_mempool_check_cookies; rte_mempool_obj_iter; rte_mempool_mem_iter;@@ -29,6 +31,8 @@ DPDK_16.7 { rte_mempool_populate_default; rte_mempool_populate_anon; rte_mempool_free; + rte_mempool_set_ops_byname; + rte_mempool_ops_register;
Please keep it in alphabetical order.
It seems the order was not respected before in mempool.
Re: [PATCH v10 1/3] mempool: support external mempool operations
Hi Thomas,
Quoted 15 lines · Thomas Monjalon
Hi David,
2016-06-14 10:46, David Hunt:
Quoted 12 lines
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_handler()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.This patch also adds a set of default ops (function callbacks) based on
rte_ring.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>Glad to see we are close to have this feature integrated.
I've just looked into few details before pushing.
One of them are the comments. In mempool they were all ended by a dot. Please check the new comments.
Do you mean the rte_mempool struct definition, or all comments? Shall I leave the old comments the way they were before the change, or will I clean up? If I clean up, I'd suggest I add a separate patch for that.
Quoted 2 lines
The
doc/guides/rel_notes/deprecation.rstmust be updated to remove the deprecation notice in this patch.
Will do. As a separate patch in the set?
Quoted 2 lines
Isn't there some explanations to add in
doc/guides/prog_guide/mempool_lib.rst?
Yes, I'll adapt some of the cover letter, and add as a separate patch.
Quoted 2 lines
Isn't there a better name than "default" for the default implementation? I don't think the filename
rte_mempool_default.cis meaningful.
I could call it rte_mempool_ring.c? Since the default handler is ring based?
Quoted 6 lines
Quoted 5 lines
+/**
+ * Register mempool operations
+ *
+ * @param h
+ * Pointer to and ops structure to registerThe parameter name and its description are not correct.
Will fix.
Quoted 8 lines
Quoted 6 lines
+ * @return
+ * - >=0: Success; return the index of the ops struct in the table. + * - -EINVAL - some missing callbacks while registering ops struct + * - -ENOSPC - the maximum number of ops structs has been reached+ */
+intrte_mempool_ops_register(const struct rte_mempool_ops *ops);You can check the doc with doxygen:
make doc-api-html
Will do.
Quoted 9 lines
lib/librte_mempool/rte_mempool_version.map DPDK_2.0 { · line 23
Quoted 8 lines
lib/librte_mempool/rte_mempool_version.map +2
-0@@ -19,6 +19,8 @@ DPDK_2.0 { DPDK_16.7 { global: + rte_mempool_ops_table; +Why this empty line?
No particular reason. I will remove.
Quoted 11 lines
lib/librte_mempool/rte_mempool_version.map DPDK_16.7 { · line 35
Quoted 9 lines
lib/librte_mempool/rte_mempool_version.map +2
-0rte_mempool_check_cookies; rte_mempool_obj_iter; rte_mempool_mem_iter;@@ -29,6 +31,8 @@ DPDK_16.7 { rte_mempool_populate_default; rte_mempool_populate_anon; rte_mempool_free; + rte_mempool_set_ops_byname; + rte_mempool_ops_register;Please keep it in alphabetical order.
It seems the order was not respected before in mempool.
I will fix this also.
Regards,
Dave.
Re: [PATCH v10 1/3] mempool: support external mempool operations
2016-06-14 14:20, Hunt, David:
Quoted 23 lines
Hi Thomas,
Quoted 19 lines · Thomas Monjalon
Hi David,
2016-06-14 10:46, David Hunt:
Quoted 9 lines
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_handler()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.Quoted 5 lines
This patch also adds a set of default ops (function callbacks) based on
rte_ring.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>Glad to see we are close to have this feature integrated.
Quoted 8 lines
Quoted 3 lines
I've just looked into few details before pushing.
One of them are the comments. In mempool they were all ended by a dot. Please check the new comments.Do you mean the
rte_mempoolstruct definition, or all comments? Shall I leave the
old comments the way they were before the change, or will I clean up? If I clean up, I'd suggest I add a separate patch for that.
Just check and clean the comments added in this patch.
Quoted 4 lines
Quoted 2 lines
The
doc/guides/rel_notes/deprecation.rstmust be updated to remove the deprecation notice in this patch.Will do. As a separate patch in the set?
In this patch.
Quoted 4 lines
Quoted 2 lines
Isn't there some explanations to add in
doc/guides/prog_guide/mempool_lib.rst?Yes, I'll adapt some of the cover letter, and add as a separate patch.
It is OK (and better) to add it in this patch.
Maybe you can request John's help for doc review.
Quoted 4 lines
Quoted 2 lines
Isn't there a better name than "default" for the default implementation? I don't think the filename
rte_mempool_default.cis meaningful.I could call it
rte_mempool_ring.c? Since the default handler is ring based?
It is an idea.
Thanks
PATCH v10 2/3 app/test: test external mempool manager
In reply to David HuntUse a minimal custom mempool external ops and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-)
app/test/test_mempool.c +120 -2
@@ -83,6 +83,99 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static int +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return -ENOMEM ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; + mp->pool_data = cm; +return 0 ; +} + +static void +custom_mempool_free (struct rte_mempool *mp) +{ +rte_free ((void *)(mp->pool_data)); +} + +static int +custom_mempool_enqueue (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_dequeue (struct rte_mempool *mp,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (const struct rte_mempool *mp) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .enqueue = custom_mempool_enqueue, + .dequeue = custom_mempool_dequeue, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -292,12 +385,14 @@ static int test_mempool_single_consumer(void)* test function for mempool test based on singple consumer and single producer, * can run on one lcore only */ -static int test_mempool_launch_single_consumer (__attribute__((unused))void *arg) +static int +test_mempool_launch_single_consumer (__attribute__((unused))void *arg) {return test_mempool_single_consumer (); } -static void my_mp_init (struct rte_mempool * mp, __attribute__((unused))void * arg) +static void +my_mp_init (struct rte_mempool *mp, __attribute__((unused))void *arg) {printf ("mempool name is %s\n" , mp->name);/* nothing to be implemented here*/
@@ -477,6 +572,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +601,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +662,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
Re: [PATCH v10 2/3] app/test: test external mempool manager
Quoted 9 lines
-----Original Message-----
From: David Hunt [mailto:[email protected]]
Sent: Tuesday, June 14, 2016 3:16 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shreyansh Jain <[email protected]>; David Hunt <[email protected]>
Subject: [PATCH v10 2/3] app/test: test external mempool manager
Quoted 5 lines
Use a minimal custom mempool external ops and check that it also passes basic mempool autotests.
Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>
PATCH v10 3/3 mbuf: make default mempool ops configurable at build
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
Re: [PATCH v10 3/3] mbuf: make default mempool ops configurable at build
Quoted 9 lines
-----Original Message-----
From: David Hunt [mailto:[email protected]]
Sent: Tuesday, June 14, 2016 3:16 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shreyansh Jain <[email protected]>; David Hunt <[email protected]>
Subject: [PATCH v10 3/3] mbuf: make default mempool ops configurable at build
Quoted 8 lines
By default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for
RTE_MBUF_DEFAULT_MEMPOOL_OPS.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>
Re: [PATCH v10 0/3] mempool: add external mempool manager
In reply to David HuntQuoted 5 lines · David Hunt
Here's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 14/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
Thanks David for working on this!
Series
v11 cover mempool: add external mempool manager
In reply to David HuntHere's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 14/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v11 changes:
* Fixed comments (added '.' where needed for consistency)
* removed ABI breakage notice for mempool manager in deprecation.rst
* Added description of the external mempool manager functionality to doc/guides/prog_guide/mempool_lib.rst (John Mc reviewed)
* renamed rte_mempool_default.c to rte_mempool_ring.c
* Kept the v10 ACK from Shreyansh and Olivier for v11
v10 changes:
* changed the _put/_get op names to _enqueue/_dequeue to be consistent with the function names
* some rte_errno cleanup
* comment tweaks about when to set pool_data
* removed an un-needed check for ops->alloc == NULL
v9 changes:
* added a check for NULL alloc in rte_mempool_ops_register
* rte_mempool_alloc_t now returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return -EEXIST in rte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check from rte_mempool_create_empty to rte_mempool_create
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_OPS macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops_byname to create a new mempool using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new rte_mempool_create_empty function, then calling rte_mempool_set_ops_byname to point the mempool to the relevant mempool manager callback structure.
Legacy applications will continue to use the old rte_mempool_create API call, which uses a ring based mempool manager by default. These applications will need to be modified to use a new external mempool manager.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. enqueue - puts an object back into the mempool once an application has
finished with it
3. dequeue - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time an enqueue/dequeue/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
intrte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support external mempool operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test external mempool handler
PATCH v11 1/3 mempool: support external mempool operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_ops_byname() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - doc/guides/prog_guide/mempool_lib.rst | 31 +++- doc/guides/rel_notes/deprecation.rst | 9 -- lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 66 +++----- lib/librte_mempool/rte_mempool.h | 251 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_ops.c | 148 +++++++++++++++++ lib/librte_mempool/rte_mempool_ring.c | 161 ++++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 13 +- 9 files changed, 601 insertions(+), 81 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_ops.c create mode 100644 lib/librte_mempool/rte_mempool_ring.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
doc/guides/prog_guide/mempool_lib.rst +30 -1
@@ -34,7 +34,7 @@ Mempool Library =============== A memory pool is an allocator of a fixed-sized object. -In the DPDK, it is identified by name and uses a ring to store free objects. +In the DPDK, it is identified by name and uses a ring or an external mempool manager to store free objects. It provides some other optional services such as a per-core object cache and an alignment helper to ensure that objects are padded to spread them equally on all DRAM or DDR3 channels.
@@ -127,6 +127,35 @@ The maximum size of the cache is static and is defined at compilation time (CONF A mempool in Memory with its Associated Ring +External Mempool Manager +------------------------ + +This allows external memory subsystems, such as external hardware memory +management systems and software based memory allocators, to be used with DPDK. + +There are two aspects to external mempool manager. + +* Adding the code for your new mempool operations (ops). This is achieved by + adding a new mempool ops code, and using the ``REGISTER_MEMPOOL_OPS`` macro. + +* Using the new API to call ``rte_mempool_create_empty()`` and + ``rte_mempool_set_ops_byname()`` to create a new mempool and specifying which + ops to use. + +Several external mempool managers may be used in the same application. A new +mempool can be created by using the ``rte_mempool_create_empty()`` function, +then using ``rte_mempool_set_ops_byname()`` to point the mempool to the +relevant mempool manager callbacki (ops) structure. + +Legacy applications may continue to use the old ``rte_mempool_create()`` API +call, which uses a ring based mempool manager by default. These applications +will need to be modified to use a new external mempool manager. + +For applications that use ``rte_pktmbuf_create()``, there is a config setting +(``RTE_MBUF_DEFAULT_MEMPOOL_OPS``) that allows the application to make use of +an external mempool manager. + + Use Cases ---------
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -45,15 +45,6 @@ Deprecation Notices compact API. The ones that remain are backwards compatible and use the per-lcore default cache if available. This change targets release 16.07. -* The rte_mempool struct will be changed in 16.07 to facilitate the new - external mempool manager functionality. - The ring element will be replaced with a more generic 'pool' opaque pointer - to allow new mempool handlers to use their own user-defined mempool - layout. Also newly added to rte_mempool is a handler index. - The existing API will be backward compatible, but there will be new API - functions added to facilitate the creation of mempools using an external - handler. The 16.07 release will contain these changes. - * A librte_vhost public structures refactor is planned for DPDK 16.07 that requires both ABI and API change. The proposed refactor would expose DPDK vhost dev to applications as
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +23 -43
126 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +229 -22
307 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +148 -0
148 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ring.c new file +161 -0
161 lines not on this page · raw message
lib/librte_mempool/rte_mempool_version.map +8 -5
@@ -20,15 +20,18 @@ DPDK_16.7 { global: rte_mempool_check_cookies; - rte_mempool_obj_iter; - rte_mempool_mem_iter; rte_mempool_create_empty; + rte_mempool_free; + rte_mempool_mem_iter; + rte_mempool_obj_iter; + rte_mempool_ops_register; + rte_mempool_ops_table; + rte_mempool_populate_anon; + rte_mempool_populate_default; rte_mempool_populate_phys; rte_mempool_populate_phys_tab; rte_mempool_populate_virt; - rte_mempool_populate_default; - rte_mempool_populate_anon; - rte_mempool_free; + rte_mempool_set_ops_byname; local: *; } DPDK_2.0;
Signature · 1 line
2.5.5
Re: [PATCH v11 1/3] mempool: support external mempool operations
2016-06-14 16:48, David Hunt:
doc/guides/prog_guide/mempool_lib.rst The maximum size of the cache is static and is defined at compilation time (CONF · line 148
Quoted 4 lines
doc/guides/prog_guide/mempool_lib.rst +4
-0+Several external mempool managers may be used in the same application. A new +mempool can be created by using the ``rte_mempool_create_empty()`` function, +then using ``rte_mempool_set_ops_byname()`` to point the mempool to the +relevant mempool manager callbacki (ops) structure.
vim typo: callbacki
Quoted 5 lines
+/**
+ * Register mempool operations.
+ *
+ * @param h
+ * Pointer to and ops structure to register.
Same error as in v10.
Quoted 6 lines
+ * @return
+ * - >=0: Success; return the index of the ops struct in the table. + * - -EINVAL - some missing callbacks while registering ops struct. + * - -ENOSPC - the maximum number of ops structs has been reached.+ */
+intrte_mempool_ops_register(const struct rte_mempool_ops *ops);
PATCH v11 2/3 app/test: test external mempool manager
In reply to David HuntUse a minimal custom mempool external ops and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-)
app/test/test_mempool.c +120 -2
@@ -83,6 +83,99 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static int +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return -ENOMEM ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; + mp->pool_data = cm; +return 0 ; +} + +static void +custom_mempool_free (struct rte_mempool *mp) +{ +rte_free ((void *)(mp->pool_data)); +} + +static int +custom_mempool_enqueue (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_dequeue (struct rte_mempool *mp,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (const struct rte_mempool *mp) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .enqueue = custom_mempool_enqueue, + .dequeue = custom_mempool_dequeue, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -292,12 +385,14 @@ static int test_mempool_single_consumer(void)* test function for mempool test based on singple consumer and single producer, * can run on one lcore only */ -static int test_mempool_launch_single_consumer (__attribute__((unused))void *arg) +static int +test_mempool_launch_single_consumer (__attribute__((unused))void *arg) {return test_mempool_single_consumer (); } -static void my_mp_init (struct rte_mempool * mp, __attribute__((unused))void * arg) +static void +my_mp_init (struct rte_mempool *mp, __attribute__((unused))void *arg) {printf ("mempool name is %s\n" , mp->name);/* nothing to be implemented here*/
@@ -477,6 +572,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +601,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +662,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
PATCH v11 3/3 mbuf: make default mempool ops configurable at build
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
v12 cover mempool: add external mempool manager
In reply to David HuntHere's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 14/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v12 changes:
* Fixed a comment (function pram h -> ops)
* Fixed a typo in mempool docs (callbacki)
v11 changes:
* Fixed comments (added '.' where needed for consistency)
* removed ABI breakage notice for mempool manager in deprecation.rst
* Added description of the external mempool manager functionality to doc/guides/prog_guide/mempool_lib.rst (John Mc reviewed)
* renamed rte_mempool_default.c to rte_mempool_ring.c
v10 changes:
* changed the _put/_get op names to _enqueue/_dequeue to be consistent with the function names
* some rte_errno cleanup
* comment tweaks about when to set pool_data
* removed an un-needed check for ops->alloc == NULL
v9 changes:
* added a check for NULL alloc in rte_mempool_ops_register
* rte_mempool_alloc_t now returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return -EEXIST in rte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check from rte_mempool_create_empty to rte_mempool_create
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_OPS macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops_byname to create a new mempool using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new rte_mempool_create_empty function, then calling rte_mempool_set_ops_byname to point the mempool to the relevant mempool manager callback structure.
Legacy applications will continue to use the old rte_mempool_create API call, which uses a ring based mempool manager by default. These applications will need to be modified to use a new external mempool manager.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. enqueue - puts an object back into the mempool once an application has
finished with it
3. dequeue - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time an enqueue/dequeue/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
intrte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support external mempool operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test external mempool manager
PATCH v12 1/3 mempool: support external mempool operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_ops_byname() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - doc/guides/prog_guide/mempool_lib.rst | 31 +++- doc/guides/rel_notes/deprecation.rst | 9 -- lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 66 +++----- lib/librte_mempool/rte_mempool.h | 251 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_ops.c | 148 +++++++++++++++++ lib/librte_mempool/rte_mempool_ring.c | 161 ++++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 13 +- 9 files changed, 601 insertions(+), 81 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_ops.c create mode 100644 lib/librte_mempool/rte_mempool_ring.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
doc/guides/prog_guide/mempool_lib.rst +30 -1
@@ -34,7 +34,7 @@ Mempool Library =============== A memory pool is an allocator of a fixed-sized object. -In the DPDK, it is identified by name and uses a ring to store free objects. +In the DPDK, it is identified by name and uses a ring or an external mempool manager to store free objects. It provides some other optional services such as a per-core object cache and an alignment helper to ensure that objects are padded to spread them equally on all DRAM or DDR3 channels.
@@ -127,6 +127,35 @@ The maximum size of the cache is static and is defined at compilation time (CONF A mempool in Memory with its Associated Ring +External Mempool Manager +------------------------ + +This allows external memory subsystems, such as external hardware memory +management systems and software based memory allocators, to be used with DPDK. + +There are two aspects to external mempool manager. + +* Adding the code for your new mempool operations (ops). This is achieved by + adding a new mempool ops code, and using the ``REGISTER_MEMPOOL_OPS`` macro. + +* Using the new API to call ``rte_mempool_create_empty()`` and + ``rte_mempool_set_ops_byname()`` to create a new mempool and specifying which + ops to use. + +Several external mempool managers may be used in the same application. A new +mempool can be created by using the ``rte_mempool_create_empty()`` function, +then using ``rte_mempool_set_ops_byname()`` to point the mempool to the +relevant mempool manager callback (ops) structure. + +Legacy applications may continue to use the old ``rte_mempool_create()`` API +call, which uses a ring based mempool manager by default. These applications +will need to be modified to use a new external mempool manager. + +For applications that use ``rte_pktmbuf_create()``, there is a config setting +(``RTE_MBUF_DEFAULT_MEMPOOL_OPS``) that allows the application to make use of +an external mempool manager. + + Use Cases ---------
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -39,15 +39,6 @@ Deprecation Notices compact API. The ones that remain are backwards compatible and use the per-lcore default cache if available. This change targets release 16.07. -* The rte_mempool struct will be changed in 16.07 to facilitate the new - external mempool manager functionality. - The ring element will be replaced with a more generic 'pool' opaque pointer - to allow new mempool handlers to use their own user-defined mempool - layout. Also newly added to rte_mempool is a handler index. - The existing API will be backward compatible, but there will be new API - functions added to facilitate the creation of mempools using an external - handler. The 16.07 release will contain these changes. - * A librte_vhost public structures refactor is planned for DPDK 16.07 that requires both ABI and API change. The proposed refactor would expose DPDK vhost dev to applications as
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +23 -43
126 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +229 -22
307 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +148 -0
148 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ring.c new file +161 -0
161 lines not on this page · raw message
lib/librte_mempool/rte_mempool_version.map +8 -5
@@ -20,15 +20,18 @@ DPDK_16.7 { global: rte_mempool_check_cookies; - rte_mempool_obj_iter; - rte_mempool_mem_iter; rte_mempool_create_empty; + rte_mempool_free; + rte_mempool_mem_iter; + rte_mempool_obj_iter; + rte_mempool_ops_register; + rte_mempool_ops_table; + rte_mempool_populate_anon; + rte_mempool_populate_default; rte_mempool_populate_phys; rte_mempool_populate_phys_tab; rte_mempool_populate_virt; - rte_mempool_populate_default; - rte_mempool_populate_anon; - rte_mempool_free; + rte_mempool_set_ops_byname; local: *; } DPDK_2.0;
Signature · 1 line
2.5.5
Re: [PATCH v12 1/3] mempool: support external mempool operations
Quoted 30 lines · On Wed, 15 Jun 2016 08:47:02 +0100 David Hunt <[email protected]> wrote:
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function
rte_mempool_set_ops_byname()right afterrte_mempool_create_empty()allows the user to change the handler that will be used when populating the mempool.This patch also adds a set of default ops (function callbacks) based on
rte_ring.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>Acked-by Shreyansh Jain <[email protected]>Acked-by Olivier Matz <[email protected]>--- app/test/test_mempool_perf.c | 1 - doc/guides/prog_guide/mempool_lib.rst | 31 +++- doc/guides/rel_notes/deprecation.rst | 9 -- lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 66 +++----- lib/librte_mempool/rte_mempool.h | 251 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_ops.c | 148 +++++++++++++++++ lib/librte_mempool/rte_mempool_ring.c | 161 ++++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 13 +- 9 files changed, 601 insertions(+), 81 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_ops.c create mode 100644 lib/librte_mempool/rte_mempool_ring.c
[...]
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +5
-0+ +/** Array of registered ops structs. */ +extern struct rte_mempool_ops_table rte_mempool_ops_table; + +/**
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 419
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* @internal Get the mempool ops struct from its index. +* +* @param ops_index +* The index of the ops struct in the ops struct table. It must be a valid +* index: (0 <= idx < num_ops). +* @return +* The pointer to the ops struct in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_ops_get (int ops_index)
Shouldn't this function be called rte_mempool_get/find_ops instead?
Jan
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +6
-0+{ +RTE_VERIFY (ops_index <RTE_MEMPOOL_MAX_OPS_IDX ); + +return &rte_mempool_ops_table.ops[ops_index]; +} +
Re: [PATCH v12 1/3] mempool: support external mempool operations
Quoted 3 lines · Jan Viktorin
On Wed, 15 Jun 2016 08:47:02 +0100
David Hunt <[email protected]> wrote:
[...]
Quoted 19 lines
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +5
-0+ +/** Array of registered ops structs. */ +extern struct rte_mempool_ops_table rte_mempool_ops_table; + +/** lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 419
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* @internal Get the mempool ops struct from its index. +* +* @param ops_index +* The index of the ops struct in the ops struct table. It must be a valid +* index: (0 <= idx < num_ops). +* @return +* The pointer to the ops struct in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_ops_get (int ops_index)Shouldn't this function be called rte_mempool_get/find_ops instead?
Jan,
I think at this stage that it's probably OK as it is. :)
Rgds,
Dave.
Re: [PATCH v12 1/3] mempool: support external mempool operations
Quoted 27 lines · David
Quoted 3 lines · Jan Viktorin
On Wed, 15 Jun 2016 08:47:02 +0100
David Hunt <[email protected]> wrote:[...]
Quoted 19 lines
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +5
-0+ +/** Array of registered ops structs. */ +extern struct rte_mempool_ops_table rte_mempool_ops_table; + +/** lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 419
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* @internal Get the mempool ops struct from its index. +* +* @param ops_index +* The index of the ops struct in the ops struct table. It must be a valid +* index: (0 <= idx < num_ops). +* @return +* The pointer to the ops struct in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_ops_get (int ops_index)Shouldn't this function be called rte_mempool_get/find_ops instead?
Quoted 3 lines
Jan,
I think at this stage that it's probably OK as it is. :)
Ok. I just remember some discussion about this. I didn't follow the thread during last days so I wanted to be sure that it's not forgotten.
Jan
Quoted 7 lines
Rgds,
Dave.
Signature · 4 lines
Jan Viktorin E-mail: [email protected] System Architect Web: www.RehiveTech.com RehiveTech Brno, Czech Republic
Re: [PATCH v12 1/3] mempool: support external mempool operations
In reply to Hunt, David2016-06-15 11:29, Hunt, David:
Quoted 26 lines · Jan Viktorin
Quoted 3 lines
On Wed, 15 Jun 2016 08:47:02 +0100
David Hunt <[email protected]> wrote:[...]
Quoted 17 lines
Quoted 6 lines
lib/librte_mempool/rte_mempool.h +5
-0+ +/** Array of registered ops structs. */ +extern struct rte_mempool_ops_table rte_mempool_ops_table; + +/** lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 419
Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10
-0+* @internal Get the mempool ops struct from its index. +* +* @param ops_index +* The index of the ops struct in the ops struct table. It must be a valid +* index: (0 <= idx < num_ops). +* @return +* The pointer to the ops struct in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_ops_get (int ops_index)Shouldn't this function be called rte_mempool_get/find_ops instead?
Quoted 3 lines
Jan,
I think at this stage that it's probably OK as it is. :)
?
What is the justification?
PATCH v12 2/3 app/test: test external mempool manager
In reply to David HuntUse a minimal custom mempool external ops and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-)
app/test/test_mempool.c +120 -2
@@ -83,6 +83,99 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static int +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return -ENOMEM ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; + mp->pool_data = cm; +return 0 ; +} + +static void +custom_mempool_free (struct rte_mempool *mp) +{ +rte_free ((void *)(mp->pool_data)); +} + +static int +custom_mempool_enqueue (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_dequeue (struct rte_mempool *mp,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (const struct rte_mempool *mp) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .enqueue = custom_mempool_enqueue, + .dequeue = custom_mempool_dequeue, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -292,12 +385,14 @@ static int test_mempool_single_consumer(void)* test function for mempool test based on singple consumer and single producer, * can run on one lcore only */ -static int test_mempool_launch_single_consumer (__attribute__((unused))void *arg) +static int +test_mempool_launch_single_consumer (__attribute__((unused))void *arg) {return test_mempool_single_consumer (); } -static void my_mp_init (struct rte_mempool * mp, __attribute__((unused))void * arg) +static void +my_mp_init (struct rte_mempool *mp, __attribute__((unused))void *arg) {printf ("mempool name is %s\n" , mp->name);/* nothing to be implemented here*/
@@ -477,6 +572,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +601,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +662,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
PATCH v12 3/3 mbuf: make default mempool ops configurable at build
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
Re: [PATCH v12 0/3] mempool: add external mempool manager
In reply to David HuntHi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd = open("/dev/uio0" ...);
...rte_mempool *pool = rte_mempool_create_empty(...); rte_mempool_set_ops_byname(pool, "uio_allocator_ops");
I am not sure how to pass the file descriptor pointer. I thought it would be possible by the rte_mempool_alloc but it's not... Is it possible to solve this case?
The allocator is device-specific.
Regards
Jan
Quoted 229 lines · On Wed, 15 Jun 2016 08:47:01 +0100 David Hunt <[email protected]> wrote:
Here's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 14/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v12 changes:
* Fixed a comment (function pram h -> ops)
* Fixed a typo in mempool docs (callbacki)v11 changes:
* Fixed comments (added '.' where needed for consistency)
* removed ABI breakage notice for mempool manager indeprecation.rst
* Added description of the external mempool manager functionality todoc/guides/prog_guide/mempool_lib.rst(John Mc reviewed)
* renamedrte_mempool_default.ctorte_mempool_ring.cv10 changes:
* changed the _put/_get op names to _enqueue/_dequeue to be consistent with the function names
* somerte_errnocleanup
* comment tweaks about when to setpool_data
* removed an un-needed check forops->alloc== NULLv9 changes:
* added a check for NULL alloc in
rte_mempool_ops_register
*rte_mempool_alloc_tnow returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return-EEXISTinrte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check fromrte_mempool_create_emptytorte_mempool_createv8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all berte_mempoolpointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to_freefunction (was inconsistent).
* changedMEMPOOL_F_RING_CREATEDtoMEMPOOL_F_POOL_CREATEDv7 changes:
* Changed
rte_mempool_handler_tabletorte_mempool_ops_table
* Changedhander_idxtoops_indexinrte_mempoolstruct
* Reworked comments inrte_mempool.haround ops functions
* Changedrte_mempool_hander.ctorte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing listv6 changes:
* Moved the flags handling from
rte_mempool_create_emptytorte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamedrte_mempool_handlertorte_mempool_ops
* Added a union for *pool and u64pool_idin structrte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences ofrte_mempool_opsto const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier reviewv5 changes:
* rebasing, as it is dependent on another patch series [1]v4 changes (Olivier Matz):
* remove therte_mempool_create_ext()function. To change the handler, the user has to do the following:
- mp =rte_mempool_create_empty()
-rte_mempool_set_handler(mp, "my_handler")
-rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api ofrte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api ofrte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unusedMEMPOOL_F_INT_HANDLER(note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n)remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused functionrte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front ofrte_tailq_elemrte_mempool_tailq(comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler inmempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen commentsv3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers intorte_mempool_default.c
* moved the example handler out intoapp/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviewsv2 changes:
* There was a lot of duplicate code betweenrte_mempool_xmem_createandrte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* TheRTE_NEXT_ABIdefine is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing
RTE_NEXT_ABIdefs, and the current or next code can be changed with theCONFIG_RTE_NEXT_ABIconfig settingThere are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into thelibrte_mempoollibrary, and using theREGISTER_MEMPOOL_OPSmacro.
2. Using the new API to callrte_mempool_create_emptyandrte_mempool_set_ops_bynameto create a new mempool using the name parameter to identify which ops to use.New API calls added
1. A newrte_mempool_create_empty()function
2.rte_mempool_set_ops_byname()which sets the mempool's ops (functions)
3. Anrte_mempool_populate_default()andrte_mempool_populate_anon()functions which populates the mempool using the relevant opsSeveral external mempool managers may be used in the same application. A new mempool can then be created by using the new
rte_mempool_create_emptyfunction, then callingrte_mempool_set_ops_bynameto point the mempool to the relevant mempool manager callback structure.Legacy applications will continue to use the old
rte_mempool_createAPI call, which uses a ring based mempool manager by default. These applications will need to be modified to use a new external mempool manager.The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. enqueue - puts an object back into the mempool once an application has
finished with it
3. dequeue - gets an object from the mempool for use by the application
4.get_count- gets the number of available objects in the mempool
5. free - frees the mempool memoryEvery time an enqueue/dequeue/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1.
rte_mempool_create_emptystruct
rte_mempool*
rte_mempool_create_empty(const char *name, unsigned n, unsignedelt_size,
unsignedcache_size, unsignedprivate_data_size,
intsocket_id, unsigned flags);2.
rte_mempool_set_ops_byname()int
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name);3.
rte_mempool_populate_default()int
rte_mempool_populate_default(struct rte_mempool *mp);4.
rte_mempool_populate_anon()int
rte_mempool_populate_anon(struct rte_mempool *mp);Please see
rte_mempool.hfor further information on the parameters.The important thing to note is that the mempool ops struct is passed by name to
rte_mempool_set_ops_byname, which looks through the ops struct array to get theops_index, which is then stored in therte_memoolstructure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct
rte_mempool_opsops_sp_mc= {
.name = "ring_sp_mc",
.alloc =rte_mempool_common_ring_alloc,
.enqueue =common_ring_sp_enqueue,
.dequeue =common_ring_mc_dequeue,
.get_count =common_ring_get_count,
.free =common_ring_free,
};And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);For an example of API usage, please see
app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.David Hunt (2):
mempool: support external mempool operations
mbuf: make default mempool ops configurable at buildOlivier Matz (1):
app/test: test external mempool manager
Signature · 4 lines
Jan Viktorin E-mail: [email protected] System Architect Web: www.RehiveTech.com RehiveTech Brno, Czech Republic
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 13 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");
Quoted 8 lines
I am not sure how to pass the file descriptor pointer. I thought it would be possible by the
rte_mempool_allocbut it's not... Is it possible to solve this case?The allocator is device-specific.
Regards
Jan
This particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)
So, the options for this use case are as follows:
1. Use the pool_data to pass data in to the alloc, then set the pool_data pointer before coming back from alloc. (It's a bit of a hack, but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can think of doing this is to
take the *opaque passed into rte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an opaque there in the _populate_ funcs, we're just
reusing it for the alloc.
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Regards,
Dave.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Hi,
Quoted 44 lines · David
Quoted 13 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");Quoted 8 lines
I am not sure how to pass the file descriptor pointer. I thought it would be possible by the
rte_mempool_allocbut it's not... Is it possible to solve this case?The allocator is device-specific.
Regards
JanThis particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)So, the options for this use case are as follows:
1. Use thepool_datato pass data in to the alloc, then set thepool_datapointer before coming back from alloc. (It's a bit of a hack, but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can think of doing this is to
take the *opaque passed intorte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an opaque there in the _populate_ funcs, we're just
reusing it for the alloc.
Quoted 2 lines
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Jan's use-case looks to be relevant.
What about changing:
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name)
into:
rte_mempool_set_ops(struct rte_mempool *mp, const char *name,
void *opaque)
?
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into each mempool_ops manager.
Olivier
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 61 lines · Olivier MATZ
Hi,
Quoted 44 lines · David
Quoted 13 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");Quoted 8 lines
I am not sure how to pass the file descriptor pointer. I thought it would be possible by the
rte_mempool_allocbut it's not... Is it possible to solve this case?The allocator is device-specific.
Regards
JanThis particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)So, the options for this use case are as follows:
1. Use thepool_datato pass data in to the alloc, then set thepool_datapointer before coming back from alloc. (It's a bit of a hack, but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can think of doing this is to
take the *opaque passed intorte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an opaque there in the _populate_ funcs, we're just
reusing it for the alloc.Quoted 2 lines
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Jan's use-case looks to be relevant.
What about changing:
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name)into:
rte_mempool_set_ops(struct
rte_mempool*mp, const char *name,
void *opaque)
Quoted 7 lines
?
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.
Yes, that was another option, which has the additional impact of needing an opaque added to the mempool struct. If we use the opaque from the _populate_ function, we use it straight away in the alloc, no storage needed.
Also, do you think we need to go ahead with this change, or can we add it later as an improvement?
Regards,
Dave.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Hi David,
Quoted 73 lines · David
Quoted 62 lines · Olivier MATZ
Hi,
Quoted 45 lines · David
Quoted 18 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");I am not sure how to pass the file descriptor pointer. I thought it would
be possible by therte_mempool_allocbut it's not... Is it possible to solve this case?Quoted 4 lines
The allocator is device-specific.
Regards
JanThis particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)So, the options for this use case are as follows:
1. Use thepool_datato pass data in to the alloc, then set thepool_datapointer before coming back from alloc. (It's a bit of a hack, but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can think of doing this is to
take the *opaque passed intorte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an opaque there in the _populate_ funcs, we're just
reusing it for the alloc.Quoted 2 lines
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Jan's use-case looks to be relevant.
What about changing:
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name)into:
rte_mempool_set_ops(struct
rte_mempool*mp, const char *name,
void *opaque)Quoted 7 lines
?
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.
Quoted 8 lines
Yes, that was another option, which has the additional impact of needing an opaque added to the mempool struct. If we use the opaque from the _populate_
function, we use it straight away in the alloc, no storage needed.Also, do you think we need to go ahead with this change, or can we add it later as an
improvement?
The opaque in populate_phys() is already used for something else (i.e. the argument for the free callback of the memory chunk). I'm afraid it could cause confusion to have it used for 2 different things.
About the change, I think it could be good to have it in 16.11, because it will probably change the API, and we should avoid to change it each version ;)
So I'd vote to have it in the patchset for consistency.
Olivier
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 90 lines · Olivier MATZ
Hi David,
Quoted 73 lines · David
Quoted 62 lines · Olivier MATZ
Hi,
Quoted 45 lines · David
Quoted 18 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");I am not sure how to pass the file descriptor pointer. I thought it would
be possible by therte_mempool_allocbut it's not... Is it possible to solve this case?Quoted 4 lines
The allocator is device-specific.
Regards
JanThis particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)So, the options for this use case are as follows:
1. Use thepool_datato pass data in to the alloc, then set thepool_datapointer before coming back from alloc. (It's a bit of a hack, but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can think of doing this is to
take the *opaque passed intorte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an opaque there in the _populate_ funcs, we're just
reusing it for the alloc.Quoted 2 lines
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Jan's use-case looks to be relevant.
What about changing:
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name)into:
rte_mempool_set_ops(struct
rte_mempool*mp, const char *name,
void *opaque)Quoted 7 lines
?
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Quoted 8 lines
Yes, that was another option, which has the additional impact of needing an opaque added to the mempool struct. If we use the opaque from the _populate_
function, we use it straight away in the alloc, no storage needed.Also, do you think we need to go ahead with this change, or can we add it later as an
improvement?The opaque in
populate_phys()is already used for something else (i.e. the argument for the free callback of the memory chunk). I'm afraid it could cause confusion to have it used for 2 different things.
Quoted 5 lines
About the change, I think it could be good to have it in 16.11, because it will probably change the API, and we should avoid to change it each version ;)
So I'd vote to have it in the patchset for consistency.
Sure, we should avoid breaking API just after we created it. :)
OK, here's a slightly different proposal.
If we add a string, to the _ops_byname, yes, that will work for Jan's case. However, if we add a void*, that allow us the flexibility of passing anything we want. We can then store the void* in the mempool struct as void *pool_config, so that when the alloc gets called, it can access whatever is stored at *pool_config and do the correct initialisation/allocation. In Jan's use case, this can simply be typecast to a string. In future cases, it can be a struct, which could including new flags.
I think that change is minimal enough to be low risk at this stage.
Thoughts?
Dave.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 108 lines · David
Quoted 95 lines · Olivier MATZ
Hi David,
Quoted 83 lines · David
Quoted 66 lines · Olivier MATZ
Hi,
Quoted 49 lines · David
Quoted 18 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");I am not sure how to pass the file descriptor pointer. I thought it would
be possible by therte_mempool_allocbut it's not... Is it possible to solve this case?Quoted 4 lines
The allocator is device-specific.
Regards
JanThis particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did
not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)So, the options for this use case are as follows:
1. Use thepool_datato pass data in to the alloc, then set thepool_datapointer before coming back from alloc. (It's a bit of a hack,
but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can
think of doing this is to
take the *opaque passed intorte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an
opaque there in the _populate_ funcs, we're just
reusing it for the alloc.Quoted 2 lines
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Jan's use-case looks to be relevant.
What about changing:
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name)into:
rte_mempool_set_ops(struct
rte_mempool*mp, const char *name,
void *opaque)Quoted 7 lines
?
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Yes, that was another option, which has the additional impact of needing an
opaque added to the mempool struct. If we use the opaque from the _populate_
function, we use it straight away in the alloc, no storage needed.Quoted 3 lines
Also, do you think we need to go ahead with this change, or can we add it later as an
improvement?The opaque in
populate_phys()is already used for something else (i.e. the argument for the free callback of the memory chunk). I'm afraid it could cause confusion to have it used for 2 different things.Quoted 5 lines
About the change, I think it could be good to have it in 16.11, because it will probably change the API, and we should avoid to change it each version ;)
So I'd vote to have it in the patchset for consistency.
Sure, we should avoid breaking API just after we created it. :)
OK, here's a slightly different proposal.
Quoted 11 lines
If we add a string, to the
_ops_byname, yes, that will work for Jan's case. However, if we add a void*, that allow us the flexibility of passing anything we
want. We can then store the void* in the mempool struct as void*pool_config,
so that when the alloc gets called, it can access whatever is stored at*pool_config
and do the correct initialisation/allocation. In Jan's use case, this can simply be typecast
to a string. In future cases, it can be a struct, which could including new flags.
Yep, agree. But not sure I'm seeing the difference with what I proposed.
Quoted 4 lines
I think that change is minimal enough to be low risk at this stage.
Thoughts?
Agree. Thanks!
Olivier
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 67 lines · On Wed, 15 Jun 2016 16:10:13 +0200 Olivier MATZ <[email protected]> wrote:
Quoted 66 lines · David
Quoted 63 lines · Olivier MATZ
Hi David,
Quoted 60 lines · David
Quoted 57 lines · Olivier MATZ
Hi,
Quoted 49 lines · David
Quoted 18 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");I am not sure how to pass the file descriptor pointer. I thought it would
be possible by therte_mempool_allocbut it's not... Is it possible to solve this case?Quoted 4 lines
The allocator is device-specific.
Regards
JanThis particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did
not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)So, the options for this use case are as follows:
1. Use thepool_datato pass data in to the alloc, then set thepool_datapointer before coming back from alloc. (It's a bit of a hack,
but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can
think of doing this is to
take the *opaque passed intorte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an
opaque there in the _populate_ funcs, we're just
reusing it for the alloc.Quoted 2 lines
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Jan's use-case looks to be relevant.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
What about changing:
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name)into:
rte_mempool_set_ops(struct
rte_mempool*mp, const char *name,
void *opaque)
Or a third function?
rte_mempool_set_ops_arg(struct rte_mempool, *mp, void *arg)
Or isn't it really a task for a kind of rte_mempool_populate_*?
This is a part of mempool I am not involved in yet.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 15 lines
Quoted 8 lines
?
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Yes, that was another option, which has the additional impact of needing an
opaque added to the mempool struct. If we use the opaque from the _populate_
function, we use it straight away in the alloc, no storage needed.Quoted 3 lines
Also, do you think we need to go ahead with this change, or can we add it later as an
improvement?The opaque in
populate_phys()is already used for something else (i.e. the argument for the free callback of the memory chunk). I'm afraid it could cause confusion to have it used for 2 different things.About the change, I think it could be good to have it in 16.11, because it will probably change the API, and we should avoid to change it each version ;)
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
So I'd vote to have it in the patchset for consistency.
Sure, we should avoid breaking API just after we created it. :)
OK, here's a slightly different proposal.
If we add a string, to the
_ops_byname, yes, that will work for Jan's case.
A string? No, I needed to pass a file descriptor or a pointer to some rte_device or something like that. So a void * is a way to go.
Quoted 4 lines
Quoted 4 lines
However, if we add a void*, that allow us the flexibility of passing anything we
want. We can then store the void* in the mempool struct as void*pool_config,
void *ops_context, ops_args, ops_data, ...
Quoted 6 lines
Quoted 6 lines
so that when the alloc gets called, it can access whatever is stored at
*pool_config
and do the correct initialisation/allocation. In Jan's use case, this can simply be typecast
to a string. In future cases, it can be a struct, which could including new flags.
New flags? Does it mean an API extension?
Quoted 3 lines
Yep, agree. But not sure I'm seeing the difference with what I proposed.
Me neither... I think it is exactly the same :).
Jan
Quoted 10 lines
Quoted 5 lines
I think that change is minimal enough to be low risk at this stage.
Thoughts?
Agree. Thanks!
Olivier
Signature · 4 lines
Jan Viktorin E-mail: [email protected] System Architect Web: www.RehiveTech.com RehiveTech Brno, Czech Republic
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 69 lines · Jan Viktorin
Quoted 66 lines · On Wed, 15 Jun 2016 16:10:13 +0200 Olivier MATZ <[email protected]> wrote:
Quoted 65 lines · David
Quoted 63 lines · Olivier MATZ
Hi David,
Quoted 60 lines · David
Quoted 58 lines · Olivier MATZ
Hi,
Quoted 47 lines · David
Quoted 18 lines · Jan Viktorin
Hi,
I've got one last question. Initially, I was interested in creating my own external memory provider based on a Linux Kernel driver. So, I've got an opened file descriptor that points to a device which can mmap a memory regions for me.
...
int fd =open("/dev/uio0" ...);
...rte_mempool*pool =rte_mempool_create_empty(...);rte_mempool_set_ops_byname(pool, "uio_allocator_ops");I am not sure how to pass the file descriptor pointer. I thought it would
be possible by therte_mempool_allocbut it's not... Is it possible to solve this case?Quoted 4 lines
The allocator is device-specific.
Regards
JanThis particular use case is not covered.
We did discuss this before, and an opaque pointer was proposed, but did
not make it in.
http://article.gmane.org/gmane.comp.networking.dpdk.devel/39821
(and following emails in that thread)So, the options for this use case are as follows:
1. Use thepool_datato pass data in to the alloc, then set thepool_datapointer before coming back from alloc. (It's a bit of a hack,
but means no code change).
2. Add an extra parameter to the alloc function. The simplest way I can
think of doing this is to
take the *opaque passed intorte_mempool_populate_phys, and pass it on into the alloc function.
This will have minimal impact on the public API,s as there is already an
opaque there in the _populate_ funcs, we're just
reusing it for the alloc.Quoted 2 lines
Do others think option 2 is OK to add this at this late stage? Even if the patch set has already been ACK'd?
Jan's use-case looks to be relevant.
What about changing:
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name)
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
into:
rte_mempool_set_ops(struct
rte_mempool*mp, const char *name,
void *opaque)Or a third function?
rte_mempool_set_ops_arg(struct rte_mempool, *mp, void *arg)
I think if we tried to add another function, there would be some opposition to that. I think it's reasonable to add it to set_ops_byname, as we're setting the ops and the ops_args in the same call. We use them later in the alloc.
Quoted 2 lines
Or isn't it really a task for a kind of rte_mempool_populate_*?
I was leaning towards that, but a different proposal was suggested. I'm OK with adding the *opaque to set_ops_byname
Quoted 27 lines
This is a part of mempool I am not involved in yet.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 13 lines
Quoted 7 lines
?
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Yes, that was another option, which has the additional impact of needing an
opaque added to the mempool struct. If we use the opaque from the _populate_
function, we use it straight away in the alloc, no storage needed.Quoted 3 lines
Also, do you think we need to go ahead with this change, or can we add it later as an
improvement?The opaque in
populate_phys()is already used for something else (i.e. the argument for the free callback of the memory chunk). I'm afraid it could cause confusion to have it used for 2 different things.About the change, I think it could be good to have it in 16.11, because it will probably change the API, and we should avoid to change it each version ;)
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
So I'd vote to have it in the patchset for consistency.
Sure, we should avoid breaking API just after we created it. :)
OK, here's a slightly different proposal.
If we add a string, to the
_ops_byname, yes, that will work for Jan's case.A string? No, I needed to pass a file descriptor or a pointer to some
rte_deviceor something like that. So a void * is a way to go.
Apologies, I misread. *opaque it is.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
However, if we add a void*, that allow us the flexibility of passing anything we
want. We can then store the void* in the mempool struct as void*pool_config,void
*ops_context,ops_args,ops_data, ...
I think I'll go with ops_args
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
so that when the alloc gets called, it can access whatever is stored at
*pool_config
and do the correct initialisation/allocation. In Jan's use case, this can simply be typecast
to a string. In future cases, it can be a struct, which could including new flags.New flags? Does it mean an API extension?
No, I mean new flags within the opaque data, hidden from the mempool manager.
Quoted 6 lines
Quoted 3 lines
Yep, agree. But not sure I'm seeing the difference with what I proposed.
Me neither... I think it is exactly the same :).
Jan
Yes, misread on my part.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
I think that change is minimal enough to be low risk at this stage.
Thoughts?
Agree. Thanks!
Olivier
Re: [PATCH v12 0/3] mempool: add external mempool manager
In reply to Olivier MATZQuoted 9 lines · Olivier MATZ
[...]
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Olivier
OK, just to be sure before I post another patchset.....
For the rte_mempool_struct:
struct rte_mempool_memhdr_list mem_list; /**< List of memory
chunks */
+ void *ops_args; /**< optional args for ops alloc. */
(at the end of the struct, as it's just on the control path, not to affect fast path)
Then change function params:
int
-rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name); +rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
+ void *ops_args);
And (almost) finally in the rte_mempool_set_ops_byname function:
mp->ops_index = i;
+ mp->ops_args = ops_args;
return 0;Then (actually) finally, add a null to all the calls to rte_mempool_set_ops_byname.
OK? :)
Regards,
Dave.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 16 lines · David
Quoted 9 lines · Olivier MATZ
[...]
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Olivier
OK, just to be sure before I post another patchset.....
Quoted 8 lines
For the
rte_mempool_struct:
structrte_mempool_memhdr_listmem_list; /**< List of memory
chunks */
+ void*ops_args; /**< optional args for ops
alloc. */(at the end of the struct, as it's just on the control path, not to affect fast path)
Hmm, I would put it just after pool_data.
Quoted 8 lines
Then change function params:
int(quoted diff) +2
-1-rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name); +rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, + void *ops_args);And (almost) finally in the
rte_mempool_set_ops_bynamefunction:
Quoted 9 lines
mp->ops_index = i; + mp->ops_args = ops_args; return 0;Then (actually) finally, add a null to all the calls to
rte_mempool_set_ops_byname.OK? :)
Else, looks good to me! Thanks David.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Though I am late to the discussion...
Quoted 34 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Wednesday, June 15, 2016 10:10 PM
To: Hunt, David <[email protected]>; Jan Viktorin <[email protected]>
Cc: [email protected]; [email protected]; Shreyansh Jain <[email protected]>
Subject: Re: [PATCH v12 0/3] mempool: add external mempool managerQuoted 22 lines · David
Quoted 9 lines · Olivier MATZ
[...]
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Olivier
OK, just to be sure before I post another patchset.....
For the
rte_mempool_struct:
structrte_mempool_memhdr_listmem_list; /**< List of memory
chunks */
+ void*ops_args; /**< optional args for ops
alloc. */
Quoted 4 lines
Quoted 2 lines
(at the end of the struct, as it's just on the control path, not to affect fast path)
Hmm, I would put it just after
pool_data.
+1
And, would 'pool_config' (picked from a previous email from David) a better name?
Quoted 1 line
From a user perspective, the application is passing a configuration item to the pool to work one. Only the application and mempool allocator understand it (opaque).
As for 'ops_arg', it would be to control 'assignment-of-operations' to the framework.
Maybe just my point of view.
Quoted 14 lines
Quoted 14 lines
Then change function params:
int(quoted diff) +2
-1-rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name); +rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, + void *ops_args);And (almost) finally in the
rte_mempool_set_ops_bynamefunction:mp->ops_index = i; + mp->ops_args = ops_args; return 0;
Quoted 7 lines
Quoted 5 lines
Then (actually) finally, add a null to all the calls to
rte_mempool_set_ops_byname.OK? :)
Else, looks good to me! Thanks David.
Me too. Though I would like to clarify something for my understanding:
Mempool->pool_data => Used by allocator to store private data Mempool->pool_config => (or ops_arg) used by allocator to access user/app provided value.
Is that correct?
-
Shreyansh
Re: [PATCH v12 0/3] mempool: add external mempool manager
Hi Shreyansh,
Quoted 36 lines · Shreyansh Jain
Though I am late to the discussion...
Quoted 34 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Wednesday, June 15, 2016 10:10 PM
To: Hunt, David <[email protected]>; Jan Viktorin <[email protected]>
Cc: [email protected]; [email protected]; Shreyansh Jain <[email protected]>
Subject: Re: [PATCH v12 0/3] mempool: add external mempool managerQuoted 22 lines · David
Quoted 9 lines · Olivier MATZ
[...]
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Olivier
OK, just to be sure before I post another patchset.....
For the
rte_mempool_struct:
structrte_mempool_memhdr_listmem_list; /**< List of memory
chunks */
+ void*ops_args; /**< optional args for ops
alloc. */(at the end of the struct, as it's just on the control path, not to affect fast path)
Quoted 8 lines
Quoted 1 line
Hmm, I would put it just after
pool_data.+1
And, would 'pool_config' (picked from a previous email from David) a better name?From a user perspective, the application is passing a configuration item to the pool to work one. Only the application and mempool allocator understand it (opaque).
As for 'ops_arg', it would be to control 'assignment-of-operations' to the framework.Maybe just my point of view.
I agree. I was originally happy with pool_config, sits well with pool_data. And it's data for configuring the pool during allocation. I'll go with that, then.
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
Then change function params:
int(quoted diff) +2
-1-rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name); +rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, + void *ops_args);And (almost) finally in the
rte_mempool_set_ops_bynamefunction:mp->ops_index = i; + mp->ops_args = ops_args; return 0;Quoted 6 lines
Quoted 5 lines
Then (actually) finally, add a null to all the calls to
rte_mempool_set_ops_byname.OK? :)
Else, looks good to me! Thanks David.
Quoted 6 lines
Me too. Though I would like to clarify something for my understanding:
Mempool->pool_data=> Used by allocator to store private dataMempool->pool_config=> (orops_arg) used by allocator to access user/app provided value.Is that correct?
Yes, that's correct.
Regard,
David.
Re: [PATCH v12 0/3] mempool: add external mempool manager
In reply to Olivier MATZQuoted 25 lines · Olivier MATZ
Quoted 22 lines · David
Quoted 9 lines · Olivier MATZ
[...]
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Olivier
OK, just to be sure before I post another patchset.....
For the
rte_mempool_struct:
structrte_mempool_memhdr_listmem_list; /**< List of memory
chunks */
+ void*ops_args; /**< optional args for ops
alloc. */
Quoted 5 lines
Quoted 2 lines
(at the end of the struct, as it's just on the control path, not to affect fast path)
Hmm, I would put it just after
pool_data.
When I move it to just after pool data, the performance of the mempool_perf_autotest drops by 2% on my machine for the local cache tests. I think I should leave it where I suggested.
Regards,
David.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 31 lines · David
Quoted 28 lines · Olivier MATZ
Quoted 24 lines · David
Quoted 9 lines · Olivier MATZ
[...]
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Olivier
OK, just to be sure before I post another patchset.....
For the
rte_mempool_struct:
structrte_mempool_memhdr_listmem_list; /**< List of memory
chunks */
+ void*ops_args; /**< optional args for ops
alloc. */(at the end of the struct, as it's just on the control path, not to affect fast path)
Quoted 6 lines
Quoted 2 lines
Hmm, I would put it just after
pool_data.When I move it to just after pool data, the performance of the
mempool_perf_autotestdrops by 2% on my machine for the local cache tests. I think I should leave it where I suggested.
I don't really see what you call control path and data path here. For me, all the fields in mempool structure are not modified once the mempool is initialized.
So I don't think we should have more cache misses whether it's placed at the beginning or at the end. Maybe I'm missing something...
I still believe it's better to group the 2 fields as they are tightly linked together. It could be at the end if you see better performance.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 48 lines · Olivier MATZ
Quoted 31 lines · David
Quoted 28 lines · Olivier MATZ
Quoted 24 lines · David
Quoted 9 lines · Olivier MATZ
[...]
The opaque pointer would be saved in mempool structure, and used when the mempool is populated (calling
mempool_ops_alloc). The type of the structure pointed by the opaque has to be defined (and documented) into eachmempool_opsmanager.Olivier
OK, just to be sure before I post another patchset.....
For the
rte_mempool_struct:
structrte_mempool_memhdr_listmem_list; /**< List of memory
chunks */
+ void*ops_args; /**< optional args for ops
alloc. */(at the end of the struct, as it's just on the control path, not to affect fast path)
Quoted 6 lines
Quoted 2 lines
Hmm, I would put it just after
pool_data.When I move it to just after pool data, the performance of the
mempool_perf_autotestdrops by 2% on my machine for the local cache tests. I think I should leave it where I suggested.I don't really see what you call control path and data path here. For me, all the fields in mempool structure are not modified once the mempool is initialized.
Quoted 7 lines
So I don't think we should have more cache misses whether it's placed at the beginning or at the end. Maybe I'm missing something...
I still believe it's better to group the 2 fields as they are tightly linked together. It could be at the end if you see better performance.
OK, I'll leave at the end because of the performance hit.
Regards,
David.
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 10 lines
Quoted 8 lines
So I don't think we should have more cache misses whether it's placed at the beginning or at the end. Maybe I'm missing something...
I still believe it's better to group the 2 fields as they are tightly linked together. It could be at the end if you see better performance.
OK, I'll leave at the end because of the performance hit.
Sorry, my message was not clear.
I mean, having both at the end. Do you see a performance impact in that case?
Regards
Olivier
Re: [PATCH v12 0/3] mempool: add external mempool manager
Quoted 9 lines · Olivier MATZ
Quoted 9 lines
Quoted 8 lines
So I don't think we should have more cache misses whether it's placed at the beginning or at the end. Maybe I'm missing something...
I still believe it's better to group the 2 fields as they are tightly linked together. It could be at the end if you see better performance.
Quoted 6 lines
Quoted 1 line
OK, I'll leave at the end because of the performance hit.
Sorry, my message was not clear.
I mean, having both at the end. Do you see a performance impact in that case?
I ran multiple more tests, and average drop I'm seeing on an older server reduced to 1% average (local cached use-case), with 0% change on a newer Haswell server, so I think at this stage we're safe to put it up alongside pool_data. There was 0% reduction when I moved both to the bottom of the struct. So on the Haswell, it seems to have minimal impact regardless of where they go.
I'll post the patch up soon.
Regards,
Dave.
v13 cover mempool: add external mempool manager
In reply to David HuntHere's the latest version of the External Mempool Manager patchset. It's re-based on top of the latest head as of 15/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v13 changes:
* Added in extra opaque data (pool_config) to mempool struct for mempool configuration by the ops functions. For example, this can be used to pass device names or device flags to the underlying alloc function.
* Added mempool_config param to rte_mempool_set_ops_byname()
v12 changes:
* Fixed a comment (function pram h -> ops)
* fixed a typo (callbacki)
v11 changes:
* Fixed comments (added '.' where needed for consistency)
* removed ABI breakage notice for mempool manager in deprecation.rst
* Added description of the external mempool manager functionality to doc/guides/prog_guide/mempool_lib.rst (John Mc reviewed)
* renamed rte_mempool_default.c to rte_mempool_ring.c
v10 changes:
* changed the _put/_get op names to _enqueue/_dequeue to be consistent with the function names
* some rte_errno cleanup
* comment tweaks about when to set pool_data
* removed an un-needed check for ops->alloc == NULL
v9 changes:
* added a check for NULL alloc in rte_mempool_ops_register
* rte_mempool_alloc_t now returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return -EEXIST in rte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check from rte_mempool_create_empty to rte_mempool_create
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The External Mempool Manager is an extension to the mempool API that allows users to add and use an external mempool manager, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool manager will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing. These changes are all contained withing RTE_NEXT_ABI defs, and the current or next code can be changed with the CONFIG_RTE_NEXT_ABI config setting
There are two aspects to external mempool manager.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_OPS macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops_byname to create a new mempool using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempool's ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several external mempool managers may be used in the same application. A new mempool can then be created by using the new rte_mempool_create_empty function, then calling rte_mempool_set_ops_byname to point the mempool to the relevant mempool manager callback structure.
Legacy applications will continue to use the old rte_mempool_create API call, which uses a ring based mempool manager by default. These applications will need to be modified to use a new external mempool manager.
The external mempool manager needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. enqueue - puts an object back into the mempool once an application has
finished with it
3. dequeue - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time an enqueue/dequeue/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
int
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name
void *pool_config);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool manager using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support external mempool operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test external mempool handler
PATCH v13 1/3 mempool: support external mempool operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_ops_byname() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - doc/guides/prog_guide/mempool_lib.rst | 31 +++- doc/guides/rel_notes/deprecation.rst | 9 - lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 66 +++----- lib/librte_mempool/rte_mempool.h | 253 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_ops.c | 150 +++++++++++++++++ lib/librte_mempool/rte_mempool_ring.c | 161 ++++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 13 +- 9 files changed, 605 insertions(+), 81 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_ops.c create mode 100644 lib/librte_mempool/rte_mempool_ring.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
doc/guides/prog_guide/mempool_lib.rst +30 -1
@@ -34,7 +34,7 @@ Mempool Library =============== A memory pool is an allocator of a fixed-sized object. -In the DPDK, it is identified by name and uses a ring to store free objects. +In the DPDK, it is identified by name and uses a ring or an external mempool manager to store free objects. It provides some other optional services such as a per-core object cache and an alignment helper to ensure that objects are padded to spread them equally on all DRAM or DDR3 channels.
@@ -127,6 +127,35 @@ The maximum size of the cache is static and is defined at compilation time (CONF A mempool in Memory with its Associated Ring +External Mempool Manager +------------------------ + +This allows external memory subsystems, such as external hardware memory +management systems and software based memory allocators, to be used with DPDK. + +There are two aspects to external mempool manager. + +* Adding the code for your new mempool operations (ops). This is achieved by + adding a new mempool ops code, and using the ``REGISTER_MEMPOOL_OPS`` macro. + +* Using the new API to call ``rte_mempool_create_empty()`` and + ``rte_mempool_set_ops_byname()`` to create a new mempool and specifying which + ops to use. + +Several external mempool managers may be used in the same application. A new +mempool can be created by using the ``rte_mempool_create_empty()`` function, +then using ``rte_mempool_set_ops_byname()`` to point the mempool to the +relevant mempool manager callback (ops) structure. + +Legacy applications may continue to use the old ``rte_mempool_create()`` API +call, which uses a ring based mempool manager by default. These applications +will need to be modified to use a new external mempool manager. + +For applications that use ``rte_pktmbuf_create()``, there is a config setting +(``RTE_MBUF_DEFAULT_MEMPOOL_OPS``) that allows the application to make use of +an external mempool manager. + + Use Cases ---------
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -39,15 +39,6 @@ Deprecation Notices compact API. The ones that remain are backwards compatible and use the per-lcore default cache if available. This change targets release 16.07. -* The rte_mempool struct will be changed in 16.07 to facilitate the new - external mempool manager functionality. - The ring element will be replaced with a more generic 'pool' opaque pointer - to allow new mempool handlers to use their own user-defined mempool - layout. Also newly added to rte_mempool is a handler index. - The existing API will be backward compatible, but there will be new API - functions added to facilitate the creation of mempools using an external - handler. The 16.07 release will contain these changes. - * A librte_vhost public structures refactor is planned for DPDK 16.07 that requires both ABI and API change. The proposed refactor would expose DPDK vhost dev to applications as
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +23 -43
126 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +231 -22
309 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +150 -0
150 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ring.c new file +161 -0
161 lines not on this page · raw message
lib/librte_mempool/rte_mempool_version.map +8 -5
@@ -20,15 +20,18 @@ DPDK_16.7 { global: rte_mempool_check_cookies; - rte_mempool_obj_iter; - rte_mempool_mem_iter; rte_mempool_create_empty; + rte_mempool_free; + rte_mempool_mem_iter; + rte_mempool_obj_iter; + rte_mempool_ops_register; + rte_mempool_ops_table; + rte_mempool_populate_anon; + rte_mempool_populate_default; rte_mempool_populate_phys; rte_mempool_populate_phys_tab; rte_mempool_populate_virt; - rte_mempool_populate_default; - rte_mempool_populate_anon; - rte_mempool_free; + rte_mempool_set_ops_byname; local: *; } DPDK_2.0;
Signature · 1 line
2.5.5
Re: [PATCH v13 1/3] mempool: support external mempool operations
A comment below:
Quoted 10 lines · David Hunt
+/**
+ * Set the ops of a mempool.
+ *
+ * This can only be done on a mempool that is not populated, i.e. just after
+ * a call torte_mempool_create_empty().
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @param name
+ * Name of the ops structure to use for this mempool.
+ * @param pool_config
+ * Opaque data that can be used by the ops functions.
Quoted 9 lines
+ * @return
+ * - 0: Success; the mempool is now using the requested ops functions. + * - -EINVAL - Invalid ops struct name provided. + * - -EEXIST - mempool already has an ops struct assigned.+ */
lib/librte_mempool/rte_mempool.h +4
-0+int +rte_mempool_set_ops_byname (struct rte_mempool *mp,const char *name, +void *pool_config); +
Re: [PATCH v13 1/3] mempool: support external mempool operations
Hi David,
Quoted 16 lines · David
A comment below:
Quoted 11 lines · David Hunt
+/**
+ * Set the ops of a mempool.
+ *
+ * This can only be done on a mempool that is not populated, i.e. just after
+ * a call torte_mempool_create_empty().
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @param name
+ * Name of the ops structure to use for this mempool.+ * @param
pool_config
+ * Opaque data that can be used by the ops functions.
Quoted 11 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 523
Quoted 9 lines
+ * @return
+ * - 0: Success; the mempool is now using the requested ops functions. + * - -EINVAL - Invalid ops struct name provided. + * - -EEXIST - mempool already has an ops struct assigned.+ */
lib/librte_mempool/rte_mempool.h +4
-0+int +rte_mempool_set_ops_byname (struct rte_mempool *mp,const char *name, +void *pool_config); +
The changes related to the pool_config look good to me.
If you plan to do a v14 for this API comment, I'm wondering if the documentation could be slightly modified too. I think "external mempool manager" was the legacy name for the feature, but maybe it could be changed in "alternative mempool handlers" or "changing the mempool handler". I mean the word "external" is probably not appropriate now, especially if we add other handlers in the mempool lib.
My 2 cents,
Olivier
Re: [PATCH v13 1/3] mempool: support external mempool operations
Quoted 38 lines · Olivier Matz
Hi David,
Quoted 16 lines · David
A comment below:
Quoted 11 lines · David Hunt
+/**
+ * Set the ops of a mempool.
+ *
+ * This can only be done on a mempool that is not populated, i.e. just after
+ * a call torte_mempool_create_empty().
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @param name
+ * Name of the ops structure to use for this mempool.+ * @param
pool_config
+ * Opaque data that can be used by the ops functions.Quoted 10 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 523
Quoted 9 lines
+ * @return
+ * - 0: Success; the mempool is now using the requested ops functions. + * - -EINVAL - Invalid ops struct name provided. + * - -EEXIST - mempool already has an ops struct assigned.+ */
lib/librte_mempool/rte_mempool.h +4
-0+int +rte_mempool_set_ops_byname (struct rte_mempool *mp,const char *name, +void *pool_config); +The changes related to the
pool_configlook good to me.If you plan to do a v14 for this API comment, I'm wondering if the documentation could be slightly modified too. I think "external mempool manager" was the legacy name for the feature, but maybe it could be changed in "alternative mempool handlers" or "changing the mempool handler". I mean the word "external" is probably not appropriate now, especially if we add other handlers in the mempool lib.
Quoted 2 lines
My 2 cents,
Olivier
I had not planned on doing another revision. And I think the term "External Mempool Manager" accurately describes the functionality, so I'd really prefer to leave it as it is.
Regards,
David.
Re: [PATCH v13 1/3] mempool: support external mempool operations
2016-06-17 09:42, Hunt, David:
Quoted 40 lines · Olivier Matz
Quoted 38 lines
Hi David,
Quoted 16 lines · David
A comment below:
Quoted 11 lines · David Hunt
+/**
+ * Set the ops of a mempool.
+ *
+ * This can only be done on a mempool that is not populated, i.e. just after
+ * a call torte_mempool_create_empty().
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @param name
+ * Name of the ops structure to use for this mempool.+ * @param
pool_config
+ * Opaque data that can be used by the ops functions.Quoted 10 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 523
Quoted 9 lines
+ * @return
+ * - 0: Success; the mempool is now using the requested ops functions. + * - -EINVAL - Invalid ops struct name provided. + * - -EEXIST - mempool already has an ops struct assigned.+ */
lib/librte_mempool/rte_mempool.h +4
-0+int +rte_mempool_set_ops_byname (struct rte_mempool *mp,const char *name, +void *pool_config); +The changes related to the
pool_configlook good to me.If you plan to do a v14 for this API comment, I'm wondering if the documentation could be slightly modified too. I think "external mempool manager" was the legacy name for the feature, but maybe it could be changed in "alternative mempool handlers" or "changing the mempool handler". I mean the word "external" is probably not appropriate now, especially if we add other handlers in the mempool lib.
Quoted 6 lines
Quoted 2 lines
My 2 cents,
OlivierI had not planned on doing another revision. And I think the term "External Mempool Manager" accurately describes the functionality, so I'd really prefer to leave it as it is.
I think there is no manager, just a default handler which can be changed. I agree the documentation must be fixed.
Re: [PATCH v13 1/3] mempool: support external mempool operations
Quoted 39 lines · Thomas Monjalon
2016-06-17 09:42, Hunt, David:
Quoted 38 lines · Olivier Matz
Quoted 37 lines
Hi David,
Quoted 16 lines · David
A comment below:
Quoted 11 lines · David Hunt
+/**
+ * Set the ops of a mempool.
+ *
+ * This can only be done on a mempool that is not populated, i.e. just after
+ * a call torte_mempool_create_empty().
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @param name
+ * Name of the ops structure to use for this mempool.+ * @param
pool_config
+ * Opaque data that can be used by the ops functions.Quoted 9 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 523
Quoted 9 lines
+ * @return
+ * - 0: Success; the mempool is now using the requested ops functions. + * - -EINVAL - Invalid ops struct name provided. + * - -EEXIST - mempool already has an ops struct assigned.+ */
lib/librte_mempool/rte_mempool.h +4
-0+int +rte_mempool_set_ops_byname (struct rte_mempool *mp,const char *name, +void *pool_config); +The changes related to the
pool_configlook good to me.If you plan to do a v14 for this API comment, I'm wondering if the documentation could be slightly modified too. I think "external mempool manager" was the legacy name for the feature, but maybe it could be changed in "alternative mempool handlers" or "changing the mempool handler". I mean the word "external" is probably not appropriate now, especially if we add other handlers in the mempool lib.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
My 2 cents,
OlivierI had not planned on doing another revision. And I think the term "External Mempool Manager" accurately describes the functionality, so I'd really prefer to leave it as it is.
I think there is no manager, just a default handler which can be changed. I agree the documentation must be fixed.
OK, I have two suggestions to add into the mix.
1. mempool handler framework
or simply
2. mempool handlers. (the alternative is implied). "The mempool handler feature", etc.
Thoughts?
David.
Re: [PATCH v13 1/3] mempool: support external mempool operations
Hi David,
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines
If you plan to do a v14 for this API comment, I'm wondering if the documentation could be slightly modified too. I think "external mempool manager" was the legacy name for the feature, but maybe it could be changed in "alternative mempool handlers" or "changing the mempool handler". I mean the word "external" is probably not appropriate now, especially if we add other handlers in the mempool lib.
My 2 cents,
OlivierI had not planned on doing another revision. And I think the term "External
Mempool Manager" accurately describes the functionality, so I'd really prefer to leave it as it is.
Quoted 8 lines
Quoted 2 lines
I think there is no manager, just a default handler which can be changed. I agree the documentation must be fixed.
OK, I have two suggestions to add into the mix.
1. mempool handler framework
or simply
2. mempool handlers. (the alternative is implied). "The mempool handler feature", etc.
Option 2 is fine for me.
Thanks!
Re: [PATCH v13 1/3] mempool: support external mempool operations
In reply to David HuntHi David,
While testing Lazaros' patch, I found an issue in this series. I the test application is started with --no-huge, it does not work, the mempool_autotest does not work. Please find the exaplanation below:
lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, · line 360
Quoted 13 lines · David Hunt
lib/librte_mempool/rte_mempool.c +3
-3@@ -386,9 +352,9 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,int ret;/* create the internal ring if not already done */ -if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) { - ret =rte_mempool_ring_create (mp); -if (ret <0 ) +if ((mp->flags &MEMPOOL_F_POOL_CREATED ) ==0 ) { + ret =rte_mempool_ops_alloc (mp); +if (ret !=0 )return ret; }
Previously, the function rte_mempool_ring_create(mp) was setting the MEMPOOL_F_RING_CREATED flag. Now it is not set. I think we could set it just after the "return ret".
When started with --no-huge, the mempool memory is allocated in several chunks (one per page), so it tries to allocate the ring for each chunk.
Regards,
Olivier
Re: [PATCH v13 1/3] mempool: support external mempool operations
Quoted 25 lines · Olivier Matz
Hi David,
While testing Lazaros' patch, I found an issue in this series. I the test application is started with --no-huge, it does not work, the
mempool_autotestdoes not work. Please find the exaplanation below:lib/librte_mempool/rte_mempool.c rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, · line 360
Quoted 13 lines · David Hunt
lib/librte_mempool/rte_mempool.c +3
-3@@ -386,9 +352,9 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,int ret;/* create the internal ring if not already done */ -if ((mp->flags &MEMPOOL_F_RING_CREATED ) ==0 ) { - ret =rte_mempool_ring_create (mp); -if (ret <0 ) +if ((mp->flags &MEMPOOL_F_POOL_CREATED ) ==0 ) { + ret =rte_mempool_ops_alloc (mp); +if (ret !=0 )return ret; }Previously, the function
rte_mempool_ring_create(mp)was setting theMEMPOOL_F_RING_CREATEDflag. Now it is not set. I think we could set it just after the "return ret".
Quoted 6 lines
When started with --no-huge, the mempool memory is allocated in several chunks (one per page), so it tries to allocate the ring for each chunk.
Regards,
Olivier
OK, Will do.
ret = rte_mempool_ops_alloc(mp);
if (ret != 0)
return ret;+ mp->flags |= MEMPOOL_F_POOL_CREATED;
Rgds,
Dave.
PATCH v13 2/3 app/test: test external mempool manager
In reply to David HuntUse a minimal custom mempool external ops and check that it also passes basic mempool autotests.
--- app/test/test_mempool.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-)
app/test/test_mempool.c +120 -2
@@ -83,6 +83,99 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static int +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return -ENOMEM ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; + mp->pool_data = cm; +return 0 ; +} + +static void +custom_mempool_free (struct rte_mempool *mp) +{ +rte_free ((void *)(mp->pool_data)); +} + +static int +custom_mempool_enqueue (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_dequeue (struct rte_mempool *mp,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (const struct rte_mempool *mp) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .enqueue = custom_mempool_enqueue, + .dequeue = custom_mempool_dequeue, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -292,12 +385,14 @@ static int test_mempool_single_consumer(void)* test function for mempool test based on singple consumer and single producer, * can run on one lcore only */ -static int test_mempool_launch_single_consumer (__attribute__((unused))void *arg) +static int +test_mempool_launch_single_consumer (__attribute__((unused))void *arg) {return test_mempool_single_consumer (); } -static void my_mp_init (struct rte_mempool * mp, __attribute__((unused))void * arg) +static void +my_mp_init (struct rte_mempool *mp, __attribute__((unused))void *arg) {printf ("mempool name is %s\n" , mp->name);/* nothing to be implemented here*/
@@ -477,6 +572,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +601,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ,NULL ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +662,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
PATCH v13 3/3 mbuf: make default mempool ops configurable at build
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ,NULL ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
v14 cover mempool: add mempool handler feature
In reply to David HuntHere's the latest version of the Mempool Handler feature (previously known as the External Mempool Manager.
It's re-based on top of the latest head as of 17/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v14 changes:
* set MEMPOOL_F_RING_CREATED flag after rte_mempool_ring_create() is called.
* Changed name of feature from "external mempool manager" to "mempool handler" and updated comments and release notes accordingly.
* Added a comment for newly added pool_config param in rte_mempool_set_ops_byname.
v13 changes:
* Added in extra opaque data (pool_config) to mempool struct for mempool configuration by the ops functions. For example, this can be used to pass device names or device flags to the underlying alloc function.
* Added mempool_config param to rte_mempool_set_ops_byname()
v12 changes:
* Fixed a comment (function pram h -> ops)
* fixed a typo (callbacki)
v11 changes:
* Fixed comments (added '.' where needed for consistency)
* removed ABI breakage notice for mempool manager in deprecation.rst
* Added description of the external mempool manager functionality to doc/guides/prog_guide/mempool_lib.rst (John Mc reviewed)
* renamed rte_mempool_default.c to rte_mempool_ring.c
v10 changes:
* changed the _put/_get op names to _enqueue/_dequeue to be consistent with the function names
* some rte_errno cleanup
* comment tweaks about when to set pool_data
* removed an un-needed check for ops->alloc == NULL
v9 changes:
* added a check for NULL alloc in rte_mempool_ops_register
* rte_mempool_alloc_t now returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return -EEXIST in rte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check from rte_mempool_create_empty to rte_mempool_create
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The Mempool Handler feature is an extension to the mempool API that allows users to add and use an alternative mempool handler, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool handler will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing.
There are two aspects to mempool handlers.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_OPS macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops_byname to create a new mempool using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempools ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several mempool handlers may be used in the same application. A new mempool can then be created by using the new rte_mempool_create_empty function, then calling rte_mempool_set_ops_byname to point the mempool to the relevant mempool handler callback (ops) structure.
Legacy applications will continue to use the old rte_mempool_create API call, which uses a ring based mempool handler by default. These applications will need to be modified to use a new mempool handler.
A mempool handler needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. enqueue - puts an object back into the mempool once an application has
finished with it
3. dequeue - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time an enqueue/dequeue/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
int
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name
void *pool_config);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool handler using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support mempool handler operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test mempool handler
PATCH v14 1/3 mempool: support mempool handler operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_ops_byname() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - doc/guides/prog_guide/mempool_lib.rst | 32 +++- doc/guides/rel_notes/deprecation.rst | 9 - lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 67 +++----- lib/librte_mempool/rte_mempool.h | 255 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_ops.c | 150 +++++++++++++++++ lib/librte_mempool/rte_mempool_ring.c | 161 ++++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 13 +- 9 files changed, 609 insertions(+), 81 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_ops.c create mode 100644 lib/librte_mempool/rte_mempool_ring.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
doc/guides/prog_guide/mempool_lib.rst +31 -1
@@ -34,7 +34,8 @@ Mempool Library =============== A memory pool is an allocator of a fixed-sized object. -In the DPDK, it is identified by name and uses a ring to store free objects. +In the DPDK, it is identified by name and uses a mempool handler to store free objects. +The default mempool handler is ring based. It provides some other optional services such as a per-core object cache and an alignment helper to ensure that objects are padded to spread them equally on all DRAM or DDR3 channels.
@@ -127,6 +128,35 @@ The maximum size of the cache is static and is defined at compilation time (CONF A mempool in Memory with its Associated Ring +Mempool Handlers +------------------------ + +This allows external memory subsystems, such as external hardware memory +management systems and software based memory allocators, to be used with DPDK. + +There are two aspects to a mempool handler. + +* Adding the code for your new mempool operations (ops). This is achieved by + adding a new mempool ops code, and using the ``REGISTER_MEMPOOL_OPS`` macro. + +* Using the new API to call ``rte_mempool_create_empty()`` and + ``rte_mempool_set_ops_byname()`` to create a new mempool and specifying which + ops to use. + +Several different mempool handlers may be used in the same application. A new +mempool can be created by using the ``rte_mempool_create_empty()`` function, +then using ``rte_mempool_set_ops_byname()`` to point the mempool to the +relevant mempool handler callback (ops) structure. + +Legacy applications may continue to use the old ``rte_mempool_create()`` API +call, which uses a ring based mempool handler by default. These applications +will need to be modified to use a new mempool handler. + +For applications that use ``rte_pktmbuf_create()``, there is a config setting +(``RTE_MBUF_DEFAULT_MEMPOOL_OPS``) that allows the application to make use of +an alternative mempool handler. + + Use Cases ---------
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -34,15 +34,6 @@ Deprecation Notices compact API. The ones that remain are backwards compatible and use the per-lcore default cache if available. This change targets release 16.07. -* The rte_mempool struct will be changed in 16.07 to facilitate the new - external mempool manager functionality. - The ring element will be replaced with a more generic 'pool' opaque pointer - to allow new mempool handlers to use their own user-defined mempool - layout. Also newly added to rte_mempool is a handler index. - The existing API will be backward compatible, but there will be new API - functions added to facilitate the creation of mempools using an external - handler. The 16.07 release will contain these changes. - * A librte_vhost public structures refactor is planned for DPDK 16.07 that requires both ABI and API change. The proposed refactor would expose DPDK vhost dev to applications as
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +24 -43
128 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +233 -22
311 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +150 -0
150 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ring.c new file +161 -0
161 lines not on this page · raw message
lib/librte_mempool/rte_mempool_version.map +8 -5
@@ -20,15 +20,18 @@ DPDK_16.7 { global: rte_mempool_check_cookies; - rte_mempool_obj_iter; - rte_mempool_mem_iter; rte_mempool_create_empty; + rte_mempool_free; + rte_mempool_mem_iter; + rte_mempool_obj_iter; + rte_mempool_ops_register; + rte_mempool_ops_table; + rte_mempool_populate_anon; + rte_mempool_populate_default; rte_mempool_populate_phys; rte_mempool_populate_phys_tab; rte_mempool_populate_virt; - rte_mempool_populate_default; - rte_mempool_populate_anon; - rte_mempool_free; + rte_mempool_set_ops_byname; local: *; } DPDK_2.0;
Signature · 1 line
2.5.5
Re: [PATCH v14 1/3] mempool: support mempool handler operations
Hi David,
still few nits... Do you like the upstreaming process? :) I hope finish this patchset soon. The major issues seem to be OK.
[...]
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 420
Quoted 12 lines
lib/librte_mempool/rte_mempool.h +12
-0+ +/** +* @internal Get the mempool ops struct from its index. +* +* @param ops_index +* The index of the ops struct in the ops struct table. It must be a valid +* index: (0 <= idx < num_ops). +* @return +* The pointer to the ops struct in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_ops_get (int ops_index)
What about to rename the ops_get to get_ops to not confuse with the ops wrappers? The thread on this topic has not been finished. I think, we can live with this name, it's just a bit weird...
Olivier? Thomas?
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 422
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+{ +RTE_VERIFY (ops_index <RTE_MEMPOOL_MAX_OPS_IDX );
According to the doc comment:
RTE_VERIFY(ops_index >= 0);
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +return &rte_mempool_ops_table.ops[ops_index]; +}
[...]
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 440
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** +* @internal Wrapper for mempool_ops get callback.
This comment is obsolete "get callback" vs. dequeue_bulk.
Quoted 10 lines
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @paramobj_table
+ * Pointer to a table of void * pointers (objects).
+ * @param n
+ * Number of objects to get.
+ * @return
+ * - 0: Success; got n objects.
+ * - <0: Error; code of get function.
"get function" seems to be obsolete, too...
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 463
Quoted 13 lines
+ */
lib/librte_mempool/rte_mempool.h +12
-0+static inline int +rte_mempool_ops_dequeue_bulk (struct rte_mempool *mp, +void **obj_table,unsigned n) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->dequeue (mp, obj_table, n); +} + +/** +* @internal wrapper for mempool_ops put callback.
similar: "put callback"
Quoted 10 lines
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @paramobj_table
+ * Pointer to a table of void * pointers (objects).
+ * @param n
+ * Number of objects to put.
+ * @return
+ * - 0: Success; n objects supplied.
+ * - <0: Error; code of put function.
similar: "put function"
Quoted 11 lines
+ */
lib/librte_mempool/rte_mempool.h +10
-0+static inline int +rte_mempool_ops_enqueue_bulk (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->enqueue (mp, obj_table, n); +} +
[...]
Quoted 19 lines
lib/librte_mempool/rte_mempool_ops.c new file +19
-0+ +/* add a new ops struct in rte_mempool_ops_table, return its index. */ +int +rte_mempool_ops_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + +if (rte_mempool_ops_table.num_ops >= +RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool ops structs exceeded\n" ); +return -ENOSPC ; + } + + if (h->alloc == NULL || h->enqueue == NULL ||
lib/librte_mempool/rte_mempool_ops.c line 74
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+ h->dequeue == NULL || h->get_count == NULL) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Missing callback while registering mempool ops\n" ); +return -EINVAL ; + } + +if (strlen (h->name) >=sizeof (ops->name) -1 ) { +RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , + __func__, h->name);
The unlock is missing here, isn't?
Quoted 24 lines
lib/librte_mempool/rte_mempool_ops.c new file +24
-0+ rte_errno =EEXIST ; +return -EEXIST ; + } + + ops_index = rte_mempool_ops_table.num_ops++; + ops = &rte_mempool_ops_table.ops[ops_index]; +snprintf (ops->name,sizeof (ops->name),"%s" , h->name); + ops->alloc = h->alloc; + ops->enqueue = h->enqueue; + ops->dequeue = h->dequeue; + ops->get_count = h->get_count; + +rte_spinlock_unlock (&rte_mempool_ops_table.sl); + +return ops_index; +} + +/* wrapper to allocate an external mempool's private (pool) data. */ +int +rte_mempool_ops_alloc (struct rte_mempool *mp) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index);
lib/librte_mempool/rte_mempool_ops.c line 108
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c new file +10
-0+return ops->alloc (mp); +} + +/* wrapper to free an external pool ops. */ +void +rte_mempool_ops_free (struct rte_mempool *mp) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index);
I assume there would never be an rte_mempool_ops_unregister. Otherwise this function can return NULL and may lead to a NULL pointer exception.
lib/librte_mempool/rte_mempool_ops.c line 111
Quoted 3 lines
lib/librte_mempool/rte_mempool_ops.c new file +3
-0+if (ops->free ==NULL ) +return ; +return ops->free (mp);
This return statement here is redundant (void).
lib/librte_mempool/rte_mempool_ops.c line 116
Quoted 5 lines
lib/librte_mempool/rte_mempool_ops.c new file +5
-0+} + +/* wrapper to get available objects in an external mempool. */ +unsigned int +rte_mempool_ops_get_count (const struct rte_mempool *mp)
[...]
Regards
Jan
Re: [PATCH v14 1/3] mempool: support mempool handler operations
Quoted 24 lines · Jan Viktorin
Hi David,
still few nits... Do you like the upstreaming process? :) I hope finish this patchset soon. The major issues seem to be OK.
[...]
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 420
Quoted 12 lines
lib/librte_mempool/rte_mempool.h +12
-0+ +/** +* @internal Get the mempool ops struct from its index. +* +* @param ops_index +* The index of the ops struct in the ops struct table. It must be a valid +* index: (0 <= idx < num_ops). +* @return +* The pointer to the ops struct in the table. +*/ +static inline struct rte_mempool_ops * +rte_mempool_ops_get (int ops_index)What about to rename the
ops_gettoget_opsto not confuse with the ops wrappers? The thread on this topic has not been finished. I think, we can live with this name, it's just a bit weird...
Quoted 1 line
Olivier? Thomas?
I'll change it, if you think it's weird.
-rte_mempool_ops_get(int ops_index)
+rte_mempool_get_ops(int ops_index)
Quoted 5 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 422
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+{ +RTE_VERIFY (ops_index <RTE_MEMPOOL_MAX_OPS_IDX );According to the doc comment:
RTE_VERIFY(ops_index >= 0);
Fixed.
- RTE_VERIFY(ops_index < RTE_MEMPOOL_MAX_OPS_IDX);
+ RTE_VERIFY((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
Quoted 9 lines
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +return &rte_mempool_ops_table.ops[ops_index]; +}[...]
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 440
Quoted 3 lines
lib/librte_mempool/rte_mempool.h +3
-0+ +/** +* @internal Wrapper for mempool_ops get callback. This comment is obsolete "get callback" vs.
dequeue_bulk.
Done.
- * @internal Wrapper for mempool_ops get callback.
+ * @internal Wrapper for mempool_ops dequeue callback.
Quoted 11 lines
Quoted 10 lines
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @paramobj_table
+ * Pointer to a table of void * pointers (objects).
+ * @param n
+ * Number of objects to get.
+ * @return
+ * - 0: Success; got n objects.
+ * - <0: Error; code of get function."get function" seems to be obsolete, too...
Done.
- * - <0: Error; code of get function.
+ * - <0: Error; code of dequeue function.
Quoted 6 lines
Quoted 6 lines
+ */
lib/librte_mempool/rte_mempool.h +5
-0+static inline int +rte_mempool_ops_dequeue_bulk (struct rte_mempool *mp, +void **obj_table,unsigned n) +{ +struct rte_mempool_ops *ops;
Quoted 8 lines
lib/librte_mempool/rte_mempool.h void rte_mempool_check_cookies(const struct rte_mempool *mp, · line 463
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +7
-0+ + ops =rte_mempool_ops_get (mp->ops_index); +return ops->dequeue (mp, obj_table, n); +} + +/** +* @internal wrapper for mempool_ops put callback. similar: "put callback"
Done.
- * @internal wrapper for mempool_ops put callback.
+ * @internal wrapper for mempool_ops enqueue callback.
Quoted 11 lines
Quoted 10 lines
+ *
+ * @param mp
+ * Pointer to the memory pool.
+ * @paramobj_table
+ * Pointer to a table of void * pointers (objects).
+ * @param n
+ * Number of objects to put.
+ * @return
+ * - 0: Success; n objects supplied.
+ * - <0: Error; code of put function.similar: "put function"
Done.
- * - <0: Error; code of put function.
+ * - <0: Error; code of enqueue function.
Quoted 35 lines
Quoted 11 lines
+ */
lib/librte_mempool/rte_mempool.h +10
-0+static inline int +rte_mempool_ops_enqueue_bulk (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->enqueue (mp, obj_table, n); +} +[...]
Quoted 22 lines
lib/librte_mempool/rte_mempool_ops.c new file +22
-0+ +/* add a new ops struct in rte_mempool_ops_table, return its index. */ +int +rte_mempool_ops_register (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + +if (rte_mempool_ops_table.num_ops >= +RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); +RTE_LOG (ERR ,MEMPOOL , +"Maximum number of mempool ops structs exceeded\n" ); +return -ENOSPC ; + } + +if (h->alloc ==NULL || h->enqueue ==NULL || + h->dequeue ==NULL || h->get_count ==NULL ) { +rte_spinlock_unlock (&rte_mempool_ops_table.sl); + RTE_LOG(ERR, MEMPOOL,
Quoted 8 lines
lib/librte_mempool/rte_mempool_ops.c line 74
Quoted 7 lines
lib/librte_mempool/rte_mempool_ops.c new file +7
-0+ "Missing callback while registering mempool ops\n"); +return -EINVAL ; + } + +if (strlen (h->name) >=sizeof (ops->name) -1 ) { +RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , + __func__, h->name);The unlock is missing here, isn't?
Yes, well spotted. Fixed.
+ rte_spinlock_unlock(&rte_mempool_ops_table.sl);
Quoted 28 lines
Quoted 28 lines
lib/librte_mempool/rte_mempool_ops.c new file +28
-0+ rte_errno =EEXIST ; +return -EEXIST ; + } + + ops_index = rte_mempool_ops_table.num_ops++; + ops = &rte_mempool_ops_table.ops[ops_index]; +snprintf (ops->name,sizeof (ops->name),"%s" , h->name); + ops->alloc = h->alloc; + ops->enqueue = h->enqueue; + ops->dequeue = h->dequeue; + ops->get_count = h->get_count; + +rte_spinlock_unlock (&rte_mempool_ops_table.sl); + +return ops_index; +} + +/* wrapper to allocate an external mempool's private (pool) data. */ +int +rte_mempool_ops_alloc (struct rte_mempool *mp) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index); +return ops->alloc (mp); +} + +/* wrapper to free an external pool ops. */
Quoted 8 lines
lib/librte_mempool/rte_mempool_ops.c line 108
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c new file +6
-0+void +rte_mempool_ops_free (struct rte_mempool *mp) +{ +struct rte_mempool_ops *ops; + + ops =rte_mempool_ops_get (mp->ops_index);I assume there would never be an
rte_mempool_ops_unregister. Otherwise this function can return NULL and may lead to a NULL pointer exception.
I've put in a check for NULL.
Quoted 4 lines
lib/librte_mempool/rte_mempool_ops.c line 111
Quoted 3 lines
lib/librte_mempool/rte_mempool_ops.c new file +3
-0+if (ops->free ==NULL ) +return ; +return ops->free (mp);This return statement here is redundant (void).
Removed.
Quoted 9 lines
lib/librte_mempool/rte_mempool_ops.c line 116
Quoted 5 lines
lib/librte_mempool/rte_mempool_ops.c new file +5
-0+} + +/* wrapper to get available objects in an external mempool. */ +unsigned int +rte_mempool_ops_get_count (const struct rte_mempool *mp)[...]
Regards
Jan
Regards,
David.
PATCH v14 2/3 app/test: test mempool handler
In reply to David HuntCreate a minimal custom mempool handler and check that it passes basic mempool autotests.
--- app/test/test_mempool.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-)
app/test/test_mempool.c +120 -2
@@ -83,6 +83,99 @@static rte_atomic32_t synchro;/* +* Simple example of custom mempool structure. Holds pointers to all the +* elements which are simply malloc'd in this example. +*/ +struct custom_mempool { +rte_spinlock_t lock; +unsigned count; +unsigned size; +void *elts[]; +}; + +/* +* Loop through all the element pointers and allocate a chunk of memory, then +* insert that memory into the ring. +*/ +static int +custom_mempool_alloc (struct rte_mempool *mp) +{ +struct custom_mempool *cm; + + cm =rte_zmalloc ("custom_mempool" , +sizeof (struct custom_mempool ) + mp->size *sizeof (void *),0 ); +if (cm ==NULL ) +return -ENOMEM ; + +rte_spinlock_init (&cm->lock); + cm->count =0 ; + cm->size = mp->size; + mp->pool_data = cm; +return 0 ; +} + +static void +custom_mempool_free (struct rte_mempool *mp) +{ +rte_free ((void *)(mp->pool_data)); +} + +static int +custom_mempool_enqueue (struct rte_mempool *mp,void *const *obj_table, +unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (cm->count + n > cm->size) { + ret = -ENOBUFS ; + }else { +memcpy (&cm->elts[cm->count], obj_table,sizeof (void *) * n); + cm->count += n; + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + + +static int +custom_mempool_dequeue (struct rte_mempool *mp,void **obj_table,unsigned n) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); +int ret =0 ; + +rte_spinlock_lock (&cm->lock); +if (n > cm->count) { + ret = -ENOENT ; + }else { + cm->count -= n; +memcpy (obj_table, &cm->elts[cm->count],sizeof (void *) * n); + } +rte_spinlock_unlock (&cm->lock); +return ret; +} + +static unsigned +custom_mempool_get_count (const struct rte_mempool *mp) +{ +struct custom_mempool *cm = (struct custom_mempool *)(mp->pool_data); + +return cm->count; +} + +static struct rte_mempool_ops mempool_ops_custom = { + .name ="custom_handler" , + .alloc = custom_mempool_alloc, + .free = custom_mempool_free, + .enqueue = custom_mempool_enqueue, + .dequeue = custom_mempool_dequeue, + .get_count = custom_mempool_get_count, +}; + +MEMPOOL_REGISTER_OPS (mempool_ops_custom); + +/* * save the object number in the first 4 bytes of object data. All * other bytes are set to 0. */
@@ -292,12 +385,14 @@ static int test_mempool_single_consumer(void)* test function for mempool test based on singple consumer and single producer, * can run on one lcore only */ -static int test_mempool_launch_single_consumer (__attribute__((unused))void *arg) +static int +test_mempool_launch_single_consumer (__attribute__((unused))void *arg) {return test_mempool_single_consumer (); } -static void my_mp_init (struct rte_mempool * mp, __attribute__((unused))void * arg) +static void +my_mp_init (struct rte_mempool *mp, __attribute__((unused))void *arg) {printf ("mempool name is %s\n" , mp->name);/* nothing to be implemented here*/
@@ -477,6 +572,7 @@ test_mempool(void) {struct rte_mempool *mp_cache =NULL ;struct rte_mempool *mp_nocache =NULL ; +struct rte_mempool *mp_ext =NULL ;rte_atomic32_init (&synchro);
@@ -505,6 +601,27 @@ test_mempool(void) goto err; } +/* create a mempool with an external handler */ + mp_ext =rte_mempool_create_empty ("test_ext" , +MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE , +RTE_MEMPOOL_CACHE_MAX_SIZE ,0 , +SOCKET_ID_ANY ,0 ); + +if (mp_ext ==NULL ) { +printf ("cannot allocate mp_ext mempool\n" ); + goto err; + } +if (rte_mempool_set_ops_byname (mp_ext,"custom_handler" ,NULL ) <0 ) { +printf ("cannot set custom handler\n" ); + goto err; + } +if (rte_mempool_populate_default (mp_ext) <0 ) { +printf ("cannot populate mp_ext mempool\n" ); + goto err; + } +rte_mempool_obj_iter (mp_ext, my_obj_init,NULL ); +/* retrieve the mempool from its name */ if (rte_mempool_lookup ("test_nocache" ) != mp_nocache) {printf ("Cannot lookup mempool from its name\n" );
@@ -545,6 +662,7 @@ test_mempool(void) err:rte_mempool_free (mp_nocache);rte_mempool_free (mp_cache); +rte_mempool_free (mp_ext);return -1 ; }
Signature · 1 line
2.5.5
Re: [PATCH v14 2/3] app/test: test mempool handler
Quoted 8 lines · On Fri, 17 Jun 2016 14:53:37 +0100 David Hunt <[email protected]> wrote:
Create a minimal custom mempool handler and check that it passes basic mempool autotests.
Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>Acked-by Shreyansh Jain <[email protected]>Acked-by Olivier Matz <[email protected]>---
PATCH v14 3/3 mbuf: make default mempool ops configurable at build
In reply to David HuntBy default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for RTE_MBUF_DEFAULT_MEMPOOL_OPS.
--- config/common_base | 1 + lib/librte_mbuf/rte_mbuf.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-)
config/common_base +1 -0
@@ -394,6 +394,7 @@ CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=n # CONFIG_RTE_LIBRTE_MBUF=y CONFIG_RTE_LIBRTE_MBUF_DEBUG=n +CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS="ring_mp_mc" CONFIG_RTE_MBUF_REFCNT_ATOMIC=y CONFIG_RTE_PKTMBUF_HEADROOM=128
lib/librte_mbuf/rte_mbuf.c +22 -4
@@ -153,6 +153,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id) { + struct rte_mempool *mp;struct rte_pktmbuf_pool_private mbp_priv;unsigned elt_size;
@@ -167,10 +168,27 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, mbp_priv.mbuf_data_room_size = data_room_size; mbp_priv.mbuf_priv_size = priv_size; -return rte_mempool_create (name, n, elt_size, - cache_size,sizeof (struct rte_pktmbuf_pool_private ), - rte_pktmbuf_pool_init, &mbp_priv, rte_pktmbuf_init,NULL , - socket_id,0 ); + mp =rte_mempool_create_empty (name, n, elt_size, cache_size, +sizeof (struct rte_pktmbuf_pool_private ), socket_id,0 ); +if (mp ==NULL ) +return NULL ; + + rte_errno =rte_mempool_set_ops_byname (mp, +RTE_MBUF_DEFAULT_MEMPOOL_OPS ,NULL ); +if (rte_errno !=0 ) { +RTE_LOG (ERR ,MBUF ,"error setting mempool handler\n" ); +return NULL ; + } +rte_pktmbuf_pool_init (mp, &mbp_priv); + +if (rte_mempool_populate_default (mp) <0 ) { +rte_mempool_free (mp); +return NULL ; + } + +rte_mempool_obj_iter (mp, rte_pktmbuf_init,NULL ); + +return mp; }/* do some sanity checks on a mbuf: panic if it fails */
Signature · 1 line
2.5.5
Re: [PATCH v14 3/3] mbuf: make default mempool ops configurable at build
Quoted 11 lines · On Fri, 17 Jun 2016 14:53:38 +0100 David Hunt <[email protected]> wrote:
By default, the mempool ops used for mbuf allocations is a multi producer and multi consumer ring. We could imagine a target (maybe some network processors?) that provides an hardware-assisted pool mechanism. In this case, the default configuration for this architecture would contain a different value for
RTE_MBUF_DEFAULT_MEMPOOL_OPS.Signed-off-by Olivier Matz <[email protected]>Signed-off-by David Hunt <[email protected]>Acked-by Shreyansh Jain <[email protected]>Acked-by Olivier Matz <[email protected]>---
v15 cover mempool: add mempool handler feature
In reply to David HuntHere's the latest version of the Mempool Handler feature patch set.
It's re-based on top of the latest head as of 19/6/2016, including Olivier's 35-part patch series on mempool re-org [1]
[1] http://dpdk.org/ml/archives/dev/2016-May/039229.html
v15 changes:
* Changed rte_mempool_ops_get() to rte_mempool_get_ops()
* Did some minor tweaks to comments after the previous change of function names from put/get to enqueue/dequeue
* Added missing spinlock_unlock in rte_mempool_ops_register()
* Added check for null in ops_free
* removed unneeded return statement
v14 changes:
* set MEMPOOL_F_RING_CREATED flag after rte_mempool_ring_create() is called.
* Changed name of feature from "external mempool manager" to "mempool handler" and updated comments and release notes accordingly.
* Added a comment for newly added pool_config param in rte_mempool_set_ops_byname.
v13 changes:
* Added in extra opaque data (pool_config) to mempool struct for mempool configuration by the ops functions. For example, this can be used to pass device names or device flags to the underlying alloc function.
* Added mempool_config param to rte_mempool_set_ops_byname()
v12 changes:
* Fixed a comment (function pram h -> ops)
* fixed a typo (callbacki)
v11 changes:
* Fixed comments (added '.' where needed for consistency)
* removed ABI breakage notice for mempool manager in deprecation.rst
* Added description of the external mempool manager functionality to doc/guides/prog_guide/mempool_lib.rst (John Mc reviewed)
* renamed rte_mempool_default.c to rte_mempool_ring.c
v10 changes:
* changed the _put/_get op names to _enqueue/_dequeue to be consistent with the function names
* some rte_errno cleanup
* comment tweaks about when to set pool_data
* removed an un-needed check for ops->alloc == NULL
v9 changes:
* added a check for NULL alloc in rte_mempool_ops_register
* rte_mempool_alloc_t now returns int instead of void*
* fixed some comment typo's
* removed some unneeded typecasts
* changed a return NULL to return -EEXIST in rte_mempool_ops_register
* fixed rte_mempool_version.map file so builds ok as shared libs
* moved flags check from rte_mempool_create_empty to rte_mempool_create
v8 changes:
* merged first three patches in the series into one.
* changed parameters to ops callback to all be rte_mempool pointer rather than than pointer to opaque data or uint64.
* comment fixes.
* fixed parameter to _free function (was inconsistent).
* changed MEMPOOL_F_RING_CREATED to MEMPOOL_F_POOL_CREATED
v7 changes:
* Changed rte_mempool_handler_table to rte_mempool_ops_table
* Changed hander_idx to ops_index in rte_mempool struct
* Reworked comments in rte_mempool.h around ops functions
* Changed rte_mempool_hander.c to rte_mempool_ops.c
* Changed all functions containing _handler_ to _ops_
* Now there is no mention of 'handler' left
* Other small changes out of review of mailing list
v6 changes:
* Moved the flags handling from rte_mempool_create_empty to rte_mempool_create, as it's only there for backward compatibility
* Various comment additions and cleanup
* Renamed rte_mempool_handler to rte_mempool_ops
* Added a union for *pool and u64 pool_id in struct rte_mempool
* split the original patch into a few parts for easier review.
* rename functions with _ext_ to _ops_.
* addressed review comments
* renamed put and get functions to enqueue and dequeue
* changed occurences of rte_mempool_ops to const, as they contain function pointers (security)
* split out the default external mempool handler into a separate patch for easier review
v5 changes:
* rebasing, as it is dependent on another patch series [1]
v4 changes (Olivier Matz):
* remove the rte_mempool_create_ext() function. To change the handler, the user has to do the following:
- mp = rte_mempool_create_empty()
- rte_mempool_set_handler(mp, "my_handler")
- rte_mempool_populate_default(mp)
This avoids to add another function with more than 10 arguments, duplicating the doxygen comments
* change the api of rte_mempool_alloc_t: only the mempool pointer is required as all information is available in it
* change the api of rte_mempool_free_t: remove return value
* move inline wrapper functions from the .c to the .h (else they won't be inlined). This implies to have one header file (rte_mempool.h), or it would have generate cross dependencies issues.
* remove now unused MEMPOOL_F_INT_HANDLER (note: it was misused anyway due to the use of && instead of &)
* fix build in debug mode (__MEMPOOL_STAT_ADD(mp, put_pool, n) remaining)
* fix build with shared libraries (global handler has to be declared in the .map file)
* rationalize #include order
* remove unused function rte_mempool_get_handler_name()
* rename some structures, fields, functions
* remove the static in front of rte_tailq_elem rte_mempool_tailq (comment from Yuanhan)
* test the ext mempool handler in the same file than standard mempool tests, avoiding to duplicate the code
* rework the custom handler in mempool_test
* rework a bit the patch selecting default mbuf pool handler
* fix some doxygen comments
v3 changes:
* simplified the file layout, renamed to rte_mempool_handler.[hc]
* moved the default handlers into rte_mempool_default.c
* moved the example handler out into app/test/test_ext_mempool.c
* removed is_mc/is_mp change, slight perf degredation on sp cached operation
* removed stack hanler, may re-introduce at a later date
* Changes out of code reviews
v2 changes:
* There was a lot of duplicate code between rte_mempool_xmem_create and rte_mempool_create_ext. This has now been refactored and is now hopefully cleaner.
* The RTE_NEXT_ABI define is now used to allow building of the library in a format that is compatible with binaries built against previous versions of DPDK.
* Changes out of code reviews. Hopefully I've got most of them included.
The Mempool Handler feature is an extension to the mempool API that allows users to add and use an alternative mempool handler, which allows external memory subsystems such as external hardware memory management systems and software based memory allocators to be used with DPDK.
The existing API to the internal DPDK mempool handler will remain unchanged and will be backward compatible. However, there will be an ABI breakage, as the mempool struct is changing.
There are two aspects to mempool handlers.
1. Adding the code for your new mempool operations (ops). This is achieved by adding a new mempool ops source file into the librte_mempool library, and using the REGISTER_MEMPOOL_OPS macro.
2. Using the new API to call rte_mempool_create_empty and rte_mempool_set_ops_byname to create a new mempool using the name parameter to identify which ops to use.
New API calls added
1. A new rte_mempool_create_empty() function
2. rte_mempool_set_ops_byname() which sets the mempools ops (functions)
3. An rte_mempool_populate_default() and rte_mempool_populate_anon() functions which populates the mempool using the relevant ops
Several mempool handlers may be used in the same application. A new mempool can then be created by using the new rte_mempool_create_empty function, then calling rte_mempool_set_ops_byname to point the mempool to the relevant mempool handler callback (ops) structure.
Legacy applications will continue to use the old rte_mempool_create API call, which uses a ring based mempool handler by default. These applications will need to be modified to use a new mempool handler.
A mempool handler needs to provide the following functions.
1. alloc - allocates the mempool memory, and adds each object onto a ring
2. enqueue - puts an object back into the mempool once an application has
finished with it
3. dequeue - gets an object from the mempool for use by the application
4. get_count - gets the number of available objects in the mempool
5. free - frees the mempool memory
Every time an enqueue/dequeue/get_count is called from the application/PMD, the callback for that mempool is called. These functions are in the fastpath, and any unoptimised ops may limit performance.
The new APIs are as follows:
1. rte_mempool_create_empty
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
int socket_id, unsigned flags);
2. rte_mempool_set_ops_byname()
int
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name
void *pool_config);
3. rte_mempool_populate_default()
int rte_mempool_populate_default(struct rte_mempool *mp);
4. rte_mempool_populate_anon()
int rte_mempool_populate_anon(struct rte_mempool *mp);
Please see rte_mempool.h for further information on the parameters.
The important thing to note is that the mempool ops struct is passed by name to rte_mempool_set_ops_byname, which looks through the ops struct array to get the ops_index, which is then stored in the rte_memool structure. This allow multiple processes to use the same mempool, as the function pointers are accessed via ops index.
The mempool ops structure contains callbacks to the implementation of the ops function, and is set up for registration as follows:
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = rte_mempool_common_ring_alloc,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
.free = common_ring_free,
};
And then the following macro will register the ops in the array of ops structures
REGISTER_MEMPOOL_OPS(ops_mp_mc);
For an example of API usage, please see app/test/test_mempool.c, which implements a rudimentary "custom_handler" mempool handler using simple mallocs for each mempool object. This file also contains the callbacks and self registration for the new handler.
David Hunt (2):
mempool: support mempool handler operations
mbuf: make default mempool ops configurable at build
Olivier Matz (1):
app/test: test mempool handler
PATCH v15 1/3 mempool: support mempool handler operations
Until now, the objects stored in a mempool were internally stored in a ring. This patch introduces the possibility to register external handlers replacing the ring.
The default behavior remains unchanged, but calling the new function rte_mempool_set_ops_byname() right after rte_mempool_create_empty() allows the user to change the handler that will be used when populating the mempool.
This patch also adds a set of default ops (function callbacks) based on rte_ring.
--- app/test/test_mempool_perf.c | 1 - doc/guides/prog_guide/mempool_lib.rst | 32 +++- doc/guides/rel_notes/deprecation.rst | 9 - lib/librte_mempool/Makefile | 2 + lib/librte_mempool/rte_mempool.c | 67 +++----- lib/librte_mempool/rte_mempool.h | 255 ++++++++++++++++++++++++++--- lib/librte_mempool/rte_mempool_ops.c | 150 +++++++++++++++++ lib/librte_mempool/rte_mempool_ring.c | 161 ++++++++++++++++++ lib/librte_mempool/rte_mempool_version.map | 13 +- 9 files changed, 609 insertions(+), 81 deletions(-) create mode 100644 lib/librte_mempool/rte_mempool_ops.c create mode 100644 lib/librte_mempool/rte_mempool_ring.c
app/test/test_mempool_perf.c +0 -1
@@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) n_get_bulk);if (unlikely (ret <0 )) {rte_mempool_dump (stdout, mp); -rte_ring_dump (stdout, mp->ring);/* in this case, objects are lost... */ return -1 ; }
doc/guides/prog_guide/mempool_lib.rst +31 -1
@@ -34,7 +34,8 @@ Mempool Library =============== A memory pool is an allocator of a fixed-sized object. -In the DPDK, it is identified by name and uses a ring to store free objects. +In the DPDK, it is identified by name and uses a mempool handler to store free objects. +The default mempool handler is ring based. It provides some other optional services such as a per-core object cache and an alignment helper to ensure that objects are padded to spread them equally on all DRAM or DDR3 channels.
@@ -127,6 +128,35 @@ The maximum size of the cache is static and is defined at compilation time (CONF A mempool in Memory with its Associated Ring +Mempool Handlers +------------------------ + +This allows external memory subsystems, such as external hardware memory +management systems and software based memory allocators, to be used with DPDK. + +There are two aspects to a mempool handler. + +* Adding the code for your new mempool operations (ops). This is achieved by + adding a new mempool ops code, and using the ``REGISTER_MEMPOOL_OPS`` macro. + +* Using the new API to call ``rte_mempool_create_empty()`` and + ``rte_mempool_set_ops_byname()`` to create a new mempool and specifying which + ops to use. + +Several different mempool handlers may be used in the same application. A new +mempool can be created by using the ``rte_mempool_create_empty()`` function, +then using ``rte_mempool_set_ops_byname()`` to point the mempool to the +relevant mempool handler callback (ops) structure. + +Legacy applications may continue to use the old ``rte_mempool_create()`` API +call, which uses a ring based mempool handler by default. These applications +will need to be modified to use a new mempool handler. + +For applications that use ``rte_pktmbuf_create()``, there is a config setting +(``RTE_MBUF_DEFAULT_MEMPOOL_OPS``) that allows the application to make use of +an alternative mempool handler. + + Use Cases ---------
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -34,15 +34,6 @@ Deprecation Notices compact API. The ones that remain are backwards compatible and use the per-lcore default cache if available. This change targets release 16.07. -* The rte_mempool struct will be changed in 16.07 to facilitate the new - external mempool manager functionality. - The ring element will be replaced with a more generic 'pool' opaque pointer - to allow new mempool handlers to use their own user-defined mempool - layout. Also newly added to rte_mempool is a handler index. - The existing API will be backward compatible, but there will be new API - functions added to facilitate the creation of mempools using an external - handler. The 16.07 release will contain these changes. - * A librte_vhost public structures refactor is planned for DPDK 16.07 that requires both ABI and API change. The proposed refactor would expose DPDK vhost dev to applications as
lib/librte_mempool/Makefile +2 -0
@@ -42,6 +42,8 @@ LIBABIVER := 2 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h
lib/librte_mempool/rte_mempool.c +24 -43
128 lines not on this page · raw message
lib/librte_mempool/rte_mempool.h +233 -22
311 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ops.c new file +150 -0
150 lines not on this page · raw message
lib/librte_mempool/rte_mempool_ring.c new file +161 -0
161 lines not on this page · raw message
lib/librte_mempool/rte_mempool_version.map +8 -5
@@ -20,15 +20,18 @@ DPDK_16.7 { global: rte_mempool_check_cookies; - rte_mempool_obj_iter; - rte_mempool_mem_iter; rte_mempool_create_empty; + rte_mempool_free; + rte_mempool_mem_iter; + rte_mempool_obj_iter; + rte_mempool_ops_register; + rte_mempool_ops_table; + rte_mempool_populate_anon; + rte_mempool_populate_default; rte_mempool_populate_phys; rte_mempool_populate_phys_tab; rte_mempool_populate_virt; - rte_mempool_populate_default; - rte_mempool_populate_anon; - rte_mempool_free; + rte_mempool_set_ops_byname; local: *; } DPDK_2.0;
Signature · 1 line
2.5.5