DPDK
2.0.0
|
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <inttypes.h>
#include <sys/queue.h>
#include <rte_log.h>
#include <rte_debug.h>
#include <rte_lcore.h>
#include <rte_memory.h>
#include <rte_branch_prediction.h>
#include <rte_ring.h>
Data Structures | |
struct | rte_mempool |
Macros | |
#define | RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL |
#define | RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL |
#define | RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL |
#define | RTE_MEMPOOL_NAMESIZE 32 |
#define | MEMPOOL_PG_NUM_DEFAULT 1 |
#define | MEMPOOL_F_NO_SPREAD 0x0001 |
#define | MEMPOOL_F_NO_CACHE_ALIGN 0x0002 |
#define | MEMPOOL_F_SP_PUT 0x0004 |
#define | MEMPOOL_F_SC_GET 0x0008 |
#define | MEMPOOL_HEADER_SIZE(mp, pgn) |
#define | MEMPOOL_IS_CONTIG(mp) |
Typedefs | |
typedef void(* | rte_mempool_obj_iter_t )(void *, void *, void *, uint32_t) |
typedef void( | rte_mempool_obj_ctor_t )(struct rte_mempool *, void *, void *, unsigned) |
typedef void( | rte_mempool_ctor_t )(struct rte_mempool *, void *) |
Functions | |
static struct rte_mempool * | rte_mempool_from_obj (void *obj) |
struct rte_mempool * | rte_mempool_create (const char *name, unsigned n, unsigned elt_size, unsigned cache_size, unsigned private_data_size, rte_mempool_ctor_t *mp_init, void *mp_init_arg, rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg, int socket_id, unsigned flags) |
struct rte_mempool * | rte_mempool_xmem_create (const char *name, unsigned n, unsigned elt_size, unsigned cache_size, unsigned private_data_size, rte_mempool_ctor_t *mp_init, void *mp_init_arg, rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg, int socket_id, unsigned flags, void *vaddr, const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift) |
void | rte_mempool_dump (FILE *f, const struct rte_mempool *mp) |
static void | rte_mempool_mp_put_bulk (struct rte_mempool *mp, void *const *obj_table, unsigned n) |
static void | rte_mempool_sp_put_bulk (struct rte_mempool *mp, void *const *obj_table, unsigned n) |
static void | rte_mempool_put_bulk (struct rte_mempool *mp, void *const *obj_table, unsigned n) |
static void | rte_mempool_mp_put (struct rte_mempool *mp, void *obj) |
static void | rte_mempool_sp_put (struct rte_mempool *mp, void *obj) |
static void | rte_mempool_put (struct rte_mempool *mp, void *obj) |
static int | rte_mempool_mc_get_bulk (struct rte_mempool *mp, void **obj_table, unsigned n) |
static int | rte_mempool_sc_get_bulk (struct rte_mempool *mp, void **obj_table, unsigned n) |
static int | rte_mempool_get_bulk (struct rte_mempool *mp, void **obj_table, unsigned n) |
static int | rte_mempool_mc_get (struct rte_mempool *mp, void **obj_p) |
static int | rte_mempool_sc_get (struct rte_mempool *mp, void **obj_p) |
static int | rte_mempool_get (struct rte_mempool *mp, void **obj_p) |
unsigned | rte_mempool_count (const struct rte_mempool *mp) |
static unsigned | rte_mempool_free_count (const struct rte_mempool *mp) |
static int | rte_mempool_full (const struct rte_mempool *mp) |
static int | rte_mempool_empty (const struct rte_mempool *mp) |
static phys_addr_t | rte_mempool_virt2phy (const struct rte_mempool *mp, const void *elt) |
void | rte_mempool_audit (const struct rte_mempool *mp) |
static void * | rte_mempool_get_priv (struct rte_mempool *mp) |
void | rte_mempool_list_dump (FILE *f) |
struct rte_mempool * | rte_mempool_lookup (const char *name) |
uint32_t | rte_mempool_calc_obj_size (uint32_t elt_size, uint32_t flags, struct rte_mempool_objsz *sz) |
size_t | rte_mempool_xmem_size (uint32_t elt_num, size_t elt_sz, uint32_t pg_shift) |
ssize_t | rte_mempool_xmem_usage (void *vaddr, uint32_t elt_num, size_t elt_sz, const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift) |
void | rte_mempool_walk (void(*func)(const struct rte_mempool *, void *arg), void *arg) |
RTE Mempool.
A memory pool is an allocator of fixed-size object. It is identified by its name, and uses a ring to store free objects. It provides some other optional services, like a per-core object cache, and an alignment helper to ensure that objects are padded to spread them equally on all RAM channels, ranks, and so on.
Objects owned by a mempool should never be added in another mempool. When an object is freed using rte_mempool_put() or equivalent, the object data is not modified; the user can save some meta-data in the object data and retrieve them when allocating a new object.
Note: the mempool implementation is not preemptable. A lcore must not be interrupted by another task that uses the same mempool (because it uses a ring which is not preemptable). Also, mempool functions must not be used outside the DPDK environment: for example, in linuxapp environment, a thread that is not created by the EAL must not use mempools. This is due to the per-lcore cache that won't work as rte_lcore_id() will not return a correct value.
#define MEMPOOL_F_NO_CACHE_ALIGN 0x0002 |
Do not align objs on cache lines.
#define MEMPOOL_F_NO_SPREAD 0x0001 |
Do not spread in memory.
#define MEMPOOL_F_SC_GET 0x0008 |
Default get is "single-consumer".
#define MEMPOOL_F_SP_PUT 0x0004 |
Default put is "single-producer".
#define MEMPOOL_HEADER_SIZE | ( | mp, | |
pgn | |||
) |
Calculates size of the mempool header.
mp | Pointer to the memory pool. |
pgn | Number of page used to store mempool objects. |
#define MEMPOOL_IS_CONTIG | ( | mp | ) |
Returns TRUE if whole mempool is allocated in one contiguous block of memory.
#define MEMPOOL_PG_NUM_DEFAULT 1 |
Mempool over one chunk of physically continuous memory
#define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL |
Header cookie.
#define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL |
Header cookie.
#define RTE_MEMPOOL_NAMESIZE 32 |
Maximum length of a memory pool.
#define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL |
Trailer cookie.
typedef void( rte_mempool_ctor_t)(struct rte_mempool *, void *) |
A mempool constructor callback function.
Arguments are the mempool and the opaque pointer given by the user in rte_mempool_create().
typedef void( rte_mempool_obj_ctor_t)(struct rte_mempool *, void *, void *, unsigned) |
An object constructor callback function for mempool.
Arguments are the mempool, the opaque pointer given by the user in rte_mempool_create(), the pointer to the element and the index of the element in the pool.
typedef void(* rte_mempool_obj_iter_t)(void *, void *, void *, uint32_t) |
An mempool's object iterator callback function.
void rte_mempool_audit | ( | const struct rte_mempool * | mp | ) |
Check the consistency of mempool objects.
Verify the coherency of fields in the mempool structure. Also check that the cookies of mempool objects (even the ones that are not present in pool) have a correct value. If not, a panic will occur.
mp | A pointer to the mempool structure. |
uint32_t rte_mempool_calc_obj_size | ( | uint32_t | elt_size, |
uint32_t | flags, | ||
struct rte_mempool_objsz * | sz | ||
) |
Given a desired size of the mempool element and mempool flags, caluclates header, trailer, body and total sizes of the mempool object.
elt_size | The size of each element. |
flags | The flags used for the mempool creation. Consult rte_mempool_create() for more information about possible values. The size of each element. |
unsigned rte_mempool_count | ( | const struct rte_mempool * | mp | ) |
Return the number of entries in the mempool.
When cache is enabled, this function has to browse the length of all lcores, so it should not be used in a data path, but only for debug purposes.
mp | A pointer to the mempool structure. |
|
read |
Creates a new mempool named name in memory.
This function uses memzone_reserve()
to allocate memory. The pool contains n elements of elt_size. Its size is set to n. All elements of the mempool are allocated together with the mempool header, in one physically continuous chunk of memory.
name | The name of the mempool. |
n | The number of elements in the mempool. The optimum size (in terms of memory usage) for a mempool is when n is a power of two minus one: n = (2^q - 1). |
elt_size | The size of each element. |
cache_size | If cache_size is non-zero, the rte_mempool library will try to limit the accesses to the common lockless pool, by maintaining a per-lcore object cache. This argument must be lower or equal to CONFIG_RTE_MEMPOOL_CACHE_MAX_SIZE. It is advised to choose cache_size to have "n modulo cache_size == 0": if this is not the case, some elements will always stay in the pool and will never be used. The access to the per-lcore table is of course faster than the multi-producer/consumer pool. The cache can be disabled if the cache_size argument is set to 0; it can be useful to avoid losing objects in cache. Note that even if not used, the memory space for cache is always reserved in a mempool structure, except if CONFIG_RTE_MEMPOOL_CACHE_MAX_SIZE is set to 0. |
private_data_size | The size of the private data appended after the mempool structure. This is useful for storing some private data after the mempool structure, as is done for rte_mbuf_pool for example. |
mp_init | A function pointer that is called for initialization of the pool, before object initialization. The user can initialize the private data in this function if needed. This parameter can be NULL if not needed. |
mp_init_arg | An opaque pointer to data that can be used in the mempool constructor function. |
obj_init | A function pointer that is called for each object at initialization of the pool. The user can set some meta data in objects if needed. This parameter can be NULL if not needed. The obj_init() function takes the mempool pointer, the init_arg, the object pointer and the object number as parameters. |
obj_init_arg | An opaque pointer to data that can be used as an argument for each call to the object constructor function. |
socket_id | The socket_id argument is the socket identifier in the case of NUMA. The value can be SOCKET_ID_ANY if there is no NUMA constraint for the reserved zone. |
flags | The flags arguments is an OR of following flags:
|
void rte_mempool_dump | ( | FILE * | f, |
const struct rte_mempool * | mp | ||
) |
Dump the status of the mempool to the console.
f | A pointer to a file for output |
mp | A pointer to the mempool structure. |
|
inlinestatic |
Test if the mempool is empty.
When cache is enabled, this function has to browse the length of all lcores, so it should not be used in a data path, but only for debug purposes.
mp | A pointer to the mempool structure. |
|
inlinestatic |
Return the number of free entries in the mempool ring. i.e. how many entries can be freed back to the mempool.
NOTE: This corresponds to the number of elements allocated from the memory pool, not the number of elements in the pool itself. To count the number elements currently available in the pool, use "rte_mempool_count"
When cache is enabled, this function has to browse the length of all lcores, so it should not be used in a data path, but only for debug purposes.
mp | A pointer to the mempool structure. |
|
staticread |
Return a pointer to the mempool owning this object.
obj | An object that is owned by a pool. If this is not the case, the behavior is undefined. |
|
inlinestatic |
Test if the mempool is full.
When cache is enabled, this function has to browse the length of all lcores, so it should not be used in a data path, but only for debug purposes.
mp | A pointer to the mempool structure. |
|
inlinestatic |
Get one object from the mempool.
This function calls the multi-consumers or the single-consumer version, depending on the default behavior that was specified at mempool creation (see flags).
If cache is enabled, objects will be retrieved first from cache, subsequently from the common pool. Note that it can return -ENOENT when the local cache and common pool are empty, even if cache from other lcores are full.
mp | A pointer to the mempool structure. |
obj_p | A pointer to a void * pointer (object) that will be filled. |
|
inlinestatic |
Get several objects from the mempool.
This function calls the multi-consumers or the single-consumer version, depending on the default behaviour that was specified at mempool creation time (see flags).
If cache is enabled, objects will be retrieved first from cache, subsequently from the common pool. Note that it can return -ENOENT when the local cache and common pool are empty, even if cache from other lcores are full.
mp | A pointer to the mempool structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to get from the mempool to obj_table. |
|
inlinestatic |
Return a pointer to the private data in an mempool structure.
mp | A pointer to the mempool structure. |
void rte_mempool_list_dump | ( | FILE * | f | ) |
Dump the status of all mempools on the console
f | A pointer to a file for output |
|
read |
Search a mempool from its name
name | The name of the mempool. |
|
inlinestatic |
Get one object from the mempool (multi-consumers safe).
If cache is enabled, objects will be retrieved first from cache, subsequently from the common pool. Note that it can return -ENOENT when the local cache and common pool are empty, even if cache from other lcores are full.
mp | A pointer to the mempool structure. |
obj_p | A pointer to a void * pointer (object) that will be filled. |
|
inlinestatic |
Get several objects from the mempool (multi-consumers safe).
If cache is enabled, objects will be retrieved first from cache, subsequently from the common pool. Note that it can return -ENOENT when the local cache and common pool are empty, even if cache from other lcores are full.
mp | A pointer to the mempool structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to get from mempool to obj_table. |
|
inlinestatic |
Put one object in the mempool (multi-producers safe).
mp | A pointer to the mempool structure. |
obj | A pointer to the object to be added. |
|
inlinestatic |
Put several objects back in the mempool (multi-producers safe).
mp | A pointer to the mempool structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the mempool from the obj_table. |
|
inlinestatic |
Put one object back in the mempool.
This function calls the multi-producer or the single-producer version depending on the default behavior that was specified at mempool creation time (see flags).
mp | A pointer to the mempool structure. |
obj | A pointer to the object to be added. |
|
inlinestatic |
Put several objects back in the mempool.
This function calls the multi-producer or the single-producer version depending on the default behavior that was specified at mempool creation time (see flags).
mp | A pointer to the mempool structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the mempool from obj_table. |
|
inlinestatic |
Get one object from the mempool (NOT multi-consumers safe).
If cache is enabled, objects will be retrieved first from cache, subsequently from the common pool. Note that it can return -ENOENT when the local cache and common pool are empty, even if cache from other lcores are full.
mp | A pointer to the mempool structure. |
obj_p | A pointer to a void * pointer (object) that will be filled. |
|
inlinestatic |
Get several objects from the mempool (NOT multi-consumers safe).
If cache is enabled, objects will be retrieved first from cache, subsequently from the common pool. Note that it can return -ENOENT when the local cache and common pool are empty, even if cache from other lcores are full.
mp | A pointer to the mempool structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to get from the mempool to obj_table. |
|
inlinestatic |
Put one object back in the mempool (NOT multi-producers safe).
mp | A pointer to the mempool structure. |
obj | A pointer to the object to be added. |
|
inlinestatic |
Put several objects back in the mempool (NOT multi-producers safe).
mp | A pointer to the mempool structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the mempool from obj_table. |
|
inlinestatic |
Return the physical address of elt, which is an element of the pool mp.
mp | A pointer to the mempool structure. |
elt | A pointer (virtual address) to the element of the pool. |
void rte_mempool_walk | ( | void(*)(const struct rte_mempool *, void *arg) | func, |
void * | arg | ||
) |
Walk list of all memory pools
func | Iterator function |
arg | Argument passed to iterator |
|
read |
Creates a new mempool named name in memory.
This function uses memzone_reserve()
to allocate memory. The pool contains n elements of elt_size. Its size is set to n. Depending on the input parameters, mempool elements can be either allocated together with the mempool header, or an externally provided memory buffer could be used to store mempool objects. In later case, that external memory buffer can consist of set of disjoint phyiscal pages.
name | The name of the mempool. |
n | The number of elements in the mempool. The optimum size (in terms of memory usage) for a mempool is when n is a power of two minus one: n = (2^q - 1). |
elt_size | The size of each element. |
cache_size | If cache_size is non-zero, the rte_mempool library will try to limit the accesses to the common lockless pool, by maintaining a per-lcore object cache. This argument must be lower or equal to CONFIG_RTE_MEMPOOL_CACHE_MAX_SIZE. It is advised to choose cache_size to have "n modulo cache_size == 0": if this is not the case, some elements will always stay in the pool and will never be used. The access to the per-lcore table is of course faster than the multi-producer/consumer pool. The cache can be disabled if the cache_size argument is set to 0; it can be useful to avoid losing objects in cache. Note that even if not used, the memory space for cache is always reserved in a mempool structure, except if CONFIG_RTE_MEMPOOL_CACHE_MAX_SIZE is set to 0. |
private_data_size | The size of the private data appended after the mempool structure. This is useful for storing some private data after the mempool structure, as is done for rte_mbuf_pool for example. |
mp_init | A function pointer that is called for initialization of the pool, before object initialization. The user can initialize the private data in this function if needed. This parameter can be NULL if not needed. |
mp_init_arg | An opaque pointer to data that can be used in the mempool constructor function. |
obj_init | A function pointer that is called for each object at initialization of the pool. The user can set some meta data in objects if needed. This parameter can be NULL if not needed. The obj_init() function takes the mempool pointer, the init_arg, the object pointer and the object number as parameters. |
obj_init_arg | An opaque pointer to data that can be used as an argument for each call to the object constructor function. |
socket_id | The socket_id argument is the socket identifier in the case of NUMA. The value can be SOCKET_ID_ANY if there is no NUMA constraint for the reserved zone. |
flags | The flags arguments is an OR of following flags:
|
vaddr | Virtual address of the externally allocated memory buffer. Will be used to store mempool objects. |
paddr | Array of phyiscall addresses of the pages that comprises given memory buffer. |
pg_num | Number of elements in the paddr array. |
pg_shift | LOG2 of the physical pages size. |
size_t rte_mempool_xmem_size | ( | uint32_t | elt_num, |
size_t | elt_sz, | ||
uint32_t | pg_shift | ||
) |
Calculate maximum amount of memory required to store given number of objects. Assumes that the memory buffer will be aligned at page boundary. Note, that if object size is bigger then page size, then it assumes that we have a subsets of physically continuous pages big enough to store at least one object.
elt_num | Number of elements. |
elt_sz | The size of each element. |
pg_shift | LOG2 of the physical pages size. |
ssize_t rte_mempool_xmem_usage | ( | void * | vaddr, |
uint32_t | elt_num, | ||
size_t | elt_sz, | ||
const phys_addr_t | paddr[], | ||
uint32_t | pg_num, | ||
uint32_t | pg_shift | ||
) |
Calculate how much memory would be actually required with the given memory footprint to store required number of objects.
vaddr | Virtual address of the externally allocated memory buffer. Will be used to store mempool objects. |
elt_num | Number of elements. |
elt_sz | The size of each element. |
paddr | Array of phyiscall addresses of the pages that comprises given memory buffer. |
pg_num | Number of elements in the paddr array. |
pg_shift | LOG2 of the physical pages size. |