ssize_trte_ring_get_memsize(unsignedintcount)
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.
Parameterscount The number of elements in the ring (must be a power of 2).
Returns
• The memory size needed for the ring on success.
• -EINVAL if count is not a power of 2.
intrte_ring_init(structrte_ring*r,constchar*name,unsignedintcount,unsignedintflags)
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. The real usable ring size is count-1 instead
of count to differentiate a full 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.
Parametersr 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, unless RING_F_EXACT_SZ is set in
flags).
flags An OR of the following:
• One of mutually exclusive flags that define producer behavior:
• RING_F_SP_ENQ: If this flag is set, the default behavior when using rte_ring_enqueue()orrte_ring_enqueue_bulk()is'single-producer'.
• RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when using rte_ring_enqueue()orrte_ring_enqueue_bulk()is'multi-producerRTSmode'.
• RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when using rte_ring_enqueue()orrte_ring_enqueue_bulk()is'multi-producerHTSmode'.Ifnoneoftheseflagsisset,thendefault'multi-producer'behaviorisselected.
• One of mutually exclusive flags that define consumer behavior:
• RING_F_SC_DEQ: If this flag is set, the default behavior when using rte_ring_dequeue()orrte_ring_dequeue_bulk()is'single-consumer'.Otherwise,itis'multi-consumers'.
• RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when using rte_ring_dequeue()orrte_ring_dequeue_bulk()is'multi-consumerRTSmode'.
• RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when using rte_ring_dequeue()orrte_ring_dequeue_bulk()is'multi-consumerHTSmode'.Ifnoneoftheseflagsisset,thendefault'multi-consumer'behaviorisselected.
• RING_F_EXACT_SZ: If this flag is set, the ring will hold exactly the requested number of entries,
and the requested size will be rounded up to the next power of two, but the usable space will be
exactly that requested. Worst case, if a power-of-2 size is requested, half the ring space will be
wasted. Without this flag set, the ring size requested must be a power of 2, and the usable space
will be that size - 1.
Returns
0 on success, or a negative value on error.
structrte_ring*rte_ring_create(constchar*name,unsignedintcount,intsocket_id,unsignedintflags)
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. The real usable ring size is count-1
instead of count to differentiate a full ring from an empty ring.
The ring is added in RTE_TAILQ_RING list.
Parametersname The name of the ring.
count The size of the ring (must be a power of 2, unless RING_F_EXACT_SZ is set in flags).
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:
• One of mutually exclusive flags that define producer behavior:
• RING_F_SP_ENQ: If this flag is set, the default behavior when using rte_ring_enqueue()orrte_ring_enqueue_bulk()is'single-producer'.
• RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when using rte_ring_enqueue()orrte_ring_enqueue_bulk()is'multi-producerRTSmode'.
• RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when using rte_ring_enqueue()orrte_ring_enqueue_bulk()is'multi-producerHTSmode'.Ifnoneoftheseflagsisset,thendefault'multi-producer'behaviorisselected.
• One of mutually exclusive flags that define consumer behavior:
• RING_F_SC_DEQ: If this flag is set, the default behavior when using rte_ring_dequeue()orrte_ring_dequeue_bulk()is'single-consumer'.Otherwise,itis'multi-consumers'.
• RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when using rte_ring_dequeue()orrte_ring_dequeue_bulk()is'multi-consumerRTSmode'.
• RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when using rte_ring_dequeue()orrte_ring_dequeue_bulk()is'multi-consumerHTSmode'.Ifnoneoftheseflagsisset,thendefault'multi-consumer'behaviorisselected.
• RING_F_EXACT_SZ: If this flag is set, the ring will hold exactly the requested number of entries,
and the requested size will be rounded up to the next power of two, but the usable space will be
exactly that requested. Worst case, if a power-of-2 size is requested, half the ring space will be
wasted. Without this flag set, the ring size requested must be a power of 2, and the usable space
will be that size - 1.
Returns
On success, the pointer to the new allocated ring. NULL on error with rte_errno set appropriately.
Possible errno values include:
• E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
• EINVAL - count provided is not a power of 2
• ENOSPC - the maximum number of memzones has already been allocated
• EEXIST - a memzone with the same name already exists
• ENOMEM - no appropriate memory area found in which to create memzone
voidrte_ring_free(structrte_ring*r)
De-allocate all memory used by the ring.
Parametersr Ring to free. If NULL then, the function does nothing.
voidrte_ring_dump(FILE*f,conststructrte_ring*r)
Dump the status of the ring to a file.
Parametersf A pointer to a file for output
r A pointer to the ring structure.
static__rte_always_inlineunsignedintrte_ring_mp_enqueue_bulk(structrte_ring*r,void*const*obj_table,unsignedintn,unsignedint*free_space)[static]
Enqueue several objects on the ring (multi-producers safe).
This function uses a 'compare and set' instruction to move the producer index atomically.
Parametersr 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.
Returns
The number of objects enqueued, either 0 or n
Definition at line 226 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_sp_enqueue_bulk(structrte_ring*r,void*const*obj_table,unsignedintn,unsignedint*free_space)[static]
Enqueue several objects on a ring (NOT multi-producers safe).
Parametersr 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.
Returns
The number of objects enqueued, either 0 or n
Definition at line 249 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_enqueue_bulk(structrte_ring*r,void*const*obj_table,unsignedintn,unsignedint*free_space)[static]
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).
Parametersr 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.
Returns
The number of objects enqueued, either 0 or n
Definition at line 276 of file rte_ring.h.
static__rte_always_inlineintrte_ring_mp_enqueue(structrte_ring*r,void*obj)[static]
Enqueue one object on a ring (multi-producers safe).
This function uses a 'compare and set' instruction to move the producer index atomically.
Parametersr A pointer to the ring structure.
obj A pointer to the object to be added.
Returns
• 0: Success; objects enqueued.
• -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
Definition at line 298 of file rte_ring.h.
static__rte_always_inlineintrte_ring_sp_enqueue(structrte_ring*r,void*obj)[static]
Enqueue one object on a ring (NOT multi-producers safe).
Parametersr A pointer to the ring structure.
obj A pointer to the object to be added.
Returns
• 0: Success; objects enqueued.
• -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
Definition at line 315 of file rte_ring.h.
static__rte_always_inlineintrte_ring_enqueue(structrte_ring*r,void*obj)[static]
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).
Parametersr A pointer to the ring structure.
obj A pointer to the object to be added.
Returns
• 0: Success; objects enqueued.
• -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
Definition at line 336 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_mc_dequeue_bulk(structrte_ring*r,void**obj_table,unsignedintn,unsignedint*available)[static]
Dequeue several objects from a ring (multi-consumers safe).
This function uses a 'compare and set' instruction to move the consumer index atomically.
Parametersr 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.
Returns
The number of objects dequeued, either 0 or n
Definition at line 360 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_sc_dequeue_bulk(structrte_ring*r,void**obj_table,unsignedintn,unsignedint*available)[static]
Dequeue several objects from a ring (NOT multi-consumers safe).
Parametersr 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.
Returns
The number of objects dequeued, either 0 or n
Definition at line 384 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_dequeue_bulk(structrte_ring*r,void**obj_table,unsignedintn,unsignedint*available)[static]
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).
Parametersr 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.
Returns
The number of objects dequeued, either 0 or n
Definition at line 411 of file rte_ring.h.
static__rte_always_inlineintrte_ring_mc_dequeue(structrte_ring*r,void**obj_p)[static]
Dequeue one object from a ring (multi-consumers safe).
This function uses a 'compare and set' instruction to move the consumer index atomically.
Parametersr A pointer to the ring structure.
obj_p A pointer to a void * pointer (object) that will be filled.
Returns
• 0: Success; objects dequeued.
• -ENOENT: Not enough entries in the ring to dequeue; no object is dequeued.
Definition at line 434 of file rte_ring.h.
static__rte_always_inlineintrte_ring_sc_dequeue(structrte_ring*r,void**obj_p)[static]
Dequeue one object from a ring (NOT multi-consumers safe).
Parametersr A pointer to the ring structure.
obj_p A pointer to a void * pointer (object) that will be filled.
Returns
• 0: Success; objects dequeued.
• -ENOENT: Not enough entries in the ring to dequeue, no object is dequeued.
Definition at line 452 of file rte_ring.h.
static__rte_always_inlineintrte_ring_dequeue(structrte_ring*r,void**obj_p)[static]
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).
Parametersr A pointer to the ring structure.
obj_p A pointer to a void * pointer (object) that will be filled.
Returns
• 0: Success, objects dequeued.
• -ENOENT: Not enough entries in the ring to dequeue, no object is dequeued.
Definition at line 474 of file rte_ring.h.
voidrte_ring_reset(structrte_ring*r)
Flush a ring.
This function flush all the elements in a ring
Warning
Make sure the ring is not in use while calling this function.
Parametersr A pointer to the ring structure.
staticunsignedintrte_ring_count(conststructrte_ring*r)[inline],[static]
Return the number of entries in a ring.
Parametersr A pointer to the ring structure.
Returns
The number of entries in the ring.
Definition at line 502 of file rte_ring.h.
staticunsignedintrte_ring_free_count(conststructrte_ring*r)[inline],[static]
Return the number of free entries in a ring.
Parametersr A pointer to the ring structure.
Returns
The number of free entries in the ring.
Definition at line 519 of file rte_ring.h.
staticintrte_ring_full(conststructrte_ring*r)[inline],[static]
Test if a ring is full.
Parametersr A pointer to the ring structure.
Returns
• 1: The ring is full.
• 0: The ring is not full.
Definition at line 534 of file rte_ring.h.
staticintrte_ring_empty(conststructrte_ring*r)[inline],[static]
Test if a ring is empty.
Parametersr A pointer to the ring structure.
Returns
• 1: The ring is empty.
• 0: The ring is not empty.
Definition at line 549 of file rte_ring.h.
staticunsignedintrte_ring_get_size(conststructrte_ring*r)[inline],[static]
Return the size of the ring.
Parametersr A pointer to the ring structure.
Returns
The size of the data store used by the ring. NOTE: this is not the same as the usable space in the
ring. To query that use rte_ring_get_capacity().
Definition at line 567 of file rte_ring.h.
staticunsignedintrte_ring_get_capacity(conststructrte_ring*r)[inline],[static]
Return the number of elements which can be stored in the ring.
Parametersr A pointer to the ring structure.
Returns
The usable size of the ring.
Definition at line 581 of file rte_ring.h.
staticenumrte_ring_sync_typerte_ring_get_prod_sync_type(conststructrte_ring*r)[inline],[static]
Return sync type used by producer in the ring.
Parametersr A pointer to the ring structure.
Returns
Producer sync type value.
Definition at line 595 of file rte_ring.h.
staticintrte_ring_is_prod_single(conststructrte_ring*r)[inline],[static]
Check is the ring for single producer.
Parametersr A pointer to the ring structure.
Returns
true if ring is SP, zero otherwise.
Definition at line 609 of file rte_ring.h.
staticenumrte_ring_sync_typerte_ring_get_cons_sync_type(conststructrte_ring*r)[inline],[static]
Return sync type used by consumer in the ring.
Parametersr A pointer to the ring structure.
Returns
Consumer sync type value.
Definition at line 623 of file rte_ring.h.
staticintrte_ring_is_cons_single(conststructrte_ring*r)[inline],[static]
Check is the ring for single consumer.
Parametersr A pointer to the ring structure.
Returns
true if ring is SC, zero otherwise.
Definition at line 637 of file rte_ring.h.
voidrte_ring_list_dump(FILE*f)
Dump the status of all rings on the console
Parametersf A pointer to a file for output
structrte_ring*rte_ring_lookup(constchar*name)
Search a ring from its name
Parametersname The name of the ring.
Returns
The pointer to the ring matching the name, or NULL if not found, with rte_errno set appropriately.
Possible rte_errno values include:
• ENOENT - required entry not available to return.
static__rte_always_inlineunsignedintrte_ring_mp_enqueue_burst(structrte_ring*r,void*const*obj_table,unsignedintn,unsignedint*free_space)[static]
Enqueue several objects on the ring (multi-producers safe).
This function uses a 'compare and set' instruction to move the producer index atomically.
Parametersr 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.
Returns
• n: Actual number of objects enqueued.
Definition at line 681 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_sp_enqueue_burst(structrte_ring*r,void*const*obj_table,unsignedintn,unsignedint*free_space)[static]
Enqueue several objects on a ring (NOT multi-producers safe).
Parametersr 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.
Returns
• n: Actual number of objects enqueued.
Definition at line 704 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_enqueue_burst(structrte_ring*r,void*const*obj_table,unsignedintn,unsignedint*free_space)[static]
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).
Parametersr 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.
Returns
• n: Actual number of objects enqueued.
Definition at line 731 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_mc_dequeue_burst(structrte_ring*r,void**obj_table,unsignedintn,unsignedint*available)[static]
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.
Parametersr 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.
Returns
• n: Actual number of objects dequeued, 0 if ring is empty
Definition at line 759 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_sc_dequeue_burst(structrte_ring*r,void**obj_table,unsignedintn,unsignedint*available)[static]
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
Parametersr 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.
Returns
• n: Actual number of objects dequeued, 0 if ring is empty
Definition at line 784 of file rte_ring.h.
static__rte_always_inlineunsignedintrte_ring_dequeue_burst(structrte_ring*r,void**obj_table,unsignedintn,unsignedint*available)[static]
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).
Parametersr 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.
Returns
• Number of objects dequeued
Definition at line 811 of file rte_ring.h.