diff mbox

[v2,06/10] linux-generic: buffer_pool: add term_global

Message ID 1424116520-20381-7-git-send-email-mike.holmes@linaro.org
State New
Headers show

Commit Message

Mike Holmes Feb. 16, 2015, 7:55 p.m. UTC
From: Yan Sonming <yan.songming@linaro.org>

Signed-off-by: Yan Songming <yan.songming@linaro.org>
Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/include/odp_internal.h |  1 +
 platform/linux-generic/odp_buffer_pool.c      | 31 ++++++++++++++++++++++++++-
 platform/linux-generic/odp_init.c             |  5 +++++
 3 files changed, 36 insertions(+), 1 deletion(-)

Comments

Bill Fischofer Feb. 20, 2015, 12:56 a.m. UTC | #1
This will need to be rebased following application of my most recent pool
patch since odp_buffer_pool.c is being renamed to odp_pool.c and
SHM_DEFAULT_NAME should be changed from "odp_buffer_pools" to "odp_pools".
The name of the routine is also now odp_pool_term_global().

Bill

On Mon, Feb 16, 2015 at 1:55 PM, Mike Holmes <mike.holmes@linaro.org> wrote:

> From: Yan Sonming <yan.songming@linaro.org>
>
> Signed-off-by: Yan Songming <yan.songming@linaro.org>
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
>  platform/linux-generic/include/odp_internal.h |  1 +
>  platform/linux-generic/odp_buffer_pool.c      | 31
> ++++++++++++++++++++++++++-
>  platform/linux-generic/odp_init.c             |  5 +++++
>  3 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/platform/linux-generic/include/odp_internal.h
> b/platform/linux-generic/include/odp_internal.h
> index 202c914..59c65e2 100644
> --- a/platform/linux-generic/include/odp_internal.h
> +++ b/platform/linux-generic/include/odp_internal.h
> @@ -39,6 +39,7 @@ int odp_shm_init_global(void);
>  int odp_shm_init_local(void);
>
>  int odp_buffer_pool_init_global(void);
> +int odp_buffer_pool_term_global(void);
>
>  int odp_pktio_init_global(void);
>  int odp_pktio_term_global(void);
> diff --git a/platform/linux-generic/odp_buffer_pool.c
> b/platform/linux-generic/odp_buffer_pool.c
> index f8e35b4..bb384bc 100644
> --- a/platform/linux-generic/odp_buffer_pool.c
> +++ b/platform/linux-generic/odp_buffer_pool.c
> @@ -55,6 +55,7 @@ typedef struct pool_table_t {
>
>  /* The pool table */
>  static pool_table_t *pool_tbl;
> +static const char SHM_DEFAULT_NAME[] = "odp_buffer_pools";
>
>  /* Pool entry pointers (for inlining) */
>  void *pool_entry_ptr[ODP_CONFIG_POOLS];
> @@ -67,7 +68,7 @@ int odp_buffer_pool_init_global(void)
>         uint32_t i;
>         odp_shm_t shm;
>
> -       shm = odp_shm_reserve("odp_buffer_pools",
> +       shm = odp_shm_reserve(SHM_DEFAULT_NAME,
>                               sizeof(pool_table_t),
>                               sizeof(pool_entry_t), 0);
>
> @@ -95,6 +96,34 @@ int odp_buffer_pool_init_global(void)
>         return 0;
>  }
>
> +int odp_buffer_pool_term_global(void)
> +{
> +       odp_shm_t shm;
> +       int i;
> +       pool_entry_t *pool;
> +       int ret = 0;
> +
> +       for (i = 0; i < ODP_CONFIG_POOLS; i++) {
> +               pool = get_pool_entry(i);
> +
> +               POOL_LOCK(&pool->s.lock);
> +               if (pool->s.pool_shm != ODP_SHM_INVALID) {
> +                       ODP_ERR("Not destroyed pool: %s\n", pool->s.name);
> +                       ret = -1;
> +               }
> +               POOL_UNLOCK(&pool->s.lock);
> +       }
> +       if (ret)
> +               return ret;
> +
> +       shm = odp_shm_lookup(SHM_DEFAULT_NAME);
> +       if (shm == ODP_SHM_INVALID)
> +               return -1;
> +       ret = odp_shm_free(shm);
> +
> +       return ret;
> +}
> +
>  /**
>   * Pool creation
>   */
> diff --git a/platform/linux-generic/odp_init.c
> b/platform/linux-generic/odp_init.c
> index 93fdc2c..58faa59 100644
> --- a/platform/linux-generic/odp_init.c
> +++ b/platform/linux-generic/odp_init.c
> @@ -101,6 +101,11 @@ int odp_term_global(void)
>                 return -1;
>         }
>
> +       if (odp_buffer_pool_term_global()) {
> +               ODP_ERR("ODP buffer pool term failed.\n");
> +               return -1;
> +       }
> +
>         return 0;
>  }
>
> --
> 2.1.0
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index 202c914..59c65e2 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -39,6 +39,7 @@  int odp_shm_init_global(void);
 int odp_shm_init_local(void);
 
 int odp_buffer_pool_init_global(void);
+int odp_buffer_pool_term_global(void);
 
 int odp_pktio_init_global(void);
 int odp_pktio_term_global(void);
diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index f8e35b4..bb384bc 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -55,6 +55,7 @@  typedef struct pool_table_t {
 
 /* The pool table */
 static pool_table_t *pool_tbl;
+static const char SHM_DEFAULT_NAME[] = "odp_buffer_pools";
 
 /* Pool entry pointers (for inlining) */
 void *pool_entry_ptr[ODP_CONFIG_POOLS];
@@ -67,7 +68,7 @@  int odp_buffer_pool_init_global(void)
 	uint32_t i;
 	odp_shm_t shm;
 
-	shm = odp_shm_reserve("odp_buffer_pools",
+	shm = odp_shm_reserve(SHM_DEFAULT_NAME,
 			      sizeof(pool_table_t),
 			      sizeof(pool_entry_t), 0);
 
@@ -95,6 +96,34 @@  int odp_buffer_pool_init_global(void)
 	return 0;
 }
 
+int odp_buffer_pool_term_global(void)
+{
+	odp_shm_t shm;
+	int i;
+	pool_entry_t *pool;
+	int ret = 0;
+
+	for (i = 0; i < ODP_CONFIG_POOLS; i++) {
+		pool = get_pool_entry(i);
+
+		POOL_LOCK(&pool->s.lock);
+		if (pool->s.pool_shm != ODP_SHM_INVALID) {
+			ODP_ERR("Not destroyed pool: %s\n", pool->s.name);
+			ret = -1;
+		}
+		POOL_UNLOCK(&pool->s.lock);
+	}
+	if (ret)
+		return ret;
+
+	shm = odp_shm_lookup(SHM_DEFAULT_NAME);
+	if (shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(shm);
+
+	return ret;
+}
+
 /**
  * Pool creation
  */
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index 93fdc2c..58faa59 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -101,6 +101,11 @@  int odp_term_global(void)
 		return -1;
 	}
 
+	if (odp_buffer_pool_term_global()) {
+		ODP_ERR("ODP buffer pool term failed.\n");
+		return -1;
+	}
+
 	return 0;
 }