]> git.droids-corp.org - dpdk.git/commitdiff
ring: support freeing
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Fri, 2 Oct 2015 15:53:44 +0000 (16:53 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 3 Nov 2015 23:49:59 +0000 (00:49 +0100)
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>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
doc/guides/rel_notes/release_2_2.rst
lib/librte_ring/rte_ring.c
lib/librte_ring/rte_ring.h
lib/librte_ring/rte_ring_version.map

index b9884d47a29606650361d92e610b5abeb4ec4e5e..52a382d5c67ad61d1c258e611db01ccad971e55c 100644 (file)
@@ -4,6 +4,11 @@ DPDK Release 2.2
 New Features
 ------------
 
+* **Enabled freeing of ring.**
+
+  New function rte_ring_free() allows the user to free a ring
+  if it was created with rte_ring_create().
+
 * **Extended Statistics**
 
   Define extended statistics naming scheme to store metadata in the name
index 4e78e144c9bbed0d10656e33aa919e2fece03c00..d80faf3b20ed2b9b659e82e51dd7ebd3ec8a86ed 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -209,6 +209,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;
+       struct rte_tailq_entry *te;
+
+       if (r == NULL)
+               return;
+
+       /*
+        * Ring was not created with rte_ring_create,
+        * therefore, there is no memzone to free.
+        */
+       if (r->memzone == NULL) {
+               RTE_LOG(ERR, RING, "Cannot free ring (not created with rte_ring_create()");
+               return;
+       }
+
+       if (rte_memzone_free(r->memzone) != 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
index df45f3ff999e0e327d0dd8fcd284d5cb455f51f0..fb5a6263a1f9e9bb178518daac78fd0a75ffa248 100644 (file)
@@ -304,6 +304,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.
index 982fdd1e1dff2b40f462a2a578dccc74fb8711cc..5474b985e55c50c1bb83555e91612ac9ddf7d106 100644 (file)
@@ -11,3 +11,10 @@ DPDK_2.0 {
 
        local: *;
 };
+
+DPDK_2.2 {
+       global:
+
+       rte_ring_free;
+
+} DPDK_2.0;