DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pablo de Lara <pablo.de.lara.guarch@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2] ring: add function to free a ring
Date: Tue, 22 Sep 2015 14:55:22 +0100	[thread overview]
Message-ID: <1442930122-119572-1-git-send-email-pablo.de.lara.guarch@intel.com> (raw)
In-Reply-To: <1439906454-12860-1-git-send-email-pablo.de.lara.guarch@intel.com>

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 <pablo.de.lara.guarch@intel.com>
---
Changes in v2:
- Include note in release notes
- Add error log when ring cannot be freed

 doc/guides/rel_notes/release_2_2.rst |  4 ++++
 lib/librte_ring/rte_ring.c           | 45 ++++++++++++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.h           |  7 ++++++
 lib/librte_ring/rte_ring_version.map |  7 ++++++
 4 files changed, 63 insertions(+)

diff --git a/doc/guides/rel_notes/release_2_2.rst b/doc/guides/rel_notes/release_2_2.rst
index 682f468..f6501a3 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -4,6 +4,10 @@ DPDK Release 2.2
 New Features
 ------------
 
+* **Enabled freeing of rte_ring.**
+
+  New function rte_ring_free() allows the user to free a ring
+  if it was created with rte_ring_create().
 
 Resolved Issues
 ---------------
diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c
index c9e59d4..2bcfd89 100644
--- a/lib/librte_ring/rte_ring.c
+++ b/lib/librte_ring/rte_ring.c
@@ -208,6 +208,51 @@ 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) {
+		RTE_LOG(ERR, RING, "Cannot free memory\n");
+		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.3

  parent reply	other threads:[~2015-09-22 13:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18 14:00 [dpdk-dev] [PATCH] " Pablo de Lara
2015-09-07  8:45 ` Olivier MATZ
2015-09-09  7:48   ` De Lara Guarch, Pablo
2015-09-22 13:55 ` Pablo de Lara [this message]
2015-10-02 14:01   ` [dpdk-dev] [PATCH v3] " Pablo de Lara
2015-10-02 14:09     ` Bruce Richardson
2015-10-02 14:27       ` De Lara Guarch, Pablo
2015-10-02 15:53     ` [dpdk-dev] [PATCH v4] " Pablo de Lara
2015-10-13 14:01       ` Olivier MATZ
2015-11-03 23:50         ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442930122-119572-1-git-send-email-pablo.de.lara.guarch@intel.com \
    --to=pablo.de.lara.guarch@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).