diff mbox

[v2] linux-generic: implement of odp_term_global.

Message ID 1421754040-16514-1-git-send-email-yan.songming@linaro.org
State New
Headers show

Commit Message

yan.songming Jan. 20, 2015, 11:40 a.m. UTC
From: Yan Sonming <yan.songming@linaro.org>

Free all resource of odp which include share memory, queue and buffer pool.Fix the bug of odp_shm_free.

Signed-off-by: Yan Songming <yan.songming@linaro.org>
---
 platform/linux-generic/include/odp_internal.h | 10 +++++++
 platform/linux-generic/odp_buffer_pool.c      | 38 ++++++++++++++++++++++++-
 platform/linux-generic/odp_classification.c   | 25 +++++++++++++++++
 platform/linux-generic/odp_crypto.c           | 12 ++++++++
 platform/linux-generic/odp_init.c             | 40 ++++++++++++++++++++++++++-
 platform/linux-generic/odp_packet_io.c        | 19 +++++++++++++
 platform/linux-generic/odp_queue.c            | 24 ++++++++++++++++
 platform/linux-generic/odp_schedule.c         | 30 ++++++++++++++++++--
 platform/linux-generic/odp_shared_memory.c    | 12 ++++++--
 platform/linux-generic/odp_thread.c           | 13 +++++++++
 10 files changed, 217 insertions(+), 6 deletions(-)

Comments

Anders Roxell Jan. 21, 2015, 1:25 p.m. UTC | #1
This should be split up into a patch set.

Cheers,
Anders

