#include <rte_errno.h>
#include <rte_ring.h>
#include <rte_mempool.h>
+#include <rte_malloc.h>
#include <rte_common.h>
#include <rte_ivshmem.h>
#include <rte_tailq_elem.h>
static int pagesz;
/* Tailq heads to add rings to */
-TAILQ_HEAD(rte_ring_list, rte_ring);
+TAILQ_HEAD(rte_ring_list, rte_tailq_entry);
/*
* Utility functions
struct ivshmem_segment * seg;
struct rte_memzone * mz;
struct rte_ring * r;
+ struct rte_tailq_entry *te;
unsigned i, ms, idx;
uint64_t offset;
mcfg->memzone_idx++;
}
+ rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
+
/* find rings */
for (i = 0; i < mcfg->memzone_idx; i++) {
mz = &mcfg->memzone[i];
r = (struct rte_ring*) (mz->addr_64);
- TAILQ_INSERT_TAIL(ring_list, r, next);
+ te = rte_zmalloc("RING_TAILQ_ENTRY", sizeof(*te), 0);
+ if (te == NULL) {
+ RTE_LOG(ERR, EAL, "Cannot allocate ring tailq entry!\n");
+ return -1;
+ }
+
+ te->data = (void *) r;
+
+ TAILQ_INSERT_TAIL(ring_list, te, next);
RTE_LOG(DEBUG, EAL, "Found ring: '%s' at %p\n", r->name, mz->addr);
}
+ rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
#ifdef RTE_LIBRTE_IVSHMEM_DEBUG
rte_memzone_dump(stdout);
#include <rte_log.h>
#include <rte_memory.h>
#include <rte_memzone.h>
+#include <rte_malloc.h>
#include <rte_launch.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include "rte_ring.h"
-TAILQ_HEAD(rte_ring_list, rte_ring);
+TAILQ_HEAD(rte_ring_list, rte_tailq_entry);
/* true if x is a power of 2 */
#define POWEROF2(x) ((((x)-1) & (x)) == 0)
{
char mz_name[RTE_MEMZONE_NAMESIZE];
struct rte_ring *r;
+ struct rte_tailq_entry *te;
const struct rte_memzone *mz;
ssize_t ring_size;
int mz_flags = 0;
return NULL;
}
+ te = rte_zmalloc("RING_TAILQ_ENTRY", sizeof(*te), 0);
+ if (te == NULL) {
+ RTE_LOG(ERR, RING, "Cannot reserve memory for tailq\n");
+ rte_errno = ENOMEM;
+ return NULL;
+ }
+
snprintf(mz_name, sizeof(mz_name), "%s%s", RTE_RING_MZ_PREFIX, name);
rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
/* no need to check return value here, we already checked the
* arguments above */
rte_ring_init(r, name, count, flags);
- TAILQ_INSERT_TAIL(ring_list, r, next);
+
+ te->data = (void *) r;
+
+ TAILQ_INSERT_TAIL(ring_list, te, next);
} else {
r = NULL;
RTE_LOG(ERR, RING, "Cannot reserve memory\n");
+ rte_free(te);
}
rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
void
rte_ring_list_dump(FILE *f)
{
- const struct rte_ring *mp;
+ const struct rte_tailq_entry *te;
struct rte_ring_list *ring_list;
/* check that we have an initialised tail queue */
rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
- TAILQ_FOREACH(mp, ring_list, next) {
- rte_ring_dump(f, mp);
+ TAILQ_FOREACH(te, ring_list, next) {
+ rte_ring_dump(f, (struct rte_ring *) te->data);
}
rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK);
struct rte_ring *
rte_ring_lookup(const char *name)
{
- struct rte_ring *r;
+ struct rte_tailq_entry *te;
+ struct rte_ring *r = NULL;
struct rte_ring_list *ring_list;
/* check that we have an initialized tail queue */
rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
- TAILQ_FOREACH(r, ring_list, next) {
+ TAILQ_FOREACH(te, ring_list, next) {
+ r = (struct rte_ring *) te->data;
if (strncmp(name, r->name, RTE_RING_NAMESIZE) == 0)
break;
}
rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK);
- if (r == NULL)
+ if (te == NULL) {
rte_errno = ENOENT;
+ return NULL;
+ }
return r;
}