generalise rte_ring to allow different datatypes
v2 cover generalise rte_ring to allow different datatypes
Following on from the previous RFC, this generalises the rte_ring structure using C constructs rather than using macros. The idea here is to have the size of the data objects passed in to all common functions and then switching the code paths, where necessary, based on those size parameters. For the standard rte_ring APIs, these work on void pointers, so the extra parameter is always specified as sizeof(void *). A new event_ring type is also added as a patch to test out creating and using rings with different size objects.
Comments welcome on this RFC, though I still hope to try out some other options, as I think there may be still better ways to achieve the same end.
Bruce Richardson (4):
ring: create common ring files
ring: separate common and rte_ring specific functions
ring: allow common ring to use 8 or 16 byte values
ring: add new event ring class
app/test/Makefile | 1 + app/test/test_event_ring.c | 83 ++++ lib/librte_ring/Makefile | 8 +- lib/librte_ring/rte_common_ring.c | 386 ++++++++++++++++ lib/librte_ring/rte_common_ring.h | 925 ++++++++++++++++++++++++++++++++++++++ lib/librte_ring/rte_event_ring.c | 87 ++++ lib/librte_ring/rte_event_ring.h | 696 ++++++++++++++++++++++++++++ lib/librte_ring/rte_ring.c | 320 +------------ lib/librte_ring/rte_ring.h | 606 +------------------------ 9 files changed, 2210 insertions(+), 902 deletions(-) create mode 100644 app/test/test_event_ring.c create mode 100644 lib/librte_ring/rte_common_ring.c create mode 100644 lib/librte_ring/rte_common_ring.h create mode 100644 lib/librte_ring/rte_event_ring.c create mode 100644 lib/librte_ring/rte_event_ring.h
Signature · 1 line
2.9.3
RFC PATCH v2 1/4 ring: create common ring files
Create rte_common_ring.[ch] files which will be modified to contain generic ring implementation code to be shared across multiple ring implementations for different sizes and types of data. For now, these are exact copies of the original rte_ring files.
---
lib/librte_ring/Makefile | 5 +-
lib/librte_ring/{rte_ring.c => rte_common_ring.c} | 0
lib/librte_ring/rte_common_ring.h | 1269 ++++++++++++++++++++
lib/librte_ring/rte_ring.h | 1270 +--------------------
4 files changed, 1273 insertions(+), 1271 deletions(-)
rename lib/librte_ring/{rte_ring.c => rte_common_ring.c} (100%)
create mode 100644 lib/librte_ring/rte_common_ring.h
mode change 100644 => 120000 lib/librte_ring/rte_ring.hlib/librte_ring/Makefile +3 -2
@@ -41,10 +41,11 @@ EXPORT_MAP := rte_ring_version.map LIBABIVER := 1 # all source are stored in SRCS-y -SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c +SRCS-$(CONFIG_RTE_LIBRTE_RING) += rte_common_ring.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h +SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include += rte_ring.h +SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include += rte_common_ring.h DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal
lib/librte_ring/rte_common_ring.c renamed from lib/librte_ring/rte_ring.c +0 -0
lib/librte_ring/rte_common_ring.h new file +1269 -0
1,269 lines not on this page · raw message
lib/librte_ring/rte_ring.h deleted +0 -1269
1,269 lines not on this page · raw message
lib/librte_ring/rte_ring.h new file +1 -0
@@ -0,0 +1 @@ +rte_common_ring.h
Signature · 1 line
2.9.3
RFC PATCH v2 2/4 ring: separate common and rte_ring specific functions
In reply to Bruce RichardsonProvide a separate rte_ring implementation which just calls into the common ring code. This allows us to generalise the common ring code without affecting the API/ABI of the rte_ring. The common functions are now all renamed to have an rte_common_ring prefix.
--- lib/librte_ring/Makefile | 1 + lib/librte_ring/rte_common_ring.c | 57 ++-- lib/librte_ring/rte_common_ring.h | 463 ++----------------------- lib/librte_ring/rte_ring.c | 86 +++++ lib/librte_ring/rte_ring.h | 692 +++++++++++++++++++++++++++++++++++++- 5 files changed, 832 insertions(+), 467 deletions(-) create mode 100644 lib/librte_ring/rte_ring.c mode change 120000 => 100644 lib/librte_ring/rte_ring.h
lib/librte_ring/Makefile +1 -0
@@ -42,6 +42,7 @@ LIBABIVER := 1 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_RING) += rte_common_ring.c +SRCS-$(CONFIG_RTE_LIBRTE_RING) += rte_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include += rte_ring.h
lib/librte_ring/rte_common_ring.c +29 -28
170 lines not on this page · raw message
lib/librte_ring/rte_common_ring.h +25 -438
599 lines not on this page · raw message
lib/librte_ring/rte_ring.c new file +86 -0
86 lines not on this page · raw message
lib/librte_ring/rte_ring.h deleted +0 -1
@@ -1 +0,0 @@ -rte_common_ring.h
lib/librte_ring/rte_ring.h new file +691 -0
691 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH v2 3/4 ring: allow common ring to use 8 or 16 byte values
In reply to Bruce RichardsonChange the common ring enqueue/dequeue functions to support enqueuing and dequeuing 16B values. Add the element size as parameter to all common ring functions that need it, and pass that as parameter from the rte_ring functions.
--- lib/librte_ring/rte_common_ring.c | 14 ++-- lib/librte_ring/rte_common_ring.h | 135 ++++++++++++++++++++++++++++---------- lib/librte_ring/rte_ring.c | 7 +- lib/librte_ring/rte_ring.h | 16 ++--- 4 files changed, 122 insertions(+), 50 deletions(-)
lib/librte_ring/rte_common_ring.c +8 -6
@@ -101,7 +101,7 @@ EAL_REGISTER_TAILQ(rte_common_ring_tailq)/* return the size of memory occupied by a ring */ ssize_t -rte_common_ring_get_memsize (unsigned count) +rte_common_ring_get_memsize (unsigned count,unsigned int elem_sz) {ssize_t sz;
@@ -113,14 +113,14 @@ rte_common_ring_get_memsize(unsigned count)return -EINVAL ; } - sz =sizeof (struct rte_ring ) + count *sizeof (void *); + sz =sizeof (struct rte_ring ) + count * elem_sz; sz =RTE_ALIGN (sz,RTE_CACHE_LINE_SIZE );return sz; }int rte_common_ring_init (struct rte_ring *r,const char *name,unsigned count, -unsigned flags) +unsigned flags,unsigned int elem_sz) {int ret;
@@ -146,6 +146,7 @@ rte_common_ring_init(struct rte_ring *r, const char *name, unsigned count,if (ret <0 || ret >= (int )sizeof (r->name))return -ENAMETOOLONG ; r->flags = flags; + r->elem_sz = elem_sz; r->prod.watermark = count; r->prod.sp_enqueue = !!(flags &RING_F_SP_ENQ ); r->cons.sc_dequeue = !!(flags &RING_F_SC_DEQ );
@@ -160,7 +161,7 @@ rte_common_ring_init(struct rte_ring *r, const char *name, unsigned count,/* create the ring */ struct rte_ring *rte_common_ring_create (const char *name,unsigned count,int socket_id, -unsigned flags) +unsigned flags,unsigned int elem_sz) {char mz_name[RTE_MEMZONE_NAMESIZE ];struct rte_ring *r;
@@ -173,7 +174,7 @@ rte_common_ring_create(const char *name, unsigned count, int socket_id, ring_list =RTE_TAILQ_CAST (rte_common_ring_tailq.head, rte_common_ring_list); - ring_size =rte_common_ring_get_memsize (count); + ring_size =rte_common_ring_get_memsize (count, elem_sz);if (ring_size <0 ) { rte_errno = ring_size;return NULL ;
@@ -203,7 +204,7 @@ rte_common_ring_create(const char *name, unsigned count, int socket_id, r = mz->addr;/* no need to check return value here, we already checked the * arguments above */ -rte_common_ring_init (r, name, count, flags); +rte_common_ring_init (r, name, count, flags, elem_sz); te->data = (void *) r; r->memzone = mz;
@@ -293,6 +294,7 @@ rte_common_ring_dump(FILE *f, const struct rte_ring *r)fprintf (f,"ring <%s>@%p\n" , r->name, r);fprintf (f," flags=%x\n" , r->flags); +fprintf (f," elem_sz=%u\n" , r->elem_sz);fprintf (f," size=%" PRIu32"\n" , r->prod.size);fprintf (f," ct=%" PRIu32"\n" , r->cons.tail);fprintf (f," ch=%" PRIu32"\n" , r->cons.head);
lib/librte_ring/rte_common_ring.h +102 -33
245 lines not on this page · raw message
lib/librte_ring/rte_ring.c +4 -3
@@ -36,14 +36,14 @@ssize_t rte_ring_get_memsize (unsigned count) { -return rte_common_ring_get_memsize (count); +return rte_common_ring_get_memsize (count,sizeof (void *)); }int rte_ring_init (struct rte_ring *r,const char *name,unsigned count,unsigned flags) { -return rte_common_ring_init (r, name, count, flags); +return rte_common_ring_init (r, name, count, flags,sizeof (void *)); }
@@ -51,7 +51,8 @@ struct rte_ring * rte_ring_create(const char *name, unsigned count, int socket_id, unsigned flags) { - return rte_common_ring_create(name, count, socket_id, flags); + return rte_common_ring_create(name, count, socket_id, flags, + sizeof(void *)); }void
lib/librte_ring/rte_ring.h +8 -8
@@ -215,7 +215,7 @@ static inline int __attribute__((always_inline)) rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, unsigned n) { - return __rte_common_ring_mp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED); + return __rte_common_ring_mp_do_enqueue(r, obj_table, n, sizeof(void *), RTE_RING_QUEUE_FIXED); }/**
@@ -237,7 +237,7 @@ static inline int __attribute__((always_inline)) rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table, unsigned n) { - return __rte_common_ring_sp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED); + return __rte_common_ring_sp_do_enqueue(r, obj_table, n, sizeof(void *), RTE_RING_QUEUE_FIXED); }/**
@@ -356,7 +356,7 @@ rte_ring_enqueue(struct rte_ring *r, void *obj)static inline int __attribute__((always_inline))rte_ring_mc_dequeue_bulk (struct rte_ring *r,void **obj_table,unsigned n) { -return __rte_common_ring_mc_do_dequeue (r, obj_table, n,RTE_RING_QUEUE_FIXED ); +return __rte_common_ring_mc_do_dequeue (r, obj_table, n,sizeof (void *),RTE_RING_QUEUE_FIXED ); }/**
@@ -377,7 +377,7 @@ rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n)static inline int __attribute__((always_inline))rte_ring_sc_dequeue_bulk (struct rte_ring *r,void **obj_table,unsigned n) { -return __rte_common_ring_sc_do_dequeue (r, obj_table, n,RTE_RING_QUEUE_FIXED ); +return __rte_common_ring_sc_do_dequeue (r, obj_table, n,sizeof (void *),RTE_RING_QUEUE_FIXED ); }/**
@@ -568,7 +568,7 @@ static inline unsigned __attribute__((always_inline)) rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table, unsigned n) { - return __rte_common_ring_mp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE); + return __rte_common_ring_mp_do_enqueue(r, obj_table, n, sizeof(void *), RTE_RING_QUEUE_VARIABLE); }/**
@@ -587,7 +587,7 @@ static inline unsigned __attribute__((always_inline)) rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table, unsigned n) { - return __rte_common_ring_sp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE); + return __rte_common_ring_sp_do_enqueue(r, obj_table, n, sizeof(void *), RTE_RING_QUEUE_VARIABLE); }/**
@@ -636,7 +636,7 @@ rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,static inline unsigned __attribute__((always_inline))rte_ring_mc_dequeue_burst (struct rte_ring *r,void **obj_table,unsigned n) { -return __rte_common_ring_mc_do_dequeue (r, obj_table, n,RTE_RING_QUEUE_VARIABLE ); +return __rte_common_ring_mc_do_dequeue (r, obj_table, n,sizeof (void *),RTE_RING_QUEUE_VARIABLE ); }/**
@@ -656,7 +656,7 @@ rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned n)static inline unsigned __attribute__((always_inline))rte_ring_sc_dequeue_burst (struct rte_ring *r,void **obj_table,unsigned n) { -return __rte_common_ring_sc_do_dequeue (r, obj_table, n,RTE_RING_QUEUE_VARIABLE ); +return __rte_common_ring_sc_do_dequeue (r, obj_table, n,sizeof (void *),RTE_RING_QUEUE_VARIABLE ); }/**
Signature · 1 line
2.9.3
RFC PATCH v2 4/4 ring: add new event ring class
In reply to Bruce Richardsonusing a placeholder struct type of the correct (16B) size, create an event ring type and unit test it to verify the generalized ring implementation works.
--- app/test/Makefile | 1 + app/test/test_event_ring.c | 83 +++++ lib/librte_ring/Makefile | 2 + lib/librte_ring/rte_event_ring.c | 87 +++++ lib/librte_ring/rte_event_ring.h | 696 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 869 insertions(+) create mode 100644 app/test/test_event_ring.c create mode 100644 lib/librte_ring/rte_event_ring.c create mode 100644 lib/librte_ring/rte_event_ring.h
app/test/Makefile +1 -0
@@ -96,6 +96,7 @@ SRCS-y += test_memory.c SRCS-y += test_memzone.c SRCS-y += test_ring.c +SRCS-y += test_event_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c
app/test/test_event_ring.c new file +83 -0
83 lines not on this page · raw message
lib/librte_ring/Makefile +2 -0
@@ -43,10 +43,12 @@ LIBABIVER := 1 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_RING) += rte_common_ring.c SRCS-$(CONFIG_RTE_LIBRTE_RING) += rte_ring.c +SRCS-$(CONFIG_RTE_LIBRTE_RING) += rte_event_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include += rte_ring.h SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include += rte_common_ring.h +SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include += rte_event_ring.h DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal
lib/librte_ring/rte_event_ring.c new file +87 -0
87 lines not on this page · raw message
lib/librte_ring/rte_event_ring.h new file +696 -0
696 lines not on this page · raw message
Signature · 1 line
2.9.3