From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 9BFC5B12F for ; Fri, 13 Jun 2014 17:29:21 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 13 Jun 2014 08:29:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,471,1400050800"; d="scan'208";a="547608829" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 13 Jun 2014 08:29:35 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s5DFTYQ1006726; Fri, 13 Jun 2014 16:29:34 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id s5DFTYtY020660; Fri, 13 Jun 2014 16:29:34 +0100 Received: (from aburakov@localhost) by sivswdev02.ir.intel.com with id s5DFTYa2020656; Fri, 13 Jun 2014 16:29:34 +0100 From: Anatoly Burakov To: dev@dpdk.org Date: Fri, 13 Jun 2014 16:29:28 +0100 Message-Id: <716edfa0364ee9cea1317b6256905a941cd08913.1402672392.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/7] rte_ring: make ring tailq completely local X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jun 2014 15:29:22 -0000 --- lib/librte_eal/linuxapp/eal/eal_ivshmem.c | 14 +++++++++++-- lib/librte_ring/Makefile | 4 ++-- lib/librte_ring/rte_ring.c | 33 +++++++++++++++++++++++-------- lib/librte_ring/rte_ring.h | 2 -- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c index 4ad76a7..69e5ea6 100644 --- a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c +++ b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -101,7 +102,7 @@ static int memseg_idx; 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 @@ -754,6 +755,7 @@ rte_eal_ivshmem_obj_init(void) struct ivshmem_segment * seg; struct rte_memzone * mz; struct rte_ring * r; + struct rte_tailq_entry *te; unsigned i, ms, idx; uint64_t offset; @@ -819,7 +821,15 @@ rte_eal_ivshmem_obj_init(void) 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); } diff --git a/lib/librte_ring/Makefile b/lib/librte_ring/Makefile index 550507d..2380a43 100644 --- a/lib/librte_ring/Makefile +++ b/lib/librte_ring/Makefile @@ -42,7 +42,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h -# this lib needs eal -DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal +# this lib needs eal and rte_malloc +DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc include $(RTE_SDK)/mk/rte.lib.mk diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c index 2fe4024..d2ff3fe 100644 --- a/lib/librte_ring/rte_ring.c +++ b/lib/librte_ring/rte_ring.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,7 @@ #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) @@ -155,6 +156,7 @@ rte_ring_create(const char *name, unsigned count, int socket_id, { 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; @@ -173,6 +175,13 @@ rte_ring_create(const char *name, unsigned count, int socket_id, 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; + } + rte_snprintf(mz_name, sizeof(mz_name), "%s%s", RTE_RING_MZ_PREFIX, name); rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); @@ -186,10 +195,14 @@ rte_ring_create(const char *name, unsigned count, int socket_id, /* 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); @@ -272,7 +285,7 @@ rte_ring_dump(FILE *f, const struct rte_ring *r) 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 */ @@ -284,8 +297,8 @@ rte_ring_list_dump(FILE *f) 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); @@ -295,7 +308,8 @@ rte_ring_list_dump(FILE *f) 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 */ @@ -307,15 +321,18 @@ rte_ring_lookup(const char *name) 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; } diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index 4f3e20f..3920830 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -138,8 +138,6 @@ struct rte_ring_debug_stats { * a problem. */ struct rte_ring { - TAILQ_ENTRY(rte_ring) next; /**< Next in list. */ - char name[RTE_RING_NAMESIZE]; /**< Name of the ring. */ int flags; /**< Flags supplied at creation. */ -- 1.8.1.4