DPDK
17.05.2
|
#include <stdio.h>
#include <stdint.h>
#include <sys/queue.h>
#include <errno.h>
#include <rte_common.h>
#include <rte_memory.h>
#include <rte_lcore.h>
#include <rte_atomic.h>
#include <rte_branch_prediction.h>
#include <rte_memzone.h>
Go to the source code of this file.
Data Structures | |
struct | rte_ring |
Macros | |
#define | RTE_RING_MZ_PREFIX "RG_" |
#define | RING_F_SP_ENQ 0x0001 |
#define | RING_F_SC_DEQ 0x0002 |
#define | RTE_RING_SZ_MASK (unsigned)(0x0fffffff) |
Functions | |
ssize_t | rte_ring_get_memsize (unsigned count) |
int | rte_ring_init (struct rte_ring *r, const char *name, unsigned count, unsigned flags) |
struct rte_ring * | rte_ring_create (const char *name, unsigned count, int socket_id, unsigned flags) |
void | rte_ring_free (struct rte_ring *r) |
void | rte_ring_dump (FILE *f, const struct rte_ring *r) |
static unsigned int | rte_ring_mp_enqueue_bulk (struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space) |
static unsigned int | rte_ring_sp_enqueue_bulk (struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space) |
static unsigned int | rte_ring_enqueue_bulk (struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space) |
static int | rte_ring_mp_enqueue (struct rte_ring *r, void *obj) |
static int | rte_ring_sp_enqueue (struct rte_ring *r, void *obj) |
static int | rte_ring_enqueue (struct rte_ring *r, void *obj) |
static unsigned int | rte_ring_mc_dequeue_bulk (struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available) |
static unsigned int | rte_ring_sc_dequeue_bulk (struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available) |
static unsigned int | rte_ring_dequeue_bulk (struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available) |
static int | rte_ring_mc_dequeue (struct rte_ring *r, void **obj_p) |
static int | rte_ring_sc_dequeue (struct rte_ring *r, void **obj_p) |
static int | rte_ring_dequeue (struct rte_ring *r, void **obj_p) |
static int | rte_ring_full (const struct rte_ring *r) |
static int | rte_ring_empty (const struct rte_ring *r) |
static unsigned | rte_ring_count (const struct rte_ring *r) |
static unsigned | rte_ring_free_count (const struct rte_ring *r) |
static unsigned int | rte_ring_get_size (const struct rte_ring *r) |
void | rte_ring_list_dump (FILE *f) |
struct rte_ring * | rte_ring_lookup (const char *name) |
static unsigned | rte_ring_mp_enqueue_burst (struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space) |
static unsigned | rte_ring_sp_enqueue_burst (struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space) |
static unsigned | rte_ring_enqueue_burst (struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space) |
static unsigned | rte_ring_mc_dequeue_burst (struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available) |
static unsigned | rte_ring_sc_dequeue_burst (struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available) |
static unsigned | rte_ring_dequeue_burst (struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available) |
RTE Ring
The Ring Manager is a fixed-size queue, implemented as a table of pointers. Head and tail pointers are modified atomically, allowing concurrent access to it. It has the following features:
Note: the ring implementation is not preemptable. A lcore must not be interrupted by another task that uses the same ring.
Definition in file rte_ring.h.
#define RTE_RING_MZ_PREFIX "RG_" |
The maximum length of a ring name.
Definition at line 112 of file rte_ring.h.
#define RING_F_SP_ENQ 0x0001 |
The default enqueue is "single-producer".
Definition at line 164 of file rte_ring.h.
#define RING_F_SC_DEQ 0x0002 |
The default dequeue is "single-consumer".
Definition at line 165 of file rte_ring.h.
#define RTE_RING_SZ_MASK (unsigned)(0x0fffffff) |
Ring size mask
Definition at line 166 of file rte_ring.h.
ssize_t rte_ring_get_memsize | ( | unsigned | count | ) |
Calculate the memory size needed for a ring
This function returns the number of bytes needed for a ring, given the number of elements in it. This value is the sum of the size of the structure rte_ring and the size of the memory needed by the objects pointers. The value is aligned to a cache line size.
count | The number of elements in the ring (must be a power of 2). |
int rte_ring_init | ( | struct rte_ring * | r, |
const char * | name, | ||
unsigned | count, | ||
unsigned | flags | ||
) |
Initialize a ring structure.
Initialize a ring structure in memory pointed by "r". The size of the memory area must be large enough to store the ring structure and the object table. It is advised to use rte_ring_get_memsize() to get the appropriate size.
The ring size is set to count, which must be a power of two. Water marking is disabled by default. The real usable ring size is count-1 instead of count to differentiate a free ring from an empty ring.
The ring is not added in RTE_TAILQ_RING global list. Indeed, the memory given by the caller may not be shareable among dpdk processes.
r | The pointer to the ring structure followed by the objects table. |
name | The name of the ring. |
count | The number of elements in the ring (must be a power of 2). |
flags | An OR of the following:
|
|
read |
Create a new ring named name in memory.
This function uses memzone_reserve()
to allocate memory. Then it calls rte_ring_init() to initialize an empty ring.
The new ring size is set to count, which must be a power of two. Water marking is disabled by default. The real usable ring size is count-1 instead of count to differentiate a free ring from an empty ring.
The ring is added in RTE_TAILQ_RING list.
name | The name of the ring. |
count | The size of the ring (must be a power of 2). |
socket_id | The socket_id argument is the socket identifier in case of NUMA. The value can be SOCKET_ID_ANY if there is no NUMA constraint for the reserved zone. |
flags | An OR of the following:
|
void rte_ring_free | ( | struct rte_ring * | r | ) |
De-allocate all memory used by the ring.
r | Ring to free |
void rte_ring_dump | ( | FILE * | f, |
const struct rte_ring * | r | ||
) |
Dump the status of the ring to a file.
f | A pointer to a file for output |
r | A pointer to the ring structure. |
|
inlinestatic |
Enqueue several objects on the ring (multi-producers safe).
This function uses a "compare and set" instruction to move the producer index atomically.
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the ring from the obj_table. |
free_space | if non-NULL, returns the amount of space in the ring after the enqueue operation has finished. |
Definition at line 594 of file rte_ring.h.
|
inlinestatic |
Enqueue several objects on a ring (NOT multi-producers safe).
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the ring from the obj_table. |
free_space | if non-NULL, returns the amount of space in the ring after the enqueue operation has finished. |
Definition at line 617 of file rte_ring.h.
|
inlinestatic |
Enqueue several objects on a ring.
This function calls the multi-producer or the single-producer version depending on the default behavior that was specified at ring creation time (see flags).
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the ring from the obj_table. |
free_space | if non-NULL, returns the amount of space in the ring after the enqueue operation has finished. |
Definition at line 644 of file rte_ring.h.
|
inlinestatic |
Enqueue one object on a ring (multi-producers safe).
This function uses a "compare and set" instruction to move the producer index atomically.
r | A pointer to the ring structure. |
obj | A pointer to the object to be added. |
Definition at line 666 of file rte_ring.h.
|
inlinestatic |
Enqueue one object on a ring (NOT multi-producers safe).
r | A pointer to the ring structure. |
obj | A pointer to the object to be added. |
Definition at line 683 of file rte_ring.h.
|
inlinestatic |
Enqueue one object on a ring.
This function calls the multi-producer or the single-producer version, depending on the default behaviour that was specified at ring creation time (see flags).
r | A pointer to the ring structure. |
obj | A pointer to the object to be added. |
Definition at line 704 of file rte_ring.h.
|
inlinestatic |
Dequeue several objects from a ring (multi-consumers safe).
This function uses a "compare and set" instruction to move the consumer index atomically.
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to dequeue from the ring to the obj_table. |
available | If non-NULL, returns the number of remaining ring entries after the dequeue has finished. |
Definition at line 728 of file rte_ring.h.
|
inlinestatic |
Dequeue several objects from a ring (NOT multi-consumers safe).
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to dequeue from the ring to the obj_table, must be strictly positive. |
available | If non-NULL, returns the number of remaining ring entries after the dequeue has finished. |
Definition at line 752 of file rte_ring.h.
|
inlinestatic |
Dequeue several objects from a ring.
This function calls the multi-consumers or the single-consumer version, depending on the default behaviour that was specified at ring creation time (see flags).
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to dequeue from the ring to the obj_table. |
available | If non-NULL, returns the number of remaining ring entries after the dequeue has finished. |
Definition at line 779 of file rte_ring.h.
|
inlinestatic |
Dequeue one object from a ring (multi-consumers safe).
This function uses a "compare and set" instruction to move the consumer index atomically.
r | A pointer to the ring structure. |
obj_p | A pointer to a void * pointer (object) that will be filled. |
Definition at line 802 of file rte_ring.h.
|
inlinestatic |
Dequeue one object from a ring (NOT multi-consumers safe).
r | A pointer to the ring structure. |
obj_p | A pointer to a void * pointer (object) that will be filled. |
Definition at line 820 of file rte_ring.h.
|
inlinestatic |
Dequeue one object from a ring.
This function calls the multi-consumers or the single-consumer version depending on the default behaviour that was specified at ring creation time (see flags).
r | A pointer to the ring structure. |
obj_p | A pointer to a void * pointer (object) that will be filled. |
Definition at line 842 of file rte_ring.h.
|
inlinestatic |
Test if a ring is full.
r | A pointer to the ring structure. |
Definition at line 857 of file rte_ring.h.
|
inlinestatic |
Test if a ring is empty.
r | A pointer to the ring structure. |
Definition at line 874 of file rte_ring.h.
|
inlinestatic |
Return the number of entries in a ring.
r | A pointer to the ring structure. |
Definition at line 890 of file rte_ring.h.
|
inlinestatic |
Return the number of free entries in a ring.
r | A pointer to the ring structure. |
Definition at line 906 of file rte_ring.h.
|
inlinestatic |
Return the size of the ring.
r | A pointer to the ring structure. |
Definition at line 922 of file rte_ring.h.
void rte_ring_list_dump | ( | FILE * | f | ) |
Dump the status of all rings on the console
f | A pointer to a file for output |
|
read |
Search a ring from its name
name | The name of the ring. |
|
inlinestatic |
Enqueue several objects on the ring (multi-producers safe).
This function uses a "compare and set" instruction to move the producer index atomically.
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the ring from the obj_table. |
free_space | if non-NULL, returns the amount of space in the ring after the enqueue operation has finished. |
Definition at line 966 of file rte_ring.h.
|
inlinestatic |
Enqueue several objects on a ring (NOT multi-producers safe).
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the ring from the obj_table. |
free_space | if non-NULL, returns the amount of space in the ring after the enqueue operation has finished. |
Definition at line 989 of file rte_ring.h.
|
inlinestatic |
Enqueue several objects on a ring.
This function calls the multi-producer or the single-producer version depending on the default behavior that was specified at ring creation time (see flags).
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects). |
n | The number of objects to add in the ring from the obj_table. |
free_space | if non-NULL, returns the amount of space in the ring after the enqueue operation has finished. |
Definition at line 1016 of file rte_ring.h.
|
inlinestatic |
Dequeue several objects from a ring (multi-consumers safe). When the request objects are more than the available objects, only dequeue the actual number of objects
This function uses a "compare and set" instruction to move the consumer index atomically.
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to dequeue from the ring to the obj_table. |
available | If non-NULL, returns the number of remaining ring entries after the dequeue has finished. |
Definition at line 1044 of file rte_ring.h.
|
inlinestatic |
Dequeue several objects from a ring (NOT multi-consumers safe).When the request objects are more than the available objects, only dequeue the actual number of objects
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to dequeue from the ring to the obj_table. |
available | If non-NULL, returns the number of remaining ring entries after the dequeue has finished. |
Definition at line 1069 of file rte_ring.h.
|
inlinestatic |
Dequeue multiple objects from a ring up to a maximum number.
This function calls the multi-consumers or the single-consumer version, depending on the default behaviour that was specified at ring creation time (see flags).
r | A pointer to the ring structure. |
obj_table | A pointer to a table of void * pointers (objects) that will be filled. |
n | The number of objects to dequeue from the ring to the obj_table. |
available | If non-NULL, returns the number of remaining ring entries after the dequeue has finished. |
Definition at line 1096 of file rte_ring.h.