diff mbox

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

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

Commit Message

Mike Holmes Jan. 30, 2015, 2:46 a.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

Maxim Uvarov Feb. 2, 2015, 10:25 a.m. UTC | #1
On 01/30/2015 05:46 AM, Mike Holmes 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 4790481..cdd6a9b 100644
> --- a/platform/linux-generic/include/odp_internal.h
> +++ b/platform/linux-generic/include/odp_internal.h
> @@ -34,6 +34,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 3e13e6f..2634bff 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_name[] = "odp_buffer_pools";

const char SHM_DEFAULT_NAME[] is better here.

>   
>   /* 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_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_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 d381fd4..f5be742 100644
> --- a/platform/linux-generic/odp_init.c
> +++ b/platform/linux-generic/odp_init.c
> @@ -97,6 +97,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;
>   }
>
Mike Holmes Feb. 16, 2015, 7:55 p.m. UTC | #2
V2 sent

On 2 February 2015 at 05:25, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> On 01/30/2015 05:46 AM, Mike Holmes 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 4790481..cdd6a9b 100644
>> --- a/platform/linux-generic/include/odp_internal.h
>> +++ b/platform/linux-generic/include/odp_internal.h
>> @@ -34,6 +34,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 3e13e6f..2634bff 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_name[] = "odp_buffer_pools";
>>
>
> const char SHM_DEFAULT_NAME[] is better here.
>
>
>      /* 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_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_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 d381fd4..f5be742 100644
>> --- a/platform/linux-generic/odp_init.c
>> +++ b/platform/linux-generic/odp_init.c
>> @@ -97,6 +97,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;
>>   }
>>
>>
>
>
> _______________________________________________
> 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 4790481..cdd6a9b 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -34,6 +34,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 3e13e6f..2634bff 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_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_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_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 d381fd4..f5be742 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -97,6 +97,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;
 }