Message ID | 1450438154-2062-6-git-send-email-maxim.uvarov@linaro.org |
---|---|
State | Superseded |
Headers | show |
From checkpatch There should be a "default:" statement, if not we can clear this warning in checkpatch by adding a comment in the actual code explaining why a default is not needed. WARNING: Possible switch case/default not preceeded by break or fallthrough comment #2069: FILE: platform/linux-generic/pktio/ring.c:105: + case 1: \ WARNING: Possible switch case/default not preceeded by break or fallthrough comment #2098: FILE: platform/linux-generic/pktio/ring.c:134: + case 1: \ There are other BIT macro warnings like this one, but I think we need to disable them and I sent a patch to do so, maybe that will prompt us to add a BIT macro but for now I dont think these should block acceptance CHECK: Prefer using the BIT macro #1523: FILE: platform/linux-generic/include/odp_packet_io_ring_internal.h:158: +#define _RING_F_SP_ENQ (1 << 0) On 18 December 2015 at 06:29, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: > Move ring and it's test from helper to linux-generic/pktio and kill > not needed api_test directory. Unfortunately odp_ring_test.c had some old > dirty code so I had to clean up it to to use cunit and > latest helper apis. > > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> > --- > configure.ac | 1 - > helper/Makefile.am | 2 - > helper/test/Makefile.am | 5 +- > platform/linux-generic/Makefile.am | 2 + > .../include/odp_packet_io_ring_internal.h | 112 +++++---- > platform/linux-generic/m4/configure.m4 | 3 +- > {helper => platform/linux-generic/pktio}/ring.c | 263 > ++++++++++----------- > platform/linux-generic/test/Makefile.am | 3 +- > platform/linux-generic/test/ring/.gitignore | 1 + > platform/linux-generic/test/ring/Makefile.am | 16 ++ > .../linux-generic/test/ring/ringtest.c | 180 +++++++------- > test/Makefile.am | 2 +- > test/api_test/.gitignore | 2 - > test/api_test/Makefile.am | 13 - > test/api_test/odp_common.c | 91 ------- > test/api_test/odp_common.h | 42 ---- > 16 files changed, 309 insertions(+), 429 deletions(-) > rename helper/include/odp/helper/ring.h => > platform/linux-generic/include/odp_packet_io_ring_internal.h (87%) > rename {helper => platform/linux-generic/pktio}/ring.c (71%) > create mode 100644 platform/linux-generic/test/ring/.gitignore > create mode 100644 platform/linux-generic/test/ring/Makefile.am > rename test/api_test/odp_ring_test.c => > platform/linux-generic/test/ring/ringtest.c (72%) > delete mode 100644 test/api_test/.gitignore > delete mode 100644 test/api_test/Makefile.am > delete mode 100644 test/api_test/odp_common.c > delete mode 100644 test/api_test/odp_common.h > > diff --git a/configure.ac b/configure.ac > index e45d90a..28b9ec9 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -345,7 +345,6 @@ AC_CONFIG_FILES([Makefile > pkgconfig/libodphelper.pc > scripts/Makefile > test/Makefile > - test/api_test/Makefile > test/performance/Makefile > test/validation/Makefile > test/validation/buffer/Makefile > diff --git a/helper/Makefile.am b/helper/Makefile.am > index 1906ae2..6828092 100644 > --- a/helper/Makefile.am > +++ b/helper/Makefile.am > @@ -8,7 +8,6 @@ AM_CFLAGS += -I$(top_srcdir)/include > > helperincludedir = $(includedir)/odp/helper/ > helperinclude_HEADERS = \ > - $(srcdir)/include/odp/helper/ring.h \ > $(srcdir)/include/odp/helper/linux.h \ > $(srcdir)/include/odp/helper/chksum.h\ > $(srcdir)/include/odp/helper/eth.h\ > @@ -29,7 +28,6 @@ noinst_HEADERS = \ > > __LIB__libodphelper_la_SOURCES = \ > linux.c \ > - ring.c \ > hashtable.c \ > lineartable.c > > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > index 1c6a802..cf3b7aa 100644 > --- a/helper/test/Makefile.am > +++ b/helper/test/Makefile.am > @@ -1,6 +1,7 @@ > include $(top_srcdir)/test/Makefile.inc > > AM_CFLAGS += -I$(srcdir)/common > +AM_CFLAGS += -I$(top_srcdir)/test/validation/common > AM_LDFLAGS += -static > > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > @@ -28,5 +29,5 @@ dist_thread_SOURCES = thread.c > thread_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp.la > dist_process_SOURCES = process.c > process_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp.la > -odph_pause_SOURCES = pause.c > -dist_odp_table_SOURCES = table.c > +dist_pause_SOURCES = pause.c > +dist_table_SOURCES = table.c > diff --git a/platform/linux-generic/Makefile.am > b/platform/linux-generic/Makefile.am > index 4639ebc..8160649 100644 > --- a/platform/linux-generic/Makefile.am > +++ b/platform/linux-generic/Makefile.am > @@ -90,6 +90,7 @@ noinst_HEADERS = \ > ${srcdir}/include/odp_packet_internal.h \ > ${srcdir}/include/odp_packet_io_internal.h \ > ${srcdir}/include/odp_packet_io_queue.h \ > + ${srcdir}/include/odp_packet_io_ring_internal.h \ > ${srcdir}/include/odp_packet_netmap.h \ > ${srcdir}/include/odp_packet_socket.h \ > ${srcdir}/include/odp_packet_tap.h \ > @@ -122,6 +123,7 @@ __LIB__libodp_la_SOURCES = \ > pktio/socket.c \ > pktio/socket_mmap.c \ > pktio/tap.c \ > + pktio/ring.c \ > odp_pool.c \ > odp_queue.c \ > odp_rwlock.c \ > diff --git a/helper/include/odp/helper/ring.h > b/platform/linux-generic/include/odp_packet_io_ring_internal.h > similarity index 87% > rename from helper/include/odp/helper/ring.h > rename to platform/linux-generic/include/odp_packet_io_ring_internal.h > index 541a466..f97c026 100644 > --- a/helper/include/odp/helper/ring.h > +++ b/platform/linux-generic/include/odp_packet_io_ring_internal.h > @@ -89,29 +89,28 @@ > * > */ > > -#ifndef ODPH_RING_H_ > -#define ODPH_RING_H_ > +#ifndef _RING_H_ > +#define _RING_H_ > > #ifdef __cplusplus > extern "C" { > #endif > > - > #include <odp/std_types.h> > #include <odp/hints.h> > #include <odp/atomic.h> > #include <errno.h> > #include <sys/queue.h> > +#include <odp_debug_internal.h> > > -enum odph_ring_queue_behavior { > - ODPH_RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number > +enum _ring_queue_behavior { > + _RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number > of items from a ring */ > - ODPH_RING_QUEUE_VARIABLE /**< Enq/Deq as many items > + _RING_QUEUE_VARIABLE /**< Enq/Deq as many items > a possible from ring */ > }; > > - > -#define ODPH_RING_NAMESIZE 32 /**< The maximum length of a ring name. */ > +#define _RING_NAMESIZE 32 /**< The maximum length of a ring name. */ > > /** > * An ODP ring structure. > @@ -123,12 +122,12 @@ enum odph_ring_queue_behavior { > * values in a modulo-32bit base: that's why the overflow of the indexes > is not > * a problem. > */ > -typedef struct odph_ring { > +typedef struct _ring { > /** @private Next in list. */ > - TAILQ_ENTRY(odph_ring) next; > + TAILQ_ENTRY(_ring) next; > > /** @private Name of the ring. */ > - char name[ODPH_RING_NAMESIZE]; > + char name[_RING_NAMESIZE]; > /** @private Flags supplied at creation. */ > int flags; > > @@ -153,21 +152,21 @@ typedef struct odph_ring { > > /** @private Memory space of ring starts here. */ > void *ring[0] ODP_ALIGNED_CACHE; > -} odph_ring_t; > +} _ring_t; > > /* The default enqueue is "single-producer".*/ > -#define ODPH_RING_F_SP_ENQ (1 << 0) > +#define _RING_F_SP_ENQ (1 << 0) > /* The default dequeue is "single-consumer".*/ > -#define ODPH_RING_F_SC_DEQ (1 << 1) > +#define _RING_F_SC_DEQ (1 << 1) > /* If set - ring is visible from different processes. > * Default is thread visible.*/ > -#define ODPH_RING_SHM_PROC (1 << 2) > +#define _RING_SHM_PROC (1 << 2) > /* Do not link ring to linked list. */ > -#define ODPH_RING_NO_LIST (1 << 3) > +#define _RING_NO_LIST (1 << 3) > /* Quota exceed for burst ops */ > -#define ODPH_RING_QUOT_EXCEED (1 << 31) > +#define _RING_QUOT_EXCEED (1 << 31) > /* Ring size mask */ > -#define ODPH_RING_SZ_MASK (unsigned)(0x0fffffff) > +#define _RING_SZ_MASK (unsigned)(0x0fffffff) > > /** > * Create a new ring named *name* in memory. > @@ -198,9 +197,8 @@ typedef struct odph_ring { > * - EEXIST - a memzone with the same name already exists > * - ENOMEM - no appropriate memory area found in which to create > memzone > */ > -odph_ring_t *odph_ring_create(const char *name, unsigned count, > - unsigned flags); > - > +_ring_t *_ring_create(const char *name, unsigned count, > + unsigned flags); > > /** > * Change the high water mark. > @@ -217,14 +215,14 @@ odph_ring_t *odph_ring_create(const char *name, > unsigned count, > * @return 0: Success; water mark changed. > * -EINVAL: Invalid water mark value. > */ > -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count); > +int _ring_set_water_mark(_ring_t *r, unsigned count); > > /** > * Dump the status of the ring to the console. > * > * @param r A pointer to the ring structure. > */ > -void odph_ring_dump(const odph_ring_t *r); > +void _ring_dump(const _ring_t *r); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -251,9 +249,9 @@ void odph_ring_dump(const odph_ring_t *r); > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects enqueued. > */ > -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -277,9 +275,9 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects enqueued. > */ > -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Dequeue several objects from a ring (multi-consumers safe). When > @@ -308,9 +306,9 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > * - n: Actual number of objects dequeued. > */ > > -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > @@ -335,9 +333,9 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void > **obj_table, > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects dequeued. > */ > -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -357,8 +355,8 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void > **obj_table, > * high water mark is exceeded. > * - -ENOBUFS: Not enough room in the ring to enqueue, no object is > enqueued. > */ > -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, > - unsigned n); > +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -375,8 +373,8 @@ int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * > const *obj_table, > * high water mark is exceeded. > * - -ENOBUFS: Not enough room in the ring to enqueue; no object is > enqueued. > */ > -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, > - unsigned n); > +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Dequeue several objects from a ring (multi-consumers safe). > @@ -395,7 +393,7 @@ int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * > const *obj_table, > * - -ENOENT: Not enough entries in the ring to dequeue; no object is > * dequeued. > */ > -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned > n); > +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > @@ -412,7 +410,7 @@ int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void > **obj_table, unsigned n); > * - -ENOENT: Not enough entries in the ring to dequeue; no object is > * dequeued. > */ > -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned > n); > +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); > > /** > * Test if a ring is full. > @@ -423,7 +421,7 @@ int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void > **obj_table, unsigned n); > * - 1: The ring is full. > * - 0: The ring is not full. > */ > -int odph_ring_full(const odph_ring_t *r); > +int _ring_full(const _ring_t *r); > > /** > * Test if a ring is empty. > @@ -434,7 +432,7 @@ int odph_ring_full(const odph_ring_t *r); > * - 1: The ring is empty. > * - 0: The ring is not empty. > */ > -int odph_ring_empty(const odph_ring_t *r); > +int _ring_empty(const _ring_t *r); > > /** > * Return the number of entries in a ring. > @@ -444,7 +442,7 @@ int odph_ring_empty(const odph_ring_t *r); > * @return > * The number of entries in the ring. > */ > -unsigned odph_ring_count(const odph_ring_t *r); > +unsigned _ring_count(const _ring_t *r); > > /** > * Return the number of free entries in a ring. > @@ -454,14 +452,14 @@ unsigned odph_ring_count(const odph_ring_t *r); > * @return > * The number of free entries in the ring. > */ > -unsigned odph_ring_free_count(const odph_ring_t *r); > +unsigned _ring_free_count(const _ring_t *r); > > /** > * search ring by name > * @param name ring name to search > * @return pointer to ring otherwise NULL > */ > -odph_ring_t *odph_ring_lookup(const char *name); > +_ring_t *_ring_lookup(const char *name); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -478,8 +476,8 @@ odph_ring_t *odph_ring_lookup(const char *name); > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n); > +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -493,8 +491,8 @@ int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * > const *obj_table, > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n); > +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > /** > * Enqueue several objects on a ring. > * > @@ -511,8 +509,8 @@ int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * > const *obj_table, > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n); > +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Dequeue several objects from a ring (multi-consumers safe). When the > request > @@ -531,7 +529,7 @@ int odph_ring_enqueue_burst(odph_ring_t *r, void * > const *obj_table, > * @return > * - n: Actual number of objects dequeued, 0 if ring is empty > */ > -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned > n); > +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe).When the > @@ -547,7 +545,7 @@ int odph_ring_mc_dequeue_burst(odph_ring_t *r, void > **obj_table, unsigned n); > * @return > * - n: Actual number of objects dequeued, 0 if ring is empty > */ > -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned > n); > +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); > > /** > * Dequeue multiple objects from a ring up to a maximum number. > @@ -565,17 +563,17 @@ int odph_ring_sc_dequeue_burst(odph_ring_t *r, void > **obj_table, unsigned n); > * @return > * - Number of objects dequeued, or a negative error code on error > */ > -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n); > +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); > > /** > * dump the status of all rings on the console > */ > -void odph_ring_list_dump(void); > +void _ring_list_dump(void); > > /** > * initialise ring tailq > */ > -void odph_ring_tailq_init(void); > +void _ring_tailq_init(void); > > #ifdef __cplusplus > } > diff --git a/platform/linux-generic/m4/configure.m4 > b/platform/linux-generic/m4/configure.m4 > index df6dc64..6bb159f 100644 > --- a/platform/linux-generic/m4/configure.m4 > +++ b/platform/linux-generic/m4/configure.m4 > @@ -23,4 +23,5 @@ m4_include([platform/linux-generic/m4/odp_pcap.m4]) > > AC_CONFIG_FILES([platform/linux-generic/Makefile > platform/linux-generic/test/Makefile > - platform/linux-generic/test/pktio/Makefile]) > + platform/linux-generic/test/pktio/Makefile > + platform/linux-generic/test/ring/Makefile]) > diff --git a/helper/ring.c b/platform/linux-generic/pktio/ring.c > similarity index 71% > rename from helper/ring.c > rename to platform/linux-generic/pktio/ring.c > index e113606..e978420 100644 > --- a/helper/ring.c > +++ b/platform/linux-generic/pktio/ring.c > @@ -78,9 +78,9 @@ > #include <string.h> > #include "odph_debug.h" > #include <odp/rwlock.h> > -#include <odp/helper/ring.h> > +#include <odp_packet_io_ring_internal.h> > > -static TAILQ_HEAD(, odph_ring) odp_ring_list; > +static TAILQ_HEAD(, _ring) odp_ring_list; > > #define RING_VAL_IS_POWER_2(x) ((((x) - 1) & (x)) == 0) > > @@ -93,9 +93,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > if (odp_likely(idx + n < size)) { \ > for (i = 0; i < (n & ((~(unsigned)0x3))); i += 4, idx += > 4) { \ > r->ring[idx] = obj_table[i]; \ > - r->ring[idx+1] = obj_table[i+1]; \ > - r->ring[idx+2] = obj_table[i+2]; \ > - r->ring[idx+3] = obj_table[i+3]; \ > + r->ring[idx + 1] = obj_table[i + 1]; \ > + r->ring[idx + 2] = obj_table[i + 2]; \ > + r->ring[idx + 3] = obj_table[i + 3]; \ > } \ > switch (n & 0x3) { \ > case 3: \ > @@ -122,9 +122,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > if (odp_likely(idx + n < size)) { \ > for (i = 0; i < (n & (~(unsigned)0x3)); i += 4, idx += 4) > {\ > obj_table[i] = r->ring[idx]; \ > - obj_table[i+1] = r->ring[idx+1]; \ > - obj_table[i+2] = r->ring[idx+2]; \ > - obj_table[i+3] = r->ring[idx+3]; \ > + obj_table[i + 1] = r->ring[idx + 1]; \ > + obj_table[i + 2] = r->ring[idx + 2]; \ > + obj_table[i + 3] = r->ring[idx + 3]; \ > } \ > switch (n & 0x3) { \ > case 3: \ > @@ -145,36 +145,37 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > static odp_rwlock_t qlock; /* rings tailq lock */ > > /* init tailq_ring */ > -void odph_ring_tailq_init(void) > +void _ring_tailq_init(void) > { > TAILQ_INIT(&odp_ring_list); > odp_rwlock_init(&qlock); > } > > /* create the ring */ > -odph_ring_t * > -odph_ring_create(const char *name, unsigned count, unsigned flags) > +_ring_t * > +_ring_create(const char *name, unsigned count, unsigned flags) > { > - char ring_name[ODPH_RING_NAMESIZE]; > - odph_ring_t *r; > + char ring_name[_RING_NAMESIZE]; > + _ring_t *r; > size_t ring_size; > uint32_t shm_flag; > odp_shm_t shm; > > - if (flags & ODPH_RING_SHM_PROC) > + if (flags & _RING_SHM_PROC) > shm_flag = ODP_SHM_PROC; > else > shm_flag = 0; > > /* count must be a power of 2 */ > - if (!RING_VAL_IS_POWER_2(count) || (count > ODPH_RING_SZ_MASK)) { > - ODPH_ERR("Requested size is invalid, must be power of 2, > and do not exceed the size limit %u\n", > - ODPH_RING_SZ_MASK); > + if (!RING_VAL_IS_POWER_2(count) || (count > _RING_SZ_MASK)) { > + ODPH_ERR("Requested size is invalid, must be power of 2," > + "and do not exceed the size limit %u\n", > + _RING_SZ_MASK); > return NULL; > } > > snprintf(ring_name, sizeof(ring_name), "%s", name); > - ring_size = count*sizeof(void *)+sizeof(odph_ring_t); > + ring_size = count * sizeof(void *) + sizeof(_ring_t); > > odp_rwlock_write_lock(&qlock); > /* reserve a memory zone for this ring.*/ > @@ -188,18 +189,18 @@ odph_ring_create(const char *name, unsigned count, > unsigned flags) > snprintf(r->name, sizeof(r->name), "%s", name); > r->flags = flags; > r->prod.watermark = count; > - r->prod.sp_enqueue = !!(flags & ODPH_RING_F_SP_ENQ); > - r->cons.sc_dequeue = !!(flags & ODPH_RING_F_SC_DEQ); > + r->prod.sp_enqueue = !!(flags & _RING_F_SP_ENQ); > + r->cons.sc_dequeue = !!(flags & _RING_F_SC_DEQ); > r->prod.size = count; > r->cons.size = count; > - r->prod.mask = count-1; > - r->cons.mask = count-1; > + r->prod.mask = count - 1; > + r->cons.mask = count - 1; > r->prod.head = 0; > r->cons.head = 0; > r->prod.tail = 0; > r->cons.tail = 0; > > - if (!(flags & ODPH_RING_NO_LIST)) > + if (!(flags & _RING_NO_LIST)) > TAILQ_INSERT_TAIL(&odp_ring_list, r, next); > } else { > ODPH_ERR("Cannot reserve memory\n"); > @@ -213,7 +214,7 @@ odph_ring_create(const char *name, unsigned count, > unsigned flags) > * change the high water mark. If *count* is 0, water marking is > * disabled > */ > -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count) > +int _ring_set_water_mark(_ring_t *r, unsigned count) > { > if (count >= r->prod.size) > return -EINVAL; > @@ -229,8 +230,8 @@ int odph_ring_set_water_mark(odph_ring_t *r, unsigned > count) > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, > - unsigned n, enum odph_ring_queue_behavior > behavior) > +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, enum _ring_queue_behavior behavior) > { > uint32_t prod_head, prod_next; > uint32_t cons_tail, free_entries; > @@ -255,24 +256,22 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > > /* check that we have enough room in ring */ > if (odp_unlikely(n > free_entries)) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOBUFS; > - } else { > - /* No free entry available */ > - if (odp_unlikely(free_entries == 0)) > - return 0; > + /* No free entry available */ > + if (odp_unlikely(free_entries == 0)) > + return 0; > > - n = free_entries; > - } > + n = free_entries; > } > > prod_next = prod_head + n; > success = __atomic_compare_exchange_n(&r->prod.head, > - &prod_head, > - prod_next, > - false/*strong*/, > - __ATOMIC_ACQUIRE, > - __ATOMIC_RELAXED); > + &prod_head, > + prod_next, > + false/*strong*/, > + __ATOMIC_ACQUIRE, > + __ATOMIC_RELAXED); > } while (odp_unlikely(success == 0)); > > /* write entries in ring */ > @@ -280,10 +279,10 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > > /* if we exceed the watermark */ > if (odp_unlikely(((mask + 1) - free_entries + n) > > r->prod.watermark)) { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : > - (int)(n | ODPH_RING_QUOT_EXCEED); > + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : > + (int)(n | _RING_QUOT_EXCEED); > } else { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; > + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; > } > > /* > @@ -302,8 +301,8 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, > - unsigned n, enum odph_ring_queue_behavior > behavior) > +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, enum _ring_queue_behavior behavior) > { > uint32_t prod_head, cons_tail; > uint32_t prod_next, free_entries; > @@ -321,15 +320,13 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > > /* check that we have enough room in ring */ > if (odp_unlikely(n > free_entries)) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOBUFS; > - } else { > - /* No free entry available */ > - if (odp_unlikely(free_entries == 0)) > - return 0; > + /* No free entry available */ > + if (odp_unlikely(free_entries == 0)) > + return 0; > > - n = free_entries; > - } > + n = free_entries; > } > > prod_next = prod_head + n; > @@ -340,10 +337,10 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > > /* if we exceed the watermark */ > if (odp_unlikely(((mask + 1) - free_entries + n) > > r->prod.watermark)) { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : > - (int)(n | ODPH_RING_QUOT_EXCEED); > + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : > + (int)(n | _RING_QUOT_EXCEED); > } else { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; > + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; > } > > /* Release our entries and the memory they refer to */ > @@ -356,8 +353,8 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * > const *obj_table, > * Dequeue several objects from a ring (multi-consumers safe). > */ > > -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, enum odph_ring_queue_behavior > behavior) > +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, enum _ring_queue_behavior behavior) > { > uint32_t cons_head, prod_tail; > uint32_t cons_next, entries; > @@ -381,23 +378,21 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void > **obj_table, > > /* Set the actual entries for dequeue */ > if (n > entries) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOENT; > - } else { > - if (odp_unlikely(entries == 0)) > - return 0; > + if (odp_unlikely(entries == 0)) > + return 0; > > - n = entries; > - } > + n = entries; > } > > cons_next = cons_head + n; > success = __atomic_compare_exchange_n(&r->cons.head, > - &cons_head, > - cons_next, > - false/*strong*/, > - __ATOMIC_ACQUIRE, > - __ATOMIC_RELAXED); > + &cons_head, > + cons_next, > + false/*strong*/, > + __ATOMIC_ACQUIRE, > + __ATOMIC_RELAXED); > } while (odp_unlikely(success == 0)); > > /* copy in table */ > @@ -414,14 +409,14 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void > **obj_table, > __atomic_thread_fence(__ATOMIC_RELEASE); > r->cons.tail = cons_next; > > - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; > + return behavior == _RING_QUEUE_FIXED ? 0 : n; > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > */ > -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, enum odph_ring_queue_behavior > behavior) > +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, enum _ring_queue_behavior behavior) > { > uint32_t cons_head, prod_tail; > uint32_t cons_next, entries; > @@ -437,14 +432,12 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void > **obj_table, > entries = prod_tail - cons_head; > > if (n > entries) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOENT; > - } else { > - if (odp_unlikely(entries == 0)) > - return 0; > + if (odp_unlikely(entries == 0)) > + return 0; > > - n = entries; > - } > + n = entries; > } > > cons_next = cons_head + n; > @@ -456,127 +449,131 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void > **obj_table, > DEQUEUE_PTRS(); > > r->cons.tail = cons_next; > - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; > + return behavior == _RING_QUEUE_FIXED ? 0 : n; > } > > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, > - unsigned n) > +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_mp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_mp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, > - unsigned n) > +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_sp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_sp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Dequeue several objects from a ring (multi-consumers safe). > */ > -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned > n) > +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_mc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_mc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > */ > -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned > n) > +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_sc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_sc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Test if a ring is full. > */ > -int odph_ring_full(const odph_ring_t *r) > +int _ring_full(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (((cons_tail - prod_tail - 1) & r->prod.mask) == 0); > } > > /** > * Test if a ring is empty. > */ > -int odph_ring_empty(const odph_ring_t *r) > +int _ring_empty(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return !!(cons_tail == prod_tail); > } > > /** > * Return the number of entries in a ring. > */ > -unsigned odph_ring_count(const odph_ring_t *r) > +unsigned _ring_count(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (prod_tail - cons_tail) & r->prod.mask; > } > > /** > * Return the number of free entries in a ring. > */ > -unsigned odph_ring_free_count(const odph_ring_t *r) > +unsigned _ring_free_count(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (cons_tail - prod_tail - 1) & r->prod.mask; > } > > /* dump the status of the ring on the console */ > -void odph_ring_dump(const odph_ring_t *r) > +void _ring_dump(const _ring_t *r) > { > - ODPH_DBG("ring <%s>@%p\n", r->name, r); > - ODPH_DBG(" flags=%x\n", r->flags); > - ODPH_DBG(" size=%" PRIu32 "\n", r->prod.size); > - ODPH_DBG(" ct=%" PRIu32 "\n", r->cons.tail); > - ODPH_DBG(" ch=%" PRIu32 "\n", r->cons.head); > - ODPH_DBG(" pt=%" PRIu32 "\n", r->prod.tail); > - ODPH_DBG(" ph=%" PRIu32 "\n", r->prod.head); > - ODPH_DBG(" used=%u\n", odph_ring_count(r)); > - ODPH_DBG(" avail=%u\n", odph_ring_free_count(r)); > + ODP_DBG("ring <%s>@%p\n", r->name, r); > + ODP_DBG(" flags=%x\n", r->flags); > + ODP_DBG(" size=%" PRIu32 "\n", r->prod.size); > + ODP_DBG(" ct=%" PRIu32 "\n", r->cons.tail); > + ODP_DBG(" ch=%" PRIu32 "\n", r->cons.head); > + ODP_DBG(" pt=%" PRIu32 "\n", r->prod.tail); > + ODP_DBG(" ph=%" PRIu32 "\n", r->prod.head); > + ODP_DBG(" used=%u\n", _ring_count(r)); > + ODP_DBG(" avail=%u\n", _ring_free_count(r)); > if (r->prod.watermark == r->prod.size) > - ODPH_DBG(" watermark=0\n"); > + ODP_DBG(" watermark=0\n"); > else > - ODPH_DBG(" watermark=%" PRIu32 "\n", r->prod.watermark); > + ODP_DBG(" watermark=%" PRIu32 "\n", r->prod.watermark); > } > > /* dump the status of all rings on the console */ > -void odph_ring_list_dump(void) > +void _ring_list_dump(void) > { > - const odph_ring_t *mp = NULL; > + const _ring_t *mp = NULL; > > odp_rwlock_read_lock(&qlock); > > TAILQ_FOREACH(mp, &odp_ring_list, next) { > - odph_ring_dump(mp); > + _ring_dump(mp); > } > > odp_rwlock_read_unlock(&qlock); > } > > /* search a ring from its name */ > -odph_ring_t *odph_ring_lookup(const char *name) > +_ring_t *_ring_lookup(const char *name) > { > - odph_ring_t *r; > + _ring_t *r; > > odp_rwlock_read_lock(&qlock); > TAILQ_FOREACH(r, &odp_ring_list, next) { > - if (strncmp(name, r->name, ODPH_RING_NAMESIZE) == 0) > + if (strncmp(name, r->name, _RING_NAMESIZE) == 0) > break; > } > odp_rwlock_read_unlock(&qlock); > @@ -587,60 +584,60 @@ odph_ring_t *odph_ring_lookup(const char *name) > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n) > +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_mp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_mp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n) > +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_sp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_sp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Enqueue several objects on a ring. > */ > -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n) > +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > if (r->prod.sp_enqueue) > - return odph_ring_sp_enqueue_burst(r, obj_table, n); > + return _ring_sp_enqueue_burst(r, obj_table, n); > else > - return odph_ring_mp_enqueue_burst(r, obj_table, n); > + return _ring_mp_enqueue_burst(r, obj_table, n); > } > > /** > * Dequeue several objects from a ring (multi-consumers safe). > */ > -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned > n) > +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_mc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_mc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > */ > -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned > n) > +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_sc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_sc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Dequeue multiple objects from a ring up to a maximum number. > */ > -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n) > +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) > { > if (r->cons.sc_dequeue) > - return odph_ring_sc_dequeue_burst(r, obj_table, n); > + return _ring_sc_dequeue_burst(r, obj_table, n); > else > - return odph_ring_mc_dequeue_burst(r, obj_table, n); > + return _ring_mc_dequeue_burst(r, obj_table, n); > } > diff --git a/platform/linux-generic/test/Makefile.am > b/platform/linux-generic/test/Makefile.am > index 594aa11..f81eeb8 100644 > --- a/platform/linux-generic/test/Makefile.am > +++ b/platform/linux-generic/test/Makefile.am > @@ -1,11 +1,12 @@ > include $(top_srcdir)/test/Makefile.inc > TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation > > -ODP_MODULES = pktio > +ODP_MODULES = pktio ring > > if test_vald > TESTS = pktio/pktio_run \ > pktio/pktio_run_tap \ > + ring/ringtest$(EXEEXT) \ > ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ > > ${top_builddir}/test/validation/classification/classification_main$(EXEEXT) > \ > ${top_builddir}/test/validation/config/config_main$(EXEEXT) \ > diff --git a/platform/linux-generic/test/ring/.gitignore > b/platform/linux-generic/test/ring/.gitignore > new file mode 100644 > index 0000000..4767f5e > --- /dev/null > +++ b/platform/linux-generic/test/ring/.gitignore > @@ -0,0 +1 @@ > +ringtest > diff --git a/platform/linux-generic/test/ring/Makefile.am > b/platform/linux-generic/test/ring/Makefile.am > new file mode 100644 > index 0000000..5a949d0 > --- /dev/null > +++ b/platform/linux-generic/test/ring/Makefile.am > @@ -0,0 +1,16 @@ > +include $(top_srcdir)/test/validation/Makefile.inc > + > +AM_CFLAGS += -I$(srcdir)/common > +AM_CFLAGS += -I$(top_srcdir)/test/validation/common > +AM_LDFLAGS += -static > + > +COMPILE_ONLY = > + > +TESTSCRIPTS = > + > +EXECUTABLES = ringtest$(EXEEXT) > + > +test_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) > + > +ringtest_SOURCES = ringtest.c > +ringtest_LDADD = $(LIBCUNIT_COMMON) $(LIBODP) > diff --git a/test/api_test/odp_ring_test.c > b/platform/linux-generic/test/ring/ringtest.c > similarity index 72% > rename from test/api_test/odp_ring_test.c > rename to platform/linux-generic/test/ring/ringtest.c > index e8a962a..dfa220b 100644 > --- a/test/api_test/odp_ring_test.c > +++ b/platform/linux-generic/test/ring/ringtest.c > @@ -37,7 +37,6 @@ > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > */ > > - > /** > * @file > * > @@ -48,86 +47,96 @@ > #include <stdio.h> > #include <string.h> > #include <odp.h> > -#include <odp_common.h> > -#include <odp/helper/ring.h> > +#include <odp/helper/linux.h> > +#include <odp_packet_io_ring_internal.h> > #include <test_debug.h> > +#include <odp_cunit_common.h> > > #define RING_SIZE 4096 > #define MAX_BULK 32 > > -#define RING_TEST_BASIC > +enum { > + ODP_RING_TEST_BASIC, > + ODP_RING_TEST_STRESS, > +}; > > -static int test_ring_basic(odph_ring_t *r) > +/* local struct for ring_thread argument */ > +typedef struct { > + pthrd_arg thrdarg; > + int stress_type; > +} ring_arg_t; > + > +static int test_ring_basic(_ring_t *r) > { > void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = > NULL; > int ret; > unsigned i, num_elems; > > /* alloc dummy object pointers */ > - src = malloc(RING_SIZE*2*sizeof(void *)); > + src = malloc(RING_SIZE * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate test ring src memory\n"); > goto fail; > } > - for (i = 0; i < RING_SIZE*2; i++) > + for (i = 0; i < RING_SIZE * 2; i++) > src[i] = (void *)(unsigned long)i; > > cur_src = src; > > /* alloc some room for copied objects */ > - dst = malloc(RING_SIZE*2*sizeof(void *)); > + dst = malloc(RING_SIZE * 2 * sizeof(void *)); > if (dst == NULL) { > LOG_ERR("failed to allocate test ring dst memory\n"); > goto fail; > } > > - memset(dst, 0, RING_SIZE*2*sizeof(void *)); > + memset(dst, 0, RING_SIZE * 2 * sizeof(void *)); > cur_dst = dst; > > printf("Test SP & SC basic functions\n"); > printf("enqueue 1 obj\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, 1); > + ret = _ring_sp_enqueue_burst(r, cur_src, 1); > cur_src += 1; > - if ((ret & ODPH_RING_SZ_MASK) != 1) { > + if ((ret & _RING_SZ_MASK) != 1) { > LOG_ERR("sp_enq for 1 obj failed\n"); > goto fail; > } > > printf("enqueue 2 objs\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, 2); > + ret = _ring_sp_enqueue_burst(r, cur_src, 2); > cur_src += 2; > - if ((ret & ODPH_RING_SZ_MASK) != 2) { > + if ((ret & _RING_SZ_MASK) != 2) { > LOG_ERR("sp_enq for 2 obj failed\n"); > goto fail; > } > > printf("enqueue MAX_BULK objs\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK); > - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { > + ret = _ring_sp_enqueue_burst(r, cur_src, MAX_BULK); > + if ((ret & _RING_SZ_MASK) != MAX_BULK) { > LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK); > goto fail; > } > > printf("dequeue 1 obj\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1); > + ret = _ring_sc_dequeue_burst(r, cur_dst, 1); > cur_dst += 1; > - if ((ret & ODPH_RING_SZ_MASK) != 1) { > + if ((ret & _RING_SZ_MASK) != 1) { > LOG_ERR("sc_deq for 1 obj failed\n"); > goto fail; > } > > printf("dequeue 2 objs\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2); > + ret = _ring_sc_dequeue_burst(r, cur_dst, 2); > cur_dst += 2; > - if ((ret & ODPH_RING_SZ_MASK) != 2) { > + if ((ret & _RING_SZ_MASK) != 2) { > LOG_ERR("sc_deq for 2 obj failed\n"); > goto fail; > } > > printf("dequeue MAX_BULK objs\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); > + ret = _ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); > cur_dst += MAX_BULK; > - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { > + if ((ret & _RING_SZ_MASK) != MAX_BULK) { > LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK); > goto fail; > } > @@ -144,41 +153,41 @@ static int test_ring_basic(odph_ring_t *r) > printf("Test MP & MC basic functions\n"); > > printf("enqueue 1 obj\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1); > + ret = _ring_mp_enqueue_bulk(r, cur_src, 1); > cur_src += 1; > if (ret != 0) { > LOG_ERR("mp_enq for 1 obj failed\n"); > goto fail; > } > printf("enqueue 2 objs\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2); > + ret = _ring_mp_enqueue_bulk(r, cur_src, 2); > cur_src += 2; > if (ret != 0) { > LOG_ERR("mp_enq for 2 obj failed\n"); > goto fail; > } > printf("enqueue MAX_BULK objs\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); > + ret = _ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); > if (ret != 0) { > LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK); > goto fail; > } > printf("dequeue 1 obj\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, 1); > cur_dst += 1; > if (ret != 0) { > LOG_ERR("mc_deq for 1 obj failed\n"); > goto fail; > } > printf("dequeue 2 objs\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, 2); > cur_dst += 2; > if (ret != 0) { > LOG_ERR("mc_deq for 2 obj failed\n"); > goto fail; > } > printf("dequeue MAX_BULK objs\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); > cur_dst += MAX_BULK; > if (ret != 0) { > LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK); > @@ -191,30 +200,30 @@ static int test_ring_basic(odph_ring_t *r) > } > > printf("test watermark and default bulk enqueue / dequeue\n"); > - odph_ring_set_water_mark(r, 20); > + _ring_set_water_mark(r, 20); > num_elems = 16; > > cur_src = src; > cur_dst = dst; > > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); > + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); > cur_src += num_elems; > if (ret != 0) { > LOG_ERR("Cannot enqueue\n"); > goto fail; > } > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); > + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); > if (ret != -EDQUOT) { > LOG_ERR("Watermark not exceeded\n"); > goto fail; > } > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); > cur_dst += num_elems; > if (ret != 0) { > LOG_ERR("Cannot dequeue\n"); > goto fail; > } > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); > cur_dst += num_elems; > if (ret != 0) { > LOG_ERR("Cannot dequeue2\n"); > @@ -241,7 +250,7 @@ fail: > } > > /* global shared ring used for stress testing */ > -static odph_ring_t *r_stress; > +static _ring_t *r_stress; > > /* Stress func for Multi producer only */ > static int producer_fn(void) > @@ -251,7 +260,7 @@ static int producer_fn(void) > void **src = NULL; > > /* alloc dummy object pointers */ > - src = malloc(MAX_BULK*2*sizeof(void *)); > + src = malloc(MAX_BULK * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate producer memory.\n"); > return -1; > @@ -260,7 +269,7 @@ static int producer_fn(void) > src[i] = (void *)(unsigned long)i; > > do { > - i = odph_ring_mp_enqueue_bulk(r_stress, src, MAX_BULK); > + i = _ring_mp_enqueue_bulk(r_stress, src, MAX_BULK); > if (i == 0) { > free(src); > return 0; > @@ -275,14 +284,14 @@ static int consumer_fn(void) > void **src = NULL; > > /* alloc dummy object pointers */ > - src = malloc(MAX_BULK*2*sizeof(void *)); > + src = malloc(MAX_BULK * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate consumer memory.\n"); > return -1; > } > > do { > - i = odph_ring_mc_dequeue_bulk(r_stress, src, MAX_BULK); > + i = _ring_mc_dequeue_bulk(r_stress, src, MAX_BULK); > if (i == 0) { > for (i = 0; i < MAX_BULK; i++) { > if (src[i] != (void *)(unsigned long)i) { > @@ -298,7 +307,6 @@ static int consumer_fn(void) > } while (1); > } > > - > /* > * Note : make sure that both enqueue and dequeue > * operation starts at same time so to avoid data corruption > @@ -319,24 +327,22 @@ typedef enum { > static void test_ring_stress(stress_type_t type) > { > int thr; > + > thr = odp_thread_id(); > > switch (type) { > case one_enq_one_deq: > - > if (thr == 1) > producer_fn(); > if (thr == 2) > consumer_fn(); > break; > - > case multi_enq_multi_deq: > - if (thr%2 == 0) > + if (thr % 2 == 0) > producer_fn(); > else > consumer_fn(); > break; > - > case one_deq_rest_enq: > case one_enq_rest_deq:/*TBD*/ > default: > @@ -344,19 +350,12 @@ static void test_ring_stress(stress_type_t type) > } > } > > -/* local struct for ring_thread argument */ > -typedef struct { > - pthrd_arg thrdarg; > - int stress_type; > -} ring_arg_t; > - > - > static void *test_ring(void *arg) > { > ring_arg_t *parg = (ring_arg_t *)arg; > int thr; > - char ring_name[ODPH_RING_NAMESIZE]; > - odph_ring_t *r; > + char ring_name[_RING_NAMESIZE]; > + _ring_t *r; > int result = 0; > > thr = odp_thread_id(); > @@ -367,16 +366,16 @@ static void *test_ring(void *arg) > case ODP_RING_TEST_BASIC: > snprintf(ring_name, sizeof(ring_name), "test_ring_%i", > thr); > > - r = odph_ring_create(ring_name, RING_SIZE, > - 0 /* not used, alignement > - taken care inside func : todo */); > + r = _ring_create(ring_name, RING_SIZE, > + 0 /* not used, alignement > + taken care inside func : todo */); > if (r == NULL) { > LOG_ERR("ring create failed\n"); > result = -1; > break; > } > /* lookup ring from its name */ > - if (odph_ring_lookup(ring_name) != r) { > + if (_ring_lookup(ring_name) != r) { > LOG_ERR("ring lookup failed\n"); > result = -1; > break; > @@ -388,16 +387,16 @@ static void *test_ring(void *arg) > result = -1; > } > > - /* dump ring stats */ > - odph_ring_list_dump(); > + if (result) > + _ring_list_dump(); > > break; > > case ODP_RING_TEST_STRESS: > test_ring_stress(parg->stress_type); > > - /* dump ring stats */ > - odph_ring_list_dump(); > + if (result) > + _ring_list_dump(); > break; > > default: > @@ -417,54 +416,69 @@ static void *test_ring(void *arg) > return parg; > } > > - > -int main(int argc __attribute__((__unused__)), > - char *argv[] __attribute__((__unused__))) > +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > { > ring_arg_t rarg; > + odph_linux_pthread_t thread_tbl[MAX_WORKERS]; > + odp_cpumask_t cpu_mask; > + int num_workers; > + char ring_name[_RING_NAMESIZE]; > > - if (odp_test_global_init() != 0) > - return -1; > + if (odp_init_global(NULL, NULL)) { > + LOG_ERR("Error: ODP global init failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odp_print_system_info(); > + if (odp_init_local(ODP_THREAD_CONTROL)) { > + LOG_ERR("Error: ODP local init failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odph_ring_tailq_init(); > + _ring_tailq_init(); > > - rarg.thrdarg.numthrds = odp_cpu_count(); > + num_workers = odp_cpumask_default_worker(&cpu_mask, MAX_WORKERS); > + rarg.thrdarg.numthrds = rarg.thrdarg.numthrds; > > -#ifdef RING_TEST_BASIC > rarg.thrdarg.testcase = ODP_RING_TEST_BASIC; > -#else > + printf("starting stess test type : %d..\n", rarg.stress_type); > + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > + test_ring, (void *)&rarg, > + ODP_THREAD_WORKER); > + odph_linux_pthread_join(thread_tbl, num_workers); > + > rarg.thrdarg.testcase = ODP_RING_TEST_STRESS; > rarg.stress_type = one_enq_one_deq; > -/* rarg.stress_type = multi_enq_multi_deq;*/ > - char ring_name[ODPH_RING_NAMESIZE]; > > printf("starting stess test type : %d..\n", rarg.stress_type); > - /* create a ring */ > snprintf(ring_name, sizeof(ring_name), "test_ring_stress"); > - > - r_stress = odph_ring_create(ring_name, RING_SIZE, > - 0 /* not used, alignement > - taken care inside func : todo */); > + r_stress = _ring_create(ring_name, RING_SIZE, > + 0/* not used, alignement > + taken care inside func : todo */); > if (r_stress == NULL) { > LOG_ERR("ring create failed\n"); > goto fail; > } > /* lookup ring from its name */ > - if (odph_ring_lookup(ring_name) != r_stress) { > + if (_ring_lookup(ring_name) != r_stress) { > LOG_ERR("ring lookup failed\n"); > goto fail; > } > -#endif > - odp_test_thread_create(test_ring, (pthrd_arg *)&rarg); > > -#ifndef RING_TEST_BASIC > + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > + test_ring, (void *)&rarg, > + ODP_THREAD_WORKER); > + odph_linux_pthread_join(thread_tbl, num_workers); > + > fail: > -#endif > + if (odp_term_local()) { > + LOG_ERR("Error: ODP local term failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odp_test_thread_exit(&rarg.thrdarg); > + if (odp_term_global()) { > + LOG_ERR("Error: ODP global term failed.\n"); > + exit(EXIT_FAILURE); > + } > > return 0; > } > - > diff --git a/test/Makefile.am b/test/Makefile.am > index 2ba8008..4a75364 100644 > --- a/test/Makefile.am > +++ b/test/Makefile.am > @@ -1,4 +1,4 @@ > -SUBDIRS = api_test performance miscellaneous > +SUBDIRS = performance miscellaneous > > if cunit_support > SUBDIRS += validation > diff --git a/test/api_test/.gitignore b/test/api_test/.gitignore > deleted file mode 100644 > index 950f443..0000000 > --- a/test/api_test/.gitignore > +++ /dev/null > @@ -1,2 +0,0 @@ > -odp_ring > -odp_shm > diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am > deleted file mode 100644 > index fcdba48..0000000 > --- a/test/api_test/Makefile.am > +++ /dev/null > @@ -1,13 +0,0 @@ > -include $(top_srcdir)/test/Makefile.inc > - > -bin_PROGRAMS = odp_ring$(EXEEXT) > - > -odp_ring_CFLAGS = $(AM_CFLAGS) > - > -odp_ring_LDFLAGS = $(AM_LDFLAGS) -static > - > -noinst_HEADERS = \ > - $(top_srcdir)/test/api_test/odp_common.h \ > - $(top_srcdir)/test/test_debug.h > - > -dist_odp_ring_SOURCES = odp_ring_test.c odp_common.c > diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c > deleted file mode 100644 > index cebaa12..0000000 > --- a/test/api_test/odp_common.c > +++ /dev/null > @@ -1,91 +0,0 @@ > -/* Copyright (c) 2013, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -/** > - * @file > - * > - * ODP test application common > - */ > - > -#include <string.h> > -#include <odp.h> > -#include <odp/helper/linux.h> > -#include <odp_common.h> > -#include <test_debug.h> > - > -#define MAX_WORKERS 32 /**< Max worker threads */ > - > -/* Globals */ > -static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; /**< worker threads > table*/ > -static int num_workers; /**< number of > workers */ > - > -/** > - * Print system information > - */ > -void odp_print_system_info(void) > -{ > - odp_cpumask_t cpumask; > - char str[ODP_CPUMASK_STR_SIZE]; > - > - memset(str, 1, sizeof(str)); > - > - odp_cpumask_zero(&cpumask); > - > - odp_cpumask_from_str(&cpumask, "0x1"); > - (void)odp_cpumask_to_str(&cpumask, str, sizeof(str)); > - > - printf("\n"); > - printf("ODP system info\n"); > - printf("---------------\n"); > - printf("ODP API version: %s\n", odp_version_api_str()); > - printf("CPU model: %s\n", odp_sys_cpu_model_str()); > - printf("CPU freq (hz): %"PRIu64"\n", odp_sys_cpu_hz()); > - printf("Cache line size: %i\n", odp_sys_cache_line_size()); > - printf("CPU count: %i\n", odp_cpu_count()); > - printf("CPU mask: %s\n", str); > - > - printf("\n"); > -} > - > -/** test init globals and call odp_init_global() */ > -int odp_test_global_init(void) > -{ > - memset(thread_tbl, 0, sizeof(thread_tbl)); > - > - if (odp_init_global(NULL, NULL)) { > - LOG_ERR("ODP global init failed.\n"); > - return -1; > - } > - > - num_workers = odp_cpu_count(); > - /* force to max CPU count */ > - if (num_workers > MAX_WORKERS) > - num_workers = MAX_WORKERS; > - > - return 0; > -} > - > -/** create test thread */ > -int odp_test_thread_create(void *func_ptr(void *), pthrd_arg *arg) > -{ > - odp_cpumask_t cpumask; > - > - /* Create and init additional threads */ > - odp_cpumask_default_worker(&cpumask, arg->numthrds); > - odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr, > - (void *)arg, ODP_THREAD_WORKER); > - > - return 0; > -} > - > -/** exit from test thread */ > -int odp_test_thread_exit(pthrd_arg *arg) > -{ > - /* Wait for other threads to exit */ > - odph_linux_pthread_join(thread_tbl, arg->numthrds); > - > - return 0; > -} > diff --git a/test/api_test/odp_common.h b/test/api_test/odp_common.h > deleted file mode 100644 > index f321b6b..0000000 > --- a/test/api_test/odp_common.h > +++ /dev/null > @@ -1,42 +0,0 @@ > -/* Copyright (c) 2013, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -/** > - * @file > - * > - * ODP test application common headers > - */ > - > -#ifndef ODP_COMMON_H > -#define ODP_COMMON_H > - > -#define MAX_WORKERS 32 /**< Maximum number of work threads */ > - > -/** types of tests */ > -typedef enum { > - ODP_ATOMIC_TEST = 0, > - ODP_SHM_TEST, > - ODP_RING_TEST_BASIC, > - ODP_RING_TEST_STRESS, > - ODP_TIMER_PING_TEST, > - ODP_MAX_TEST > -} odp_test_case_e; > - > -/** > - * Thread argument > - */ > -typedef struct { > - int testcase; /**< specifies which set of API's to exercise */ > - int numthrds; /**< no of pthreads to create */ > -} pthrd_arg; > - > -extern void odp_print_system_info(void); > -extern int odp_test_global_init(void); > -/** create thread fro start_routine function */ > -extern int odp_test_thread_create(void *(*start_routine) (void *), > pthrd_arg *); > -extern int odp_test_thread_exit(pthrd_arg *); > - > -#endif /* ODP_COMMON_H */ > -- > 1.9.1 > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > https://lists.linaro.org/mailman/listinfo/lng-odp > -- Mike Holmes Technical Manager - Linaro Networking Group Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
Also Using patch: lng-odp_PATCHv18_5-9_linux-generic-helper_move_ring_from_helper_to_linux-generic.mbox Trying to apply patch Patch applied CHECK: Prefer using ... .... CC pktio/ring.lo ../../../../platform/linux-generic/pktio/ring.c:74:24: fatal error: odph_pause.h: No such file or directory compilation terminated. Makefile:737: recipe for target 'pktio/ring.lo' failed make[2]: *** [pktio/ring.lo] Error 1 On 18 December 2015 at 12:09, Mike Holmes <mike.holmes@linaro.org> wrote: > From checkpatch > > There should be a "default:" statement, if not we can clear this warning > in checkpatch by adding a comment in the actual code explaining why a > default is not needed. > > WARNING: Possible switch case/default not preceeded by break or > fallthrough comment > #2069: FILE: platform/linux-generic/pktio/ring.c:105: > + case 1: \ > > WARNING: Possible switch case/default not preceeded by break or > fallthrough comment > #2098: FILE: platform/linux-generic/pktio/ring.c:134: > + case 1: \ > > > There are other BIT macro warnings like this one, but I think we need to > disable them and I sent a patch to do so, maybe that will prompt us to add > a BIT macro but for now I dont think these should block acceptance > > CHECK: Prefer using the BIT macro > #1523: FILE: > platform/linux-generic/include/odp_packet_io_ring_internal.h:158: > +#define _RING_F_SP_ENQ (1 << 0) > > > On 18 December 2015 at 06:29, Maxim Uvarov <maxim.uvarov@linaro.org> > wrote: > >> Move ring and it's test from helper to linux-generic/pktio and kill >> not needed api_test directory. Unfortunately odp_ring_test.c had some old >> dirty code so I had to clean up it to to use cunit and >> latest helper apis. >> >> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> >> --- >> configure.ac | 1 - >> helper/Makefile.am | 2 - >> helper/test/Makefile.am | 5 +- >> platform/linux-generic/Makefile.am | 2 + >> .../include/odp_packet_io_ring_internal.h | 112 +++++---- >> platform/linux-generic/m4/configure.m4 | 3 +- >> {helper => platform/linux-generic/pktio}/ring.c | 263 >> ++++++++++----------- >> platform/linux-generic/test/Makefile.am | 3 +- >> platform/linux-generic/test/ring/.gitignore | 1 + >> platform/linux-generic/test/ring/Makefile.am | 16 ++ >> .../linux-generic/test/ring/ringtest.c | 180 +++++++------- >> test/Makefile.am | 2 +- >> test/api_test/.gitignore | 2 - >> test/api_test/Makefile.am | 13 - >> test/api_test/odp_common.c | 91 ------- >> test/api_test/odp_common.h | 42 ---- >> 16 files changed, 309 insertions(+), 429 deletions(-) >> rename helper/include/odp/helper/ring.h => >> platform/linux-generic/include/odp_packet_io_ring_internal.h (87%) >> rename {helper => platform/linux-generic/pktio}/ring.c (71%) >> create mode 100644 platform/linux-generic/test/ring/.gitignore >> create mode 100644 platform/linux-generic/test/ring/Makefile.am >> rename test/api_test/odp_ring_test.c => >> platform/linux-generic/test/ring/ringtest.c (72%) >> delete mode 100644 test/api_test/.gitignore >> delete mode 100644 test/api_test/Makefile.am >> delete mode 100644 test/api_test/odp_common.c >> delete mode 100644 test/api_test/odp_common.h >> >> diff --git a/configure.ac b/configure.ac >> index e45d90a..28b9ec9 100644 >> --- a/configure.ac >> +++ b/configure.ac >> @@ -345,7 +345,6 @@ AC_CONFIG_FILES([Makefile >> pkgconfig/libodphelper.pc >> scripts/Makefile >> test/Makefile >> - test/api_test/Makefile >> test/performance/Makefile >> test/validation/Makefile >> test/validation/buffer/Makefile >> diff --git a/helper/Makefile.am b/helper/Makefile.am >> index 1906ae2..6828092 100644 >> --- a/helper/Makefile.am >> +++ b/helper/Makefile.am >> @@ -8,7 +8,6 @@ AM_CFLAGS += -I$(top_srcdir)/include >> >> helperincludedir = $(includedir)/odp/helper/ >> helperinclude_HEADERS = \ >> - $(srcdir)/include/odp/helper/ring.h \ >> $(srcdir)/include/odp/helper/linux.h \ >> $(srcdir)/include/odp/helper/chksum.h\ >> $(srcdir)/include/odp/helper/eth.h\ >> @@ -29,7 +28,6 @@ noinst_HEADERS = \ >> >> __LIB__libodphelper_la_SOURCES = \ >> linux.c \ >> - ring.c \ >> hashtable.c \ >> lineartable.c >> >> diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am >> index 1c6a802..cf3b7aa 100644 >> --- a/helper/test/Makefile.am >> +++ b/helper/test/Makefile.am >> @@ -1,6 +1,7 @@ >> include $(top_srcdir)/test/Makefile.inc >> >> AM_CFLAGS += -I$(srcdir)/common >> +AM_CFLAGS += -I$(top_srcdir)/test/validation/common >> AM_LDFLAGS += -static >> >> TESTS_ENVIRONMENT += TEST_DIR=${builddir} >> @@ -28,5 +29,5 @@ dist_thread_SOURCES = thread.c >> thread_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp.la >> dist_process_SOURCES = process.c >> process_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp.la >> -odph_pause_SOURCES = pause.c >> -dist_odp_table_SOURCES = table.c >> +dist_pause_SOURCES = pause.c >> +dist_table_SOURCES = table.c >> diff --git a/platform/linux-generic/Makefile.am >> b/platform/linux-generic/Makefile.am >> index 4639ebc..8160649 100644 >> --- a/platform/linux-generic/Makefile.am >> +++ b/platform/linux-generic/Makefile.am >> @@ -90,6 +90,7 @@ noinst_HEADERS = \ >> ${srcdir}/include/odp_packet_internal.h \ >> ${srcdir}/include/odp_packet_io_internal.h \ >> ${srcdir}/include/odp_packet_io_queue.h \ >> + ${srcdir}/include/odp_packet_io_ring_internal.h \ >> ${srcdir}/include/odp_packet_netmap.h \ >> ${srcdir}/include/odp_packet_socket.h \ >> ${srcdir}/include/odp_packet_tap.h \ >> @@ -122,6 +123,7 @@ __LIB__libodp_la_SOURCES = \ >> pktio/socket.c \ >> pktio/socket_mmap.c \ >> pktio/tap.c \ >> + pktio/ring.c \ >> odp_pool.c \ >> odp_queue.c \ >> odp_rwlock.c \ >> diff --git a/helper/include/odp/helper/ring.h >> b/platform/linux-generic/include/odp_packet_io_ring_internal.h >> similarity index 87% >> rename from helper/include/odp/helper/ring.h >> rename to platform/linux-generic/include/odp_packet_io_ring_internal.h >> index 541a466..f97c026 100644 >> --- a/helper/include/odp/helper/ring.h >> +++ b/platform/linux-generic/include/odp_packet_io_ring_internal.h >> @@ -89,29 +89,28 @@ >> * >> */ >> >> -#ifndef ODPH_RING_H_ >> -#define ODPH_RING_H_ >> +#ifndef _RING_H_ >> +#define _RING_H_ >> >> #ifdef __cplusplus >> extern "C" { >> #endif >> >> - >> #include <odp/std_types.h> >> #include <odp/hints.h> >> #include <odp/atomic.h> >> #include <errno.h> >> #include <sys/queue.h> >> +#include <odp_debug_internal.h> >> >> -enum odph_ring_queue_behavior { >> - ODPH_RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number >> +enum _ring_queue_behavior { >> + _RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number >> of items from a ring */ >> - ODPH_RING_QUEUE_VARIABLE /**< Enq/Deq as many items >> + _RING_QUEUE_VARIABLE /**< Enq/Deq as many items >> a possible from ring */ >> }; >> >> - >> -#define ODPH_RING_NAMESIZE 32 /**< The maximum length of a ring name. */ >> +#define _RING_NAMESIZE 32 /**< The maximum length of a ring name. */ >> >> /** >> * An ODP ring structure. >> @@ -123,12 +122,12 @@ enum odph_ring_queue_behavior { >> * values in a modulo-32bit base: that's why the overflow of the indexes >> is not >> * a problem. >> */ >> -typedef struct odph_ring { >> +typedef struct _ring { >> /** @private Next in list. */ >> - TAILQ_ENTRY(odph_ring) next; >> + TAILQ_ENTRY(_ring) next; >> >> /** @private Name of the ring. */ >> - char name[ODPH_RING_NAMESIZE]; >> + char name[_RING_NAMESIZE]; >> /** @private Flags supplied at creation. */ >> int flags; >> >> @@ -153,21 +152,21 @@ typedef struct odph_ring { >> >> /** @private Memory space of ring starts here. */ >> void *ring[0] ODP_ALIGNED_CACHE; >> -} odph_ring_t; >> +} _ring_t; >> >> /* The default enqueue is "single-producer".*/ >> -#define ODPH_RING_F_SP_ENQ (1 << 0) >> +#define _RING_F_SP_ENQ (1 << 0) >> /* The default dequeue is "single-consumer".*/ >> -#define ODPH_RING_F_SC_DEQ (1 << 1) >> +#define _RING_F_SC_DEQ (1 << 1) >> /* If set - ring is visible from different processes. >> * Default is thread visible.*/ >> -#define ODPH_RING_SHM_PROC (1 << 2) >> +#define _RING_SHM_PROC (1 << 2) >> /* Do not link ring to linked list. */ >> -#define ODPH_RING_NO_LIST (1 << 3) >> +#define _RING_NO_LIST (1 << 3) >> /* Quota exceed for burst ops */ >> -#define ODPH_RING_QUOT_EXCEED (1 << 31) >> +#define _RING_QUOT_EXCEED (1 << 31) >> /* Ring size mask */ >> -#define ODPH_RING_SZ_MASK (unsigned)(0x0fffffff) >> +#define _RING_SZ_MASK (unsigned)(0x0fffffff) >> >> /** >> * Create a new ring named *name* in memory. >> @@ -198,9 +197,8 @@ typedef struct odph_ring { >> * - EEXIST - a memzone with the same name already exists >> * - ENOMEM - no appropriate memory area found in which to create >> memzone >> */ >> -odph_ring_t *odph_ring_create(const char *name, unsigned count, >> - unsigned flags); >> - >> +_ring_t *_ring_create(const char *name, unsigned count, >> + unsigned flags); >> >> /** >> * Change the high water mark. >> @@ -217,14 +215,14 @@ odph_ring_t *odph_ring_create(const char *name, >> unsigned count, >> * @return 0: Success; water mark changed. >> * -EINVAL: Invalid water mark value. >> */ >> -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count); >> +int _ring_set_water_mark(_ring_t *r, unsigned count); >> >> /** >> * Dump the status of the ring to the console. >> * >> * @param r A pointer to the ring structure. >> */ >> -void odph_ring_dump(const odph_ring_t *r); >> +void _ring_dump(const _ring_t *r); >> >> /** >> * Enqueue several objects on the ring (multi-producers safe). >> @@ -251,9 +249,9 @@ void odph_ring_dump(const odph_ring_t *r); >> * if behavior = ODP_RING_QUEUE_VARIABLE >> * - n: Actual number of objects enqueued. >> */ >> -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, >> - unsigned n, >> - enum odph_ring_queue_behavior behavior); >> +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, >> + unsigned n, >> + enum _ring_queue_behavior behavior); >> >> /** >> * Enqueue several objects on a ring (NOT multi-producers safe). >> @@ -277,9 +275,9 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * >> const *obj_table, >> * if behavior = ODP_RING_QUEUE_VARIABLE >> * - n: Actual number of objects enqueued. >> */ >> -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, >> - unsigned n, >> - enum odph_ring_queue_behavior behavior); >> +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, >> + unsigned n, >> + enum _ring_queue_behavior behavior); >> >> /** >> * Dequeue several objects from a ring (multi-consumers safe). When >> @@ -308,9 +306,9 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * >> const *obj_table, >> * - n: Actual number of objects dequeued. >> */ >> >> -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, >> - unsigned n, >> - enum odph_ring_queue_behavior behavior); >> +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, >> + unsigned n, >> + enum _ring_queue_behavior behavior); >> >> /** >> * Dequeue several objects from a ring (NOT multi-consumers safe). >> @@ -335,9 +333,9 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void >> **obj_table, >> * if behavior = ODP_RING_QUEUE_VARIABLE >> * - n: Actual number of objects dequeued. >> */ >> -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, >> - unsigned n, >> - enum odph_ring_queue_behavior behavior); >> +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, >> + unsigned n, >> + enum _ring_queue_behavior behavior); >> >> /** >> * Enqueue several objects on the ring (multi-producers safe). >> @@ -357,8 +355,8 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void >> **obj_table, >> * high water mark is exceeded. >> * - -ENOBUFS: Not enough room in the ring to enqueue, no object is >> enqueued. >> */ >> -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, >> - unsigned n); >> +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, >> + unsigned n); >> >> /** >> * Enqueue several objects on a ring (NOT multi-producers safe). >> @@ -375,8 +373,8 @@ int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * >> const *obj_table, >> * high water mark is exceeded. >> * - -ENOBUFS: Not enough room in the ring to enqueue; no object is >> enqueued. >> */ >> -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, >> - unsigned n); >> +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, >> + unsigned n); >> >> /** >> * Dequeue several objects from a ring (multi-consumers safe). >> @@ -395,7 +393,7 @@ int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * >> const *obj_table, >> * - -ENOENT: Not enough entries in the ring to dequeue; no object is >> * dequeued. >> */ >> -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned >> n); >> +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); >> >> /** >> * Dequeue several objects from a ring (NOT multi-consumers safe). >> @@ -412,7 +410,7 @@ int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void >> **obj_table, unsigned n); >> * - -ENOENT: Not enough entries in the ring to dequeue; no object is >> * dequeued. >> */ >> -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned >> n); >> +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); >> >> /** >> * Test if a ring is full. >> @@ -423,7 +421,7 @@ int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void >> **obj_table, unsigned n); >> * - 1: The ring is full. >> * - 0: The ring is not full. >> */ >> -int odph_ring_full(const odph_ring_t *r); >> +int _ring_full(const _ring_t *r); >> >> /** >> * Test if a ring is empty. >> @@ -434,7 +432,7 @@ int odph_ring_full(const odph_ring_t *r); >> * - 1: The ring is empty. >> * - 0: The ring is not empty. >> */ >> -int odph_ring_empty(const odph_ring_t *r); >> +int _ring_empty(const _ring_t *r); >> >> /** >> * Return the number of entries in a ring. >> @@ -444,7 +442,7 @@ int odph_ring_empty(const odph_ring_t *r); >> * @return >> * The number of entries in the ring. >> */ >> -unsigned odph_ring_count(const odph_ring_t *r); >> +unsigned _ring_count(const _ring_t *r); >> >> /** >> * Return the number of free entries in a ring. >> @@ -454,14 +452,14 @@ unsigned odph_ring_count(const odph_ring_t *r); >> * @return >> * The number of free entries in the ring. >> */ >> -unsigned odph_ring_free_count(const odph_ring_t *r); >> +unsigned _ring_free_count(const _ring_t *r); >> >> /** >> * search ring by name >> * @param name ring name to search >> * @return pointer to ring otherwise NULL >> */ >> -odph_ring_t *odph_ring_lookup(const char *name); >> +_ring_t *_ring_lookup(const char *name); >> >> /** >> * Enqueue several objects on the ring (multi-producers safe). >> @@ -478,8 +476,8 @@ odph_ring_t *odph_ring_lookup(const char *name); >> * @return >> * - n: Actual number of objects enqueued. >> */ >> -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const *obj_table, >> - unsigned n); >> +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, >> + unsigned n); >> >> /** >> * Enqueue several objects on a ring (NOT multi-producers safe). >> @@ -493,8 +491,8 @@ int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * >> const *obj_table, >> * @return >> * - n: Actual number of objects enqueued. >> */ >> -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const *obj_table, >> - unsigned n); >> +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, >> + unsigned n); >> /** >> * Enqueue several objects on a ring. >> * >> @@ -511,8 +509,8 @@ int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * >> const *obj_table, >> * @return >> * - n: Actual number of objects enqueued. >> */ >> -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, >> - unsigned n); >> +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, >> + unsigned n); >> >> /** >> * Dequeue several objects from a ring (multi-consumers safe). When the >> request >> @@ -531,7 +529,7 @@ int odph_ring_enqueue_burst(odph_ring_t *r, void * >> const *obj_table, >> * @return >> * - n: Actual number of objects dequeued, 0 if ring is empty >> */ >> -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, >> unsigned n); >> +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); >> >> /** >> * Dequeue several objects from a ring (NOT multi-consumers safe).When >> the >> @@ -547,7 +545,7 @@ int odph_ring_mc_dequeue_burst(odph_ring_t *r, void >> **obj_table, unsigned n); >> * @return >> * - n: Actual number of objects dequeued, 0 if ring is empty >> */ >> -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, >> unsigned n); >> +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); >> >> /** >> * Dequeue multiple objects from a ring up to a maximum number. >> @@ -565,17 +563,17 @@ int odph_ring_sc_dequeue_burst(odph_ring_t *r, void >> **obj_table, unsigned n); >> * @return >> * - Number of objects dequeued, or a negative error code on error >> */ >> -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned >> n); >> +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); >> >> /** >> * dump the status of all rings on the console >> */ >> -void odph_ring_list_dump(void); >> +void _ring_list_dump(void); >> >> /** >> * initialise ring tailq >> */ >> -void odph_ring_tailq_init(void); >> +void _ring_tailq_init(void); >> >> #ifdef __cplusplus >> } >> diff --git a/platform/linux-generic/m4/configure.m4 >> b/platform/linux-generic/m4/configure.m4 >> index df6dc64..6bb159f 100644 >> --- a/platform/linux-generic/m4/configure.m4 >> +++ b/platform/linux-generic/m4/configure.m4 >> @@ -23,4 +23,5 @@ m4_include([platform/linux-generic/m4/odp_pcap.m4]) >> >> AC_CONFIG_FILES([platform/linux-generic/Makefile >> platform/linux-generic/test/Makefile >> - platform/linux-generic/test/pktio/Makefile]) >> + platform/linux-generic/test/pktio/Makefile >> + platform/linux-generic/test/ring/Makefile]) >> diff --git a/helper/ring.c b/platform/linux-generic/pktio/ring.c >> similarity index 71% >> rename from helper/ring.c >> rename to platform/linux-generic/pktio/ring.c >> index e113606..e978420 100644 >> --- a/helper/ring.c >> +++ b/platform/linux-generic/pktio/ring.c >> @@ -78,9 +78,9 @@ >> #include <string.h> >> #include "odph_debug.h" >> #include <odp/rwlock.h> >> -#include <odp/helper/ring.h> >> +#include <odp_packet_io_ring_internal.h> >> >> -static TAILQ_HEAD(, odph_ring) odp_ring_list; >> +static TAILQ_HEAD(, _ring) odp_ring_list; >> >> #define RING_VAL_IS_POWER_2(x) ((((x) - 1) & (x)) == 0) >> >> @@ -93,9 +93,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; >> if (odp_likely(idx + n < size)) { \ >> for (i = 0; i < (n & ((~(unsigned)0x3))); i += 4, idx += >> 4) { \ >> r->ring[idx] = obj_table[i]; \ >> - r->ring[idx+1] = obj_table[i+1]; \ >> - r->ring[idx+2] = obj_table[i+2]; \ >> - r->ring[idx+3] = obj_table[i+3]; \ >> + r->ring[idx + 1] = obj_table[i + 1]; \ >> + r->ring[idx + 2] = obj_table[i + 2]; \ >> + r->ring[idx + 3] = obj_table[i + 3]; \ >> } \ >> switch (n & 0x3) { \ >> case 3: \ >> @@ -122,9 +122,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; >> if (odp_likely(idx + n < size)) { \ >> for (i = 0; i < (n & (~(unsigned)0x3)); i += 4, idx += 4) >> {\ >> obj_table[i] = r->ring[idx]; \ >> - obj_table[i+1] = r->ring[idx+1]; \ >> - obj_table[i+2] = r->ring[idx+2]; \ >> - obj_table[i+3] = r->ring[idx+3]; \ >> + obj_table[i + 1] = r->ring[idx + 1]; \ >> + obj_table[i + 2] = r->ring[idx + 2]; \ >> + obj_table[i + 3] = r->ring[idx + 3]; \ >> } \ >> switch (n & 0x3) { \ >> case 3: \ >> @@ -145,36 +145,37 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; >> static odp_rwlock_t qlock; /* rings tailq lock */ >> >> /* init tailq_ring */ >> -void odph_ring_tailq_init(void) >> +void _ring_tailq_init(void) >> { >> TAILQ_INIT(&odp_ring_list); >> odp_rwlock_init(&qlock); >> } >> >> /* create the ring */ >> -odph_ring_t * >> -odph_ring_create(const char *name, unsigned count, unsigned flags) >> +_ring_t * >> +_ring_create(const char *name, unsigned count, unsigned flags) >> { >> - char ring_name[ODPH_RING_NAMESIZE]; >> - odph_ring_t *r; >> + char ring_name[_RING_NAMESIZE]; >> + _ring_t *r; >> size_t ring_size; >> uint32_t shm_flag; >> odp_shm_t shm; >> >> - if (flags & ODPH_RING_SHM_PROC) >> + if (flags & _RING_SHM_PROC) >> shm_flag = ODP_SHM_PROC; >> else >> shm_flag = 0; >> >> /* count must be a power of 2 */ >> - if (!RING_VAL_IS_POWER_2(count) || (count > ODPH_RING_SZ_MASK)) { >> - ODPH_ERR("Requested size is invalid, must be power of 2, >> and do not exceed the size limit %u\n", >> - ODPH_RING_SZ_MASK); >> + if (!RING_VAL_IS_POWER_2(count) || (count > _RING_SZ_MASK)) { >> + ODPH_ERR("Requested size is invalid, must be power of 2," >> + "and do not exceed the size limit %u\n", >> + _RING_SZ_MASK); >> return NULL; >> } >> >> snprintf(ring_name, sizeof(ring_name), "%s", name); >> - ring_size = count*sizeof(void *)+sizeof(odph_ring_t); >> + ring_size = count * sizeof(void *) + sizeof(_ring_t); >> >> odp_rwlock_write_lock(&qlock); >> /* reserve a memory zone for this ring.*/ >> @@ -188,18 +189,18 @@ odph_ring_create(const char *name, unsigned count, >> unsigned flags) >> snprintf(r->name, sizeof(r->name), "%s", name); >> r->flags = flags; >> r->prod.watermark = count; >> - r->prod.sp_enqueue = !!(flags & ODPH_RING_F_SP_ENQ); >> - r->cons.sc_dequeue = !!(flags & ODPH_RING_F_SC_DEQ); >> + r->prod.sp_enqueue = !!(flags & _RING_F_SP_ENQ); >> + r->cons.sc_dequeue = !!(flags & _RING_F_SC_DEQ); >> r->prod.size = count; >> r->cons.size = count; >> - r->prod.mask = count-1; >> - r->cons.mask = count-1; >> + r->prod.mask = count - 1; >> + r->cons.mask = count - 1; >> r->prod.head = 0; >> r->cons.head = 0; >> r->prod.tail = 0; >> r->cons.tail = 0; >> >> - if (!(flags & ODPH_RING_NO_LIST)) >> + if (!(flags & _RING_NO_LIST)) >> TAILQ_INSERT_TAIL(&odp_ring_list, r, next); >> } else { >> ODPH_ERR("Cannot reserve memory\n"); >> @@ -213,7 +214,7 @@ odph_ring_create(const char *name, unsigned count, >> unsigned flags) >> * change the high water mark. If *count* is 0, water marking is >> * disabled >> */ >> -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count) >> +int _ring_set_water_mark(_ring_t *r, unsigned count) >> { >> if (count >= r->prod.size) >> return -EINVAL; >> @@ -229,8 +230,8 @@ int odph_ring_set_water_mark(odph_ring_t *r, unsigned >> count) >> /** >> * Enqueue several objects on the ring (multi-producers safe). >> */ >> -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, >> - unsigned n, enum odph_ring_queue_behavior >> behavior) >> +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, >> + unsigned n, enum _ring_queue_behavior behavior) >> { >> uint32_t prod_head, prod_next; >> uint32_t cons_tail, free_entries; >> @@ -255,24 +256,22 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void >> * const *obj_table, >> >> /* check that we have enough room in ring */ >> if (odp_unlikely(n > free_entries)) { >> - if (behavior == ODPH_RING_QUEUE_FIXED) { >> + if (behavior == _RING_QUEUE_FIXED) >> return -ENOBUFS; >> - } else { >> - /* No free entry available */ >> - if (odp_unlikely(free_entries == 0)) >> - return 0; >> + /* No free entry available */ >> + if (odp_unlikely(free_entries == 0)) >> + return 0; >> >> - n = free_entries; >> - } >> + n = free_entries; >> } >> >> prod_next = prod_head + n; >> success = __atomic_compare_exchange_n(&r->prod.head, >> - &prod_head, >> - prod_next, >> - false/*strong*/, >> - __ATOMIC_ACQUIRE, >> - __ATOMIC_RELAXED); >> + &prod_head, >> + prod_next, >> + false/*strong*/, >> + __ATOMIC_ACQUIRE, >> + __ATOMIC_RELAXED); >> } while (odp_unlikely(success == 0)); >> >> /* write entries in ring */ >> @@ -280,10 +279,10 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void >> * const *obj_table, >> >> /* if we exceed the watermark */ >> if (odp_unlikely(((mask + 1) - free_entries + n) > >> r->prod.watermark)) { >> - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : >> - (int)(n | ODPH_RING_QUOT_EXCEED); >> + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : >> + (int)(n | _RING_QUOT_EXCEED); >> } else { >> - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; >> + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; >> } >> >> /* >> @@ -302,8 +301,8 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * >> const *obj_table, >> /** >> * Enqueue several objects on a ring (NOT multi-producers safe). >> */ >> -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, >> - unsigned n, enum odph_ring_queue_behavior >> behavior) >> +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, >> + unsigned n, enum _ring_queue_behavior behavior) >> { >> uint32_t prod_head, cons_tail; >> uint32_t prod_next, free_entries; >> @@ -321,15 +320,13 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void >> * const *obj_table, >> >> /* check that we have enough room in ring */ >> if (odp_unlikely(n > free_entries)) { >> - if (behavior == ODPH_RING_QUEUE_FIXED) { >> + if (behavior == _RING_QUEUE_FIXED) >> return -ENOBUFS; >> - } else { >> - /* No free entry available */ >> - if (odp_unlikely(free_entries == 0)) >> - return 0; >> + /* No free entry available */ >> + if (odp_unlikely(free_entries == 0)) >> + return 0; >> >> - n = free_entries; >> - } >> + n = free_entries; >> } >> >> prod_next = prod_head + n; >> @@ -340,10 +337,10 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void >> * const *obj_table, >> >> /* if we exceed the watermark */ >> if (odp_unlikely(((mask + 1) - free_entries + n) > >> r->prod.watermark)) { >> - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : >> - (int)(n | ODPH_RING_QUOT_EXCEED); >> + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : >> + (int)(n | _RING_QUOT_EXCEED); >> } else { >> - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; >> + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; >> } >> >> /* Release our entries and the memory they refer to */ >> @@ -356,8 +353,8 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * >> const *obj_table, >> * Dequeue several objects from a ring (multi-consumers safe). >> */ >> >> -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, >> - unsigned n, enum odph_ring_queue_behavior >> behavior) >> +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, >> + unsigned n, enum _ring_queue_behavior behavior) >> { >> uint32_t cons_head, prod_tail; >> uint32_t cons_next, entries; >> @@ -381,23 +378,21 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void >> **obj_table, >> >> /* Set the actual entries for dequeue */ >> if (n > entries) { >> - if (behavior == ODPH_RING_QUEUE_FIXED) { >> + if (behavior == _RING_QUEUE_FIXED) >> return -ENOENT; >> - } else { >> - if (odp_unlikely(entries == 0)) >> - return 0; >> + if (odp_unlikely(entries == 0)) >> + return 0; >> >> - n = entries; >> - } >> + n = entries; >> } >> >> cons_next = cons_head + n; >> success = __atomic_compare_exchange_n(&r->cons.head, >> - &cons_head, >> - cons_next, >> - false/*strong*/, >> - __ATOMIC_ACQUIRE, >> - __ATOMIC_RELAXED); >> + &cons_head, >> + cons_next, >> + false/*strong*/, >> + __ATOMIC_ACQUIRE, >> + __ATOMIC_RELAXED); >> } while (odp_unlikely(success == 0)); >> >> /* copy in table */ >> @@ -414,14 +409,14 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void >> **obj_table, >> __atomic_thread_fence(__ATOMIC_RELEASE); >> r->cons.tail = cons_next; >> >> - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; >> + return behavior == _RING_QUEUE_FIXED ? 0 : n; >> } >> >> /** >> * Dequeue several objects from a ring (NOT multi-consumers safe). >> */ >> -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, >> - unsigned n, enum odph_ring_queue_behavior >> behavior) >> +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, >> + unsigned n, enum _ring_queue_behavior behavior) >> { >> uint32_t cons_head, prod_tail; >> uint32_t cons_next, entries; >> @@ -437,14 +432,12 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void >> **obj_table, >> entries = prod_tail - cons_head; >> >> if (n > entries) { >> - if (behavior == ODPH_RING_QUEUE_FIXED) { >> + if (behavior == _RING_QUEUE_FIXED) >> return -ENOENT; >> - } else { >> - if (odp_unlikely(entries == 0)) >> - return 0; >> + if (odp_unlikely(entries == 0)) >> + return 0; >> >> - n = entries; >> - } >> + n = entries; >> } >> >> cons_next = cons_head + n; >> @@ -456,127 +449,131 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, >> void **obj_table, >> DEQUEUE_PTRS(); >> >> r->cons.tail = cons_next; >> - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; >> + return behavior == _RING_QUEUE_FIXED ? 0 : n; >> } >> >> /** >> * Enqueue several objects on the ring (multi-producers safe). >> */ >> -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, >> - unsigned n) >> +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, >> + unsigned n) >> { >> - return __odph_ring_mp_do_enqueue(r, obj_table, n, >> - ODPH_RING_QUEUE_FIXED); >> + return ___ring_mp_do_enqueue(r, obj_table, n, >> + _RING_QUEUE_FIXED); >> } >> >> /** >> * Enqueue several objects on a ring (NOT multi-producers safe). >> */ >> -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, >> - unsigned n) >> +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, >> + unsigned n) >> { >> - return __odph_ring_sp_do_enqueue(r, obj_table, n, >> - ODPH_RING_QUEUE_FIXED); >> + return ___ring_sp_do_enqueue(r, obj_table, n, >> + _RING_QUEUE_FIXED); >> } >> >> /** >> * Dequeue several objects from a ring (multi-consumers safe). >> */ >> -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned >> n) >> +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) >> { >> - return __odph_ring_mc_do_dequeue(r, obj_table, n, >> - ODPH_RING_QUEUE_FIXED); >> + return ___ring_mc_do_dequeue(r, obj_table, n, >> + _RING_QUEUE_FIXED); >> } >> >> /** >> * Dequeue several objects from a ring (NOT multi-consumers safe). >> */ >> -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned >> n) >> +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) >> { >> - return __odph_ring_sc_do_dequeue(r, obj_table, n, >> - ODPH_RING_QUEUE_FIXED); >> + return ___ring_sc_do_dequeue(r, obj_table, n, >> + _RING_QUEUE_FIXED); >> } >> >> /** >> * Test if a ring is full. >> */ >> -int odph_ring_full(const odph_ring_t *r) >> +int _ring_full(const _ring_t *r) >> { >> uint32_t prod_tail = r->prod.tail; >> uint32_t cons_tail = r->cons.tail; >> + >> return (((cons_tail - prod_tail - 1) & r->prod.mask) == 0); >> } >> >> /** >> * Test if a ring is empty. >> */ >> -int odph_ring_empty(const odph_ring_t *r) >> +int _ring_empty(const _ring_t *r) >> { >> uint32_t prod_tail = r->prod.tail; >> uint32_t cons_tail = r->cons.tail; >> + >> return !!(cons_tail == prod_tail); >> } >> >> /** >> * Return the number of entries in a ring. >> */ >> -unsigned odph_ring_count(const odph_ring_t *r) >> +unsigned _ring_count(const _ring_t *r) >> { >> uint32_t prod_tail = r->prod.tail; >> uint32_t cons_tail = r->cons.tail; >> + >> return (prod_tail - cons_tail) & r->prod.mask; >> } >> >> /** >> * Return the number of free entries in a ring. >> */ >> -unsigned odph_ring_free_count(const odph_ring_t *r) >> +unsigned _ring_free_count(const _ring_t *r) >> { >> uint32_t prod_tail = r->prod.tail; >> uint32_t cons_tail = r->cons.tail; >> + >> return (cons_tail - prod_tail - 1) & r->prod.mask; >> } >> >> /* dump the status of the ring on the console */ >> -void odph_ring_dump(const odph_ring_t *r) >> +void _ring_dump(const _ring_t *r) >> { >> - ODPH_DBG("ring <%s>@%p\n", r->name, r); >> - ODPH_DBG(" flags=%x\n", r->flags); >> - ODPH_DBG(" size=%" PRIu32 "\n", r->prod.size); >> - ODPH_DBG(" ct=%" PRIu32 "\n", r->cons.tail); >> - ODPH_DBG(" ch=%" PRIu32 "\n", r->cons.head); >> - ODPH_DBG(" pt=%" PRIu32 "\n", r->prod.tail); >> - ODPH_DBG(" ph=%" PRIu32 "\n", r->prod.head); >> - ODPH_DBG(" used=%u\n", odph_ring_count(r)); >> - ODPH_DBG(" avail=%u\n", odph_ring_free_count(r)); >> + ODP_DBG("ring <%s>@%p\n", r->name, r); >> + ODP_DBG(" flags=%x\n", r->flags); >> + ODP_DBG(" size=%" PRIu32 "\n", r->prod.size); >> + ODP_DBG(" ct=%" PRIu32 "\n", r->cons.tail); >> + ODP_DBG(" ch=%" PRIu32 "\n", r->cons.head); >> + ODP_DBG(" pt=%" PRIu32 "\n", r->prod.tail); >> + ODP_DBG(" ph=%" PRIu32 "\n", r->prod.head); >> + ODP_DBG(" used=%u\n", _ring_count(r)); >> + ODP_DBG(" avail=%u\n", _ring_free_count(r)); >> if (r->prod.watermark == r->prod.size) >> - ODPH_DBG(" watermark=0\n"); >> + ODP_DBG(" watermark=0\n"); >> else >> - ODPH_DBG(" watermark=%" PRIu32 "\n", r->prod.watermark); >> + ODP_DBG(" watermark=%" PRIu32 "\n", r->prod.watermark); >> } >> >> /* dump the status of all rings on the console */ >> -void odph_ring_list_dump(void) >> +void _ring_list_dump(void) >> { >> - const odph_ring_t *mp = NULL; >> + const _ring_t *mp = NULL; >> >> odp_rwlock_read_lock(&qlock); >> >> TAILQ_FOREACH(mp, &odp_ring_list, next) { >> - odph_ring_dump(mp); >> + _ring_dump(mp); >> } >> >> odp_rwlock_read_unlock(&qlock); >> } >> >> /* search a ring from its name */ >> -odph_ring_t *odph_ring_lookup(const char *name) >> +_ring_t *_ring_lookup(const char *name) >> { >> - odph_ring_t *r; >> + _ring_t *r; >> >> odp_rwlock_read_lock(&qlock); >> TAILQ_FOREACH(r, &odp_ring_list, next) { >> - if (strncmp(name, r->name, ODPH_RING_NAMESIZE) == 0) >> + if (strncmp(name, r->name, _RING_NAMESIZE) == 0) >> break; >> } >> odp_rwlock_read_unlock(&qlock); >> @@ -587,60 +584,60 @@ odph_ring_t *odph_ring_lookup(const char *name) >> /** >> * Enqueue several objects on the ring (multi-producers safe). >> */ >> -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const *obj_table, >> - unsigned n) >> +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, >> + unsigned n) >> { >> - return __odph_ring_mp_do_enqueue(r, obj_table, n, >> - ODPH_RING_QUEUE_VARIABLE); >> + return ___ring_mp_do_enqueue(r, obj_table, n, >> + _RING_QUEUE_VARIABLE); >> } >> >> /** >> * Enqueue several objects on a ring (NOT multi-producers safe). >> */ >> -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const *obj_table, >> - unsigned n) >> +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, >> + unsigned n) >> { >> - return __odph_ring_sp_do_enqueue(r, obj_table, n, >> - ODPH_RING_QUEUE_VARIABLE); >> + return ___ring_sp_do_enqueue(r, obj_table, n, >> + _RING_QUEUE_VARIABLE); >> } >> >> /** >> * Enqueue several objects on a ring. >> */ >> -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, >> - unsigned n) >> +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, >> + unsigned n) >> { >> if (r->prod.sp_enqueue) >> - return odph_ring_sp_enqueue_burst(r, obj_table, n); >> + return _ring_sp_enqueue_burst(r, obj_table, n); >> else >> - return odph_ring_mp_enqueue_burst(r, obj_table, n); >> + return _ring_mp_enqueue_burst(r, obj_table, n); >> } >> >> /** >> * Dequeue several objects from a ring (multi-consumers safe). >> */ >> -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, >> unsigned n) >> +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) >> { >> - return __odph_ring_mc_do_dequeue(r, obj_table, n, >> - ODPH_RING_QUEUE_VARIABLE); >> + return ___ring_mc_do_dequeue(r, obj_table, n, >> + _RING_QUEUE_VARIABLE); >> } >> >> /** >> * Dequeue several objects from a ring (NOT multi-consumers safe). >> */ >> -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, >> unsigned n) >> +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) >> { >> - return __odph_ring_sc_do_dequeue(r, obj_table, n, >> - ODPH_RING_QUEUE_VARIABLE); >> + return ___ring_sc_do_dequeue(r, obj_table, n, >> + _RING_QUEUE_VARIABLE); >> } >> >> /** >> * Dequeue multiple objects from a ring up to a maximum number. >> */ >> -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n) >> +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) >> { >> if (r->cons.sc_dequeue) >> - return odph_ring_sc_dequeue_burst(r, obj_table, n); >> + return _ring_sc_dequeue_burst(r, obj_table, n); >> else >> - return odph_ring_mc_dequeue_burst(r, obj_table, n); >> + return _ring_mc_dequeue_burst(r, obj_table, n); >> } >> diff --git a/platform/linux-generic/test/Makefile.am >> b/platform/linux-generic/test/Makefile.am >> index 594aa11..f81eeb8 100644 >> --- a/platform/linux-generic/test/Makefile.am >> +++ b/platform/linux-generic/test/Makefile.am >> @@ -1,11 +1,12 @@ >> include $(top_srcdir)/test/Makefile.inc >> TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation >> >> -ODP_MODULES = pktio >> +ODP_MODULES = pktio ring >> >> if test_vald >> TESTS = pktio/pktio_run \ >> pktio/pktio_run_tap \ >> + ring/ringtest$(EXEEXT) \ >> ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ >> >> ${top_builddir}/test/validation/classification/classification_main$(EXEEXT) >> \ >> ${top_builddir}/test/validation/config/config_main$(EXEEXT) \ >> diff --git a/platform/linux-generic/test/ring/.gitignore >> b/platform/linux-generic/test/ring/.gitignore >> new file mode 100644 >> index 0000000..4767f5e >> --- /dev/null >> +++ b/platform/linux-generic/test/ring/.gitignore >> @@ -0,0 +1 @@ >> +ringtest >> diff --git a/platform/linux-generic/test/ring/Makefile.am >> b/platform/linux-generic/test/ring/Makefile.am >> new file mode 100644 >> index 0000000..5a949d0 >> --- /dev/null >> +++ b/platform/linux-generic/test/ring/Makefile.am >> @@ -0,0 +1,16 @@ >> +include $(top_srcdir)/test/validation/Makefile.inc >> + >> +AM_CFLAGS += -I$(srcdir)/common >> +AM_CFLAGS += -I$(top_srcdir)/test/validation/common >> +AM_LDFLAGS += -static >> + >> +COMPILE_ONLY = >> + >> +TESTSCRIPTS = >> + >> +EXECUTABLES = ringtest$(EXEEXT) >> + >> +test_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) >> + >> +ringtest_SOURCES = ringtest.c >> +ringtest_LDADD = $(LIBCUNIT_COMMON) $(LIBODP) >> diff --git a/test/api_test/odp_ring_test.c >> b/platform/linux-generic/test/ring/ringtest.c >> similarity index 72% >> rename from test/api_test/odp_ring_test.c >> rename to platform/linux-generic/test/ring/ringtest.c >> index e8a962a..dfa220b 100644 >> --- a/test/api_test/odp_ring_test.c >> +++ b/platform/linux-generic/test/ring/ringtest.c >> @@ -37,7 +37,6 @@ >> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >> */ >> >> - >> /** >> * @file >> * >> @@ -48,86 +47,96 @@ >> #include <stdio.h> >> #include <string.h> >> #include <odp.h> >> -#include <odp_common.h> >> -#include <odp/helper/ring.h> >> +#include <odp/helper/linux.h> >> +#include <odp_packet_io_ring_internal.h> >> #include <test_debug.h> >> +#include <odp_cunit_common.h> >> >> #define RING_SIZE 4096 >> #define MAX_BULK 32 >> >> -#define RING_TEST_BASIC >> +enum { >> + ODP_RING_TEST_BASIC, >> + ODP_RING_TEST_STRESS, >> +}; >> >> -static int test_ring_basic(odph_ring_t *r) >> +/* local struct for ring_thread argument */ >> +typedef struct { >> + pthrd_arg thrdarg; >> + int stress_type; >> +} ring_arg_t; >> + >> +static int test_ring_basic(_ring_t *r) >> { >> void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = >> NULL; >> int ret; >> unsigned i, num_elems; >> >> /* alloc dummy object pointers */ >> - src = malloc(RING_SIZE*2*sizeof(void *)); >> + src = malloc(RING_SIZE * 2 * sizeof(void *)); >> if (src == NULL) { >> LOG_ERR("failed to allocate test ring src memory\n"); >> goto fail; >> } >> - for (i = 0; i < RING_SIZE*2; i++) >> + for (i = 0; i < RING_SIZE * 2; i++) >> src[i] = (void *)(unsigned long)i; >> >> cur_src = src; >> >> /* alloc some room for copied objects */ >> - dst = malloc(RING_SIZE*2*sizeof(void *)); >> + dst = malloc(RING_SIZE * 2 * sizeof(void *)); >> if (dst == NULL) { >> LOG_ERR("failed to allocate test ring dst memory\n"); >> goto fail; >> } >> >> - memset(dst, 0, RING_SIZE*2*sizeof(void *)); >> + memset(dst, 0, RING_SIZE * 2 * sizeof(void *)); >> cur_dst = dst; >> >> printf("Test SP & SC basic functions\n"); >> printf("enqueue 1 obj\n"); >> - ret = odph_ring_sp_enqueue_burst(r, cur_src, 1); >> + ret = _ring_sp_enqueue_burst(r, cur_src, 1); >> cur_src += 1; >> - if ((ret & ODPH_RING_SZ_MASK) != 1) { >> + if ((ret & _RING_SZ_MASK) != 1) { >> LOG_ERR("sp_enq for 1 obj failed\n"); >> goto fail; >> } >> >> printf("enqueue 2 objs\n"); >> - ret = odph_ring_sp_enqueue_burst(r, cur_src, 2); >> + ret = _ring_sp_enqueue_burst(r, cur_src, 2); >> cur_src += 2; >> - if ((ret & ODPH_RING_SZ_MASK) != 2) { >> + if ((ret & _RING_SZ_MASK) != 2) { >> LOG_ERR("sp_enq for 2 obj failed\n"); >> goto fail; >> } >> >> printf("enqueue MAX_BULK objs\n"); >> - ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK); >> - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { >> + ret = _ring_sp_enqueue_burst(r, cur_src, MAX_BULK); >> + if ((ret & _RING_SZ_MASK) != MAX_BULK) { >> LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK); >> goto fail; >> } >> >> printf("dequeue 1 obj\n"); >> - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1); >> + ret = _ring_sc_dequeue_burst(r, cur_dst, 1); >> cur_dst += 1; >> - if ((ret & ODPH_RING_SZ_MASK) != 1) { >> + if ((ret & _RING_SZ_MASK) != 1) { >> LOG_ERR("sc_deq for 1 obj failed\n"); >> goto fail; >> } >> >> printf("dequeue 2 objs\n"); >> - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2); >> + ret = _ring_sc_dequeue_burst(r, cur_dst, 2); >> cur_dst += 2; >> - if ((ret & ODPH_RING_SZ_MASK) != 2) { >> + if ((ret & _RING_SZ_MASK) != 2) { >> LOG_ERR("sc_deq for 2 obj failed\n"); >> goto fail; >> } >> >> printf("dequeue MAX_BULK objs\n"); >> - ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); >> + ret = _ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); >> cur_dst += MAX_BULK; >> - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { >> + if ((ret & _RING_SZ_MASK) != MAX_BULK) { >> LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK); >> goto fail; >> } >> @@ -144,41 +153,41 @@ static int test_ring_basic(odph_ring_t *r) >> printf("Test MP & MC basic functions\n"); >> >> printf("enqueue 1 obj\n"); >> - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1); >> + ret = _ring_mp_enqueue_bulk(r, cur_src, 1); >> cur_src += 1; >> if (ret != 0) { >> LOG_ERR("mp_enq for 1 obj failed\n"); >> goto fail; >> } >> printf("enqueue 2 objs\n"); >> - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2); >> + ret = _ring_mp_enqueue_bulk(r, cur_src, 2); >> cur_src += 2; >> if (ret != 0) { >> LOG_ERR("mp_enq for 2 obj failed\n"); >> goto fail; >> } >> printf("enqueue MAX_BULK objs\n"); >> - ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); >> + ret = _ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); >> if (ret != 0) { >> LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK); >> goto fail; >> } >> printf("dequeue 1 obj\n"); >> - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1); >> + ret = _ring_mc_dequeue_bulk(r, cur_dst, 1); >> cur_dst += 1; >> if (ret != 0) { >> LOG_ERR("mc_deq for 1 obj failed\n"); >> goto fail; >> } >> printf("dequeue 2 objs\n"); >> - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2); >> + ret = _ring_mc_dequeue_bulk(r, cur_dst, 2); >> cur_dst += 2; >> if (ret != 0) { >> LOG_ERR("mc_deq for 2 obj failed\n"); >> goto fail; >> } >> printf("dequeue MAX_BULK objs\n"); >> - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); >> + ret = _ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); >> cur_dst += MAX_BULK; >> if (ret != 0) { >> LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK); >> @@ -191,30 +200,30 @@ static int test_ring_basic(odph_ring_t *r) >> } >> >> printf("test watermark and default bulk enqueue / dequeue\n"); >> - odph_ring_set_water_mark(r, 20); >> + _ring_set_water_mark(r, 20); >> num_elems = 16; >> >> cur_src = src; >> cur_dst = dst; >> >> - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); >> + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); >> cur_src += num_elems; >> if (ret != 0) { >> LOG_ERR("Cannot enqueue\n"); >> goto fail; >> } >> - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); >> + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); >> if (ret != -EDQUOT) { >> LOG_ERR("Watermark not exceeded\n"); >> goto fail; >> } >> - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); >> + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); >> cur_dst += num_elems; >> if (ret != 0) { >> LOG_ERR("Cannot dequeue\n"); >> goto fail; >> } >> - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); >> + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); >> cur_dst += num_elems; >> if (ret != 0) { >> LOG_ERR("Cannot dequeue2\n"); >> @@ -241,7 +250,7 @@ fail: >> } >> >> /* global shared ring used for stress testing */ >> -static odph_ring_t *r_stress; >> +static _ring_t *r_stress; >> >> /* Stress func for Multi producer only */ >> static int producer_fn(void) >> @@ -251,7 +260,7 @@ static int producer_fn(void) >> void **src = NULL; >> >> /* alloc dummy object pointers */ >> - src = malloc(MAX_BULK*2*sizeof(void *)); >> + src = malloc(MAX_BULK * 2 * sizeof(void *)); >> if (src == NULL) { >> LOG_ERR("failed to allocate producer memory.\n"); >> return -1; >> @@ -260,7 +269,7 @@ static int producer_fn(void) >> src[i] = (void *)(unsigned long)i; >> >> do { >> - i = odph_ring_mp_enqueue_bulk(r_stress, src, MAX_BULK); >> + i = _ring_mp_enqueue_bulk(r_stress, src, MAX_BULK); >> if (i == 0) { >> free(src); >> return 0; >> @@ -275,14 +284,14 @@ static int consumer_fn(void) >> void **src = NULL; >> >> /* alloc dummy object pointers */ >> - src = malloc(MAX_BULK*2*sizeof(void *)); >> + src = malloc(MAX_BULK * 2 * sizeof(void *)); >> if (src == NULL) { >> LOG_ERR("failed to allocate consumer memory.\n"); >> return -1; >> } >> >> do { >> - i = odph_ring_mc_dequeue_bulk(r_stress, src, MAX_BULK); >> + i = _ring_mc_dequeue_bulk(r_stress, src, MAX_BULK); >> if (i == 0) { >> for (i = 0; i < MAX_BULK; i++) { >> if (src[i] != (void *)(unsigned long)i) { >> @@ -298,7 +307,6 @@ static int consumer_fn(void) >> } while (1); >> } >> >> - >> /* >> * Note : make sure that both enqueue and dequeue >> * operation starts at same time so to avoid data corruption >> @@ -319,24 +327,22 @@ typedef enum { >> static void test_ring_stress(stress_type_t type) >> { >> int thr; >> + >> thr = odp_thread_id(); >> >> switch (type) { >> case one_enq_one_deq: >> - >> if (thr == 1) >> producer_fn(); >> if (thr == 2) >> consumer_fn(); >> break; >> - >> case multi_enq_multi_deq: >> - if (thr%2 == 0) >> + if (thr % 2 == 0) >> producer_fn(); >> else >> consumer_fn(); >> break; >> - >> case one_deq_rest_enq: >> case one_enq_rest_deq:/*TBD*/ >> default: >> @@ -344,19 +350,12 @@ static void test_ring_stress(stress_type_t type) >> } >> } >> >> -/* local struct for ring_thread argument */ >> -typedef struct { >> - pthrd_arg thrdarg; >> - int stress_type; >> -} ring_arg_t; >> - >> - >> static void *test_ring(void *arg) >> { >> ring_arg_t *parg = (ring_arg_t *)arg; >> int thr; >> - char ring_name[ODPH_RING_NAMESIZE]; >> - odph_ring_t *r; >> + char ring_name[_RING_NAMESIZE]; >> + _ring_t *r; >> int result = 0; >> >> thr = odp_thread_id(); >> @@ -367,16 +366,16 @@ static void *test_ring(void *arg) >> case ODP_RING_TEST_BASIC: >> snprintf(ring_name, sizeof(ring_name), "test_ring_%i", >> thr); >> >> - r = odph_ring_create(ring_name, RING_SIZE, >> - 0 /* not used, alignement >> - taken care inside func : todo >> */); >> + r = _ring_create(ring_name, RING_SIZE, >> + 0 /* not used, alignement >> + taken care inside func : todo */); >> if (r == NULL) { >> LOG_ERR("ring create failed\n"); >> result = -1; >> break; >> } >> /* lookup ring from its name */ >> - if (odph_ring_lookup(ring_name) != r) { >> + if (_ring_lookup(ring_name) != r) { >> LOG_ERR("ring lookup failed\n"); >> result = -1; >> break; >> @@ -388,16 +387,16 @@ static void *test_ring(void *arg) >> result = -1; >> } >> >> - /* dump ring stats */ >> - odph_ring_list_dump(); >> + if (result) >> + _ring_list_dump(); >> >> break; >> >> case ODP_RING_TEST_STRESS: >> test_ring_stress(parg->stress_type); >> >> - /* dump ring stats */ >> - odph_ring_list_dump(); >> + if (result) >> + _ring_list_dump(); >> break; >> >> default: >> @@ -417,54 +416,69 @@ static void *test_ring(void *arg) >> return parg; >> } >> >> - >> -int main(int argc __attribute__((__unused__)), >> - char *argv[] __attribute__((__unused__))) >> +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) >> { >> ring_arg_t rarg; >> + odph_linux_pthread_t thread_tbl[MAX_WORKERS]; >> + odp_cpumask_t cpu_mask; >> + int num_workers; >> + char ring_name[_RING_NAMESIZE]; >> >> - if (odp_test_global_init() != 0) >> - return -1; >> + if (odp_init_global(NULL, NULL)) { >> + LOG_ERR("Error: ODP global init failed.\n"); >> + exit(EXIT_FAILURE); >> + } >> >> - odp_print_system_info(); >> + if (odp_init_local(ODP_THREAD_CONTROL)) { >> + LOG_ERR("Error: ODP local init failed.\n"); >> + exit(EXIT_FAILURE); >> + } >> >> - odph_ring_tailq_init(); >> + _ring_tailq_init(); >> >> - rarg.thrdarg.numthrds = odp_cpu_count(); >> + num_workers = odp_cpumask_default_worker(&cpu_mask, MAX_WORKERS); >> + rarg.thrdarg.numthrds = rarg.thrdarg.numthrds; >> >> -#ifdef RING_TEST_BASIC >> rarg.thrdarg.testcase = ODP_RING_TEST_BASIC; >> -#else >> + printf("starting stess test type : %d..\n", rarg.stress_type); >> + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, >> + test_ring, (void *)&rarg, >> + ODP_THREAD_WORKER); >> + odph_linux_pthread_join(thread_tbl, num_workers); >> + >> rarg.thrdarg.testcase = ODP_RING_TEST_STRESS; >> rarg.stress_type = one_enq_one_deq; >> -/* rarg.stress_type = multi_enq_multi_deq;*/ >> - char ring_name[ODPH_RING_NAMESIZE]; >> >> printf("starting stess test type : %d..\n", rarg.stress_type); >> - /* create a ring */ >> snprintf(ring_name, sizeof(ring_name), "test_ring_stress"); >> - >> - r_stress = odph_ring_create(ring_name, RING_SIZE, >> - 0 /* not used, alignement >> - taken care inside func : todo */); >> + r_stress = _ring_create(ring_name, RING_SIZE, >> + 0/* not used, alignement >> + taken care inside func : todo */); >> if (r_stress == NULL) { >> LOG_ERR("ring create failed\n"); >> goto fail; >> } >> /* lookup ring from its name */ >> - if (odph_ring_lookup(ring_name) != r_stress) { >> + if (_ring_lookup(ring_name) != r_stress) { >> LOG_ERR("ring lookup failed\n"); >> goto fail; >> } >> -#endif >> - odp_test_thread_create(test_ring, (pthrd_arg *)&rarg); >> >> -#ifndef RING_TEST_BASIC >> + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, >> + test_ring, (void *)&rarg, >> + ODP_THREAD_WORKER); >> + odph_linux_pthread_join(thread_tbl, num_workers); >> + >> fail: >> -#endif >> + if (odp_term_local()) { >> + LOG_ERR("Error: ODP local term failed.\n"); >> + exit(EXIT_FAILURE); >> + } >> >> - odp_test_thread_exit(&rarg.thrdarg); >> + if (odp_term_global()) { >> + LOG_ERR("Error: ODP global term failed.\n"); >> + exit(EXIT_FAILURE); >> + } >> >> return 0; >> } >> - >> diff --git a/test/Makefile.am b/test/Makefile.am >> index 2ba8008..4a75364 100644 >> --- a/test/Makefile.am >> +++ b/test/Makefile.am >> @@ -1,4 +1,4 @@ >> -SUBDIRS = api_test performance miscellaneous >> +SUBDIRS = performance miscellaneous >> >> if cunit_support >> SUBDIRS += validation >> diff --git a/test/api_test/.gitignore b/test/api_test/.gitignore >> deleted file mode 100644 >> index 950f443..0000000 >> --- a/test/api_test/.gitignore >> +++ /dev/null >> @@ -1,2 +0,0 @@ >> -odp_ring >> -odp_shm >> diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am >> deleted file mode 100644 >> index fcdba48..0000000 >> --- a/test/api_test/Makefile.am >> +++ /dev/null >> @@ -1,13 +0,0 @@ >> -include $(top_srcdir)/test/Makefile.inc >> - >> -bin_PROGRAMS = odp_ring$(EXEEXT) >> - >> -odp_ring_CFLAGS = $(AM_CFLAGS) >> - >> -odp_ring_LDFLAGS = $(AM_LDFLAGS) -static >> - >> -noinst_HEADERS = \ >> - $(top_srcdir)/test/api_test/odp_common.h \ >> - $(top_srcdir)/test/test_debug.h >> - >> -dist_odp_ring_SOURCES = odp_ring_test.c odp_common.c >> diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c >> deleted file mode 100644 >> index cebaa12..0000000 >> --- a/test/api_test/odp_common.c >> +++ /dev/null >> @@ -1,91 +0,0 @@ >> -/* Copyright (c) 2013, Linaro Limited >> - * All rights reserved. >> - * >> - * SPDX-License-Identifier: BSD-3-Clause >> - */ >> - >> -/** >> - * @file >> - * >> - * ODP test application common >> - */ >> - >> -#include <string.h> >> -#include <odp.h> >> -#include <odp/helper/linux.h> >> -#include <odp_common.h> >> -#include <test_debug.h> >> - >> -#define MAX_WORKERS 32 /**< Max worker threads */ >> - >> -/* Globals */ >> -static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; /**< worker threads >> table*/ >> -static int num_workers; /**< number >> of workers */ >> - >> -/** >> - * Print system information >> - */ >> -void odp_print_system_info(void) >> -{ >> - odp_cpumask_t cpumask; >> - char str[ODP_CPUMASK_STR_SIZE]; >> - >> - memset(str, 1, sizeof(str)); >> - >> - odp_cpumask_zero(&cpumask); >> - >> - odp_cpumask_from_str(&cpumask, "0x1"); >> - (void)odp_cpumask_to_str(&cpumask, str, sizeof(str)); >> - >> - printf("\n"); >> - printf("ODP system info\n"); >> - printf("---------------\n"); >> - printf("ODP API version: %s\n", odp_version_api_str()); >> - printf("CPU model: %s\n", odp_sys_cpu_model_str()); >> - printf("CPU freq (hz): %"PRIu64"\n", odp_sys_cpu_hz()); >> - printf("Cache line size: %i\n", odp_sys_cache_line_size()); >> - printf("CPU count: %i\n", odp_cpu_count()); >> - printf("CPU mask: %s\n", str); >> - >> - printf("\n"); >> -} >> - >> -/** test init globals and call odp_init_global() */ >> -int odp_test_global_init(void) >> -{ >> - memset(thread_tbl, 0, sizeof(thread_tbl)); >> - >> - if (odp_init_global(NULL, NULL)) { >> - LOG_ERR("ODP global init failed.\n"); >> - return -1; >> - } >> - >> - num_workers = odp_cpu_count(); >> - /* force to max CPU count */ >> - if (num_workers > MAX_WORKERS) >> - num_workers = MAX_WORKERS; >> - >> - return 0; >> -} >> - >> -/** create test thread */ >> -int odp_test_thread_create(void *func_ptr(void *), pthrd_arg *arg) >> -{ >> - odp_cpumask_t cpumask; >> - >> - /* Create and init additional threads */ >> - odp_cpumask_default_worker(&cpumask, arg->numthrds); >> - odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr, >> - (void *)arg, ODP_THREAD_WORKER); >> - >> - return 0; >> -} >> - >> -/** exit from test thread */ >> -int odp_test_thread_exit(pthrd_arg *arg) >> -{ >> - /* Wait for other threads to exit */ >> - odph_linux_pthread_join(thread_tbl, arg->numthrds); >> - >> - return 0; >> -} >> diff --git a/test/api_test/odp_common.h b/test/api_test/odp_common.h >> deleted file mode 100644 >> index f321b6b..0000000 >> --- a/test/api_test/odp_common.h >> +++ /dev/null >> @@ -1,42 +0,0 @@ >> -/* Copyright (c) 2013, Linaro Limited >> - * All rights reserved. >> - * >> - * SPDX-License-Identifier: BSD-3-Clause >> - */ >> - >> -/** >> - * @file >> - * >> - * ODP test application common headers >> - */ >> - >> -#ifndef ODP_COMMON_H >> -#define ODP_COMMON_H >> - >> -#define MAX_WORKERS 32 /**< Maximum number of work threads */ >> - >> -/** types of tests */ >> -typedef enum { >> - ODP_ATOMIC_TEST = 0, >> - ODP_SHM_TEST, >> - ODP_RING_TEST_BASIC, >> - ODP_RING_TEST_STRESS, >> - ODP_TIMER_PING_TEST, >> - ODP_MAX_TEST >> -} odp_test_case_e; >> - >> -/** >> - * Thread argument >> - */ >> -typedef struct { >> - int testcase; /**< specifies which set of API's to exercise */ >> - int numthrds; /**< no of pthreads to create */ >> -} pthrd_arg; >> - >> -extern void odp_print_system_info(void); >> -extern int odp_test_global_init(void); >> -/** create thread fro start_routine function */ >> -extern int odp_test_thread_create(void *(*start_routine) (void *), >> pthrd_arg *); >> -extern int odp_test_thread_exit(pthrd_arg *); >> - >> -#endif /* ODP_COMMON_H */ >> -- >> 1.9.1 >> >> _______________________________________________ >> lng-odp mailing list >> lng-odp@lists.linaro.org >> https://lists.linaro.org/mailman/listinfo/lng-odp >> > > > > -- > Mike Holmes > Technical Manager - Linaro Networking Group > Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs > > > -- Mike Holmes Technical Manager - Linaro Networking Group Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
On 12/18/2015 20:09, Mike Holmes wrote: > From checkpatch > > There should be a "default:" statement, if not we can clear this > warning in checkpatch by adding a comment in the actual code > explaining why a default is not needed. > > WARNING: Possible switch case/default not preceeded by break or > fallthrough comment > #2069: FILE: platform/linux-generic/pktio/ring.c:105: > +case 1: \ > > WARNING: Possible switch case/default not preceeded by break or > fallthrough comment > #2098: FILE: platform/linux-generic/pktio/ring.c:134: > +case 1: \ > default is not needed here: switch (n & 0x3) { \ case 3: \ r->ring[idx++] = obj_table[i++]; \ case 2: \ r->ring[idx++] = obj_table[i++]; \ case 1: \ > > There are other BIT macro warnings like this one, but I think we need > to disable them and I sent a patch to do so, maybe that will prompt us > to add a BIT macro but for now I dont think these should block acceptance > > CHECK: Prefer using the BIT macro > #1523: FILE: > platform/linux-generic/include/odp_packet_io_ring_internal.h:158: > +#define _RING_F_SP_ENQ (1 << 0) > > > On 18 December 2015 at 06:29, Maxim Uvarov <maxim.uvarov@linaro.org > <mailto:maxim.uvarov@linaro.org>> wrote: > > Move ring and it's test from helper to linux-generic/pktio and kill > not needed api_test directory. Unfortunately odp_ring_test.c had > some old > dirty code so I had to clean up it to to use cunit and > latest helper apis. > > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org > <mailto:maxim.uvarov@linaro.org>> > --- > configure.ac <http://configure.ac> | > 1 - > helper/Makefile.am | 2 - > helper/test/Makefile.am | 5 +- > platform/linux-generic/Makefile.am | 2 + > .../include/odp_packet_io_ring_internal.h | 112 +++++---- > platform/linux-generic/m4/configure.m4 | 3 +- > {helper => platform/linux-generic/pktio}/ring.c | 263 > ++++++++++----------- > platform/linux-generic/test/Makefile.am | 3 +- > platform/linux-generic/test/ring/.gitignore | 1 + > platform/linux-generic/test/ring/Makefile.am | 16 ++ > .../linux-generic/test/ring/ringtest.c | 180 > +++++++------- > test/Makefile.am | 2 +- > test/api_test/.gitignore | 2 - > test/api_test/Makefile.am | 13 - > test/api_test/odp_common.c | 91 ------- > test/api_test/odp_common.h | 42 ---- > 16 files changed, 309 insertions(+), 429 deletions(-) > rename helper/include/odp/helper/ring.h => > platform/linux-generic/include/odp_packet_io_ring_internal.h (87%) > rename {helper => platform/linux-generic/pktio}/ring.c (71%) > create mode 100644 platform/linux-generic/test/ring/.gitignore > create mode 100644 platform/linux-generic/test/ring/Makefile.am > rename test/api_test/odp_ring_test.c => > platform/linux-generic/test/ring/ringtest.c (72%) > delete mode 100644 test/api_test/.gitignore > delete mode 100644 test/api_test/Makefile.am > delete mode 100644 test/api_test/odp_common.c > delete mode 100644 test/api_test/odp_common.h > > diff --git a/configure.ac <http://configure.ac> b/configure.ac > <http://configure.ac> > index e45d90a..28b9ec9 100644 > --- a/configure.ac <http://configure.ac> > +++ b/configure.ac <http://configure.ac> > @@ -345,7 +345,6 @@ AC_CONFIG_FILES([Makefile > pkgconfig/libodphelper.pc > scripts/Makefile > test/Makefile > - test/api_test/Makefile > test/performance/Makefile > test/validation/Makefile > test/validation/buffer/Makefile > diff --git a/helper/Makefile.am b/helper/Makefile.am > index 1906ae2..6828092 100644 > --- a/helper/Makefile.am > +++ b/helper/Makefile.am > @@ -8,7 +8,6 @@ AM_CFLAGS += -I$(top_srcdir)/include > > helperincludedir = $(includedir)/odp/helper/ > helperinclude_HEADERS = \ > - $(srcdir)/include/odp/helper/ring.h \ > $(srcdir)/include/odp/helper/linux.h \ > $(srcdir)/include/odp/helper/chksum.h\ > $(srcdir)/include/odp/helper/eth.h\ > @@ -29,7 +28,6 @@ noinst_HEADERS = \ > > __LIB__libodphelper_la_SOURCES = \ > linux.c \ > - ring.c \ > hashtable.c \ > lineartable.c > > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > index 1c6a802..cf3b7aa 100644 > --- a/helper/test/Makefile.am > +++ b/helper/test/Makefile.am > @@ -1,6 +1,7 @@ > include $(top_srcdir)/test/Makefile.inc > > AM_CFLAGS += -I$(srcdir)/common > +AM_CFLAGS += -I$(top_srcdir)/test/validation/common > AM_LDFLAGS += -static > > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > @@ -28,5 +29,5 @@ dist_thread_SOURCES = thread.c > thread_LDADD = $(LIB)/libodphelper.la <http://libodphelper.la> > $(LIB)/libodp.la <http://libodp.la> > dist_process_SOURCES = process.c > process_LDADD = $(LIB)/libodphelper.la <http://libodphelper.la> > $(LIB)/libodp.la <http://libodp.la> > -odph_pause_SOURCES = pause.c > -dist_odp_table_SOURCES = table.c > +dist_pause_SOURCES = pause.c > +dist_table_SOURCES = table.c > diff --git a/platform/linux-generic/Makefile.am > b/platform/linux-generic/Makefile.am > index 4639ebc..8160649 100644 > --- a/platform/linux-generic/Makefile.am > +++ b/platform/linux-generic/Makefile.am > @@ -90,6 +90,7 @@ noinst_HEADERS = \ > ${srcdir}/include/odp_packet_internal.h \ > ${srcdir}/include/odp_packet_io_internal.h \ > ${srcdir}/include/odp_packet_io_queue.h \ > + ${srcdir}/include/odp_packet_io_ring_internal.h \ > ${srcdir}/include/odp_packet_netmap.h \ > ${srcdir}/include/odp_packet_socket.h \ > ${srcdir}/include/odp_packet_tap.h \ > @@ -122,6 +123,7 @@ __LIB__libodp_la_SOURCES = \ > pktio/socket.c \ > pktio/socket_mmap.c \ > pktio/tap.c \ > + pktio/ring.c \ > odp_pool.c \ > odp_queue.c \ > odp_rwlock.c \ > diff --git a/helper/include/odp/helper/ring.h > b/platform/linux-generic/include/odp_packet_io_ring_internal.h > similarity index 87% > rename from helper/include/odp/helper/ring.h > rename to platform/linux-generic/include/odp_packet_io_ring_internal.h > index 541a466..f97c026 100644 > --- a/helper/include/odp/helper/ring.h > +++ b/platform/linux-generic/include/odp_packet_io_ring_internal.h > @@ -89,29 +89,28 @@ > * > */ > > -#ifndef ODPH_RING_H_ > -#define ODPH_RING_H_ > +#ifndef _RING_H_ > +#define _RING_H_ > > #ifdef __cplusplus > extern "C" { > #endif > > - > #include <odp/std_types.h> > #include <odp/hints.h> > #include <odp/atomic.h> > #include <errno.h> > #include <sys/queue.h> > +#include <odp_debug_internal.h> > > -enum odph_ring_queue_behavior { > - ODPH_RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number > +enum _ring_queue_behavior { > + _RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number > of items from a ring */ > - ODPH_RING_QUEUE_VARIABLE /**< Enq/Deq as many items > + _RING_QUEUE_VARIABLE /**< Enq/Deq as many items > a possible from ring */ > }; > > - > -#define ODPH_RING_NAMESIZE 32 /**< The maximum length of a ring > name. */ > +#define _RING_NAMESIZE 32 /**< The maximum length of a ring name. */ > > /** > * An ODP ring structure. > @@ -123,12 +122,12 @@ enum odph_ring_queue_behavior { > * values in a modulo-32bit base: that's why the overflow of the > indexes is not > * a problem. > */ > -typedef struct odph_ring { > +typedef struct _ring { > /** @private Next in list. */ > - TAILQ_ENTRY(odph_ring) next; > + TAILQ_ENTRY(_ring) next; > > /** @private Name of the ring. */ > - char name[ODPH_RING_NAMESIZE]; > + char name[_RING_NAMESIZE]; > /** @private Flags supplied at creation. */ > int flags; > > @@ -153,21 +152,21 @@ typedef struct odph_ring { > > /** @private Memory space of ring starts here. */ > void *ring[0] ODP_ALIGNED_CACHE; > -} odph_ring_t; > +} _ring_t; > > /* The default enqueue is "single-producer".*/ > -#define ODPH_RING_F_SP_ENQ (1 << 0) > +#define _RING_F_SP_ENQ (1 << 0) > /* The default dequeue is "single-consumer".*/ > -#define ODPH_RING_F_SC_DEQ (1 << 1) > +#define _RING_F_SC_DEQ (1 << 1) > /* If set - ring is visible from different processes. > * Default is thread visible.*/ > -#define ODPH_RING_SHM_PROC (1 << 2) > +#define _RING_SHM_PROC (1 << 2) > /* Do not link ring to linked list. */ > -#define ODPH_RING_NO_LIST (1 << 3) > +#define _RING_NO_LIST (1 << 3) > /* Quota exceed for burst ops */ > -#define ODPH_RING_QUOT_EXCEED (1 << 31) > +#define _RING_QUOT_EXCEED (1 << 31) > /* Ring size mask */ > -#define ODPH_RING_SZ_MASK (unsigned)(0x0fffffff) > +#define _RING_SZ_MASK (unsigned)(0x0fffffff) > > /** > * Create a new ring named *name* in memory. > @@ -198,9 +197,8 @@ typedef struct odph_ring { > * - EEXIST - a memzone with the same name already exists > * - ENOMEM - no appropriate memory area found in which to > create memzone > */ > -odph_ring_t *odph_ring_create(const char *name, unsigned count, > - unsigned flags); > - > +_ring_t *_ring_create(const char *name, unsigned count, > + unsigned flags); > > /** > * Change the high water mark. > @@ -217,14 +215,14 @@ odph_ring_t *odph_ring_create(const char > *name, unsigned count, > * @return 0: Success; water mark changed. > * -EINVAL: Invalid water mark value. > */ > -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count); > +int _ring_set_water_mark(_ring_t *r, unsigned count); > > /** > * Dump the status of the ring to the console. > * > * @param r A pointer to the ring structure. > */ > -void odph_ring_dump(const odph_ring_t *r); > +void _ring_dump(const _ring_t *r); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -251,9 +249,9 @@ void odph_ring_dump(const odph_ring_t *r); > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects enqueued. > */ > -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -277,9 +275,9 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, > void * const *obj_table, > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects enqueued. > */ > -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Dequeue several objects from a ring (multi-consumers safe). When > @@ -308,9 +306,9 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, > void * const *obj_table, > * - n: Actual number of objects dequeued. > */ > > -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > @@ -335,9 +333,9 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, > void **obj_table, > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects dequeued. > */ > -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, > - enum odph_ring_queue_behavior behavior); > +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -357,8 +355,8 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, > void **obj_table, > * high water mark is exceeded. > * - -ENOBUFS: Not enough room in the ring to enqueue, no > object is enqueued. > */ > -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -375,8 +373,8 @@ int odph_ring_mp_enqueue_bulk(odph_ring_t *r, > void * const *obj_table, > * high water mark is exceeded. > * - -ENOBUFS: Not enough room in the ring to enqueue; no > object is enqueued. > */ > -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Dequeue several objects from a ring (multi-consumers safe). > @@ -395,7 +393,7 @@ int odph_ring_sp_enqueue_bulk(odph_ring_t *r, > void * const *obj_table, > * - -ENOENT: Not enough entries in the ring to dequeue; no > object is > * dequeued. > */ > -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, > unsigned n); > +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > @@ -412,7 +410,7 @@ int odph_ring_mc_dequeue_bulk(odph_ring_t *r, > void **obj_table, unsigned n); > * - -ENOENT: Not enough entries in the ring to dequeue; no > object is > * dequeued. > */ > -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, > unsigned n); > +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); > > /** > * Test if a ring is full. > @@ -423,7 +421,7 @@ int odph_ring_sc_dequeue_bulk(odph_ring_t *r, > void **obj_table, unsigned n); > * - 1: The ring is full. > * - 0: The ring is not full. > */ > -int odph_ring_full(const odph_ring_t *r); > +int _ring_full(const _ring_t *r); > > /** > * Test if a ring is empty. > @@ -434,7 +432,7 @@ int odph_ring_full(const odph_ring_t *r); > * - 1: The ring is empty. > * - 0: The ring is not empty. > */ > -int odph_ring_empty(const odph_ring_t *r); > +int _ring_empty(const _ring_t *r); > > /** > * Return the number of entries in a ring. > @@ -444,7 +442,7 @@ int odph_ring_empty(const odph_ring_t *r); > * @return > * The number of entries in the ring. > */ > -unsigned odph_ring_count(const odph_ring_t *r); > +unsigned _ring_count(const _ring_t *r); > > /** > * Return the number of free entries in a ring. > @@ -454,14 +452,14 @@ unsigned odph_ring_count(const odph_ring_t *r); > * @return > * The number of free entries in the ring. > */ > -unsigned odph_ring_free_count(const odph_ring_t *r); > +unsigned _ring_free_count(const _ring_t *r); > > /** > * search ring by name > * @param name ring name to search > * @return pointer to ring otherwise NULL > */ > -odph_ring_t *odph_ring_lookup(const char *name); > +_ring_t *_ring_lookup(const char *name); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -478,8 +476,8 @@ odph_ring_t *odph_ring_lookup(const char *name); > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -493,8 +491,8 @@ int odph_ring_mp_enqueue_burst(odph_ring_t *r, > void * const *obj_table, > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > /** > * Enqueue several objects on a ring. > * > @@ -511,8 +509,8 @@ int odph_ring_sp_enqueue_burst(odph_ring_t *r, > void * const *obj_table, > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n); > +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Dequeue several objects from a ring (multi-consumers safe). > When the request > @@ -531,7 +529,7 @@ int odph_ring_enqueue_burst(odph_ring_t *r, > void * const *obj_table, > * @return > * - n: Actual number of objects dequeued, 0 if ring is empty > */ > -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n); > +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); > > /** > * Dequeue several objects from a ring (NOT multi-consumers > safe).When the > @@ -547,7 +545,7 @@ int odph_ring_mc_dequeue_burst(odph_ring_t *r, > void **obj_table, unsigned n); > * @return > * - n: Actual number of objects dequeued, 0 if ring is empty > */ > -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n); > +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); > > /** > * Dequeue multiple objects from a ring up to a maximum number. > @@ -565,17 +563,17 @@ int odph_ring_sc_dequeue_burst(odph_ring_t > *r, void **obj_table, unsigned n); > * @return > * - Number of objects dequeued, or a negative error code on error > */ > -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n); > +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); > > /** > * dump the status of all rings on the console > */ > -void odph_ring_list_dump(void); > +void _ring_list_dump(void); > > /** > * initialise ring tailq > */ > -void odph_ring_tailq_init(void); > +void _ring_tailq_init(void); > > #ifdef __cplusplus > } > diff --git a/platform/linux-generic/m4/configure.m4 > b/platform/linux-generic/m4/configure.m4 > index df6dc64..6bb159f 100644 > --- a/platform/linux-generic/m4/configure.m4 > +++ b/platform/linux-generic/m4/configure.m4 > @@ -23,4 +23,5 @@ m4_include([platform/linux-generic/m4/odp_pcap.m4]) > > AC_CONFIG_FILES([platform/linux-generic/Makefile > platform/linux-generic/test/Makefile > - platform/linux-generic/test/pktio/Makefile]) > + platform/linux-generic/test/pktio/Makefile > + platform/linux-generic/test/ring/Makefile]) > diff --git a/helper/ring.c b/platform/linux-generic/pktio/ring.c > similarity index 71% > rename from helper/ring.c > rename to platform/linux-generic/pktio/ring.c > index e113606..e978420 100644 > --- a/helper/ring.c > +++ b/platform/linux-generic/pktio/ring.c > @@ -78,9 +78,9 @@ > #include <string.h> > #include "odph_debug.h" > #include <odp/rwlock.h> > -#include <odp/helper/ring.h> > +#include <odp_packet_io_ring_internal.h> > > -static TAILQ_HEAD(, odph_ring) odp_ring_list; > +static TAILQ_HEAD(, _ring) odp_ring_list; > > #define RING_VAL_IS_POWER_2(x) ((((x) - 1) & (x)) == 0) > > @@ -93,9 +93,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > if (odp_likely(idx + n < size)) { \ > for (i = 0; i < (n & ((~(unsigned)0x3))); i += 4, > idx += 4) { \ > r->ring[idx] = obj_table[i]; \ > - r->ring[idx+1] = obj_table[i+1]; \ > - r->ring[idx+2] = obj_table[i+2]; \ > - r->ring[idx+3] = obj_table[i+3]; \ > + r->ring[idx + 1] = obj_table[i + 1]; \ > + r->ring[idx + 2] = obj_table[i + 2]; \ > + r->ring[idx + 3] = obj_table[i + 3]; \ > } \ > switch (n & 0x3) { \ > case 3: \ > @@ -122,9 +122,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > if (odp_likely(idx + n < size)) { \ > for (i = 0; i < (n & (~(unsigned)0x3)); i += 4, > idx += 4) {\ > obj_table[i] = r->ring[idx]; \ > - obj_table[i+1] = r->ring[idx+1]; \ > - obj_table[i+2] = r->ring[idx+2]; \ > - obj_table[i+3] = r->ring[idx+3]; \ > + obj_table[i + 1] = r->ring[idx + 1]; \ > + obj_table[i + 2] = r->ring[idx + 2]; \ > + obj_table[i + 3] = r->ring[idx + 3]; \ > } \ > switch (n & 0x3) { \ > case 3: \ > @@ -145,36 +145,37 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > static odp_rwlock_t qlock; /* rings tailq lock */ > > /* init tailq_ring */ > -void odph_ring_tailq_init(void) > +void _ring_tailq_init(void) > { > TAILQ_INIT(&odp_ring_list); > odp_rwlock_init(&qlock); > } > > /* create the ring */ > -odph_ring_t * > -odph_ring_create(const char *name, unsigned count, unsigned flags) > +_ring_t * > +_ring_create(const char *name, unsigned count, unsigned flags) > { > - char ring_name[ODPH_RING_NAMESIZE]; > - odph_ring_t *r; > + char ring_name[_RING_NAMESIZE]; > + _ring_t *r; > size_t ring_size; > uint32_t shm_flag; > odp_shm_t shm; > > - if (flags & ODPH_RING_SHM_PROC) > + if (flags & _RING_SHM_PROC) > shm_flag = ODP_SHM_PROC; > else > shm_flag = 0; > > /* count must be a power of 2 */ > - if (!RING_VAL_IS_POWER_2(count) || (count > > ODPH_RING_SZ_MASK)) { > - ODPH_ERR("Requested size is invalid, must be power > of 2, and do not exceed the size limit %u\n", > - ODPH_RING_SZ_MASK); > + if (!RING_VAL_IS_POWER_2(count) || (count > _RING_SZ_MASK)) { > + ODPH_ERR("Requested size is invalid, must be power > of 2," > + "and do not exceed the size limit %u\n", > + _RING_SZ_MASK); > return NULL; > } > > snprintf(ring_name, sizeof(ring_name), "%s", name); > - ring_size = count*sizeof(void *)+sizeof(odph_ring_t); > + ring_size = count * sizeof(void *) + sizeof(_ring_t); > > odp_rwlock_write_lock(&qlock); > /* reserve a memory zone for this ring.*/ > @@ -188,18 +189,18 @@ odph_ring_create(const char *name, unsigned > count, unsigned flags) > snprintf(r->name, sizeof(r->name), "%s", name); > r->flags = flags; > r->prod.watermark = count; > - r->prod.sp_enqueue = !!(flags & ODPH_RING_F_SP_ENQ); > - r->cons.sc_dequeue = !!(flags & ODPH_RING_F_SC_DEQ); > + r->prod.sp_enqueue = !!(flags & _RING_F_SP_ENQ); > + r->cons.sc_dequeue = !!(flags & _RING_F_SC_DEQ); > r->prod.size = count; > r->cons.size = count; > - r->prod.mask = count-1; > - r->cons.mask = count-1; > + r->prod.mask = count - 1; > + r->cons.mask = count - 1; > r->prod.head = 0; > r->cons.head = 0; > r->prod.tail = 0; > r->cons.tail = 0; > > - if (!(flags & ODPH_RING_NO_LIST)) > + if (!(flags & _RING_NO_LIST)) > TAILQ_INSERT_TAIL(&odp_ring_list, r, next); > } else { > ODPH_ERR("Cannot reserve memory\n"); > @@ -213,7 +214,7 @@ odph_ring_create(const char *name, unsigned > count, unsigned flags) > * change the high water mark. If *count* is 0, water marking is > * disabled > */ > -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count) > +int _ring_set_water_mark(_ring_t *r, unsigned count) > { > if (count >= r->prod.size) > return -EINVAL; > @@ -229,8 +230,8 @@ int odph_ring_set_water_mark(odph_ring_t *r, > unsigned count) > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, enum odph_ring_queue_behavior > behavior) > +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, enum _ring_queue_behavior > behavior) > { > uint32_t prod_head, prod_next; > uint32_t cons_tail, free_entries; > @@ -255,24 +256,22 @@ int __odph_ring_mp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > > /* check that we have enough room in ring */ > if (odp_unlikely(n > free_entries)) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOBUFS; > - } else { > - /* No free entry available */ > - if (odp_unlikely(free_entries == 0)) > - return 0; > + /* No free entry available */ > + if (odp_unlikely(free_entries == 0)) > + return 0; > > - n = free_entries; > - } > + n = free_entries; > } > > prod_next = prod_head + n; > success = __atomic_compare_exchange_n(&r->prod.head, > - &prod_head, > - prod_next, > - false/*strong*/, > - __ATOMIC_ACQUIRE, > - __ATOMIC_RELAXED); > + &prod_head, > + prod_next, > + false/*strong*/, > + __ATOMIC_ACQUIRE, > + __ATOMIC_RELAXED); > } while (odp_unlikely(success == 0)); > > /* write entries in ring */ > @@ -280,10 +279,10 @@ int __odph_ring_mp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > > /* if we exceed the watermark */ > if (odp_unlikely(((mask + 1) - free_entries + n) > > r->prod.watermark)) { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : > - (int)(n | ODPH_RING_QUOT_EXCEED); > + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : > + (int)(n | _RING_QUOT_EXCEED); > } else { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; > + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; > } > > /* > @@ -302,8 +301,8 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, > void * const *obj_table, > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, enum > odph_ring_queue_behavior behavior) > +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, enum _ring_queue_behavior > behavior) > { > uint32_t prod_head, cons_tail; > uint32_t prod_next, free_entries; > @@ -321,15 +320,13 @@ int __odph_ring_sp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > > /* check that we have enough room in ring */ > if (odp_unlikely(n > free_entries)) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOBUFS; > - } else { > - /* No free entry available */ > - if (odp_unlikely(free_entries == 0)) > - return 0; > + /* No free entry available */ > + if (odp_unlikely(free_entries == 0)) > + return 0; > > - n = free_entries; > - } > + n = free_entries; > } > > prod_next = prod_head + n; > @@ -340,10 +337,10 @@ int __odph_ring_sp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > > /* if we exceed the watermark */ > if (odp_unlikely(((mask + 1) - free_entries + n) > > r->prod.watermark)) { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : > - (int)(n | ODPH_RING_QUOT_EXCEED); > + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : > + (int)(n | _RING_QUOT_EXCEED); > } else { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; > + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; > } > > /* Release our entries and the memory they refer to */ > @@ -356,8 +353,8 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, > void * const *obj_table, > * Dequeue several objects from a ring (multi-consumers safe). > */ > > -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, enum odph_ring_queue_behavior > behavior) > +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, enum _ring_queue_behavior > behavior) > { > uint32_t cons_head, prod_tail; > uint32_t cons_next, entries; > @@ -381,23 +378,21 @@ int __odph_ring_mc_do_dequeue(odph_ring_t > *r, void **obj_table, > > /* Set the actual entries for dequeue */ > if (n > entries) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOENT; > - } else { > - if (odp_unlikely(entries == 0)) > - return 0; > + if (odp_unlikely(entries == 0)) > + return 0; > > - n = entries; > - } > + n = entries; > } > > cons_next = cons_head + n; > success = __atomic_compare_exchange_n(&r->cons.head, > - &cons_head, > - cons_next, > - false/*strong*/, > - __ATOMIC_ACQUIRE, > - __ATOMIC_RELAXED); > + &cons_head, > + cons_next, > + false/*strong*/, > + __ATOMIC_ACQUIRE, > + __ATOMIC_RELAXED); > } while (odp_unlikely(success == 0)); > > /* copy in table */ > @@ -414,14 +409,14 @@ int __odph_ring_mc_do_dequeue(odph_ring_t > *r, void **obj_table, > __atomic_thread_fence(__ATOMIC_RELEASE); > r->cons.tail = cons_next; > > - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; > + return behavior == _RING_QUEUE_FIXED ? 0 : n; > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > */ > -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, enum > odph_ring_queue_behavior behavior) > +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, enum _ring_queue_behavior > behavior) > { > uint32_t cons_head, prod_tail; > uint32_t cons_next, entries; > @@ -437,14 +432,12 @@ int __odph_ring_sc_do_dequeue(odph_ring_t > *r, void **obj_table, > entries = prod_tail - cons_head; > > if (n > entries) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOENT; > - } else { > - if (odp_unlikely(entries == 0)) > - return 0; > + if (odp_unlikely(entries == 0)) > + return 0; > > - n = entries; > - } > + n = entries; > } > > cons_next = cons_head + n; > @@ -456,127 +449,131 @@ int __odph_ring_sc_do_dequeue(odph_ring_t > *r, void **obj_table, > DEQUEUE_PTRS(); > > r->cons.tail = cons_next; > - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; > + return behavior == _RING_QUEUE_FIXED ? 0 : n; > } > > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_mp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_mp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_sp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_sp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Dequeue several objects from a ring (multi-consumers safe). > */ > -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, > unsigned n) > +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_mc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_mc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > */ > -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, > unsigned n) > +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_sc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_sc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Test if a ring is full. > */ > -int odph_ring_full(const odph_ring_t *r) > +int _ring_full(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (((cons_tail - prod_tail - 1) & r->prod.mask) == 0); > } > > /** > * Test if a ring is empty. > */ > -int odph_ring_empty(const odph_ring_t *r) > +int _ring_empty(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return !!(cons_tail == prod_tail); > } > > /** > * Return the number of entries in a ring. > */ > -unsigned odph_ring_count(const odph_ring_t *r) > +unsigned _ring_count(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (prod_tail - cons_tail) & r->prod.mask; > } > > /** > * Return the number of free entries in a ring. > */ > -unsigned odph_ring_free_count(const odph_ring_t *r) > +unsigned _ring_free_count(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (cons_tail - prod_tail - 1) & r->prod.mask; > } > > /* dump the status of the ring on the console */ > -void odph_ring_dump(const odph_ring_t *r) > +void _ring_dump(const _ring_t *r) > { > - ODPH_DBG("ring <%s>@%p\n", r->name, r); > - ODPH_DBG(" flags=%x\n", r->flags); > - ODPH_DBG(" size=%" PRIu32 "\n", r->prod.size); > - ODPH_DBG(" ct=%" PRIu32 "\n", r->cons.tail); > - ODPH_DBG(" ch=%" PRIu32 "\n", r->cons.head); > - ODPH_DBG(" pt=%" PRIu32 "\n", r->prod.tail); > - ODPH_DBG(" ph=%" PRIu32 "\n", r->prod.head); > - ODPH_DBG(" used=%u\n", odph_ring_count(r)); > - ODPH_DBG(" avail=%u\n", odph_ring_free_count(r)); > + ODP_DBG("ring <%s>@%p\n", r->name, r); > + ODP_DBG(" flags=%x\n", r->flags); > + ODP_DBG(" size=%" PRIu32 "\n", r->prod.size); > + ODP_DBG(" ct=%" PRIu32 "\n", r->cons.tail); > + ODP_DBG(" ch=%" PRIu32 "\n", r->cons.head); > + ODP_DBG(" pt=%" PRIu32 "\n", r->prod.tail); > + ODP_DBG(" ph=%" PRIu32 "\n", r->prod.head); > + ODP_DBG(" used=%u\n", _ring_count(r)); > + ODP_DBG(" avail=%u\n", _ring_free_count(r)); > if (r->prod.watermark == r->prod.size) > - ODPH_DBG(" watermark=0\n"); > + ODP_DBG(" watermark=0\n"); > else > - ODPH_DBG(" watermark=%" PRIu32 "\n", > r->prod.watermark); > + ODP_DBG(" watermark=%" PRIu32 "\n", > r->prod.watermark); > } > > /* dump the status of all rings on the console */ > -void odph_ring_list_dump(void) > +void _ring_list_dump(void) > { > - const odph_ring_t *mp = NULL; > + const _ring_t *mp = NULL; > > odp_rwlock_read_lock(&qlock); > > TAILQ_FOREACH(mp, &odp_ring_list, next) { > - odph_ring_dump(mp); > + _ring_dump(mp); > } > > odp_rwlock_read_unlock(&qlock); > } > > /* search a ring from its name */ > -odph_ring_t *odph_ring_lookup(const char *name) > +_ring_t *_ring_lookup(const char *name) > { > - odph_ring_t *r; > + _ring_t *r; > > odp_rwlock_read_lock(&qlock); > TAILQ_FOREACH(r, &odp_ring_list, next) { > - if (strncmp(name, r->name, ODPH_RING_NAMESIZE) == 0) > + if (strncmp(name, r->name, _RING_NAMESIZE) == 0) > break; > } > odp_rwlock_read_unlock(&qlock); > @@ -587,60 +584,60 @@ odph_ring_t *odph_ring_lookup(const char *name) > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_mp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_mp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_sp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_sp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Enqueue several objects on a ring. > */ > -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, > - unsigned n) > +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > if (r->prod.sp_enqueue) > - return odph_ring_sp_enqueue_burst(r, obj_table, n); > + return _ring_sp_enqueue_burst(r, obj_table, n); > else > - return odph_ring_mp_enqueue_burst(r, obj_table, n); > + return _ring_mp_enqueue_burst(r, obj_table, n); > } > > /** > * Dequeue several objects from a ring (multi-consumers safe). > */ > -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n) > +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_mc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_mc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers safe). > */ > -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n) > +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) > { > - return __odph_ring_sc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_sc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Dequeue multiple objects from a ring up to a maximum number. > */ > -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n) > +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) > { > if (r->cons.sc_dequeue) > - return odph_ring_sc_dequeue_burst(r, obj_table, n); > + return _ring_sc_dequeue_burst(r, obj_table, n); > else > - return odph_ring_mc_dequeue_burst(r, obj_table, n); > + return _ring_mc_dequeue_burst(r, obj_table, n); > } > diff --git a/platform/linux-generic/test/Makefile.am > b/platform/linux-generic/test/Makefile.am > index 594aa11..f81eeb8 100644 > --- a/platform/linux-generic/test/Makefile.am > +++ b/platform/linux-generic/test/Makefile.am > @@ -1,11 +1,12 @@ > include $(top_srcdir)/test/Makefile.inc > TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation > > -ODP_MODULES = pktio > +ODP_MODULES = pktio ring > > if test_vald > TESTS = pktio/pktio_run \ > pktio/pktio_run_tap \ > + ring/ringtest$(EXEEXT) \ > ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ > ${top_builddir}/test/validation/classification/classification_main$(EXEEXT) > \ > ${top_builddir}/test/validation/config/config_main$(EXEEXT) \ > diff --git a/platform/linux-generic/test/ring/.gitignore > b/platform/linux-generic/test/ring/.gitignore > new file mode 100644 > index 0000000..4767f5e > --- /dev/null > +++ b/platform/linux-generic/test/ring/.gitignore > @@ -0,0 +1 @@ > +ringtest > diff --git a/platform/linux-generic/test/ring/Makefile.am > b/platform/linux-generic/test/ring/Makefile.am > new file mode 100644 > index 0000000..5a949d0 > --- /dev/null > +++ b/platform/linux-generic/test/ring/Makefile.am > @@ -0,0 +1,16 @@ > +include $(top_srcdir)/test/validation/Makefile.inc > + > +AM_CFLAGS += -I$(srcdir)/common > +AM_CFLAGS += -I$(top_srcdir)/test/validation/common > +AM_LDFLAGS += -static > + > +COMPILE_ONLY = > + > +TESTSCRIPTS = > + > +EXECUTABLES = ringtest$(EXEEXT) > + > +test_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) > + > +ringtest_SOURCES = ringtest.c > +ringtest_LDADD = $(LIBCUNIT_COMMON) $(LIBODP) > diff --git a/test/api_test/odp_ring_test.c > b/platform/linux-generic/test/ring/ringtest.c > similarity index 72% > rename from test/api_test/odp_ring_test.c > rename to platform/linux-generic/test/ring/ringtest.c > index e8a962a..dfa220b 100644 > --- a/test/api_test/odp_ring_test.c > +++ b/platform/linux-generic/test/ring/ringtest.c > @@ -37,7 +37,6 @@ > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH > DAMAGE. > */ > > - > /** > * @file > * > @@ -48,86 +47,96 @@ > #include <stdio.h> > #include <string.h> > #include <odp.h> > -#include <odp_common.h> > -#include <odp/helper/ring.h> > +#include <odp/helper/linux.h> > +#include <odp_packet_io_ring_internal.h> > #include <test_debug.h> > +#include <odp_cunit_common.h> > > #define RING_SIZE 4096 > #define MAX_BULK 32 > > -#define RING_TEST_BASIC > +enum { > + ODP_RING_TEST_BASIC, > + ODP_RING_TEST_STRESS, > +}; > > -static int test_ring_basic(odph_ring_t *r) > +/* local struct for ring_thread argument */ > +typedef struct { > + pthrd_arg thrdarg; > + int stress_type; > +} ring_arg_t; > + > +static int test_ring_basic(_ring_t *r) > { > void **src = NULL, **cur_src = NULL, **dst = NULL, > **cur_dst = NULL; > int ret; > unsigned i, num_elems; > > /* alloc dummy object pointers */ > - src = malloc(RING_SIZE*2*sizeof(void *)); > + src = malloc(RING_SIZE * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate test ring src memory\n"); > goto fail; > } > - for (i = 0; i < RING_SIZE*2; i++) > + for (i = 0; i < RING_SIZE * 2; i++) > src[i] = (void *)(unsigned long)i; > > cur_src = src; > > /* alloc some room for copied objects */ > - dst = malloc(RING_SIZE*2*sizeof(void *)); > + dst = malloc(RING_SIZE * 2 * sizeof(void *)); > if (dst == NULL) { > LOG_ERR("failed to allocate test ring dst memory\n"); > goto fail; > } > > - memset(dst, 0, RING_SIZE*2*sizeof(void *)); > + memset(dst, 0, RING_SIZE * 2 * sizeof(void *)); > cur_dst = dst; > > printf("Test SP & SC basic functions\n"); > printf("enqueue 1 obj\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, 1); > + ret = _ring_sp_enqueue_burst(r, cur_src, 1); > cur_src += 1; > - if ((ret & ODPH_RING_SZ_MASK) != 1) { > + if ((ret & _RING_SZ_MASK) != 1) { > LOG_ERR("sp_enq for 1 obj failed\n"); > goto fail; > } > > printf("enqueue 2 objs\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, 2); > + ret = _ring_sp_enqueue_burst(r, cur_src, 2); > cur_src += 2; > - if ((ret & ODPH_RING_SZ_MASK) != 2) { > + if ((ret & _RING_SZ_MASK) != 2) { > LOG_ERR("sp_enq for 2 obj failed\n"); > goto fail; > } > > printf("enqueue MAX_BULK objs\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK); > - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { > + ret = _ring_sp_enqueue_burst(r, cur_src, MAX_BULK); > + if ((ret & _RING_SZ_MASK) != MAX_BULK) { > LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK); > goto fail; > } > > printf("dequeue 1 obj\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1); > + ret = _ring_sc_dequeue_burst(r, cur_dst, 1); > cur_dst += 1; > - if ((ret & ODPH_RING_SZ_MASK) != 1) { > + if ((ret & _RING_SZ_MASK) != 1) { > LOG_ERR("sc_deq for 1 obj failed\n"); > goto fail; > } > > printf("dequeue 2 objs\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2); > + ret = _ring_sc_dequeue_burst(r, cur_dst, 2); > cur_dst += 2; > - if ((ret & ODPH_RING_SZ_MASK) != 2) { > + if ((ret & _RING_SZ_MASK) != 2) { > LOG_ERR("sc_deq for 2 obj failed\n"); > goto fail; > } > > printf("dequeue MAX_BULK objs\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); > + ret = _ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); > cur_dst += MAX_BULK; > - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { > + if ((ret & _RING_SZ_MASK) != MAX_BULK) { > LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK); > goto fail; > } > @@ -144,41 +153,41 @@ static int test_ring_basic(odph_ring_t *r) > printf("Test MP & MC basic functions\n"); > > printf("enqueue 1 obj\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1); > + ret = _ring_mp_enqueue_bulk(r, cur_src, 1); > cur_src += 1; > if (ret != 0) { > LOG_ERR("mp_enq for 1 obj failed\n"); > goto fail; > } > printf("enqueue 2 objs\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2); > + ret = _ring_mp_enqueue_bulk(r, cur_src, 2); > cur_src += 2; > if (ret != 0) { > LOG_ERR("mp_enq for 2 obj failed\n"); > goto fail; > } > printf("enqueue MAX_BULK objs\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); > + ret = _ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); > if (ret != 0) { > LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK); > goto fail; > } > printf("dequeue 1 obj\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, 1); > cur_dst += 1; > if (ret != 0) { > LOG_ERR("mc_deq for 1 obj failed\n"); > goto fail; > } > printf("dequeue 2 objs\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, 2); > cur_dst += 2; > if (ret != 0) { > LOG_ERR("mc_deq for 2 obj failed\n"); > goto fail; > } > printf("dequeue MAX_BULK objs\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); > cur_dst += MAX_BULK; > if (ret != 0) { > LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK); > @@ -191,30 +200,30 @@ static int test_ring_basic(odph_ring_t *r) > } > > printf("test watermark and default bulk enqueue / dequeue\n"); > - odph_ring_set_water_mark(r, 20); > + _ring_set_water_mark(r, 20); > num_elems = 16; > > cur_src = src; > cur_dst = dst; > > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); > + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); > cur_src += num_elems; > if (ret != 0) { > LOG_ERR("Cannot enqueue\n"); > goto fail; > } > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); > + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); > if (ret != -EDQUOT) { > LOG_ERR("Watermark not exceeded\n"); > goto fail; > } > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); > cur_dst += num_elems; > if (ret != 0) { > LOG_ERR("Cannot dequeue\n"); > goto fail; > } > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); > cur_dst += num_elems; > if (ret != 0) { > LOG_ERR("Cannot dequeue2\n"); > @@ -241,7 +250,7 @@ fail: > } > > /* global shared ring used for stress testing */ > -static odph_ring_t *r_stress; > +static _ring_t *r_stress; > > /* Stress func for Multi producer only */ > static int producer_fn(void) > @@ -251,7 +260,7 @@ static int producer_fn(void) > void **src = NULL; > > /* alloc dummy object pointers */ > - src = malloc(MAX_BULK*2*sizeof(void *)); > + src = malloc(MAX_BULK * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate producer memory.\n"); > return -1; > @@ -260,7 +269,7 @@ static int producer_fn(void) > src[i] = (void *)(unsigned long)i; > > do { > - i = odph_ring_mp_enqueue_bulk(r_stress, src, > MAX_BULK); > + i = _ring_mp_enqueue_bulk(r_stress, src, MAX_BULK); > if (i == 0) { > free(src); > return 0; > @@ -275,14 +284,14 @@ static int consumer_fn(void) > void **src = NULL; > > /* alloc dummy object pointers */ > - src = malloc(MAX_BULK*2*sizeof(void *)); > + src = malloc(MAX_BULK * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate consumer memory.\n"); > return -1; > } > > do { > - i = odph_ring_mc_dequeue_bulk(r_stress, src, > MAX_BULK); > + i = _ring_mc_dequeue_bulk(r_stress, src, MAX_BULK); > if (i == 0) { > for (i = 0; i < MAX_BULK; i++) { > if (src[i] != (void *)(unsigned > long)i) { > @@ -298,7 +307,6 @@ static int consumer_fn(void) > } while (1); > } > > - > /* > * Note : make sure that both enqueue and dequeue > * operation starts at same time so to avoid data corruption > @@ -319,24 +327,22 @@ typedef enum { > static void test_ring_stress(stress_type_t type) > { > int thr; > + > thr = odp_thread_id(); > > switch (type) { > case one_enq_one_deq: > - > if (thr == 1) > producer_fn(); > if (thr == 2) > consumer_fn(); > break; > - > case multi_enq_multi_deq: > - if (thr%2 == 0) > + if (thr % 2 == 0) > producer_fn(); > else > consumer_fn(); > break; > - > case one_deq_rest_enq: > case one_enq_rest_deq:/*TBD*/ > default: > @@ -344,19 +350,12 @@ static void test_ring_stress(stress_type_t type) > } > } > > -/* local struct for ring_thread argument */ > -typedef struct { > - pthrd_arg thrdarg; > - int stress_type; > -} ring_arg_t; > - > - > static void *test_ring(void *arg) > { > ring_arg_t *parg = (ring_arg_t *)arg; > int thr; > - char ring_name[ODPH_RING_NAMESIZE]; > - odph_ring_t *r; > + char ring_name[_RING_NAMESIZE]; > + _ring_t *r; > int result = 0; > > thr = odp_thread_id(); > @@ -367,16 +366,16 @@ static void *test_ring(void *arg) > case ODP_RING_TEST_BASIC: > snprintf(ring_name, sizeof(ring_name), > "test_ring_%i", thr); > > - r = odph_ring_create(ring_name, RING_SIZE, > - 0 /* not used, alignement > - taken care inside func : > todo */); > + r = _ring_create(ring_name, RING_SIZE, > + 0 /* not used, alignement > + taken care inside func : > todo */); > if (r == NULL) { > LOG_ERR("ring create failed\n"); > result = -1; > break; > } > /* lookup ring from its name */ > - if (odph_ring_lookup(ring_name) != r) { > + if (_ring_lookup(ring_name) != r) { > LOG_ERR("ring lookup failed\n"); > result = -1; > break; > @@ -388,16 +387,16 @@ static void *test_ring(void *arg) > result = -1; > } > > - /* dump ring stats */ > - odph_ring_list_dump(); > + if (result) > + _ring_list_dump(); > > break; > > case ODP_RING_TEST_STRESS: > test_ring_stress(parg->stress_type); > > - /* dump ring stats */ > - odph_ring_list_dump(); > + if (result) > + _ring_list_dump(); > break; > > default: > @@ -417,54 +416,69 @@ static void *test_ring(void *arg) > return parg; > } > > - > -int main(int argc __attribute__((__unused__)), > - char *argv[] __attribute__((__unused__))) > +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > { > ring_arg_t rarg; > + odph_linux_pthread_t thread_tbl[MAX_WORKERS]; > + odp_cpumask_t cpu_mask; > + int num_workers; > + char ring_name[_RING_NAMESIZE]; > > - if (odp_test_global_init() != 0) > - return -1; > + if (odp_init_global(NULL, NULL)) { > + LOG_ERR("Error: ODP global init failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odp_print_system_info(); > + if (odp_init_local(ODP_THREAD_CONTROL)) { > + LOG_ERR("Error: ODP local init failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odph_ring_tailq_init(); > + _ring_tailq_init(); > > - rarg.thrdarg.numthrds = odp_cpu_count(); > + num_workers = odp_cpumask_default_worker(&cpu_mask, > MAX_WORKERS); > + rarg.thrdarg.numthrds = rarg.thrdarg.numthrds; > > -#ifdef RING_TEST_BASIC > rarg.thrdarg.testcase = ODP_RING_TEST_BASIC; > -#else > + printf("starting stess test type : %d..\n", rarg.stress_type); > + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > + test_ring, (void *)&rarg, > + ODP_THREAD_WORKER); > + odph_linux_pthread_join(thread_tbl, num_workers); > + > rarg.thrdarg.testcase = ODP_RING_TEST_STRESS; > rarg.stress_type = one_enq_one_deq; > -/* rarg.stress_type = multi_enq_multi_deq;*/ > - char ring_name[ODPH_RING_NAMESIZE]; > > printf("starting stess test type : %d..\n", rarg.stress_type); > - /* create a ring */ > snprintf(ring_name, sizeof(ring_name), "test_ring_stress"); > - > - r_stress = odph_ring_create(ring_name, RING_SIZE, > - 0 /* not used, alignement > - taken care inside func : todo */); > + r_stress = _ring_create(ring_name, RING_SIZE, > + 0/* not used, alignement > + taken care inside func : todo */); > if (r_stress == NULL) { > LOG_ERR("ring create failed\n"); > goto fail; > } > /* lookup ring from its name */ > - if (odph_ring_lookup(ring_name) != r_stress) { > + if (_ring_lookup(ring_name) != r_stress) { > LOG_ERR("ring lookup failed\n"); > goto fail; > } > -#endif > - odp_test_thread_create(test_ring, (pthrd_arg *)&rarg); > > -#ifndef RING_TEST_BASIC > + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > + test_ring, (void *)&rarg, > + ODP_THREAD_WORKER); > + odph_linux_pthread_join(thread_tbl, num_workers); > + > fail: > -#endif > + if (odp_term_local()) { > + LOG_ERR("Error: ODP local term failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odp_test_thread_exit(&rarg.thrdarg); > + if (odp_term_global()) { > + LOG_ERR("Error: ODP global term failed.\n"); > + exit(EXIT_FAILURE); > + } > > return 0; > } > - > diff --git a/test/Makefile.am b/test/Makefile.am > index 2ba8008..4a75364 100644 > --- a/test/Makefile.am > +++ b/test/Makefile.am > @@ -1,4 +1,4 @@ > -SUBDIRS = api_test performance miscellaneous > +SUBDIRS = performance miscellaneous > > if cunit_support > SUBDIRS += validation > diff --git a/test/api_test/.gitignore b/test/api_test/.gitignore > deleted file mode 100644 > index 950f443..0000000 > --- a/test/api_test/.gitignore > +++ /dev/null > @@ -1,2 +0,0 @@ > -odp_ring > -odp_shm > diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am > deleted file mode 100644 > index fcdba48..0000000 > --- a/test/api_test/Makefile.am > +++ /dev/null > @@ -1,13 +0,0 @@ > -include $(top_srcdir)/test/Makefile.inc > - > -bin_PROGRAMS = odp_ring$(EXEEXT) > - > -odp_ring_CFLAGS = $(AM_CFLAGS) > - > -odp_ring_LDFLAGS = $(AM_LDFLAGS) -static > - > -noinst_HEADERS = \ > - $(top_srcdir)/test/api_test/odp_common.h \ > - $(top_srcdir)/test/test_debug.h > - > -dist_odp_ring_SOURCES = odp_ring_test.c odp_common.c > diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c > deleted file mode 100644 > index cebaa12..0000000 > --- a/test/api_test/odp_common.c > +++ /dev/null > @@ -1,91 +0,0 @@ > -/* Copyright (c) 2013, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -/** > - * @file > - * > - * ODP test application common > - */ > - > -#include <string.h> > -#include <odp.h> > -#include <odp/helper/linux.h> > -#include <odp_common.h> > -#include <test_debug.h> > - > -#define MAX_WORKERS 32 /**< Max worker > threads */ > - > -/* Globals */ > -static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; /**< worker > threads table*/ > -static int num_workers; /**< number of workers */ > - > -/** > - * Print system information > - */ > -void odp_print_system_info(void) > -{ > - odp_cpumask_t cpumask; > - char str[ODP_CPUMASK_STR_SIZE]; > - > - memset(str, 1, sizeof(str)); > - > - odp_cpumask_zero(&cpumask); > - > - odp_cpumask_from_str(&cpumask, "0x1"); > - (void)odp_cpumask_to_str(&cpumask, str, sizeof(str)); > - > - printf("\n"); > - printf("ODP system info\n"); > - printf("---------------\n"); > - printf("ODP API version: %s\n", odp_version_api_str()); > - printf("CPU model: %s\n", odp_sys_cpu_model_str()); > - printf("CPU freq (hz): %"PRIu64"\n", odp_sys_cpu_hz()); > - printf("Cache line size: %i\n", odp_sys_cache_line_size()); > - printf("CPU count: %i\n", odp_cpu_count()); > - printf("CPU mask: %s\n", str); > - > - printf("\n"); > -} > - > -/** test init globals and call odp_init_global() */ > -int odp_test_global_init(void) > -{ > - memset(thread_tbl, 0, sizeof(thread_tbl)); > - > - if (odp_init_global(NULL, NULL)) { > - LOG_ERR("ODP global init failed.\n"); > - return -1; > - } > - > - num_workers = odp_cpu_count(); > - /* force to max CPU count */ > - if (num_workers > MAX_WORKERS) > - num_workers = MAX_WORKERS; > - > - return 0; > -} > - > -/** create test thread */ > -int odp_test_thread_create(void *func_ptr(void *), pthrd_arg *arg) > -{ > - odp_cpumask_t cpumask; > - > - /* Create and init additional threads */ > - odp_cpumask_default_worker(&cpumask, arg->numthrds); > - odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr, > - (void *)arg, ODP_THREAD_WORKER); > - > - return 0; > -} > - > -/** exit from test thread */ > -int odp_test_thread_exit(pthrd_arg *arg) > -{ > - /* Wait for other threads to exit */ > - odph_linux_pthread_join(thread_tbl, arg->numthrds); > - > - return 0; > -} > diff --git a/test/api_test/odp_common.h b/test/api_test/odp_common.h > deleted file mode 100644 > index f321b6b..0000000 > --- a/test/api_test/odp_common.h > +++ /dev/null > @@ -1,42 +0,0 @@ > -/* Copyright (c) 2013, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -/** > - * @file > - * > - * ODP test application common headers > - */ > - > -#ifndef ODP_COMMON_H > -#define ODP_COMMON_H > - > -#define MAX_WORKERS 32 /**< Maximum number of work threads */ > - > -/** types of tests */ > -typedef enum { > - ODP_ATOMIC_TEST = 0, > - ODP_SHM_TEST, > - ODP_RING_TEST_BASIC, > - ODP_RING_TEST_STRESS, > - ODP_TIMER_PING_TEST, > - ODP_MAX_TEST > -} odp_test_case_e; > - > -/** > - * Thread argument > - */ > -typedef struct { > - int testcase; /**< specifies which set of API's to exercise */ > - int numthrds; /**< no of pthreads to create */ > -} pthrd_arg; > - > -extern void odp_print_system_info(void); > -extern int odp_test_global_init(void); > -/** create thread fro start_routine function */ > -extern int odp_test_thread_create(void *(*start_routine) (void > *), pthrd_arg *); > -extern int odp_test_thread_exit(pthrd_arg *); > - > -#endif /* ODP_COMMON_H */ > -- > 1.9.1 > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org> > https://lists.linaro.org/mailman/listinfo/lng-odp > > > > > -- > Mike Holmes > Technical Manager - Linaro Networking Group > Linaro.org <http://www.linaro.org/>***│ *Open source software for ARM SoCs >
Hm, I did not see that. Apply-and-build.sh passed for me. Maxim. On 12/18/2015 20:10, Mike Holmes wrote: > Also > Using patch: > lng-odp_PATCHv18_5-9_linux-generic-helper_move_ring_from_helper_to_linux-generic.mbox > Trying to apply patch > Patch applied > CHECK: Prefer using > ... > .... > CC pktio/ring.lo > ../../../../platform/linux-generic/pktio/ring.c:74:24: fatal error: > odph_pause.h: No such file or directory > compilation terminated. > Makefile:737: recipe for target 'pktio/ring.lo' failed > make[2]: *** [pktio/ring.lo] Error 1 > > > > > > On 18 December 2015 at 12:09, Mike Holmes <mike.holmes@linaro.org > <mailto:mike.holmes@linaro.org>> wrote: > > From checkpatch > > There should be a "default:" statement, if not we can clear this > warning in checkpatch by adding a comment in the actual code > explaining why a default is not needed. > > WARNING: Possible switch case/default not preceeded by break or > fallthrough comment > #2069: FILE: platform/linux-generic/pktio/ring.c:105: > +case 1: \ > > WARNING: Possible switch case/default not preceeded by break or > fallthrough comment > #2098: FILE: platform/linux-generic/pktio/ring.c:134: > +case 1: \ > > > There are other BIT macro warnings like this one, but I think we > need to disable them and I sent a patch to do so, maybe that will > prompt us to add a BIT macro but for now I dont think these should > block acceptance > > CHECK: Prefer using the BIT macro > #1523: FILE: > platform/linux-generic/include/odp_packet_io_ring_internal.h:158: > +#define _RING_F_SP_ENQ (1 << 0) > > > On 18 December 2015 at 06:29, Maxim Uvarov > <maxim.uvarov@linaro.org <mailto:maxim.uvarov@linaro.org>> wrote: > > Move ring and it's test from helper to linux-generic/pktio and > kill > not needed api_test directory. Unfortunately odp_ring_test.c > had some old > dirty code so I had to clean up it to to use cunit and > latest helper apis. > > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org > <mailto:maxim.uvarov@linaro.org>> > --- > configure.ac <http://configure.ac> | 1 - > helper/Makefile.am | 2 - > helper/test/Makefile.am | 5 +- > platform/linux-generic/Makefile.am | 2 + > .../include/odp_packet_io_ring_internal.h | 112 +++++---- > platform/linux-generic/m4/configure.m4 | 3 +- > {helper => platform/linux-generic/pktio}/ring.c | 263 > ++++++++++----------- > platform/linux-generic/test/Makefile.am | 3 +- > platform/linux-generic/test/ring/.gitignore | 1 + > platform/linux-generic/test/ring/Makefile.am | 16 ++ > .../linux-generic/test/ring/ringtest.c | 180 +++++++------- > test/Makefile.am | 2 +- > test/api_test/.gitignore | 2 - > test/api_test/Makefile.am | 13 - > test/api_test/odp_common.c | 91 ------- > test/api_test/odp_common.h | 42 ---- > 16 files changed, 309 insertions(+), 429 deletions(-) > rename helper/include/odp/helper/ring.h => > platform/linux-generic/include/odp_packet_io_ring_internal.h (87%) > rename {helper => platform/linux-generic/pktio}/ring.c (71%) > create mode 100644 platform/linux-generic/test/ring/.gitignore > create mode 100644 platform/linux-generic/test/ring/Makefile.am > rename test/api_test/odp_ring_test.c => > platform/linux-generic/test/ring/ringtest.c (72%) > delete mode 100644 test/api_test/.gitignore > delete mode 100644 test/api_test/Makefile.am > delete mode 100644 test/api_test/odp_common.c > delete mode 100644 test/api_test/odp_common.h > > diff --git a/configure.ac <http://configure.ac> b/configure.ac > <http://configure.ac> > index e45d90a..28b9ec9 100644 > --- a/configure.ac <http://configure.ac> > +++ b/configure.ac <http://configure.ac> > @@ -345,7 +345,6 @@ AC_CONFIG_FILES([Makefile > pkgconfig/libodphelper.pc > scripts/Makefile > test/Makefile > - test/api_test/Makefile > test/performance/Makefile > test/validation/Makefile > test/validation/buffer/Makefile > diff --git a/helper/Makefile.am b/helper/Makefile.am > index 1906ae2..6828092 100644 > --- a/helper/Makefile.am > +++ b/helper/Makefile.am > @@ -8,7 +8,6 @@ AM_CFLAGS += -I$(top_srcdir)/include > > helperincludedir = $(includedir)/odp/helper/ > helperinclude_HEADERS = \ > - $(srcdir)/include/odp/helper/ring.h \ > $(srcdir)/include/odp/helper/linux.h \ > $(srcdir)/include/odp/helper/chksum.h\ > $(srcdir)/include/odp/helper/eth.h\ > @@ -29,7 +28,6 @@ noinst_HEADERS = \ > > __LIB__libodphelper_la_SOURCES = \ > linux.c \ > - ring.c \ > hashtable.c \ > lineartable.c > > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > index 1c6a802..cf3b7aa 100644 > --- a/helper/test/Makefile.am > +++ b/helper/test/Makefile.am > @@ -1,6 +1,7 @@ > include $(top_srcdir)/test/Makefile.inc > > AM_CFLAGS += -I$(srcdir)/common > +AM_CFLAGS += -I$(top_srcdir)/test/validation/common > AM_LDFLAGS += -static > > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > @@ -28,5 +29,5 @@ dist_thread_SOURCES = thread.c > thread_LDADD = $(LIB)/libodphelper.la > <http://libodphelper.la> $(LIB)/libodp.la <http://libodp.la> > dist_process_SOURCES = process.c > process_LDADD = $(LIB)/libodphelper.la > <http://libodphelper.la> $(LIB)/libodp.la <http://libodp.la> > -odph_pause_SOURCES = pause.c > -dist_odp_table_SOURCES = table.c > +dist_pause_SOURCES = pause.c > +dist_table_SOURCES = table.c > diff --git a/platform/linux-generic/Makefile.am > b/platform/linux-generic/Makefile.am > index 4639ebc..8160649 100644 > --- a/platform/linux-generic/Makefile.am > +++ b/platform/linux-generic/Makefile.am > @@ -90,6 +90,7 @@ noinst_HEADERS = \ > ${srcdir}/include/odp_packet_internal.h \ > ${srcdir}/include/odp_packet_io_internal.h \ > ${srcdir}/include/odp_packet_io_queue.h \ > + ${srcdir}/include/odp_packet_io_ring_internal.h \ > ${srcdir}/include/odp_packet_netmap.h \ > ${srcdir}/include/odp_packet_socket.h \ > ${srcdir}/include/odp_packet_tap.h \ > @@ -122,6 +123,7 @@ __LIB__libodp_la_SOURCES = \ > pktio/socket.c \ > pktio/socket_mmap.c \ > pktio/tap.c \ > + pktio/ring.c \ > odp_pool.c \ > odp_queue.c \ > odp_rwlock.c \ > diff --git a/helper/include/odp/helper/ring.h > b/platform/linux-generic/include/odp_packet_io_ring_internal.h > similarity index 87% > rename from helper/include/odp/helper/ring.h > rename to > platform/linux-generic/include/odp_packet_io_ring_internal.h > index 541a466..f97c026 100644 > --- a/helper/include/odp/helper/ring.h > +++ b/platform/linux-generic/include/odp_packet_io_ring_internal.h > @@ -89,29 +89,28 @@ > * > */ > > -#ifndef ODPH_RING_H_ > -#define ODPH_RING_H_ > +#ifndef _RING_H_ > +#define _RING_H_ > > #ifdef __cplusplus > extern "C" { > #endif > > - > #include <odp/std_types.h> > #include <odp/hints.h> > #include <odp/atomic.h> > #include <errno.h> > #include <sys/queue.h> > +#include <odp_debug_internal.h> > > -enum odph_ring_queue_behavior { > - ODPH_RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number > +enum _ring_queue_behavior { > + _RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number > of items from a ring */ > - ODPH_RING_QUEUE_VARIABLE /**< Enq/Deq as many items > + _RING_QUEUE_VARIABLE /**< Enq/Deq as many items > a possible from ring */ > }; > > - > -#define ODPH_RING_NAMESIZE 32 /**< The maximum length of a > ring name. */ > +#define _RING_NAMESIZE 32 /**< The maximum length of a ring > name. */ > > /** > * An ODP ring structure. > @@ -123,12 +122,12 @@ enum odph_ring_queue_behavior { > * values in a modulo-32bit base: that's why the overflow of > the indexes is not > * a problem. > */ > -typedef struct odph_ring { > +typedef struct _ring { > /** @private Next in list. */ > - TAILQ_ENTRY(odph_ring) next; > + TAILQ_ENTRY(_ring) next; > > /** @private Name of the ring. */ > - char name[ODPH_RING_NAMESIZE]; > + char name[_RING_NAMESIZE]; > /** @private Flags supplied at creation. */ > int flags; > > @@ -153,21 +152,21 @@ typedef struct odph_ring { > > /** @private Memory space of ring starts here. */ > void *ring[0] ODP_ALIGNED_CACHE; > -} odph_ring_t; > +} _ring_t; > > /* The default enqueue is "single-producer".*/ > -#define ODPH_RING_F_SP_ENQ (1 << 0) > +#define _RING_F_SP_ENQ (1 << 0) > /* The default dequeue is "single-consumer".*/ > -#define ODPH_RING_F_SC_DEQ (1 << 1) > +#define _RING_F_SC_DEQ (1 << 1) > /* If set - ring is visible from different processes. > * Default is thread visible.*/ > -#define ODPH_RING_SHM_PROC (1 << 2) > +#define _RING_SHM_PROC (1 << 2) > /* Do not link ring to linked list. */ > -#define ODPH_RING_NO_LIST (1 << 3) > +#define _RING_NO_LIST (1 << 3) > /* Quota exceed for burst ops */ > -#define ODPH_RING_QUOT_EXCEED (1 << 31) > +#define _RING_QUOT_EXCEED (1 << 31) > /* Ring size mask */ > -#define ODPH_RING_SZ_MASK (unsigned)(0x0fffffff) > +#define _RING_SZ_MASK (unsigned)(0x0fffffff) > > /** > * Create a new ring named *name* in memory. > @@ -198,9 +197,8 @@ typedef struct odph_ring { > * - EEXIST - a memzone with the same name already exists > * - ENOMEM - no appropriate memory area found in which to > create memzone > */ > -odph_ring_t *odph_ring_create(const char *name, unsigned count, > - unsigned flags); > - > +_ring_t *_ring_create(const char *name, unsigned count, > + unsigned flags); > > /** > * Change the high water mark. > @@ -217,14 +215,14 @@ odph_ring_t *odph_ring_create(const char > *name, unsigned count, > * @return 0: Success; water mark changed. > * -EINVAL: Invalid water mark value. > */ > -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count); > +int _ring_set_water_mark(_ring_t *r, unsigned count); > > /** > * Dump the status of the ring to the console. > * > * @param r A pointer to the ring structure. > */ > -void odph_ring_dump(const odph_ring_t *r); > +void _ring_dump(const _ring_t *r); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -251,9 +249,9 @@ void odph_ring_dump(const odph_ring_t *r); > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects enqueued. > */ > -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, > - enum odph_ring_queue_behavior > behavior); > +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -277,9 +275,9 @@ int __odph_ring_mp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects enqueued. > */ > -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, > - enum odph_ring_queue_behavior > behavior); > +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Dequeue several objects from a ring (multi-consumers > safe). When > @@ -308,9 +306,9 @@ int __odph_ring_sp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > * - n: Actual number of objects dequeued. > */ > > -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, > - enum odph_ring_queue_behavior > behavior); > +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Dequeue several objects from a ring (NOT multi-consumers > safe). > @@ -335,9 +333,9 @@ int __odph_ring_mc_do_dequeue(odph_ring_t > *r, void **obj_table, > * if behavior = ODP_RING_QUEUE_VARIABLE > * - n: Actual number of objects dequeued. > */ > -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, > - enum odph_ring_queue_behavior > behavior); > +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, > + enum _ring_queue_behavior behavior); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -357,8 +355,8 @@ int __odph_ring_sc_do_dequeue(odph_ring_t > *r, void **obj_table, > * high water mark is exceeded. > * - -ENOBUFS: Not enough room in the ring to enqueue, no > object is enqueued. > */ > -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -375,8 +373,8 @@ int odph_ring_mp_enqueue_bulk(odph_ring_t > *r, void * const *obj_table, > * high water mark is exceeded. > * - -ENOBUFS: Not enough room in the ring to enqueue; no > object is enqueued. > */ > -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Dequeue several objects from a ring (multi-consumers safe). > @@ -395,7 +393,7 @@ int odph_ring_sp_enqueue_bulk(odph_ring_t > *r, void * const *obj_table, > * - -ENOENT: Not enough entries in the ring to dequeue; no > object is > * dequeued. > */ > -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void > **obj_table, unsigned n); > +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, > unsigned n); > > /** > * Dequeue several objects from a ring (NOT multi-consumers > safe). > @@ -412,7 +410,7 @@ int odph_ring_mc_dequeue_bulk(odph_ring_t > *r, void **obj_table, unsigned n); > * - -ENOENT: Not enough entries in the ring to dequeue; no > object is > * dequeued. > */ > -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void > **obj_table, unsigned n); > +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, > unsigned n); > > /** > * Test if a ring is full. > @@ -423,7 +421,7 @@ int odph_ring_sc_dequeue_bulk(odph_ring_t > *r, void **obj_table, unsigned n); > * - 1: The ring is full. > * - 0: The ring is not full. > */ > -int odph_ring_full(const odph_ring_t *r); > +int _ring_full(const _ring_t *r); > > /** > * Test if a ring is empty. > @@ -434,7 +432,7 @@ int odph_ring_full(const odph_ring_t *r); > * - 1: The ring is empty. > * - 0: The ring is not empty. > */ > -int odph_ring_empty(const odph_ring_t *r); > +int _ring_empty(const _ring_t *r); > > /** > * Return the number of entries in a ring. > @@ -444,7 +442,7 @@ int odph_ring_empty(const odph_ring_t *r); > * @return > * The number of entries in the ring. > */ > -unsigned odph_ring_count(const odph_ring_t *r); > +unsigned _ring_count(const _ring_t *r); > > /** > * Return the number of free entries in a ring. > @@ -454,14 +452,14 @@ unsigned odph_ring_count(const > odph_ring_t *r); > * @return > * The number of free entries in the ring. > */ > -unsigned odph_ring_free_count(const odph_ring_t *r); > +unsigned _ring_free_count(const _ring_t *r); > > /** > * search ring by name > * @param name ring name to search > * @return pointer to ring otherwise NULL > */ > -odph_ring_t *odph_ring_lookup(const char *name); > +_ring_t *_ring_lookup(const char *name); > > /** > * Enqueue several objects on the ring (multi-producers safe). > @@ -478,8 +476,8 @@ odph_ring_t *odph_ring_lookup(const char > *name); > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > @@ -493,8 +491,8 @@ int odph_ring_mp_enqueue_burst(odph_ring_t > *r, void * const *obj_table, > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > /** > * Enqueue several objects on a ring. > * > @@ -511,8 +509,8 @@ int odph_ring_sp_enqueue_burst(odph_ring_t > *r, void * const *obj_table, > * @return > * - n: Actual number of objects enqueued. > */ > -int odph_ring_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n); > +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n); > > /** > * Dequeue several objects from a ring (multi-consumers > safe). When the request > @@ -531,7 +529,7 @@ int odph_ring_enqueue_burst(odph_ring_t > *r, void * const *obj_table, > * @return > * - n: Actual number of objects dequeued, 0 if ring is empty > */ > -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void > **obj_table, unsigned n); > +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, > unsigned n); > > /** > * Dequeue several objects from a ring (NOT multi-consumers > safe).When the > @@ -547,7 +545,7 @@ int odph_ring_mc_dequeue_burst(odph_ring_t > *r, void **obj_table, unsigned n); > * @return > * - n: Actual number of objects dequeued, 0 if ring is empty > */ > -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void > **obj_table, unsigned n); > +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, > unsigned n); > > /** > * Dequeue multiple objects from a ring up to a maximum number. > @@ -565,17 +563,17 @@ int > odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n); > * @return > * - Number of objects dequeued, or a negative error code > on error > */ > -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n); > +int _ring_dequeue_burst(_ring_t *r, void **obj_table, > unsigned n); > > /** > * dump the status of all rings on the console > */ > -void odph_ring_list_dump(void); > +void _ring_list_dump(void); > > /** > * initialise ring tailq > */ > -void odph_ring_tailq_init(void); > +void _ring_tailq_init(void); > > #ifdef __cplusplus > } > diff --git a/platform/linux-generic/m4/configure.m4 > b/platform/linux-generic/m4/configure.m4 > index df6dc64..6bb159f 100644 > --- a/platform/linux-generic/m4/configure.m4 > +++ b/platform/linux-generic/m4/configure.m4 > @@ -23,4 +23,5 @@ > m4_include([platform/linux-generic/m4/odp_pcap.m4]) > > AC_CONFIG_FILES([platform/linux-generic/Makefile > platform/linux-generic/test/Makefile > - platform/linux-generic/test/pktio/Makefile]) > + platform/linux-generic/test/pktio/Makefile > + platform/linux-generic/test/ring/Makefile]) > diff --git a/helper/ring.c b/platform/linux-generic/pktio/ring.c > similarity index 71% > rename from helper/ring.c > rename to platform/linux-generic/pktio/ring.c > index e113606..e978420 100644 > --- a/helper/ring.c > +++ b/platform/linux-generic/pktio/ring.c > @@ -78,9 +78,9 @@ > #include <string.h> > #include "odph_debug.h" > #include <odp/rwlock.h> > -#include <odp/helper/ring.h> > +#include <odp_packet_io_ring_internal.h> > > -static TAILQ_HEAD(, odph_ring) odp_ring_list; > +static TAILQ_HEAD(, _ring) odp_ring_list; > > #define RING_VAL_IS_POWER_2(x) ((((x) - 1) & (x)) == 0) > > @@ -93,9 +93,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > if (odp_likely(idx + n < size)) { \ > for (i = 0; i < (n & ((~(unsigned)0x3))); i += > 4, idx += 4) { \ > r->ring[idx] = obj_table[i]; \ > - r->ring[idx+1] = obj_table[i+1]; \ > - r->ring[idx+2] = obj_table[i+2]; \ > - r->ring[idx+3] = obj_table[i+3]; \ > + r->ring[idx + 1] = obj_table[i + 1]; \ > + r->ring[idx + 2] = obj_table[i + 2]; \ > + r->ring[idx + 3] = obj_table[i + 3]; \ > } \ > switch (n & 0x3) { \ > case 3: \ > @@ -122,9 +122,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; > if (odp_likely(idx + n < size)) { \ > for (i = 0; i < (n & (~(unsigned)0x3)); i += > 4, idx += 4) {\ > obj_table[i] = r->ring[idx]; \ > - obj_table[i+1] = r->ring[idx+1]; \ > - obj_table[i+2] = r->ring[idx+2]; \ > - obj_table[i+3] = r->ring[idx+3]; \ > + obj_table[i + 1] = r->ring[idx + 1]; \ > + obj_table[i + 2] = r->ring[idx + 2]; \ > + obj_table[i + 3] = r->ring[idx + 3]; \ > } \ > switch (n & 0x3) { \ > case 3: \ > @@ -145,36 +145,37 @@ static TAILQ_HEAD(, odph_ring) > odp_ring_list; > static odp_rwlock_t qlock; /* rings tailq lock */ > > /* init tailq_ring */ > -void odph_ring_tailq_init(void) > +void _ring_tailq_init(void) > { > TAILQ_INIT(&odp_ring_list); > odp_rwlock_init(&qlock); > } > > /* create the ring */ > -odph_ring_t * > -odph_ring_create(const char *name, unsigned count, unsigned > flags) > +_ring_t * > +_ring_create(const char *name, unsigned count, unsigned flags) > { > - char ring_name[ODPH_RING_NAMESIZE]; > - odph_ring_t *r; > + char ring_name[_RING_NAMESIZE]; > + _ring_t *r; > size_t ring_size; > uint32_t shm_flag; > odp_shm_t shm; > > - if (flags & ODPH_RING_SHM_PROC) > + if (flags & _RING_SHM_PROC) > shm_flag = ODP_SHM_PROC; > else > shm_flag = 0; > > /* count must be a power of 2 */ > - if (!RING_VAL_IS_POWER_2(count) || (count > > ODPH_RING_SZ_MASK)) { > - ODPH_ERR("Requested size is invalid, must be > power of 2, and do not exceed the size limit %u\n", > - ODPH_RING_SZ_MASK); > + if (!RING_VAL_IS_POWER_2(count) || (count > > _RING_SZ_MASK)) { > + ODPH_ERR("Requested size is invalid, must be > power of 2," > + "and do not exceed the size limit %u\n", > + _RING_SZ_MASK); > return NULL; > } > > snprintf(ring_name, sizeof(ring_name), "%s", name); > - ring_size = count*sizeof(void *)+sizeof(odph_ring_t); > + ring_size = count * sizeof(void *) + sizeof(_ring_t); > > odp_rwlock_write_lock(&qlock); > /* reserve a memory zone for this ring.*/ > @@ -188,18 +189,18 @@ odph_ring_create(const char *name, > unsigned count, unsigned flags) > snprintf(r->name, sizeof(r->name), "%s", name); > r->flags = flags; > r->prod.watermark = count; > - r->prod.sp_enqueue = !!(flags & > ODPH_RING_F_SP_ENQ); > - r->cons.sc_dequeue = !!(flags & > ODPH_RING_F_SC_DEQ); > + r->prod.sp_enqueue = !!(flags & _RING_F_SP_ENQ); > + r->cons.sc_dequeue = !!(flags & _RING_F_SC_DEQ); > r->prod.size = count; > r->cons.size = count; > - r->prod.mask = count-1; > - r->cons.mask = count-1; > + r->prod.mask = count - 1; > + r->cons.mask = count - 1; > r->prod.head = 0; > r->cons.head = 0; > r->prod.tail = 0; > r->cons.tail = 0; > > - if (!(flags & ODPH_RING_NO_LIST)) > + if (!(flags & _RING_NO_LIST)) > TAILQ_INSERT_TAIL(&odp_ring_list, r, next); > } else { > ODPH_ERR("Cannot reserve memory\n"); > @@ -213,7 +214,7 @@ odph_ring_create(const char *name, > unsigned count, unsigned flags) > * change the high water mark. If *count* is 0, water marking is > * disabled > */ > -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count) > +int _ring_set_water_mark(_ring_t *r, unsigned count) > { > if (count >= r->prod.size) > return -EINVAL; > @@ -229,8 +230,8 @@ int odph_ring_set_water_mark(odph_ring_t > *r, unsigned count) > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, enum > odph_ring_queue_behavior behavior) > +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, enum > _ring_queue_behavior behavior) > { > uint32_t prod_head, prod_next; > uint32_t cons_tail, free_entries; > @@ -255,24 +256,22 @@ int > __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, > > /* check that we have enough room in ring */ > if (odp_unlikely(n > free_entries)) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOBUFS; > - } else { > - /* No free entry available */ > - if (odp_unlikely(free_entries > == 0)) > - return 0; > + /* No free entry available */ > + if (odp_unlikely(free_entries == 0)) > + return 0; > > - n = free_entries; > - } > + n = free_entries; > } > > prod_next = prod_head + n; > success = > __atomic_compare_exchange_n(&r->prod.head, > - &prod_head, > - prod_next, > - false/*strong*/, > - __ATOMIC_ACQUIRE, > - __ATOMIC_RELAXED); > + &prod_head, > + prod_next, > + false/*strong*/, > + __ATOMIC_ACQUIRE, > + __ATOMIC_RELAXED); > } while (odp_unlikely(success == 0)); > > /* write entries in ring */ > @@ -280,10 +279,10 @@ int > __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, > > /* if we exceed the watermark */ > if (odp_unlikely(((mask + 1) - free_entries + n) > > r->prod.watermark)) { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? > -EDQUOT : > - (int)(n | ODPH_RING_QUOT_EXCEED); > + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : > + (int)(n | _RING_QUOT_EXCEED); > } else { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; > + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; > } > > /* > @@ -302,8 +301,8 @@ int __odph_ring_mp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const > *obj_table, > - unsigned n, enum > odph_ring_queue_behavior behavior) > +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, > + unsigned n, enum > _ring_queue_behavior behavior) > { > uint32_t prod_head, cons_tail; > uint32_t prod_next, free_entries; > @@ -321,15 +320,13 @@ int > __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, > > /* check that we have enough room in ring */ > if (odp_unlikely(n > free_entries)) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOBUFS; > - } else { > - /* No free entry available */ > - if (odp_unlikely(free_entries == 0)) > - return 0; > + /* No free entry available */ > + if (odp_unlikely(free_entries == 0)) > + return 0; > > - n = free_entries; > - } > + n = free_entries; > } > > prod_next = prod_head + n; > @@ -340,10 +337,10 @@ int > __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, > > /* if we exceed the watermark */ > if (odp_unlikely(((mask + 1) - free_entries + n) > > r->prod.watermark)) { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? > -EDQUOT : > - (int)(n | ODPH_RING_QUOT_EXCEED); > + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : > + (int)(n | _RING_QUOT_EXCEED); > } else { > - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; > + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; > } > > /* Release our entries and the memory they refer to */ > @@ -356,8 +353,8 @@ int __odph_ring_sp_do_enqueue(odph_ring_t > *r, void * const *obj_table, > * Dequeue several objects from a ring (multi-consumers safe). > */ > > -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, enum > odph_ring_queue_behavior behavior) > +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, enum > _ring_queue_behavior behavior) > { > uint32_t cons_head, prod_tail; > uint32_t cons_next, entries; > @@ -381,23 +378,21 @@ int > __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > > /* Set the actual entries for dequeue */ > if (n > entries) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOENT; > - } else { > - if (odp_unlikely(entries == 0)) > - return 0; > + if (odp_unlikely(entries == 0)) > + return 0; > > - n = entries; > - } > + n = entries; > } > > cons_next = cons_head + n; > success = > __atomic_compare_exchange_n(&r->cons.head, > - &cons_head, > - cons_next, > - false/*strong*/, > - __ATOMIC_ACQUIRE, > - __ATOMIC_RELAXED); > + &cons_head, > + cons_next, > + false/*strong*/, > + __ATOMIC_ACQUIRE, > + __ATOMIC_RELAXED); > } while (odp_unlikely(success == 0)); > > /* copy in table */ > @@ -414,14 +409,14 @@ int > __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, > __atomic_thread_fence(__ATOMIC_RELEASE); > r->cons.tail = cons_next; > > - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; > + return behavior == _RING_QUEUE_FIXED ? 0 : n; > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers > safe). > */ > -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > - unsigned n, enum > odph_ring_queue_behavior behavior) > +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, > + unsigned n, enum > _ring_queue_behavior behavior) > { > uint32_t cons_head, prod_tail; > uint32_t cons_next, entries; > @@ -437,14 +432,12 @@ int > __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > entries = prod_tail - cons_head; > > if (n > entries) { > - if (behavior == ODPH_RING_QUEUE_FIXED) { > + if (behavior == _RING_QUEUE_FIXED) > return -ENOENT; > - } else { > - if (odp_unlikely(entries == 0)) > - return 0; > + if (odp_unlikely(entries == 0)) > + return 0; > > - n = entries; > - } > + n = entries; > } > > cons_next = cons_head + n; > @@ -456,127 +449,131 @@ int > __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, > DEQUEUE_PTRS(); > > r->cons.tail = cons_next; > - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; > + return behavior == _RING_QUEUE_FIXED ? 0 : n; > } > > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_mp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_mp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_sp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_sp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Dequeue several objects from a ring (multi-consumers safe). > */ > -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void > **obj_table, unsigned n) > +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, > unsigned n) > { > - return __odph_ring_mc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_mc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers > safe). > */ > -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void > **obj_table, unsigned n) > +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, > unsigned n) > { > - return __odph_ring_sc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_FIXED); > + return ___ring_sc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_FIXED); > } > > /** > * Test if a ring is full. > */ > -int odph_ring_full(const odph_ring_t *r) > +int _ring_full(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (((cons_tail - prod_tail - 1) & r->prod.mask) > == 0); > } > > /** > * Test if a ring is empty. > */ > -int odph_ring_empty(const odph_ring_t *r) > +int _ring_empty(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return !!(cons_tail == prod_tail); > } > > /** > * Return the number of entries in a ring. > */ > -unsigned odph_ring_count(const odph_ring_t *r) > +unsigned _ring_count(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (prod_tail - cons_tail) & r->prod.mask; > } > > /** > * Return the number of free entries in a ring. > */ > -unsigned odph_ring_free_count(const odph_ring_t *r) > +unsigned _ring_free_count(const _ring_t *r) > { > uint32_t prod_tail = r->prod.tail; > uint32_t cons_tail = r->cons.tail; > + > return (cons_tail - prod_tail - 1) & r->prod.mask; > } > > /* dump the status of the ring on the console */ > -void odph_ring_dump(const odph_ring_t *r) > +void _ring_dump(const _ring_t *r) > { > - ODPH_DBG("ring <%s>@%p\n", r->name, r); > - ODPH_DBG(" flags=%x\n", r->flags); > - ODPH_DBG(" size=%" PRIu32 "\n", r->prod.size); > - ODPH_DBG(" ct=%" PRIu32 "\n", r->cons.tail); > - ODPH_DBG(" ch=%" PRIu32 "\n", r->cons.head); > - ODPH_DBG(" pt=%" PRIu32 "\n", r->prod.tail); > - ODPH_DBG(" ph=%" PRIu32 "\n", r->prod.head); > - ODPH_DBG(" used=%u\n", odph_ring_count(r)); > - ODPH_DBG(" avail=%u\n", odph_ring_free_count(r)); > + ODP_DBG("ring <%s>@%p\n", r->name, r); > + ODP_DBG(" flags=%x\n", r->flags); > + ODP_DBG(" size=%" PRIu32 "\n", r->prod.size); > + ODP_DBG(" ct=%" PRIu32 "\n", r->cons.tail); > + ODP_DBG(" ch=%" PRIu32 "\n", r->cons.head); > + ODP_DBG(" pt=%" PRIu32 "\n", r->prod.tail); > + ODP_DBG(" ph=%" PRIu32 "\n", r->prod.head); > + ODP_DBG(" used=%u\n", _ring_count(r)); > + ODP_DBG(" avail=%u\n", _ring_free_count(r)); > if (r->prod.watermark == r->prod.size) > - ODPH_DBG(" watermark=0\n"); > + ODP_DBG(" watermark=0\n"); > else > - ODPH_DBG(" watermark=%" PRIu32 "\n", > r->prod.watermark); > + ODP_DBG(" watermark=%" PRIu32 "\n", > r->prod.watermark); > } > > /* dump the status of all rings on the console */ > -void odph_ring_list_dump(void) > +void _ring_list_dump(void) > { > - const odph_ring_t *mp = NULL; > + const _ring_t *mp = NULL; > > odp_rwlock_read_lock(&qlock); > > TAILQ_FOREACH(mp, &odp_ring_list, next) { > - odph_ring_dump(mp); > + _ring_dump(mp); > } > > odp_rwlock_read_unlock(&qlock); > } > > /* search a ring from its name */ > -odph_ring_t *odph_ring_lookup(const char *name) > +_ring_t *_ring_lookup(const char *name) > { > - odph_ring_t *r; > + _ring_t *r; > > odp_rwlock_read_lock(&qlock); > TAILQ_FOREACH(r, &odp_ring_list, next) { > - if (strncmp(name, r->name, ODPH_RING_NAMESIZE) > == 0) > + if (strncmp(name, r->name, _RING_NAMESIZE) == 0) > break; > } > odp_rwlock_read_unlock(&qlock); > @@ -587,60 +584,60 @@ odph_ring_t *odph_ring_lookup(const char > *name) > /** > * Enqueue several objects on the ring (multi-producers safe). > */ > -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_mp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_mp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Enqueue several objects on a ring (NOT multi-producers safe). > */ > -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > - return __odph_ring_sp_do_enqueue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_sp_do_enqueue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Enqueue several objects on a ring. > */ > -int odph_ring_enqueue_burst(odph_ring_t *r, void * const > *obj_table, > - unsigned n) > +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, > + unsigned n) > { > if (r->prod.sp_enqueue) > - return odph_ring_sp_enqueue_burst(r, > obj_table, n); > + return _ring_sp_enqueue_burst(r, obj_table, n); > else > - return odph_ring_mp_enqueue_burst(r, > obj_table, n); > + return _ring_mp_enqueue_burst(r, obj_table, n); > } > > /** > * Dequeue several objects from a ring (multi-consumers safe). > */ > -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void > **obj_table, unsigned n) > +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, > unsigned n) > { > - return __odph_ring_mc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_mc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Dequeue several objects from a ring (NOT multi-consumers > safe). > */ > -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void > **obj_table, unsigned n) > +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, > unsigned n) > { > - return __odph_ring_sc_do_dequeue(r, obj_table, n, > - ODPH_RING_QUEUE_VARIABLE); > + return ___ring_sc_do_dequeue(r, obj_table, n, > + _RING_QUEUE_VARIABLE); > } > > /** > * Dequeue multiple objects from a ring up to a maximum number. > */ > -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, > unsigned n) > +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) > { > if (r->cons.sc_dequeue) > - return odph_ring_sc_dequeue_burst(r, > obj_table, n); > + return _ring_sc_dequeue_burst(r, obj_table, n); > else > - return odph_ring_mc_dequeue_burst(r, > obj_table, n); > + return _ring_mc_dequeue_burst(r, obj_table, n); > } > diff --git a/platform/linux-generic/test/Makefile.am > b/platform/linux-generic/test/Makefile.am > index 594aa11..f81eeb8 100644 > --- a/platform/linux-generic/test/Makefile.am > +++ b/platform/linux-generic/test/Makefile.am > @@ -1,11 +1,12 @@ > include $(top_srcdir)/test/Makefile.inc > TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation > > -ODP_MODULES = pktio > +ODP_MODULES = pktio ring > > if test_vald > TESTS = pktio/pktio_run \ > pktio/pktio_run_tap \ > + ring/ringtest$(EXEEXT) \ > ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ > ${top_builddir}/test/validation/classification/classification_main$(EXEEXT) > \ > ${top_builddir}/test/validation/config/config_main$(EXEEXT) \ > diff --git a/platform/linux-generic/test/ring/.gitignore > b/platform/linux-generic/test/ring/.gitignore > new file mode 100644 > index 0000000..4767f5e > --- /dev/null > +++ b/platform/linux-generic/test/ring/.gitignore > @@ -0,0 +1 @@ > +ringtest > diff --git a/platform/linux-generic/test/ring/Makefile.am > b/platform/linux-generic/test/ring/Makefile.am > new file mode 100644 > index 0000000..5a949d0 > --- /dev/null > +++ b/platform/linux-generic/test/ring/Makefile.am > @@ -0,0 +1,16 @@ > +include $(top_srcdir)/test/validation/Makefile.inc > + > +AM_CFLAGS += -I$(srcdir)/common > +AM_CFLAGS += -I$(top_srcdir)/test/validation/common > +AM_LDFLAGS += -static > + > +COMPILE_ONLY = > + > +TESTSCRIPTS = > + > +EXECUTABLES = ringtest$(EXEEXT) > + > +test_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) > + > +ringtest_SOURCES = ringtest.c > +ringtest_LDADD = $(LIBCUNIT_COMMON) $(LIBODP) > diff --git a/test/api_test/odp_ring_test.c > b/platform/linux-generic/test/ring/ringtest.c > similarity index 72% > rename from test/api_test/odp_ring_test.c > rename to platform/linux-generic/test/ring/ringtest.c > index e8a962a..dfa220b 100644 > --- a/test/api_test/odp_ring_test.c > +++ b/platform/linux-generic/test/ring/ringtest.c > @@ -37,7 +37,6 @@ > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > SUCH DAMAGE. > */ > > - > /** > * @file > * > @@ -48,86 +47,96 @@ > #include <stdio.h> > #include <string.h> > #include <odp.h> > -#include <odp_common.h> > -#include <odp/helper/ring.h> > +#include <odp/helper/linux.h> > +#include <odp_packet_io_ring_internal.h> > #include <test_debug.h> > +#include <odp_cunit_common.h> > > #define RING_SIZE 4096 > #define MAX_BULK 32 > > -#define RING_TEST_BASIC > +enum { > + ODP_RING_TEST_BASIC, > + ODP_RING_TEST_STRESS, > +}; > > -static int test_ring_basic(odph_ring_t *r) > +/* local struct for ring_thread argument */ > +typedef struct { > + pthrd_arg thrdarg; > + int stress_type; > +} ring_arg_t; > + > +static int test_ring_basic(_ring_t *r) > { > void **src = NULL, **cur_src = NULL, **dst = NULL, > **cur_dst = NULL; > int ret; > unsigned i, num_elems; > > /* alloc dummy object pointers */ > - src = malloc(RING_SIZE*2*sizeof(void *)); > + src = malloc(RING_SIZE * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate test ring src > memory\n"); > goto fail; > } > - for (i = 0; i < RING_SIZE*2; i++) > + for (i = 0; i < RING_SIZE * 2; i++) > src[i] = (void *)(unsigned long)i; > > cur_src = src; > > /* alloc some room for copied objects */ > - dst = malloc(RING_SIZE*2*sizeof(void *)); > + dst = malloc(RING_SIZE * 2 * sizeof(void *)); > if (dst == NULL) { > LOG_ERR("failed to allocate test ring dst > memory\n"); > goto fail; > } > > - memset(dst, 0, RING_SIZE*2*sizeof(void *)); > + memset(dst, 0, RING_SIZE * 2 * sizeof(void *)); > cur_dst = dst; > > printf("Test SP & SC basic functions\n"); > printf("enqueue 1 obj\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, 1); > + ret = _ring_sp_enqueue_burst(r, cur_src, 1); > cur_src += 1; > - if ((ret & ODPH_RING_SZ_MASK) != 1) { > + if ((ret & _RING_SZ_MASK) != 1) { > LOG_ERR("sp_enq for 1 obj failed\n"); > goto fail; > } > > printf("enqueue 2 objs\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, 2); > + ret = _ring_sp_enqueue_burst(r, cur_src, 2); > cur_src += 2; > - if ((ret & ODPH_RING_SZ_MASK) != 2) { > + if ((ret & _RING_SZ_MASK) != 2) { > LOG_ERR("sp_enq for 2 obj failed\n"); > goto fail; > } > > printf("enqueue MAX_BULK objs\n"); > - ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK); > - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { > + ret = _ring_sp_enqueue_burst(r, cur_src, MAX_BULK); > + if ((ret & _RING_SZ_MASK) != MAX_BULK) { > LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK); > goto fail; > } > > printf("dequeue 1 obj\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1); > + ret = _ring_sc_dequeue_burst(r, cur_dst, 1); > cur_dst += 1; > - if ((ret & ODPH_RING_SZ_MASK) != 1) { > + if ((ret & _RING_SZ_MASK) != 1) { > LOG_ERR("sc_deq for 1 obj failed\n"); > goto fail; > } > > printf("dequeue 2 objs\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2); > + ret = _ring_sc_dequeue_burst(r, cur_dst, 2); > cur_dst += 2; > - if ((ret & ODPH_RING_SZ_MASK) != 2) { > + if ((ret & _RING_SZ_MASK) != 2) { > LOG_ERR("sc_deq for 2 obj failed\n"); > goto fail; > } > > printf("dequeue MAX_BULK objs\n"); > - ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); > + ret = _ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); > cur_dst += MAX_BULK; > - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { > + if ((ret & _RING_SZ_MASK) != MAX_BULK) { > LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK); > goto fail; > } > @@ -144,41 +153,41 @@ static int test_ring_basic(odph_ring_t *r) > printf("Test MP & MC basic functions\n"); > > printf("enqueue 1 obj\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1); > + ret = _ring_mp_enqueue_bulk(r, cur_src, 1); > cur_src += 1; > if (ret != 0) { > LOG_ERR("mp_enq for 1 obj failed\n"); > goto fail; > } > printf("enqueue 2 objs\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2); > + ret = _ring_mp_enqueue_bulk(r, cur_src, 2); > cur_src += 2; > if (ret != 0) { > LOG_ERR("mp_enq for 2 obj failed\n"); > goto fail; > } > printf("enqueue MAX_BULK objs\n"); > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); > + ret = _ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); > if (ret != 0) { > LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK); > goto fail; > } > printf("dequeue 1 obj\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, 1); > cur_dst += 1; > if (ret != 0) { > LOG_ERR("mc_deq for 1 obj failed\n"); > goto fail; > } > printf("dequeue 2 objs\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, 2); > cur_dst += 2; > if (ret != 0) { > LOG_ERR("mc_deq for 2 obj failed\n"); > goto fail; > } > printf("dequeue MAX_BULK objs\n"); > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); > cur_dst += MAX_BULK; > if (ret != 0) { > LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK); > @@ -191,30 +200,30 @@ static int test_ring_basic(odph_ring_t *r) > } > > printf("test watermark and default bulk enqueue / > dequeue\n"); > - odph_ring_set_water_mark(r, 20); > + _ring_set_water_mark(r, 20); > num_elems = 16; > > cur_src = src; > cur_dst = dst; > > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); > + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); > cur_src += num_elems; > if (ret != 0) { > LOG_ERR("Cannot enqueue\n"); > goto fail; > } > - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); > + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); > if (ret != -EDQUOT) { > LOG_ERR("Watermark not exceeded\n"); > goto fail; > } > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); > cur_dst += num_elems; > if (ret != 0) { > LOG_ERR("Cannot dequeue\n"); > goto fail; > } > - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); > + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); > cur_dst += num_elems; > if (ret != 0) { > LOG_ERR("Cannot dequeue2\n"); > @@ -241,7 +250,7 @@ fail: > } > > /* global shared ring used for stress testing */ > -static odph_ring_t *r_stress; > +static _ring_t *r_stress; > > /* Stress func for Multi producer only */ > static int producer_fn(void) > @@ -251,7 +260,7 @@ static int producer_fn(void) > void **src = NULL; > > /* alloc dummy object pointers */ > - src = malloc(MAX_BULK*2*sizeof(void *)); > + src = malloc(MAX_BULK * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate producer memory.\n"); > return -1; > @@ -260,7 +269,7 @@ static int producer_fn(void) > src[i] = (void *)(unsigned long)i; > > do { > - i = odph_ring_mp_enqueue_bulk(r_stress, src, > MAX_BULK); > + i = _ring_mp_enqueue_bulk(r_stress, src, > MAX_BULK); > if (i == 0) { > free(src); > return 0; > @@ -275,14 +284,14 @@ static int consumer_fn(void) > void **src = NULL; > > /* alloc dummy object pointers */ > - src = malloc(MAX_BULK*2*sizeof(void *)); > + src = malloc(MAX_BULK * 2 * sizeof(void *)); > if (src == NULL) { > LOG_ERR("failed to allocate consumer memory.\n"); > return -1; > } > > do { > - i = odph_ring_mc_dequeue_bulk(r_stress, src, > MAX_BULK); > + i = _ring_mc_dequeue_bulk(r_stress, src, > MAX_BULK); > if (i == 0) { > for (i = 0; i < MAX_BULK; i++) { > if (src[i] != (void > *)(unsigned long)i) { > @@ -298,7 +307,6 @@ static int consumer_fn(void) > } while (1); > } > > - > /* > * Note : make sure that both enqueue and dequeue > * operation starts at same time so to avoid data corruption > @@ -319,24 +327,22 @@ typedef enum { > static void test_ring_stress(stress_type_t type) > { > int thr; > + > thr = odp_thread_id(); > > switch (type) { > case one_enq_one_deq: > - > if (thr == 1) > producer_fn(); > if (thr == 2) > consumer_fn(); > break; > - > case multi_enq_multi_deq: > - if (thr%2 == 0) > + if (thr % 2 == 0) > producer_fn(); > else > consumer_fn(); > break; > - > case one_deq_rest_enq: > case one_enq_rest_deq:/*TBD*/ > default: > @@ -344,19 +350,12 @@ static void > test_ring_stress(stress_type_t type) > } > } > > -/* local struct for ring_thread argument */ > -typedef struct { > - pthrd_arg thrdarg; > - int stress_type; > -} ring_arg_t; > - > - > static void *test_ring(void *arg) > { > ring_arg_t *parg = (ring_arg_t *)arg; > int thr; > - char ring_name[ODPH_RING_NAMESIZE]; > - odph_ring_t *r; > + char ring_name[_RING_NAMESIZE]; > + _ring_t *r; > int result = 0; > > thr = odp_thread_id(); > @@ -367,16 +366,16 @@ static void *test_ring(void *arg) > case ODP_RING_TEST_BASIC: > snprintf(ring_name, sizeof(ring_name), > "test_ring_%i", thr); > > - r = odph_ring_create(ring_name, RING_SIZE, > - 0 /* not used, alignement > - taken care inside > func : todo */); > + r = _ring_create(ring_name, RING_SIZE, > + 0 /* not used, alignement > + taken care inside func : > todo */); > if (r == NULL) { > LOG_ERR("ring create failed\n"); > result = -1; > break; > } > /* lookup ring from its name */ > - if (odph_ring_lookup(ring_name) != r) { > + if (_ring_lookup(ring_name) != r) { > LOG_ERR("ring lookup failed\n"); > result = -1; > break; > @@ -388,16 +387,16 @@ static void *test_ring(void *arg) > result = -1; > } > > - /* dump ring stats */ > - odph_ring_list_dump(); > + if (result) > + _ring_list_dump(); > > break; > > case ODP_RING_TEST_STRESS: > test_ring_stress(parg->stress_type); > > - /* dump ring stats */ > - odph_ring_list_dump(); > + if (result) > + _ring_list_dump(); > break; > > default: > @@ -417,54 +416,69 @@ static void *test_ring(void *arg) > return parg; > } > > - > -int main(int argc __attribute__((__unused__)), > - char *argv[] __attribute__((__unused__))) > +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > { > ring_arg_t rarg; > + odph_linux_pthread_t thread_tbl[MAX_WORKERS]; > + odp_cpumask_t cpu_mask; > + int num_workers; > + char ring_name[_RING_NAMESIZE]; > > - if (odp_test_global_init() != 0) > - return -1; > + if (odp_init_global(NULL, NULL)) { > + LOG_ERR("Error: ODP global init failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odp_print_system_info(); > + if (odp_init_local(ODP_THREAD_CONTROL)) { > + LOG_ERR("Error: ODP local init failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odph_ring_tailq_init(); > + _ring_tailq_init(); > > - rarg.thrdarg.numthrds = odp_cpu_count(); > + num_workers = odp_cpumask_default_worker(&cpu_mask, > MAX_WORKERS); > + rarg.thrdarg.numthrds = rarg.thrdarg.numthrds; > > -#ifdef RING_TEST_BASIC > rarg.thrdarg.testcase = ODP_RING_TEST_BASIC; > -#else > + printf("starting stess test type : %d..\n", > rarg.stress_type); > + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > + test_ring, (void *)&rarg, > + ODP_THREAD_WORKER); > + odph_linux_pthread_join(thread_tbl, num_workers); > + > rarg.thrdarg.testcase = ODP_RING_TEST_STRESS; > rarg.stress_type = one_enq_one_deq; > -/* rarg.stress_type = multi_enq_multi_deq;*/ > - char ring_name[ODPH_RING_NAMESIZE]; > > printf("starting stess test type : %d..\n", > rarg.stress_type); > - /* create a ring */ > snprintf(ring_name, sizeof(ring_name), > "test_ring_stress"); > - > - r_stress = odph_ring_create(ring_name, RING_SIZE, > - 0 /* not used, alignement > - taken care inside func : todo > */); > + r_stress = _ring_create(ring_name, RING_SIZE, > + 0/* not used, alignement > + taken care inside func : > todo */); > if (r_stress == NULL) { > LOG_ERR("ring create failed\n"); > goto fail; > } > /* lookup ring from its name */ > - if (odph_ring_lookup(ring_name) != r_stress) { > + if (_ring_lookup(ring_name) != r_stress) { > LOG_ERR("ring lookup failed\n"); > goto fail; > } > -#endif > - odp_test_thread_create(test_ring, (pthrd_arg *)&rarg); > > -#ifndef RING_TEST_BASIC > + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > + test_ring, (void *)&rarg, > + ODP_THREAD_WORKER); > + odph_linux_pthread_join(thread_tbl, num_workers); > + > fail: > -#endif > + if (odp_term_local()) { > + LOG_ERR("Error: ODP local term failed.\n"); > + exit(EXIT_FAILURE); > + } > > - odp_test_thread_exit(&rarg.thrdarg); > + if (odp_term_global()) { > + LOG_ERR("Error: ODP global term failed.\n"); > + exit(EXIT_FAILURE); > + } > > return 0; > } > - > diff --git a/test/Makefile.am b/test/Makefile.am > index 2ba8008..4a75364 100644 > --- a/test/Makefile.am > +++ b/test/Makefile.am > @@ -1,4 +1,4 @@ > -SUBDIRS = api_test performance miscellaneous > +SUBDIRS = performance miscellaneous > > if cunit_support > SUBDIRS += validation > diff --git a/test/api_test/.gitignore b/test/api_test/.gitignore > deleted file mode 100644 > index 950f443..0000000 > --- a/test/api_test/.gitignore > +++ /dev/null > @@ -1,2 +0,0 @@ > -odp_ring > -odp_shm > diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am > deleted file mode 100644 > index fcdba48..0000000 > --- a/test/api_test/Makefile.am > +++ /dev/null > @@ -1,13 +0,0 @@ > -include $(top_srcdir)/test/Makefile.inc > - > -bin_PROGRAMS = odp_ring$(EXEEXT) > - > -odp_ring_CFLAGS = $(AM_CFLAGS) > - > -odp_ring_LDFLAGS = $(AM_LDFLAGS) -static > - > -noinst_HEADERS = \ > - $(top_srcdir)/test/api_test/odp_common.h \ > - $(top_srcdir)/test/test_debug.h > - > -dist_odp_ring_SOURCES = odp_ring_test.c odp_common.c > diff --git a/test/api_test/odp_common.c > b/test/api_test/odp_common.c > deleted file mode 100644 > index cebaa12..0000000 > --- a/test/api_test/odp_common.c > +++ /dev/null > @@ -1,91 +0,0 @@ > -/* Copyright (c) 2013, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -/** > - * @file > - * > - * ODP test application common > - */ > - > -#include <string.h> > -#include <odp.h> > -#include <odp/helper/linux.h> > -#include <odp_common.h> > -#include <test_debug.h> > - > -#define MAX_WORKERS 32 /**< Max worker threads */ > - > -/* Globals */ > -static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; /**< > worker threads table*/ > -static int num_workers; /**< number of workers */ > - > -/** > - * Print system information > - */ > -void odp_print_system_info(void) > -{ > - odp_cpumask_t cpumask; > - char str[ODP_CPUMASK_STR_SIZE]; > - > - memset(str, 1, sizeof(str)); > - > - odp_cpumask_zero(&cpumask); > - > - odp_cpumask_from_str(&cpumask, "0x1"); > - (void)odp_cpumask_to_str(&cpumask, str, sizeof(str)); > - > - printf("\n"); > - printf("ODP system info\n"); > - printf("---------------\n"); > - printf("ODP API version: %s\n", odp_version_api_str()); > - printf("CPU model: %s\n", odp_sys_cpu_model_str()); > - printf("CPU freq (hz): %"PRIu64"\n", odp_sys_cpu_hz()); > - printf("Cache line size: %i\n", > odp_sys_cache_line_size()); > - printf("CPU count: %i\n", odp_cpu_count()); > - printf("CPU mask: %s\n", str); > - > - printf("\n"); > -} > - > -/** test init globals and call odp_init_global() */ > -int odp_test_global_init(void) > -{ > - memset(thread_tbl, 0, sizeof(thread_tbl)); > - > - if (odp_init_global(NULL, NULL)) { > - LOG_ERR("ODP global init failed.\n"); > - return -1; > - } > - > - num_workers = odp_cpu_count(); > - /* force to max CPU count */ > - if (num_workers > MAX_WORKERS) > - num_workers = MAX_WORKERS; > - > - return 0; > -} > - > -/** create test thread */ > -int odp_test_thread_create(void *func_ptr(void *), pthrd_arg > *arg) > -{ > - odp_cpumask_t cpumask; > - > - /* Create and init additional threads */ > - odp_cpumask_default_worker(&cpumask, arg->numthrds); > - odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr, > - (void *)arg, ODP_THREAD_WORKER); > - > - return 0; > -} > - > -/** exit from test thread */ > -int odp_test_thread_exit(pthrd_arg *arg) > -{ > - /* Wait for other threads to exit */ > - odph_linux_pthread_join(thread_tbl, arg->numthrds); > - > - return 0; > -} > diff --git a/test/api_test/odp_common.h > b/test/api_test/odp_common.h > deleted file mode 100644 > index f321b6b..0000000 > --- a/test/api_test/odp_common.h > +++ /dev/null > @@ -1,42 +0,0 @@ > -/* Copyright (c) 2013, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -/** > - * @file > - * > - * ODP test application common headers > - */ > - > -#ifndef ODP_COMMON_H > -#define ODP_COMMON_H > - > -#define MAX_WORKERS 32 /**< Maximum number of work threads */ > - > -/** types of tests */ > -typedef enum { > - ODP_ATOMIC_TEST = 0, > - ODP_SHM_TEST, > - ODP_RING_TEST_BASIC, > - ODP_RING_TEST_STRESS, > - ODP_TIMER_PING_TEST, > - ODP_MAX_TEST > -} odp_test_case_e; > - > -/** > - * Thread argument > - */ > -typedef struct { > - int testcase; /**< specifies which set of API's to > exercise */ > - int numthrds; /**< no of pthreads to create */ > -} pthrd_arg; > - > -extern void odp_print_system_info(void); > -extern int odp_test_global_init(void); > -/** create thread fro start_routine function */ > -extern int odp_test_thread_create(void *(*start_routine) > (void *), pthrd_arg *); > -extern int odp_test_thread_exit(pthrd_arg *); > - > -#endif /* ODP_COMMON_H */ > -- > 1.9.1 > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org> > https://lists.linaro.org/mailman/listinfo/lng-odp > > > > > -- > Mike Holmes > Technical Manager - Linaro Networking Group > Linaro.org <http://www.linaro.org/>***│ *Open source software for > ARM SoCs > > > > > -- > Mike Holmes > Technical Manager - Linaro Networking Group > Linaro.org <http://www.linaro.org/>***│ *Open source software for ARM SoCs >
diff --git a/configure.ac b/configure.ac index e45d90a..28b9ec9 100644 --- a/configure.ac +++ b/configure.ac @@ -345,7 +345,6 @@ AC_CONFIG_FILES([Makefile pkgconfig/libodphelper.pc scripts/Makefile test/Makefile - test/api_test/Makefile test/performance/Makefile test/validation/Makefile test/validation/buffer/Makefile diff --git a/helper/Makefile.am b/helper/Makefile.am index 1906ae2..6828092 100644 --- a/helper/Makefile.am +++ b/helper/Makefile.am @@ -8,7 +8,6 @@ AM_CFLAGS += -I$(top_srcdir)/include helperincludedir = $(includedir)/odp/helper/ helperinclude_HEADERS = \ - $(srcdir)/include/odp/helper/ring.h \ $(srcdir)/include/odp/helper/linux.h \ $(srcdir)/include/odp/helper/chksum.h\ $(srcdir)/include/odp/helper/eth.h\ @@ -29,7 +28,6 @@ noinst_HEADERS = \ __LIB__libodphelper_la_SOURCES = \ linux.c \ - ring.c \ hashtable.c \ lineartable.c diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am index 1c6a802..cf3b7aa 100644 --- a/helper/test/Makefile.am +++ b/helper/test/Makefile.am @@ -1,6 +1,7 @@ include $(top_srcdir)/test/Makefile.inc AM_CFLAGS += -I$(srcdir)/common +AM_CFLAGS += -I$(top_srcdir)/test/validation/common AM_LDFLAGS += -static TESTS_ENVIRONMENT += TEST_DIR=${builddir} @@ -28,5 +29,5 @@ dist_thread_SOURCES = thread.c thread_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp.la dist_process_SOURCES = process.c process_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp.la -odph_pause_SOURCES = pause.c -dist_odp_table_SOURCES = table.c +dist_pause_SOURCES = pause.c +dist_table_SOURCES = table.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 4639ebc..8160649 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -90,6 +90,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_queue.h \ + ${srcdir}/include/odp_packet_io_ring_internal.h \ ${srcdir}/include/odp_packet_netmap.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ @@ -122,6 +123,7 @@ __LIB__libodp_la_SOURCES = \ pktio/socket.c \ pktio/socket_mmap.c \ pktio/tap.c \ + pktio/ring.c \ odp_pool.c \ odp_queue.c \ odp_rwlock.c \ diff --git a/helper/include/odp/helper/ring.h b/platform/linux-generic/include/odp_packet_io_ring_internal.h similarity index 87% rename from helper/include/odp/helper/ring.h rename to platform/linux-generic/include/odp_packet_io_ring_internal.h index 541a466..f97c026 100644 --- a/helper/include/odp/helper/ring.h +++ b/platform/linux-generic/include/odp_packet_io_ring_internal.h @@ -89,29 +89,28 @@ * */ -#ifndef ODPH_RING_H_ -#define ODPH_RING_H_ +#ifndef _RING_H_ +#define _RING_H_ #ifdef __cplusplus extern "C" { #endif - #include <odp/std_types.h> #include <odp/hints.h> #include <odp/atomic.h> #include <errno.h> #include <sys/queue.h> +#include <odp_debug_internal.h> -enum odph_ring_queue_behavior { - ODPH_RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number +enum _ring_queue_behavior { + _RING_QUEUE_FIXED = 0, /**< Enq/Deq a fixed number of items from a ring */ - ODPH_RING_QUEUE_VARIABLE /**< Enq/Deq as many items + _RING_QUEUE_VARIABLE /**< Enq/Deq as many items a possible from ring */ }; - -#define ODPH_RING_NAMESIZE 32 /**< The maximum length of a ring name. */ +#define _RING_NAMESIZE 32 /**< The maximum length of a ring name. */ /** * An ODP ring structure. @@ -123,12 +122,12 @@ enum odph_ring_queue_behavior { * values in a modulo-32bit base: that's why the overflow of the indexes is not * a problem. */ -typedef struct odph_ring { +typedef struct _ring { /** @private Next in list. */ - TAILQ_ENTRY(odph_ring) next; + TAILQ_ENTRY(_ring) next; /** @private Name of the ring. */ - char name[ODPH_RING_NAMESIZE]; + char name[_RING_NAMESIZE]; /** @private Flags supplied at creation. */ int flags; @@ -153,21 +152,21 @@ typedef struct odph_ring { /** @private Memory space of ring starts here. */ void *ring[0] ODP_ALIGNED_CACHE; -} odph_ring_t; +} _ring_t; /* The default enqueue is "single-producer".*/ -#define ODPH_RING_F_SP_ENQ (1 << 0) +#define _RING_F_SP_ENQ (1 << 0) /* The default dequeue is "single-consumer".*/ -#define ODPH_RING_F_SC_DEQ (1 << 1) +#define _RING_F_SC_DEQ (1 << 1) /* If set - ring is visible from different processes. * Default is thread visible.*/ -#define ODPH_RING_SHM_PROC (1 << 2) +#define _RING_SHM_PROC (1 << 2) /* Do not link ring to linked list. */ -#define ODPH_RING_NO_LIST (1 << 3) +#define _RING_NO_LIST (1 << 3) /* Quota exceed for burst ops */ -#define ODPH_RING_QUOT_EXCEED (1 << 31) +#define _RING_QUOT_EXCEED (1 << 31) /* Ring size mask */ -#define ODPH_RING_SZ_MASK (unsigned)(0x0fffffff) +#define _RING_SZ_MASK (unsigned)(0x0fffffff) /** * Create a new ring named *name* in memory. @@ -198,9 +197,8 @@ typedef struct odph_ring { * - EEXIST - a memzone with the same name already exists * - ENOMEM - no appropriate memory area found in which to create memzone */ -odph_ring_t *odph_ring_create(const char *name, unsigned count, - unsigned flags); - +_ring_t *_ring_create(const char *name, unsigned count, + unsigned flags); /** * Change the high water mark. @@ -217,14 +215,14 @@ odph_ring_t *odph_ring_create(const char *name, unsigned count, * @return 0: Success; water mark changed. * -EINVAL: Invalid water mark value. */ -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count); +int _ring_set_water_mark(_ring_t *r, unsigned count); /** * Dump the status of the ring to the console. * * @param r A pointer to the ring structure. */ -void odph_ring_dump(const odph_ring_t *r); +void _ring_dump(const _ring_t *r); /** * Enqueue several objects on the ring (multi-producers safe). @@ -251,9 +249,9 @@ void odph_ring_dump(const odph_ring_t *r); * if behavior = ODP_RING_QUEUE_VARIABLE * - n: Actual number of objects enqueued. */ -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, - unsigned n, - enum odph_ring_queue_behavior behavior); +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, + unsigned n, + enum _ring_queue_behavior behavior); /** * Enqueue several objects on a ring (NOT multi-producers safe). @@ -277,9 +275,9 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, * if behavior = ODP_RING_QUEUE_VARIABLE * - n: Actual number of objects enqueued. */ -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, - unsigned n, - enum odph_ring_queue_behavior behavior); +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, + unsigned n, + enum _ring_queue_behavior behavior); /** * Dequeue several objects from a ring (multi-consumers safe). When @@ -308,9 +306,9 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, * - n: Actual number of objects dequeued. */ -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, - unsigned n, - enum odph_ring_queue_behavior behavior); +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, + unsigned n, + enum _ring_queue_behavior behavior); /** * Dequeue several objects from a ring (NOT multi-consumers safe). @@ -335,9 +333,9 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, * if behavior = ODP_RING_QUEUE_VARIABLE * - n: Actual number of objects dequeued. */ -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, - unsigned n, - enum odph_ring_queue_behavior behavior); +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, + unsigned n, + enum _ring_queue_behavior behavior); /** * Enqueue several objects on the ring (multi-producers safe). @@ -357,8 +355,8 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, * high water mark is exceeded. * - -ENOBUFS: Not enough room in the ring to enqueue, no object is enqueued. */ -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, - unsigned n); +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, + unsigned n); /** * Enqueue several objects on a ring (NOT multi-producers safe). @@ -375,8 +373,8 @@ int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, * high water mark is exceeded. * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued. */ -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, - unsigned n); +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, + unsigned n); /** * Dequeue several objects from a ring (multi-consumers safe). @@ -395,7 +393,7 @@ int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, * - -ENOENT: Not enough entries in the ring to dequeue; no object is * dequeued. */ -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned n); +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); /** * Dequeue several objects from a ring (NOT multi-consumers safe). @@ -412,7 +410,7 @@ int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned n); * - -ENOENT: Not enough entries in the ring to dequeue; no object is * dequeued. */ -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned n); +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n); /** * Test if a ring is full. @@ -423,7 +421,7 @@ int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned n); * - 1: The ring is full. * - 0: The ring is not full. */ -int odph_ring_full(const odph_ring_t *r); +int _ring_full(const _ring_t *r); /** * Test if a ring is empty. @@ -434,7 +432,7 @@ int odph_ring_full(const odph_ring_t *r); * - 1: The ring is empty. * - 0: The ring is not empty. */ -int odph_ring_empty(const odph_ring_t *r); +int _ring_empty(const _ring_t *r); /** * Return the number of entries in a ring. @@ -444,7 +442,7 @@ int odph_ring_empty(const odph_ring_t *r); * @return * The number of entries in the ring. */ -unsigned odph_ring_count(const odph_ring_t *r); +unsigned _ring_count(const _ring_t *r); /** * Return the number of free entries in a ring. @@ -454,14 +452,14 @@ unsigned odph_ring_count(const odph_ring_t *r); * @return * The number of free entries in the ring. */ -unsigned odph_ring_free_count(const odph_ring_t *r); +unsigned _ring_free_count(const _ring_t *r); /** * search ring by name * @param name ring name to search * @return pointer to ring otherwise NULL */ -odph_ring_t *odph_ring_lookup(const char *name); +_ring_t *_ring_lookup(const char *name); /** * Enqueue several objects on the ring (multi-producers safe). @@ -478,8 +476,8 @@ odph_ring_t *odph_ring_lookup(const char *name); * @return * - n: Actual number of objects enqueued. */ -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const *obj_table, - unsigned n); +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, + unsigned n); /** * Enqueue several objects on a ring (NOT multi-producers safe). @@ -493,8 +491,8 @@ int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const *obj_table, * @return * - n: Actual number of objects enqueued. */ -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const *obj_table, - unsigned n); +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, + unsigned n); /** * Enqueue several objects on a ring. * @@ -511,8 +509,8 @@ int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const *obj_table, * @return * - n: Actual number of objects enqueued. */ -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, - unsigned n); +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, + unsigned n); /** * Dequeue several objects from a ring (multi-consumers safe). When the request @@ -531,7 +529,7 @@ int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, * @return * - n: Actual number of objects dequeued, 0 if ring is empty */ -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n); +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); /** * Dequeue several objects from a ring (NOT multi-consumers safe).When the @@ -547,7 +545,7 @@ int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n); * @return * - n: Actual number of objects dequeued, 0 if ring is empty */ -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n); +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); /** * Dequeue multiple objects from a ring up to a maximum number. @@ -565,17 +563,17 @@ int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n); * @return * - Number of objects dequeued, or a negative error code on error */ -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n); +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n); /** * dump the status of all rings on the console */ -void odph_ring_list_dump(void); +void _ring_list_dump(void); /** * initialise ring tailq */ -void odph_ring_tailq_init(void); +void _ring_tailq_init(void); #ifdef __cplusplus } diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4 index df6dc64..6bb159f 100644 --- a/platform/linux-generic/m4/configure.m4 +++ b/platform/linux-generic/m4/configure.m4 @@ -23,4 +23,5 @@ m4_include([platform/linux-generic/m4/odp_pcap.m4]) AC_CONFIG_FILES([platform/linux-generic/Makefile platform/linux-generic/test/Makefile - platform/linux-generic/test/pktio/Makefile]) + platform/linux-generic/test/pktio/Makefile + platform/linux-generic/test/ring/Makefile]) diff --git a/helper/ring.c b/platform/linux-generic/pktio/ring.c similarity index 71% rename from helper/ring.c rename to platform/linux-generic/pktio/ring.c index e113606..e978420 100644 --- a/helper/ring.c +++ b/platform/linux-generic/pktio/ring.c @@ -78,9 +78,9 @@ #include <string.h> #include "odph_debug.h" #include <odp/rwlock.h> -#include <odp/helper/ring.h> +#include <odp_packet_io_ring_internal.h> -static TAILQ_HEAD(, odph_ring) odp_ring_list; +static TAILQ_HEAD(, _ring) odp_ring_list; #define RING_VAL_IS_POWER_2(x) ((((x) - 1) & (x)) == 0) @@ -93,9 +93,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; if (odp_likely(idx + n < size)) { \ for (i = 0; i < (n & ((~(unsigned)0x3))); i += 4, idx += 4) { \ r->ring[idx] = obj_table[i]; \ - r->ring[idx+1] = obj_table[i+1]; \ - r->ring[idx+2] = obj_table[i+2]; \ - r->ring[idx+3] = obj_table[i+3]; \ + r->ring[idx + 1] = obj_table[i + 1]; \ + r->ring[idx + 2] = obj_table[i + 2]; \ + r->ring[idx + 3] = obj_table[i + 3]; \ } \ switch (n & 0x3) { \ case 3: \ @@ -122,9 +122,9 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; if (odp_likely(idx + n < size)) { \ for (i = 0; i < (n & (~(unsigned)0x3)); i += 4, idx += 4) {\ obj_table[i] = r->ring[idx]; \ - obj_table[i+1] = r->ring[idx+1]; \ - obj_table[i+2] = r->ring[idx+2]; \ - obj_table[i+3] = r->ring[idx+3]; \ + obj_table[i + 1] = r->ring[idx + 1]; \ + obj_table[i + 2] = r->ring[idx + 2]; \ + obj_table[i + 3] = r->ring[idx + 3]; \ } \ switch (n & 0x3) { \ case 3: \ @@ -145,36 +145,37 @@ static TAILQ_HEAD(, odph_ring) odp_ring_list; static odp_rwlock_t qlock; /* rings tailq lock */ /* init tailq_ring */ -void odph_ring_tailq_init(void) +void _ring_tailq_init(void) { TAILQ_INIT(&odp_ring_list); odp_rwlock_init(&qlock); } /* create the ring */ -odph_ring_t * -odph_ring_create(const char *name, unsigned count, unsigned flags) +_ring_t * +_ring_create(const char *name, unsigned count, unsigned flags) { - char ring_name[ODPH_RING_NAMESIZE]; - odph_ring_t *r; + char ring_name[_RING_NAMESIZE]; + _ring_t *r; size_t ring_size; uint32_t shm_flag; odp_shm_t shm; - if (flags & ODPH_RING_SHM_PROC) + if (flags & _RING_SHM_PROC) shm_flag = ODP_SHM_PROC; else shm_flag = 0; /* count must be a power of 2 */ - if (!RING_VAL_IS_POWER_2(count) || (count > ODPH_RING_SZ_MASK)) { - ODPH_ERR("Requested size is invalid, must be power of 2, and do not exceed the size limit %u\n", - ODPH_RING_SZ_MASK); + if (!RING_VAL_IS_POWER_2(count) || (count > _RING_SZ_MASK)) { + ODPH_ERR("Requested size is invalid, must be power of 2," + "and do not exceed the size limit %u\n", + _RING_SZ_MASK); return NULL; } snprintf(ring_name, sizeof(ring_name), "%s", name); - ring_size = count*sizeof(void *)+sizeof(odph_ring_t); + ring_size = count * sizeof(void *) + sizeof(_ring_t); odp_rwlock_write_lock(&qlock); /* reserve a memory zone for this ring.*/ @@ -188,18 +189,18 @@ odph_ring_create(const char *name, unsigned count, unsigned flags) snprintf(r->name, sizeof(r->name), "%s", name); r->flags = flags; r->prod.watermark = count; - r->prod.sp_enqueue = !!(flags & ODPH_RING_F_SP_ENQ); - r->cons.sc_dequeue = !!(flags & ODPH_RING_F_SC_DEQ); + r->prod.sp_enqueue = !!(flags & _RING_F_SP_ENQ); + r->cons.sc_dequeue = !!(flags & _RING_F_SC_DEQ); r->prod.size = count; r->cons.size = count; - r->prod.mask = count-1; - r->cons.mask = count-1; + r->prod.mask = count - 1; + r->cons.mask = count - 1; r->prod.head = 0; r->cons.head = 0; r->prod.tail = 0; r->cons.tail = 0; - if (!(flags & ODPH_RING_NO_LIST)) + if (!(flags & _RING_NO_LIST)) TAILQ_INSERT_TAIL(&odp_ring_list, r, next); } else { ODPH_ERR("Cannot reserve memory\n"); @@ -213,7 +214,7 @@ odph_ring_create(const char *name, unsigned count, unsigned flags) * change the high water mark. If *count* is 0, water marking is * disabled */ -int odph_ring_set_water_mark(odph_ring_t *r, unsigned count) +int _ring_set_water_mark(_ring_t *r, unsigned count) { if (count >= r->prod.size) return -EINVAL; @@ -229,8 +230,8 @@ int odph_ring_set_water_mark(odph_ring_t *r, unsigned count) /** * Enqueue several objects on the ring (multi-producers safe). */ -int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, - unsigned n, enum odph_ring_queue_behavior behavior) +int ___ring_mp_do_enqueue(_ring_t *r, void * const *obj_table, + unsigned n, enum _ring_queue_behavior behavior) { uint32_t prod_head, prod_next; uint32_t cons_tail, free_entries; @@ -255,24 +256,22 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, /* check that we have enough room in ring */ if (odp_unlikely(n > free_entries)) { - if (behavior == ODPH_RING_QUEUE_FIXED) { + if (behavior == _RING_QUEUE_FIXED) return -ENOBUFS; - } else { - /* No free entry available */ - if (odp_unlikely(free_entries == 0)) - return 0; + /* No free entry available */ + if (odp_unlikely(free_entries == 0)) + return 0; - n = free_entries; - } + n = free_entries; } prod_next = prod_head + n; success = __atomic_compare_exchange_n(&r->prod.head, - &prod_head, - prod_next, - false/*strong*/, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + &prod_head, + prod_next, + false/*strong*/, + __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } while (odp_unlikely(success == 0)); /* write entries in ring */ @@ -280,10 +279,10 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, /* if we exceed the watermark */ if (odp_unlikely(((mask + 1) - free_entries + n) > r->prod.watermark)) { - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : - (int)(n | ODPH_RING_QUOT_EXCEED); + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : + (int)(n | _RING_QUOT_EXCEED); } else { - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; } /* @@ -302,8 +301,8 @@ int __odph_ring_mp_do_enqueue(odph_ring_t *r, void * const *obj_table, /** * Enqueue several objects on a ring (NOT multi-producers safe). */ -int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, - unsigned n, enum odph_ring_queue_behavior behavior) +int ___ring_sp_do_enqueue(_ring_t *r, void * const *obj_table, + unsigned n, enum _ring_queue_behavior behavior) { uint32_t prod_head, cons_tail; uint32_t prod_next, free_entries; @@ -321,15 +320,13 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, /* check that we have enough room in ring */ if (odp_unlikely(n > free_entries)) { - if (behavior == ODPH_RING_QUEUE_FIXED) { + if (behavior == _RING_QUEUE_FIXED) return -ENOBUFS; - } else { - /* No free entry available */ - if (odp_unlikely(free_entries == 0)) - return 0; + /* No free entry available */ + if (odp_unlikely(free_entries == 0)) + return 0; - n = free_entries; - } + n = free_entries; } prod_next = prod_head + n; @@ -340,10 +337,10 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, /* if we exceed the watermark */ if (odp_unlikely(((mask + 1) - free_entries + n) > r->prod.watermark)) { - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? -EDQUOT : - (int)(n | ODPH_RING_QUOT_EXCEED); + ret = (behavior == _RING_QUEUE_FIXED) ? -EDQUOT : + (int)(n | _RING_QUOT_EXCEED); } else { - ret = (behavior == ODPH_RING_QUEUE_FIXED) ? 0 : n; + ret = (behavior == _RING_QUEUE_FIXED) ? 0 : n; } /* Release our entries and the memory they refer to */ @@ -356,8 +353,8 @@ int __odph_ring_sp_do_enqueue(odph_ring_t *r, void * const *obj_table, * Dequeue several objects from a ring (multi-consumers safe). */ -int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, - unsigned n, enum odph_ring_queue_behavior behavior) +int ___ring_mc_do_dequeue(_ring_t *r, void **obj_table, + unsigned n, enum _ring_queue_behavior behavior) { uint32_t cons_head, prod_tail; uint32_t cons_next, entries; @@ -381,23 +378,21 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, /* Set the actual entries for dequeue */ if (n > entries) { - if (behavior == ODPH_RING_QUEUE_FIXED) { + if (behavior == _RING_QUEUE_FIXED) return -ENOENT; - } else { - if (odp_unlikely(entries == 0)) - return 0; + if (odp_unlikely(entries == 0)) + return 0; - n = entries; - } + n = entries; } cons_next = cons_head + n; success = __atomic_compare_exchange_n(&r->cons.head, - &cons_head, - cons_next, - false/*strong*/, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + &cons_head, + cons_next, + false/*strong*/, + __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } while (odp_unlikely(success == 0)); /* copy in table */ @@ -414,14 +409,14 @@ int __odph_ring_mc_do_dequeue(odph_ring_t *r, void **obj_table, __atomic_thread_fence(__ATOMIC_RELEASE); r->cons.tail = cons_next; - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; + return behavior == _RING_QUEUE_FIXED ? 0 : n; } /** * Dequeue several objects from a ring (NOT multi-consumers safe). */ -int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, - unsigned n, enum odph_ring_queue_behavior behavior) +int ___ring_sc_do_dequeue(_ring_t *r, void **obj_table, + unsigned n, enum _ring_queue_behavior behavior) { uint32_t cons_head, prod_tail; uint32_t cons_next, entries; @@ -437,14 +432,12 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, entries = prod_tail - cons_head; if (n > entries) { - if (behavior == ODPH_RING_QUEUE_FIXED) { + if (behavior == _RING_QUEUE_FIXED) return -ENOENT; - } else { - if (odp_unlikely(entries == 0)) - return 0; + if (odp_unlikely(entries == 0)) + return 0; - n = entries; - } + n = entries; } cons_next = cons_head + n; @@ -456,127 +449,131 @@ int __odph_ring_sc_do_dequeue(odph_ring_t *r, void **obj_table, DEQUEUE_PTRS(); r->cons.tail = cons_next; - return behavior == ODPH_RING_QUEUE_FIXED ? 0 : n; + return behavior == _RING_QUEUE_FIXED ? 0 : n; } /** * Enqueue several objects on the ring (multi-producers safe). */ -int odph_ring_mp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, - unsigned n) +int _ring_mp_enqueue_bulk(_ring_t *r, void * const *obj_table, + unsigned n) { - return __odph_ring_mp_do_enqueue(r, obj_table, n, - ODPH_RING_QUEUE_FIXED); + return ___ring_mp_do_enqueue(r, obj_table, n, + _RING_QUEUE_FIXED); } /** * Enqueue several objects on a ring (NOT multi-producers safe). */ -int odph_ring_sp_enqueue_bulk(odph_ring_t *r, void * const *obj_table, - unsigned n) +int _ring_sp_enqueue_bulk(_ring_t *r, void * const *obj_table, + unsigned n) { - return __odph_ring_sp_do_enqueue(r, obj_table, n, - ODPH_RING_QUEUE_FIXED); + return ___ring_sp_do_enqueue(r, obj_table, n, + _RING_QUEUE_FIXED); } /** * Dequeue several objects from a ring (multi-consumers safe). */ -int odph_ring_mc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned n) +int _ring_mc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) { - return __odph_ring_mc_do_dequeue(r, obj_table, n, - ODPH_RING_QUEUE_FIXED); + return ___ring_mc_do_dequeue(r, obj_table, n, + _RING_QUEUE_FIXED); } /** * Dequeue several objects from a ring (NOT multi-consumers safe). */ -int odph_ring_sc_dequeue_bulk(odph_ring_t *r, void **obj_table, unsigned n) +int _ring_sc_dequeue_bulk(_ring_t *r, void **obj_table, unsigned n) { - return __odph_ring_sc_do_dequeue(r, obj_table, n, - ODPH_RING_QUEUE_FIXED); + return ___ring_sc_do_dequeue(r, obj_table, n, + _RING_QUEUE_FIXED); } /** * Test if a ring is full. */ -int odph_ring_full(const odph_ring_t *r) +int _ring_full(const _ring_t *r) { uint32_t prod_tail = r->prod.tail; uint32_t cons_tail = r->cons.tail; + return (((cons_tail - prod_tail - 1) & r->prod.mask) == 0); } /** * Test if a ring is empty. */ -int odph_ring_empty(const odph_ring_t *r) +int _ring_empty(const _ring_t *r) { uint32_t prod_tail = r->prod.tail; uint32_t cons_tail = r->cons.tail; + return !!(cons_tail == prod_tail); } /** * Return the number of entries in a ring. */ -unsigned odph_ring_count(const odph_ring_t *r) +unsigned _ring_count(const _ring_t *r) { uint32_t prod_tail = r->prod.tail; uint32_t cons_tail = r->cons.tail; + return (prod_tail - cons_tail) & r->prod.mask; } /** * Return the number of free entries in a ring. */ -unsigned odph_ring_free_count(const odph_ring_t *r) +unsigned _ring_free_count(const _ring_t *r) { uint32_t prod_tail = r->prod.tail; uint32_t cons_tail = r->cons.tail; + return (cons_tail - prod_tail - 1) & r->prod.mask; } /* dump the status of the ring on the console */ -void odph_ring_dump(const odph_ring_t *r) +void _ring_dump(const _ring_t *r) { - ODPH_DBG("ring <%s>@%p\n", r->name, r); - ODPH_DBG(" flags=%x\n", r->flags); - ODPH_DBG(" size=%" PRIu32 "\n", r->prod.size); - ODPH_DBG(" ct=%" PRIu32 "\n", r->cons.tail); - ODPH_DBG(" ch=%" PRIu32 "\n", r->cons.head); - ODPH_DBG(" pt=%" PRIu32 "\n", r->prod.tail); - ODPH_DBG(" ph=%" PRIu32 "\n", r->prod.head); - ODPH_DBG(" used=%u\n", odph_ring_count(r)); - ODPH_DBG(" avail=%u\n", odph_ring_free_count(r)); + ODP_DBG("ring <%s>@%p\n", r->name, r); + ODP_DBG(" flags=%x\n", r->flags); + ODP_DBG(" size=%" PRIu32 "\n", r->prod.size); + ODP_DBG(" ct=%" PRIu32 "\n", r->cons.tail); + ODP_DBG(" ch=%" PRIu32 "\n", r->cons.head); + ODP_DBG(" pt=%" PRIu32 "\n", r->prod.tail); + ODP_DBG(" ph=%" PRIu32 "\n", r->prod.head); + ODP_DBG(" used=%u\n", _ring_count(r)); + ODP_DBG(" avail=%u\n", _ring_free_count(r)); if (r->prod.watermark == r->prod.size) - ODPH_DBG(" watermark=0\n"); + ODP_DBG(" watermark=0\n"); else - ODPH_DBG(" watermark=%" PRIu32 "\n", r->prod.watermark); + ODP_DBG(" watermark=%" PRIu32 "\n", r->prod.watermark); } /* dump the status of all rings on the console */ -void odph_ring_list_dump(void) +void _ring_list_dump(void) { - const odph_ring_t *mp = NULL; + const _ring_t *mp = NULL; odp_rwlock_read_lock(&qlock); TAILQ_FOREACH(mp, &odp_ring_list, next) { - odph_ring_dump(mp); + _ring_dump(mp); } odp_rwlock_read_unlock(&qlock); } /* search a ring from its name */ -odph_ring_t *odph_ring_lookup(const char *name) +_ring_t *_ring_lookup(const char *name) { - odph_ring_t *r; + _ring_t *r; odp_rwlock_read_lock(&qlock); TAILQ_FOREACH(r, &odp_ring_list, next) { - if (strncmp(name, r->name, ODPH_RING_NAMESIZE) == 0) + if (strncmp(name, r->name, _RING_NAMESIZE) == 0) break; } odp_rwlock_read_unlock(&qlock); @@ -587,60 +584,60 @@ odph_ring_t *odph_ring_lookup(const char *name) /** * Enqueue several objects on the ring (multi-producers safe). */ -int odph_ring_mp_enqueue_burst(odph_ring_t *r, void * const *obj_table, - unsigned n) +int _ring_mp_enqueue_burst(_ring_t *r, void * const *obj_table, + unsigned n) { - return __odph_ring_mp_do_enqueue(r, obj_table, n, - ODPH_RING_QUEUE_VARIABLE); + return ___ring_mp_do_enqueue(r, obj_table, n, + _RING_QUEUE_VARIABLE); } /** * Enqueue several objects on a ring (NOT multi-producers safe). */ -int odph_ring_sp_enqueue_burst(odph_ring_t *r, void * const *obj_table, - unsigned n) +int _ring_sp_enqueue_burst(_ring_t *r, void * const *obj_table, + unsigned n) { - return __odph_ring_sp_do_enqueue(r, obj_table, n, - ODPH_RING_QUEUE_VARIABLE); + return ___ring_sp_do_enqueue(r, obj_table, n, + _RING_QUEUE_VARIABLE); } /** * Enqueue several objects on a ring. */ -int odph_ring_enqueue_burst(odph_ring_t *r, void * const *obj_table, - unsigned n) +int _ring_enqueue_burst(_ring_t *r, void * const *obj_table, + unsigned n) { if (r->prod.sp_enqueue) - return odph_ring_sp_enqueue_burst(r, obj_table, n); + return _ring_sp_enqueue_burst(r, obj_table, n); else - return odph_ring_mp_enqueue_burst(r, obj_table, n); + return _ring_mp_enqueue_burst(r, obj_table, n); } /** * Dequeue several objects from a ring (multi-consumers safe). */ -int odph_ring_mc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n) +int _ring_mc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) { - return __odph_ring_mc_do_dequeue(r, obj_table, n, - ODPH_RING_QUEUE_VARIABLE); + return ___ring_mc_do_dequeue(r, obj_table, n, + _RING_QUEUE_VARIABLE); } /** * Dequeue several objects from a ring (NOT multi-consumers safe). */ -int odph_ring_sc_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n) +int _ring_sc_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) { - return __odph_ring_sc_do_dequeue(r, obj_table, n, - ODPH_RING_QUEUE_VARIABLE); + return ___ring_sc_do_dequeue(r, obj_table, n, + _RING_QUEUE_VARIABLE); } /** * Dequeue multiple objects from a ring up to a maximum number. */ -int odph_ring_dequeue_burst(odph_ring_t *r, void **obj_table, unsigned n) +int _ring_dequeue_burst(_ring_t *r, void **obj_table, unsigned n) { if (r->cons.sc_dequeue) - return odph_ring_sc_dequeue_burst(r, obj_table, n); + return _ring_sc_dequeue_burst(r, obj_table, n); else - return odph_ring_mc_dequeue_burst(r, obj_table, n); + return _ring_mc_dequeue_burst(r, obj_table, n); } diff --git a/platform/linux-generic/test/Makefile.am b/platform/linux-generic/test/Makefile.am index 594aa11..f81eeb8 100644 --- a/platform/linux-generic/test/Makefile.am +++ b/platform/linux-generic/test/Makefile.am @@ -1,11 +1,12 @@ include $(top_srcdir)/test/Makefile.inc TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation -ODP_MODULES = pktio +ODP_MODULES = pktio ring if test_vald TESTS = pktio/pktio_run \ pktio/pktio_run_tap \ + ring/ringtest$(EXEEXT) \ ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ ${top_builddir}/test/validation/classification/classification_main$(EXEEXT) \ ${top_builddir}/test/validation/config/config_main$(EXEEXT) \ diff --git a/platform/linux-generic/test/ring/.gitignore b/platform/linux-generic/test/ring/.gitignore new file mode 100644 index 0000000..4767f5e --- /dev/null +++ b/platform/linux-generic/test/ring/.gitignore @@ -0,0 +1 @@ +ringtest diff --git a/platform/linux-generic/test/ring/Makefile.am b/platform/linux-generic/test/ring/Makefile.am new file mode 100644 index 0000000..5a949d0 --- /dev/null +++ b/platform/linux-generic/test/ring/Makefile.am @@ -0,0 +1,16 @@ +include $(top_srcdir)/test/validation/Makefile.inc + +AM_CFLAGS += -I$(srcdir)/common +AM_CFLAGS += -I$(top_srcdir)/test/validation/common +AM_LDFLAGS += -static + +COMPILE_ONLY = + +TESTSCRIPTS = + +EXECUTABLES = ringtest$(EXEEXT) + +test_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) + +ringtest_SOURCES = ringtest.c +ringtest_LDADD = $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/api_test/odp_ring_test.c b/platform/linux-generic/test/ring/ringtest.c similarity index 72% rename from test/api_test/odp_ring_test.c rename to platform/linux-generic/test/ring/ringtest.c index e8a962a..dfa220b 100644 --- a/test/api_test/odp_ring_test.c +++ b/platform/linux-generic/test/ring/ringtest.c @@ -37,7 +37,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - /** * @file * @@ -48,86 +47,96 @@ #include <stdio.h> #include <string.h> #include <odp.h> -#include <odp_common.h> -#include <odp/helper/ring.h> +#include <odp/helper/linux.h> +#include <odp_packet_io_ring_internal.h> #include <test_debug.h> +#include <odp_cunit_common.h> #define RING_SIZE 4096 #define MAX_BULK 32 -#define RING_TEST_BASIC +enum { + ODP_RING_TEST_BASIC, + ODP_RING_TEST_STRESS, +}; -static int test_ring_basic(odph_ring_t *r) +/* local struct for ring_thread argument */ +typedef struct { + pthrd_arg thrdarg; + int stress_type; +} ring_arg_t; + +static int test_ring_basic(_ring_t *r) { void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL; int ret; unsigned i, num_elems; /* alloc dummy object pointers */ - src = malloc(RING_SIZE*2*sizeof(void *)); + src = malloc(RING_SIZE * 2 * sizeof(void *)); if (src == NULL) { LOG_ERR("failed to allocate test ring src memory\n"); goto fail; } - for (i = 0; i < RING_SIZE*2; i++) + for (i = 0; i < RING_SIZE * 2; i++) src[i] = (void *)(unsigned long)i; cur_src = src; /* alloc some room for copied objects */ - dst = malloc(RING_SIZE*2*sizeof(void *)); + dst = malloc(RING_SIZE * 2 * sizeof(void *)); if (dst == NULL) { LOG_ERR("failed to allocate test ring dst memory\n"); goto fail; } - memset(dst, 0, RING_SIZE*2*sizeof(void *)); + memset(dst, 0, RING_SIZE * 2 * sizeof(void *)); cur_dst = dst; printf("Test SP & SC basic functions\n"); printf("enqueue 1 obj\n"); - ret = odph_ring_sp_enqueue_burst(r, cur_src, 1); + ret = _ring_sp_enqueue_burst(r, cur_src, 1); cur_src += 1; - if ((ret & ODPH_RING_SZ_MASK) != 1) { + if ((ret & _RING_SZ_MASK) != 1) { LOG_ERR("sp_enq for 1 obj failed\n"); goto fail; } printf("enqueue 2 objs\n"); - ret = odph_ring_sp_enqueue_burst(r, cur_src, 2); + ret = _ring_sp_enqueue_burst(r, cur_src, 2); cur_src += 2; - if ((ret & ODPH_RING_SZ_MASK) != 2) { + if ((ret & _RING_SZ_MASK) != 2) { LOG_ERR("sp_enq for 2 obj failed\n"); goto fail; } printf("enqueue MAX_BULK objs\n"); - ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK); - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { + ret = _ring_sp_enqueue_burst(r, cur_src, MAX_BULK); + if ((ret & _RING_SZ_MASK) != MAX_BULK) { LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK); goto fail; } printf("dequeue 1 obj\n"); - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1); + ret = _ring_sc_dequeue_burst(r, cur_dst, 1); cur_dst += 1; - if ((ret & ODPH_RING_SZ_MASK) != 1) { + if ((ret & _RING_SZ_MASK) != 1) { LOG_ERR("sc_deq for 1 obj failed\n"); goto fail; } printf("dequeue 2 objs\n"); - ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2); + ret = _ring_sc_dequeue_burst(r, cur_dst, 2); cur_dst += 2; - if ((ret & ODPH_RING_SZ_MASK) != 2) { + if ((ret & _RING_SZ_MASK) != 2) { LOG_ERR("sc_deq for 2 obj failed\n"); goto fail; } printf("dequeue MAX_BULK objs\n"); - ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); + ret = _ring_sc_dequeue_burst(r, cur_dst, MAX_BULK); cur_dst += MAX_BULK; - if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) { + if ((ret & _RING_SZ_MASK) != MAX_BULK) { LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK); goto fail; } @@ -144,41 +153,41 @@ static int test_ring_basic(odph_ring_t *r) printf("Test MP & MC basic functions\n"); printf("enqueue 1 obj\n"); - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1); + ret = _ring_mp_enqueue_bulk(r, cur_src, 1); cur_src += 1; if (ret != 0) { LOG_ERR("mp_enq for 1 obj failed\n"); goto fail; } printf("enqueue 2 objs\n"); - ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2); + ret = _ring_mp_enqueue_bulk(r, cur_src, 2); cur_src += 2; if (ret != 0) { LOG_ERR("mp_enq for 2 obj failed\n"); goto fail; } printf("enqueue MAX_BULK objs\n"); - ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); + ret = _ring_mp_enqueue_bulk(r, cur_src, MAX_BULK); if (ret != 0) { LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK); goto fail; } printf("dequeue 1 obj\n"); - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1); + ret = _ring_mc_dequeue_bulk(r, cur_dst, 1); cur_dst += 1; if (ret != 0) { LOG_ERR("mc_deq for 1 obj failed\n"); goto fail; } printf("dequeue 2 objs\n"); - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2); + ret = _ring_mc_dequeue_bulk(r, cur_dst, 2); cur_dst += 2; if (ret != 0) { LOG_ERR("mc_deq for 2 obj failed\n"); goto fail; } printf("dequeue MAX_BULK objs\n"); - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); + ret = _ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK); cur_dst += MAX_BULK; if (ret != 0) { LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK); @@ -191,30 +200,30 @@ static int test_ring_basic(odph_ring_t *r) } printf("test watermark and default bulk enqueue / dequeue\n"); - odph_ring_set_water_mark(r, 20); + _ring_set_water_mark(r, 20); num_elems = 16; cur_src = src; cur_dst = dst; - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); cur_src += num_elems; if (ret != 0) { LOG_ERR("Cannot enqueue\n"); goto fail; } - ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems); + ret = _ring_mp_enqueue_bulk(r, cur_src, num_elems); if (ret != -EDQUOT) { LOG_ERR("Watermark not exceeded\n"); goto fail; } - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); cur_dst += num_elems; if (ret != 0) { LOG_ERR("Cannot dequeue\n"); goto fail; } - ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems); + ret = _ring_mc_dequeue_bulk(r, cur_dst, num_elems); cur_dst += num_elems; if (ret != 0) { LOG_ERR("Cannot dequeue2\n"); @@ -241,7 +250,7 @@ fail: } /* global shared ring used for stress testing */ -static odph_ring_t *r_stress; +static _ring_t *r_stress; /* Stress func for Multi producer only */ static int producer_fn(void) @@ -251,7 +260,7 @@ static int producer_fn(void) void **src = NULL; /* alloc dummy object pointers */ - src = malloc(MAX_BULK*2*sizeof(void *)); + src = malloc(MAX_BULK * 2 * sizeof(void *)); if (src == NULL) { LOG_ERR("failed to allocate producer memory.\n"); return -1; @@ -260,7 +269,7 @@ static int producer_fn(void) src[i] = (void *)(unsigned long)i; do { - i = odph_ring_mp_enqueue_bulk(r_stress, src, MAX_BULK); + i = _ring_mp_enqueue_bulk(r_stress, src, MAX_BULK); if (i == 0) { free(src); return 0; @@ -275,14 +284,14 @@ static int consumer_fn(void) void **src = NULL; /* alloc dummy object pointers */ - src = malloc(MAX_BULK*2*sizeof(void *)); + src = malloc(MAX_BULK * 2 * sizeof(void *)); if (src == NULL) { LOG_ERR("failed to allocate consumer memory.\n"); return -1; } do { - i = odph_ring_mc_dequeue_bulk(r_stress, src, MAX_BULK); + i = _ring_mc_dequeue_bulk(r_stress, src, MAX_BULK); if (i == 0) { for (i = 0; i < MAX_BULK; i++) { if (src[i] != (void *)(unsigned long)i) { @@ -298,7 +307,6 @@ static int consumer_fn(void) } while (1); } - /* * Note : make sure that both enqueue and dequeue * operation starts at same time so to avoid data corruption @@ -319,24 +327,22 @@ typedef enum { static void test_ring_stress(stress_type_t type) { int thr; + thr = odp_thread_id(); switch (type) { case one_enq_one_deq: - if (thr == 1) producer_fn(); if (thr == 2) consumer_fn(); break; - case multi_enq_multi_deq: - if (thr%2 == 0) + if (thr % 2 == 0) producer_fn(); else consumer_fn(); break; - case one_deq_rest_enq: case one_enq_rest_deq:/*TBD*/ default: @@ -344,19 +350,12 @@ static void test_ring_stress(stress_type_t type) } } -/* local struct for ring_thread argument */ -typedef struct { - pthrd_arg thrdarg; - int stress_type; -} ring_arg_t; - - static void *test_ring(void *arg) { ring_arg_t *parg = (ring_arg_t *)arg; int thr; - char ring_name[ODPH_RING_NAMESIZE]; - odph_ring_t *r; + char ring_name[_RING_NAMESIZE]; + _ring_t *r; int result = 0; thr = odp_thread_id(); @@ -367,16 +366,16 @@ static void *test_ring(void *arg) case ODP_RING_TEST_BASIC: snprintf(ring_name, sizeof(ring_name), "test_ring_%i", thr); - r = odph_ring_create(ring_name, RING_SIZE, - 0 /* not used, alignement - taken care inside func : todo */); + r = _ring_create(ring_name, RING_SIZE, + 0 /* not used, alignement + taken care inside func : todo */); if (r == NULL) { LOG_ERR("ring create failed\n"); result = -1; break; } /* lookup ring from its name */ - if (odph_ring_lookup(ring_name) != r) { + if (_ring_lookup(ring_name) != r) { LOG_ERR("ring lookup failed\n"); result = -1; break; @@ -388,16 +387,16 @@ static void *test_ring(void *arg) result = -1; } - /* dump ring stats */ - odph_ring_list_dump(); + if (result) + _ring_list_dump(); break; case ODP_RING_TEST_STRESS: test_ring_stress(parg->stress_type); - /* dump ring stats */ - odph_ring_list_dump(); + if (result) + _ring_list_dump(); break; default: @@ -417,54 +416,69 @@ static void *test_ring(void *arg) return parg; } - -int main(int argc __attribute__((__unused__)), - char *argv[] __attribute__((__unused__))) +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) { ring_arg_t rarg; + odph_linux_pthread_t thread_tbl[MAX_WORKERS]; + odp_cpumask_t cpu_mask; + int num_workers; + char ring_name[_RING_NAMESIZE]; - if (odp_test_global_init() != 0) - return -1; + if (odp_init_global(NULL, NULL)) { + LOG_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } - odp_print_system_info(); + if (odp_init_local(ODP_THREAD_CONTROL)) { + LOG_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } - odph_ring_tailq_init(); + _ring_tailq_init(); - rarg.thrdarg.numthrds = odp_cpu_count(); + num_workers = odp_cpumask_default_worker(&cpu_mask, MAX_WORKERS); + rarg.thrdarg.numthrds = rarg.thrdarg.numthrds; -#ifdef RING_TEST_BASIC rarg.thrdarg.testcase = ODP_RING_TEST_BASIC; -#else + printf("starting stess test type : %d..\n", rarg.stress_type); + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, + test_ring, (void *)&rarg, + ODP_THREAD_WORKER); + odph_linux_pthread_join(thread_tbl, num_workers); + rarg.thrdarg.testcase = ODP_RING_TEST_STRESS; rarg.stress_type = one_enq_one_deq; -/* rarg.stress_type = multi_enq_multi_deq;*/ - char ring_name[ODPH_RING_NAMESIZE]; printf("starting stess test type : %d..\n", rarg.stress_type); - /* create a ring */ snprintf(ring_name, sizeof(ring_name), "test_ring_stress"); - - r_stress = odph_ring_create(ring_name, RING_SIZE, - 0 /* not used, alignement - taken care inside func : todo */); + r_stress = _ring_create(ring_name, RING_SIZE, + 0/* not used, alignement + taken care inside func : todo */); if (r_stress == NULL) { LOG_ERR("ring create failed\n"); goto fail; } /* lookup ring from its name */ - if (odph_ring_lookup(ring_name) != r_stress) { + if (_ring_lookup(ring_name) != r_stress) { LOG_ERR("ring lookup failed\n"); goto fail; } -#endif - odp_test_thread_create(test_ring, (pthrd_arg *)&rarg); -#ifndef RING_TEST_BASIC + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, + test_ring, (void *)&rarg, + ODP_THREAD_WORKER); + odph_linux_pthread_join(thread_tbl, num_workers); + fail: -#endif + if (odp_term_local()) { + LOG_ERR("Error: ODP local term failed.\n"); + exit(EXIT_FAILURE); + } - odp_test_thread_exit(&rarg.thrdarg); + if (odp_term_global()) { + LOG_ERR("Error: ODP global term failed.\n"); + exit(EXIT_FAILURE); + } return 0; } - diff --git a/test/Makefile.am b/test/Makefile.am index 2ba8008..4a75364 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = api_test performance miscellaneous +SUBDIRS = performance miscellaneous if cunit_support SUBDIRS += validation diff --git a/test/api_test/.gitignore b/test/api_test/.gitignore deleted file mode 100644 index 950f443..0000000 --- a/test/api_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -odp_ring -odp_shm diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am deleted file mode 100644 index fcdba48..0000000 --- a/test/api_test/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -include $(top_srcdir)/test/Makefile.inc - -bin_PROGRAMS = odp_ring$(EXEEXT) - -odp_ring_CFLAGS = $(AM_CFLAGS) - -odp_ring_LDFLAGS = $(AM_LDFLAGS) -static - -noinst_HEADERS = \ - $(top_srcdir)/test/api_test/odp_common.h \ - $(top_srcdir)/test/test_debug.h - -dist_odp_ring_SOURCES = odp_ring_test.c odp_common.c diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c deleted file mode 100644 index cebaa12..0000000 --- a/test/api_test/odp_common.c +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/** - * @file - * - * ODP test application common - */ - -#include <string.h> -#include <odp.h> -#include <odp/helper/linux.h> -#include <odp_common.h> -#include <test_debug.h> - -#define MAX_WORKERS 32 /**< Max worker threads */ - -/* Globals */ -static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; /**< worker threads table*/ -static int num_workers; /**< number of workers */ - -/** - * Print system information - */ -void odp_print_system_info(void) -{ - odp_cpumask_t cpumask; - char str[ODP_CPUMASK_STR_SIZE]; - - memset(str, 1, sizeof(str)); - - odp_cpumask_zero(&cpumask); - - odp_cpumask_from_str(&cpumask, "0x1"); - (void)odp_cpumask_to_str(&cpumask, str, sizeof(str)); - - printf("\n"); - printf("ODP system info\n"); - printf("---------------\n"); - printf("ODP API version: %s\n", odp_version_api_str()); - printf("CPU model: %s\n", odp_sys_cpu_model_str()); - printf("CPU freq (hz): %"PRIu64"\n", odp_sys_cpu_hz()); - printf("Cache line size: %i\n", odp_sys_cache_line_size()); - printf("CPU count: %i\n", odp_cpu_count()); - printf("CPU mask: %s\n", str); - - printf("\n"); -} - -/** test init globals and call odp_init_global() */ -int odp_test_global_init(void) -{ - memset(thread_tbl, 0, sizeof(thread_tbl)); - - if (odp_init_global(NULL, NULL)) { - LOG_ERR("ODP global init failed.\n"); - return -1; - } - - num_workers = odp_cpu_count(); - /* force to max CPU count */ - if (num_workers > MAX_WORKERS) - num_workers = MAX_WORKERS; - - return 0; -} - -/** create test thread */ -int odp_test_thread_create(void *func_ptr(void *), pthrd_arg *arg) -{ - odp_cpumask_t cpumask; - - /* Create and init additional threads */ - odp_cpumask_default_worker(&cpumask, arg->numthrds); - odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr, - (void *)arg, ODP_THREAD_WORKER); - - return 0; -} - -/** exit from test thread */ -int odp_test_thread_exit(pthrd_arg *arg) -{ - /* Wait for other threads to exit */ - odph_linux_pthread_join(thread_tbl, arg->numthrds); - - return 0; -} diff --git a/test/api_test/odp_common.h b/test/api_test/odp_common.h deleted file mode 100644 index f321b6b..0000000 --- a/test/api_test/odp_common.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/** - * @file - * - * ODP test application common headers - */ - -#ifndef ODP_COMMON_H -#define ODP_COMMON_H - -#define MAX_WORKERS 32 /**< Maximum number of work threads */ - -/** types of tests */ -typedef enum { - ODP_ATOMIC_TEST = 0, - ODP_SHM_TEST, - ODP_RING_TEST_BASIC, - ODP_RING_TEST_STRESS, - ODP_TIMER_PING_TEST, - ODP_MAX_TEST -} odp_test_case_e; - -/** - * Thread argument - */ -typedef struct { - int testcase; /**< specifies which set of API's to exercise */ - int numthrds; /**< no of pthreads to create */ -} pthrd_arg; - -extern void odp_print_system_info(void); -extern int odp_test_global_init(void); -/** create thread fro start_routine function */ -extern int odp_test_thread_create(void *(*start_routine) (void *), pthrd_arg *); -extern int odp_test_thread_exit(pthrd_arg *); - -#endif /* ODP_COMMON_H */
Move ring and it's test from helper to linux-generic/pktio and kill not needed api_test directory. Unfortunately odp_ring_test.c had some old dirty code so I had to clean up it to to use cunit and latest helper apis. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- configure.ac | 1 - helper/Makefile.am | 2 - helper/test/Makefile.am | 5 +- platform/linux-generic/Makefile.am | 2 + .../include/odp_packet_io_ring_internal.h | 112 +++++---- platform/linux-generic/m4/configure.m4 | 3 +- {helper => platform/linux-generic/pktio}/ring.c | 263 ++++++++++----------- platform/linux-generic/test/Makefile.am | 3 +- platform/linux-generic/test/ring/.gitignore | 1 + platform/linux-generic/test/ring/Makefile.am | 16 ++ .../linux-generic/test/ring/ringtest.c | 180 +++++++------- test/Makefile.am | 2 +- test/api_test/.gitignore | 2 - test/api_test/Makefile.am | 13 - test/api_test/odp_common.c | 91 ------- test/api_test/odp_common.h | 42 ---- 16 files changed, 309 insertions(+), 429 deletions(-) rename helper/include/odp/helper/ring.h => platform/linux-generic/include/odp_packet_io_ring_internal.h (87%) rename {helper => platform/linux-generic/pktio}/ring.c (71%) create mode 100644 platform/linux-generic/test/ring/.gitignore create mode 100644 platform/linux-generic/test/ring/Makefile.am rename test/api_test/odp_ring_test.c => platform/linux-generic/test/ring/ringtest.c (72%) delete mode 100644 test/api_test/.gitignore delete mode 100644 test/api_test/Makefile.am delete mode 100644 test/api_test/odp_common.c delete mode 100644 test/api_test/odp_common.h