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 EDDE48D95 for ; Tue, 18 Aug 2015 16:00:58 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 18 Aug 2015 07:00:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,701,1432623600"; d="scan'208";a="627697194" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 18 Aug 2015 07:00:56 -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 t7IE0tYr024198; Tue, 18 Aug 2015 15:00:55 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t7IE0txC012897; Tue, 18 Aug 2015 15:00:55 +0100 Received: (from pdelarax@localhost) by sivswdev02.ir.intel.com with id t7IE0txD012893; Tue, 18 Aug 2015 15:00:55 +0100 From: Pablo de Lara To: dev@dpdk.org Date: Tue, 18 Aug 2015 15:00:54 +0100 Message-Id: <1439906454-12860-1-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH] ring: add function to free a ring 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: Tue, 18 Aug 2015 14:00:59 -0000 When creating a ring, a memzone is created to allocate it in memory, but the ring could not be freed, as memzones could not be. Since memzones can be freed now, then rings can be as well, taking into account if they were initialized using pre-allocated memory (in which case, memory should be freed externally) or using rte_memzone_reserve (with rte_ring_create), freeing the memory with rte_memzone_free. Signed-off-by: Pablo de Lara --- lib/librte_ring/rte_ring.c | 43 ++++++++++++++++++++++++++++++++++++ lib/librte_ring/rte_ring.h | 7 ++++++ lib/librte_ring/rte_ring_version.map | 7 ++++++ 3 files changed, 57 insertions(+) diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c index c9e59d4..83ce6d3 100644 --- a/lib/librte_ring/rte_ring.c +++ b/lib/librte_ring/rte_ring.c @@ -208,6 +208,49 @@ rte_ring_create(const char *name, unsigned count, int socket_id, return r; } +/* free the ring */ +void +rte_ring_free(struct rte_ring *r) +{ + struct rte_ring_list *ring_list = NULL; + char mz_name[RTE_MEMZONE_NAMESIZE]; + struct rte_tailq_entry *te; + const struct rte_memzone *mz; + + if (r == NULL) + return; + + snprintf(mz_name, sizeof(mz_name), "%s%s", RTE_RING_MZ_PREFIX, r->name); + mz = rte_memzone_lookup(mz_name); + + /* + * Free ring memory if it was allocated with rte_memzone_reserve, + * otherwise it should be freed externally + */ + if (rte_memzone_free(mz) != 0) + return; + + ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list); + rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); + + /* find out tailq entry */ + TAILQ_FOREACH(te, ring_list, next) { + if (te->data == (void *) r) + break; + } + + if (te == NULL) { + rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); + return; + } + + TAILQ_REMOVE(ring_list, te, next); + + rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); + + rte_free(te); +} + /* * change the high water mark. If *count* is 0, water marking is * disabled diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index af68888..e75566f 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -300,6 +300,13 @@ int rte_ring_init(struct rte_ring *r, const char *name, unsigned count, */ struct rte_ring *rte_ring_create(const char *name, unsigned count, int socket_id, unsigned flags); +/** + * De-allocate all memory used by the ring. + * + * @param r + * Ring to free + */ +void rte_ring_free(struct rte_ring *r); /** * Change the high water mark. diff --git a/lib/librte_ring/rte_ring_version.map b/lib/librte_ring/rte_ring_version.map index 982fdd1..5474b98 100644 --- a/lib/librte_ring/rte_ring_version.map +++ b/lib/librte_ring/rte_ring_version.map @@ -11,3 +11,10 @@ DPDK_2.0 { local: *; }; + +DPDK_2.2 { + global: + + rte_ring_free; + +} DPDK_2.0; -- 2.4.2