On 2015-01-20 19:40, Yan Songming wrote:
> From: Yan Sonming <yan.songming@linaro.org>
> 
> Free all resource of odp which include share memory, queue and buffer pool.Fix the bug of odp_shm_free.
> 
> Signed-off-by: Yan Songming <yan.songming@linaro.org>
> ---
>  platform/linux-generic/include/odp_internal.h | 10 +++++++
>  platform/linux-generic/odp_buffer_pool.c      | 38 ++++++++++++++++++++++++-
>  platform/linux-generic/odp_classification.c   | 25 +++++++++++++++++
>  platform/linux-generic/odp_crypto.c           | 12 ++++++++
>  platform/linux-generic/odp_init.c             | 40 ++++++++++++++++++++++++++-
>  platform/linux-generic/odp_packet_io.c        | 19 +++++++++++++
>  platform/linux-generic/odp_queue.c            | 24 ++++++++++++++++
>  platform/linux-generic/odp_schedule.c         | 30 ++++++++++++++++++--
>  platform/linux-generic/odp_shared_memory.c    | 12 ++++++--
>  platform/linux-generic/odp_thread.c           | 13 +++++++++
>  10 files changed, 217 insertions(+), 6 deletions(-)
> 
> diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
> index 549d406..d46f5ef 100644
> --- a/platform/linux-generic/include/odp_internal.h
> +++ b/platform/linux-generic/include/odp_internal.h
> @@ -24,23 +24,33 @@ int odp_system_info_init(void);
>  int odp_thread_init_global(void);
>  int odp_thread_init_local(void);
>  int odp_thread_term_local(void);
> +int odp_thread_term_global(void);
>  
>  int odp_shm_init_global(void);
> +int odp_shm_term_global(void);
>  int odp_shm_init_local(void);
>  
>  int odp_buffer_pool_init_global(void);
> +int odp_buffer_pool_term_global(void);
> +int odp_buffer_pool_term_local(void);
>  
>  int odp_pktio_init_global(void);
> +int odp_pktio_term_global(void);
>  int odp_pktio_init_local(void);
>  
>  int odp_classification_init_global(void);
> +int odp_classification_term_global(void);
>  
>  int odp_queue_init_global(void);
> +int odp_queue_term_global(void);
>  
>  int odp_crypto_init_global(void);
> +int odp_crypto_term_global(void);
>  
>  int odp_schedule_init_global(void);
> +int odp_schedule_term_global(void);
>  int odp_schedule_init_local(void);
> +int odp_schedule_term_local(void);
>  
>  int odp_timer_init_global(void);
>  int odp_timer_disarm_all(void);
> diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
> index eedb380..a75fe68 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_BUFFER_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,41 @@ 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_BUFFER_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;
> +}
> +
> +int odp_buffer_pool_term_local(void)
> +{
> +	_odp_flush_caches();
> +	return 0;
> +}
> +
> +
>  /**
>   * Buffer pool creation
>   */
> diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
> index eeb049a..50f097b 100644
> --- a/platform/linux-generic/odp_classification.c
> +++ b/platform/linux-generic/odp_classification.c
> @@ -124,6 +124,31 @@ error:
>  	return -1;
>  }
>  
> +int odp_classification_term_global(void)
> +{
> +	odp_shm_t cos_shm;
> +	odp_shm_t pmr_shm;
> +	odp_shm_t pmr_set_shm;
> +	int ret = 0;
> +
> +	cos_shm = odp_shm_lookup("shm_odp_cos_tbl");
> +	if (cos_shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(cos_shm);
> +
> +	pmr_shm = odp_shm_lookup("shm_odp_pmr_tbl");
> +	if (pmr_shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(pmr_shm);
> +
> +	pmr_set_shm = odp_shm_lookup("shm_odp_pmr_set_tbl");
> +	if (pmr_set_shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(pmr_set_shm);
> +
> +	return ret;
> +}
> +
>  odp_cos_t odp_cos_create(const char *name)
>  {
>  	int i;
> diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
> index 2f95cbe..bf36b35 100644
> --- a/platform/linux-generic/odp_crypto.c
> +++ b/platform/linux-generic/odp_crypto.c
> @@ -421,6 +421,18 @@ odp_crypto_init_global(void)
>  
>  	return 0;
>  }
> +int odp_crypto_term_global(void)
> +{
> +	odp_shm_t shm;
> +	int ret = 0;
> +
> +	shm = odp_shm_lookup("crypto_pool");
> +	if (shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(shm);
> +
> +	return ret;
> +}
>  
>  int
>  odp_hw_random_get(uint8_t *buf, size_t *len, bool use_entropy ODP_UNUSED)
> diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
> index 4d0aa07..6d7a51d 100644
> --- a/platform/linux-generic/odp_init.c
> +++ b/platform/linux-generic/odp_init.c
> @@ -64,7 +64,45 @@ int odp_init_global(odp_init_t *params  ODP_UNUSED,
>  
>  int odp_term_global(void)
>  {
> -	ODP_UNIMPLEMENTED();
> +	if (odp_classification_term_global()) {
> +		ODP_ERR("ODP classificatio term failed.\n");
> +		return -1;
> +	}
> +
> +	if (odp_crypto_term_global()) {
> +		ODP_ERR("ODP crypto term failed.\n");
> +		return -1;
> +	}
> +
> +	if (odp_pktio_term_global()) {
> +		ODP_ERR("ODP pktio term failed.\n");
> +		return -1;
> +	}
> +
> +	if (odp_schedule_term_global()) {
> +		ODP_ERR("ODP schedule term failed.\n");
> +		return -1;
> +	}
> +
> +	if (odp_queue_term_global()) {
> +		ODP_ERR("ODP queue term failed.\n");
> +		return -1;
> +	}
> +
> +	if (odp_buffer_pool_term_global()) {
> +		ODP_ERR("ODP buffer pool term failed.\n");
> +		return -1;
> +	}
> +
> +	if (odp_thread_term_global()) {
> +		ODP_ERR("ODP thread term failed.\n");
> +		return -1;
> +	}
> +
> +	if (odp_shm_term_global()) {
> +		ODP_ERR("ODP shm term failed.\n");
> +		return -1;
> +	}
>  	return 0;
>  }
>  
> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
> index cd109d2..f1179a2 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -73,6 +73,25 @@ int odp_pktio_init_global(void)
>  
>  	return 0;
>  }
> +int odp_pktio_term_global(void)
> +{
> +	odp_shm_t shm;
> +	pktio_entry_t *pktio_entry;
> +	int ret = 0;
> +	int id;
> +
> +	for (id = 1; id <= ODP_CONFIG_PKTIO_ENTRIES; ++id) {
> +		pktio_entry = &pktio_tbl->entries[id - 1];
> +		odp_queue_destroy(pktio_entry->s.outq_default);
> +	}
> +
> +	shm = odp_shm_lookup("odp_pktio_entries");
> +	if (shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(shm);
> +
> +	return ret;
> +}
>  
>  int odp_pktio_init_local(void)
>  {
> diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c
> index 70c006d..97d11bd 100644
> --- a/platform/linux-generic/odp_queue.c
> +++ b/platform/linux-generic/odp_queue.c
> @@ -127,6 +127,30 @@ int odp_queue_init_global(void)
>  
>  	return 0;
>  }
> +int odp_queue_term_global(void)
> +{
> +	odp_shm_t shm;
> +	int ret = 0;
> +	queue_entry_t *queue;
> +	int i;
> +
> +	for (i = 0; i < ODP_CONFIG_QUEUES; i++) {
> +		queue = &queue_tbl->queue[i];
> +		LOCK(&queue->s.lock);
> +		if (queue->s.status != QUEUE_STATUS_FREE) {
> +			ODP_ERR("Not destroyed queue: %s\n", queue->s.name);
> +			ret = -1;
> +		}
> +		UNLOCK(&queue->s.lock);
> +	}
> +
> +	shm = odp_shm_lookup("odp_queues");
> +	if (shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(shm);
> +
> +	return ret;
> +}
>  
>  odp_queue_type_t odp_queue_type(odp_queue_t handle)
>  {
> diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c
> index f7c3588..956cb70 100644
> --- a/platform/linux-generic/odp_schedule.c
> +++ b/platform/linux-generic/odp_schedule.c
> @@ -20,7 +20,8 @@
>  #include <odp_hints.h>
>  
>  #include <odp_queue_internal.h>
> -
> +#include <string.h>
> +#include <stdio.h>
>  
>  /* Limits to number of scheduled queues */
>  #define SCHED_POOL_SIZE (256*1024)
> @@ -144,6 +145,27 @@ int odp_schedule_init_global(void)
>  	return 0;
>  }
>  
> +int odp_schedule_term_global(void)
> +{
> +	odp_shm_t shm;
> +	int ret = 0;
> +	int i, j;
> +
> +	for (i = 0; i < ODP_CONFIG_SCHED_PRIOS; i++) {
> +		for (j = 0; j < QUEUES_PER_PRIO; j++)
> +			odp_queue_destroy(sched->pri_queue[i][j]);
> +	}
> +
> +	if (odp_buffer_pool_destroy(sched->pool) != 0)
> +		return -1;
> +
> +	shm = odp_shm_lookup("odp_scheduler");
> +	if (shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(shm);
> +
> +	return ret;
> +}
>  
>  int odp_schedule_init_local(void)
>  {
> @@ -162,7 +184,11 @@ int odp_schedule_init_local(void)
>  
>  	return 0;
>  }
> -
> +int odp_schedule_term_local(void)
> +{
> +	memset(&sched_local, 0, sizeof(sched_local_t));
> +	return 0;
> +}
>  
>  void odp_schedule_mask_set(odp_queue_t queue, int prio)
>  {
> diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c
> index 99c5b40..7f1f6a8 100644
> --- a/platform/linux-generic/odp_shared_memory.c
> +++ b/platform/linux-generic/odp_shared_memory.c
> @@ -94,6 +94,14 @@ int odp_shm_init_global(void)
>  	return 0;
>  }
>  
> +int odp_shm_term_global(void)
> +{
> +	int ret = 0;
> +
> +	ret = munmap(odp_shm_tbl, sizeof(odp_shm_table_t));
> +	return ret;
> +}
> +
>  
>  int odp_shm_init_local(void)
>  {
> @@ -135,9 +143,9 @@ int odp_shm_free(odp_shm_t shm)
>  	shm_block = &odp_shm_tbl->block[i];
>  
>  	alloc_size = shm_block->size + shm_block->align;
> -	ret = munmap(shm_block->addr, alloc_size);
> +	ret = munmap(shm_block->addr_orig, alloc_size);
>  	if (0 != ret) {
> -		ODP_DBG("odp_shm_free: munmap failed\n");
> +		ODP_DBG("odp_shm_free: munmap failed : %s\n", shm_block->name);
>  		odp_spinlock_unlock(&odp_shm_tbl->lock);
>  		return -1;
>  	}
> diff --git a/platform/linux-generic/odp_thread.c b/platform/linux-generic/odp_thread.c
> index ccbd068..933e920 100644
> --- a/platform/linux-generic/odp_thread.c
> +++ b/platform/linux-generic/odp_thread.c
> @@ -64,6 +64,19 @@ int odp_thread_init_global(void)
>  	return 0;
>  }
>  
> +int odp_thread_term_global(void)
> +{
> +	odp_shm_t shm;
> +	int ret = 0;
> +
> +	shm = odp_shm_lookup("odp_thread_globals");
> +	if (shm == ODP_SHM_INVALID)
> +		return -1;
> +	ret = odp_shm_free(shm);
> +
> +	return ret;
> +}
> +
>  
>  static int thread_id(void)
>  {
> -- 
> 1.8.3.1
> 
> 
> _______________________________________________
> 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 549d406..d46f5ef 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -24,23 +24,33 @@  int odp_system_info_init(void);
 int odp_thread_init_global(void);
 int odp_thread_init_local(void);
 int odp_thread_term_local(void);
+int odp_thread_term_global(void);
 
 int odp_shm_init_global(void);
+int odp_shm_term_global(void);
 int odp_shm_init_local(void);
 
 int odp_buffer_pool_init_global(void);
+int odp_buffer_pool_term_global(void);
+int odp_buffer_pool_term_local(void);
 
 int odp_pktio_init_global(void);
+int odp_pktio_term_global(void);
 int odp_pktio_init_local(void);
 
 int odp_classification_init_global(void);
+int odp_classification_term_global(void);
 
 int odp_queue_init_global(void);
+int odp_queue_term_global(void);
 
 int odp_crypto_init_global(void);
+int odp_crypto_term_global(void);
 
 int odp_schedule_init_global(void);
+int odp_schedule_term_global(void);
 int odp_schedule_init_local(void);
+int odp_schedule_term_local(void);
 
 int odp_timer_init_global(void);
 int odp_timer_disarm_all(void);
diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index eedb380..a75fe68 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_BUFFER_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,41 @@  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_BUFFER_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;
+}
+
+int odp_buffer_pool_term_local(void)
+{
+	_odp_flush_caches();
+	return 0;
+}
+
+
 /**
  * Buffer pool creation
  */
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index eeb049a..50f097b 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -124,6 +124,31 @@  error:
 	return -1;
 }
 
+int odp_classification_term_global(void)
+{
+	odp_shm_t cos_shm;
+	odp_shm_t pmr_shm;
+	odp_shm_t pmr_set_shm;
+	int ret = 0;
+
+	cos_shm = odp_shm_lookup("shm_odp_cos_tbl");
+	if (cos_shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(cos_shm);
+
+	pmr_shm = odp_shm_lookup("shm_odp_pmr_tbl");
+	if (pmr_shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(pmr_shm);
+
+	pmr_set_shm = odp_shm_lookup("shm_odp_pmr_set_tbl");
+	if (pmr_set_shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(pmr_set_shm);
+
+	return ret;
+}
+
 odp_cos_t odp_cos_create(const char *name)
 {
 	int i;
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index 2f95cbe..bf36b35 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -421,6 +421,18 @@  odp_crypto_init_global(void)
 
 	return 0;
 }
+int odp_crypto_term_global(void)
+{
+	odp_shm_t shm;
+	int ret = 0;
+
+	shm = odp_shm_lookup("crypto_pool");
+	if (shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(shm);
+
+	return ret;
+}
 
 int
 odp_hw_random_get(uint8_t *buf, size_t *len, bool use_entropy ODP_UNUSED)
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index 4d0aa07..6d7a51d 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -64,7 +64,45 @@  int odp_init_global(odp_init_t *params  ODP_UNUSED,
 
 int odp_term_global(void)
 {
-	ODP_UNIMPLEMENTED();
+	if (odp_classification_term_global()) {
+		ODP_ERR("ODP classificatio term failed.\n");
+		return -1;
+	}
+
+	if (odp_crypto_term_global()) {
+		ODP_ERR("ODP crypto term failed.\n");
+		return -1;
+	}
+
+	if (odp_pktio_term_global()) {
+		ODP_ERR("ODP pktio term failed.\n");
+		return -1;
+	}
+
+	if (odp_schedule_term_global()) {
+		ODP_ERR("ODP schedule term failed.\n");
+		return -1;
+	}
+
+	if (odp_queue_term_global()) {
+		ODP_ERR("ODP queue term failed.\n");
+		return -1;
+	}
+
+	if (odp_buffer_pool_term_global()) {
+		ODP_ERR("ODP buffer pool term failed.\n");
+		return -1;
+	}
+
+	if (odp_thread_term_global()) {
+		ODP_ERR("ODP thread term failed.\n");
+		return -1;
+	}
+
+	if (odp_shm_term_global()) {
+		ODP_ERR("ODP shm term failed.\n");
+		return -1;
+	}
 	return 0;
 }
 
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index cd109d2..f1179a2 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -73,6 +73,25 @@  int odp_pktio_init_global(void)
 
 	return 0;
 }
+int odp_pktio_term_global(void)
+{
+	odp_shm_t shm;
+	pktio_entry_t *pktio_entry;
+	int ret = 0;
+	int id;
+
+	for (id = 1; id <= ODP_CONFIG_PKTIO_ENTRIES; ++id) {
+		pktio_entry = &pktio_tbl->entries[id - 1];
+		odp_queue_destroy(pktio_entry->s.outq_default);
+	}
+
+	shm = odp_shm_lookup("odp_pktio_entries");
+	if (shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(shm);
+
+	return ret;
+}
 
 int odp_pktio_init_local(void)
 {
diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c
index 70c006d..97d11bd 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -127,6 +127,30 @@  int odp_queue_init_global(void)
 
 	return 0;
 }
+int odp_queue_term_global(void)
+{
+	odp_shm_t shm;
+	int ret = 0;
+	queue_entry_t *queue;
+	int i;
+
+	for (i = 0; i < ODP_CONFIG_QUEUES; i++) {
+		queue = &queue_tbl->queue[i];
+		LOCK(&queue->s.lock);
+		if (queue->s.status != QUEUE_STATUS_FREE) {
+			ODP_ERR("Not destroyed queue: %s\n", queue->s.name);
+			ret = -1;
+		}
+		UNLOCK(&queue->s.lock);
+	}
+
+	shm = odp_shm_lookup("odp_queues");
+	if (shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(shm);
+
+	return ret;
+}
 
 odp_queue_type_t odp_queue_type(odp_queue_t handle)
 {
diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c
index f7c3588..956cb70 100644
--- a/platform/linux-generic/odp_schedule.c
+++ b/platform/linux-generic/odp_schedule.c
@@ -20,7 +20,8 @@ 
 #include <odp_hints.h>
 
 #include <odp_queue_internal.h>
-
+#include <string.h>
+#include <stdio.h>
 
 /* Limits to number of scheduled queues */
 #define SCHED_POOL_SIZE (256*1024)
@@ -144,6 +145,27 @@  int odp_schedule_init_global(void)
 	return 0;
 }
 
+int odp_schedule_term_global(void)
+{
+	odp_shm_t shm;
+	int ret = 0;
+	int i, j;
+
+	for (i = 0; i < ODP_CONFIG_SCHED_PRIOS; i++) {
+		for (j = 0; j < QUEUES_PER_PRIO; j++)
+			odp_queue_destroy(sched->pri_queue[i][j]);
+	}
+
+	if (odp_buffer_pool_destroy(sched->pool) != 0)
+		return -1;
+
+	shm = odp_shm_lookup("odp_scheduler");
+	if (shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(shm);
+
+	return ret;
+}
 
 int odp_schedule_init_local(void)
 {
@@ -162,7 +184,11 @@  int odp_schedule_init_local(void)
 
 	return 0;
 }
-
+int odp_schedule_term_local(void)
+{
+	memset(&sched_local, 0, sizeof(sched_local_t));
+	return 0;
+}
 
 void odp_schedule_mask_set(odp_queue_t queue, int prio)
 {
diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c
index 99c5b40..7f1f6a8 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -94,6 +94,14 @@  int odp_shm_init_global(void)
 	return 0;
 }
 
+int odp_shm_term_global(void)
+{
+	int ret = 0;
+
+	ret = munmap(odp_shm_tbl, sizeof(odp_shm_table_t));
+	return ret;
+}
+
 
 int odp_shm_init_local(void)
 {
@@ -135,9 +143,9 @@  int odp_shm_free(odp_shm_t shm)
 	shm_block = &odp_shm_tbl->block[i];
 
 	alloc_size = shm_block->size + shm_block->align;
-	ret = munmap(shm_block->addr, alloc_size);
+	ret = munmap(shm_block->addr_orig, alloc_size);
 	if (0 != ret) {
-		ODP_DBG("odp_shm_free: munmap failed\n");
+		ODP_DBG("odp_shm_free: munmap failed : %s\n", shm_block->name);
 		odp_spinlock_unlock(&odp_shm_tbl->lock);
 		return -1;
 	}
diff --git a/platform/linux-generic/odp_thread.c b/platform/linux-generic/odp_thread.c
index ccbd068..933e920 100644
--- a/platform/linux-generic/odp_thread.c
+++ b/platform/linux-generic/odp_thread.c
@@ -64,6 +64,19 @@  int odp_thread_init_global(void)
 	return 0;
 }
 
+int odp_thread_term_global(void)
+{
+	odp_shm_t shm;
+	int ret = 0;
+
+	shm = odp_shm_lookup("odp_thread_globals");
+	if (shm == ODP_SHM_INVALID)
+		return -1;
+	ret = odp_shm_free(shm);
+
+	return ret;
+}
+
 
 static int thread_id(void)
 {