ring: support configurable element size
Current APIs assume ring elements to be pointers. However, in many use cases, the size can be different. Add new APIs to support configurable ring element sizes. Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com> Reviewed-by: Dharmik Thakkar <dharmik.thakkar@arm.com> Reviewed-by: Gavin Hu <gavin.hu@arm.com> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com> Acked-by: Olivier Matz <olivier.matz@6wind.com>
This commit is contained in:
parent
542cf18b99
commit
cc4b218790
@ -6,7 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
|
||||
# library name
|
||||
LIB = librte_ring.a
|
||||
|
||||
CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
|
||||
CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -DALLOW_EXPERIMENTAL_API
|
||||
LDLIBS += -lrte_eal
|
||||
|
||||
EXPORT_MAP := rte_ring_version.map
|
||||
@ -16,6 +16,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c
|
||||
|
||||
# install includes
|
||||
SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h \
|
||||
rte_ring_elem.h \
|
||||
rte_ring_generic.h \
|
||||
rte_ring_c11_mem.h
|
||||
|
||||
|
@ -3,5 +3,9 @@
|
||||
|
||||
sources = files('rte_ring.c')
|
||||
headers = files('rte_ring.h',
|
||||
'rte_ring_elem.h',
|
||||
'rte_ring_c11_mem.h',
|
||||
'rte_ring_generic.h')
|
||||
|
||||
# rte_ring_create_elem and rte_ring_get_memsize_elem are experimental
|
||||
allow_experimental_apis = true
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <rte_tailq.h>
|
||||
|
||||
#include "rte_ring.h"
|
||||
#include "rte_ring_elem.h"
|
||||
|
||||
TAILQ_HEAD(rte_ring_list, rte_tailq_entry);
|
||||
|
||||
@ -46,23 +47,38 @@ EAL_REGISTER_TAILQ(rte_ring_tailq)
|
||||
|
||||
/* return the size of memory occupied by a ring */
|
||||
ssize_t
|
||||
rte_ring_get_memsize(unsigned count)
|
||||
rte_ring_get_memsize_elem(unsigned int esize, unsigned int count)
|
||||
{
|
||||
ssize_t sz;
|
||||
|
||||
/* Check if element size is a multiple of 4B */
|
||||
if (esize % 4 != 0) {
|
||||
RTE_LOG(ERR, RING, "element size is not a multiple of 4\n");
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* count must be a power of 2 */
|
||||
if ((!POWEROF2(count)) || (count > RTE_RING_SZ_MASK )) {
|
||||
RTE_LOG(ERR, RING,
|
||||
"Requested size is invalid, must be power of 2, and "
|
||||
"do not exceed the size limit %u\n", RTE_RING_SZ_MASK);
|
||||
"Requested number of elements is invalid, must be power of 2, and not exceed %u\n",
|
||||
RTE_RING_SZ_MASK);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
sz = sizeof(struct rte_ring) + count * sizeof(void *);
|
||||
sz = sizeof(struct rte_ring) + count * esize;
|
||||
sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE);
|
||||
return sz;
|
||||
}
|
||||
|
||||
/* return the size of memory occupied by a ring */
|
||||
ssize_t
|
||||
rte_ring_get_memsize(unsigned int count)
|
||||
{
|
||||
return rte_ring_get_memsize_elem(sizeof(void *), count);
|
||||
}
|
||||
|
||||
void
|
||||
rte_ring_reset(struct rte_ring *r)
|
||||
{
|
||||
@ -114,10 +130,10 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* create the ring */
|
||||
/* create the ring for a given element size */
|
||||
struct rte_ring *
|
||||
rte_ring_create(const char *name, unsigned count, int socket_id,
|
||||
unsigned flags)
|
||||
rte_ring_create_elem(const char *name, unsigned int esize, unsigned int count,
|
||||
int socket_id, unsigned int flags)
|
||||
{
|
||||
char mz_name[RTE_MEMZONE_NAMESIZE];
|
||||
struct rte_ring *r;
|
||||
@ -135,7 +151,7 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
|
||||
if (flags & RING_F_EXACT_SZ)
|
||||
count = rte_align32pow2(count + 1);
|
||||
|
||||
ring_size = rte_ring_get_memsize(count);
|
||||
ring_size = rte_ring_get_memsize_elem(esize, count);
|
||||
if (ring_size < 0) {
|
||||
rte_errno = ring_size;
|
||||
return NULL;
|
||||
@ -182,6 +198,15 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
|
||||
return r;
|
||||
}
|
||||
|
||||
/* create the ring */
|
||||
struct rte_ring *
|
||||
rte_ring_create(const char *name, unsigned int count, int socket_id,
|
||||
unsigned int flags)
|
||||
{
|
||||
return rte_ring_create_elem(name, sizeof(void *), count, socket_id,
|
||||
flags);
|
||||
}
|
||||
|
||||
/* free the ring */
|
||||
void
|
||||
rte_ring_free(struct rte_ring *r)
|
||||
|
@ -216,6 +216,7 @@ int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
|
||||
*/
|
||||
struct rte_ring *rte_ring_create(const char *name, unsigned count,
|
||||
int socket_id, unsigned flags);
|
||||
|
||||
/**
|
||||
* De-allocate all memory used by the ring.
|
||||
*
|
||||
|
1003
lib/librte_ring/rte_ring_elem.h
Normal file
1003
lib/librte_ring/rte_ring_elem.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,10 @@ DPDK_20.0 {
|
||||
EXPERIMENTAL {
|
||||
global:
|
||||
|
||||
# added in 19.08
|
||||
rte_ring_reset;
|
||||
|
||||
# added in 20.02
|
||||
rte_ring_create_elem;
|
||||
rte_ring_get_memsize_elem;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user