diff mbox

linux-generic: implement of odp_term_global.

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

Commit Message

yan.songming Jan. 19, 2015, 11:34 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      | 88 +++++++++++++++++++--------
 platform/linux-generic/odp_classification.c   | 42 ++++++++++---
 platform/linux-generic/odp_crypto.c           | 12 ++++
 platform/linux-generic/odp_init.c             | 43 ++++++++++++-
 platform/linux-generic/odp_packet_io.c        | 35 ++++++++---
 platform/linux-generic/odp_queue.c            | 24 ++++++++
 platform/linux-generic/odp_schedule.c         | 34 +++++++++--
 platform/linux-generic/odp_shared_memory.c    | 12 +++-
 platform/linux-generic/odp_thread.c           | 13 ++++
 10 files changed, 263 insertions(+), 50 deletions(-)

Comments

Mike Holmes Jan. 19, 2015, 6:22 p.m. UTC | #1
There appear to be a lot of whitespace changes, I assume they are
checkpatch cleanups in a number of cases.
Can we move all the non functional whitespace changes to their own patch so
that the logic of the change is more apparent in a single patch.



On 19 January 2015 at 06:34, Yan Songming <yan.songming@linaro.org> 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      | 88
> +++++++++++++++++++--------
>  platform/linux-generic/odp_classification.c   | 42 ++++++++++---
>  platform/linux-generic/odp_crypto.c           | 12 ++++
>  platform/linux-generic/odp_init.c             | 43 ++++++++++++-
>  platform/linux-generic/odp_packet_io.c        | 35 ++++++++---
>  platform/linux-generic/odp_queue.c            | 24 ++++++++
>  platform/linux-generic/odp_schedule.c         | 34 +++++++++--
>  platform/linux-generic/odp_shared_memory.c    | 12 +++-
>  platform/linux-generic/odp_thread.c           | 13 ++++
>  10 files changed, 263 insertions(+), 50 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..85e99e2 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,13 +96,48 @@ 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
>   */
>
>  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
> -                                        odp_shm_t shm,
> -                                        odp_buffer_pool_param_t *params)
> +               odp_shm_t shm,
> +               odp_buffer_pool_param_t *params)
>  {
>         odp_buffer_pool_t pool_hdl = ODP_BUFFER_POOL_INVALID;
>         pool_entry_t *pool;
> @@ -127,8 +163,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>
>         /* Restriction for v1.0: No udata support */
>         uint32_t udata_stride = (init_params->udata_size > sizeof(void *))
> ?
> -               ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
> -               0;
> +
>  ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
> +                       0;
>
>         uint32_t blk_size, buf_stride;
>         uint32_t buf_align = params->buf_align;
> @@ -155,8 +191,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>                         blk_size = ODP_ALIGN_ROUNDUP(blk_size, buf_align);
>
>                 buf_stride = params->buf_type == ODP_BUFFER_TYPE_RAW ?
> -                       sizeof(odp_buffer_hdr_stride) :
> -                       sizeof(odp_timeout_hdr_stride);
> +                            sizeof(odp_buffer_hdr_stride) :
> +                            sizeof(odp_timeout_hdr_stride);
>                 break;
>
>         case ODP_BUFFER_TYPE_PACKET:
> @@ -167,16 +203,16 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>
>                 if (unsegmented)
>                         blk_size = ODP_ALIGN_ROUNDUP(
> -                               headroom + params->buf_size + tailroom,
> -                               buf_align);
> +                                  headroom + params->buf_size + tailroom,
> +                                          buf_align);
>                 else
>                         blk_size = ODP_ALIGN_ROUNDUP(
> -                               headroom + params->buf_size + tailroom,
> -                               ODP_CONFIG_PACKET_BUF_LEN_MIN);
> +                                  headroom + params->buf_size + tailroom,
> +                                          ODP_CONFIG_PACKET_BUF_LEN_MIN);
>
>                 buf_stride = params->buf_type == ODP_BUFFER_TYPE_PACKET ?
> -                       sizeof(odp_packet_hdr_stride) :
> -                       sizeof(odp_any_hdr_stride);
> +                            sizeof(odp_packet_hdr_stride) :
> +                            sizeof(odp_any_hdr_stride);
>                 break;
>
>         default:
> @@ -230,9 +266,9 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>                 udata_size = params->num_bufs * udata_stride;
>
>                 pool->s.pool_size = ODP_PAGE_SIZE_ROUNDUP(block_size +
> -                                                         pad_size +
> -                                                         mdata_size +
> -                                                         udata_size);
> +                                   pad_size +
> +                                   mdata_size +
> +                                   udata_size);
>
>                 if (shm == ODP_SHM_NULL) {
>                         shm = odp_shm_reserve(pool->s.name,
> @@ -274,7 +310,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>                 pool->s.flags.unsegmented = unsegmented;
>                 pool->s.flags.zeroized = zeroized;
>                 pool->s.seg_size = unsegmented ?
> -                       blk_size : ODP_CONFIG_PACKET_BUF_LEN_MIN;
> +                                  blk_size :
> ODP_CONFIG_PACKET_BUF_LEN_MIN;
>
>
>                 uint8_t *block_base_addr = pool->s.pool_base_addr;
> @@ -297,7 +333,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>
>                 uint8_t *buf = udata_base_addr - buf_stride;
>                 uint8_t *udat = udata_stride == 0 ? NULL :
> -                       block_base_addr - udata_stride;
> +                               block_base_addr - udata_stride;
>
>                 /* Init buffer common header and add to pool buffer
> freelist */
>                 do {
> @@ -407,7 +443,7 @@ int odp_buffer_pool_info(odp_buffer_pool_t pool_hdl,
>
>         info->name = pool->s.name;
>         info->shm  = pool->s.flags.user_supplied_shm ?
> -               pool->s.pool_shm : ODP_SHM_INVALID;
> +                    pool->s.pool_shm : ODP_SHM_INVALID;
>         info->params.buf_size  = pool->s.params.buf_size;
>         info->params.buf_align = pool->s.params.buf_align;
>         info->params.num_bufs  = pool->s.params.num_bufs;
> @@ -466,7 +502,7 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl,
> size_t size)
>
>         /* Try to satisfy request from the local cache */
>         buf = (odp_anybuf_t *)(void *)get_local_buf(&local_cache[pool_id],
> -                                                   &pool->s, totsize);
> +                       &pool->s, totsize);
>
>         /* If cache is empty, satisfy request from the pool */
>         if (odp_unlikely(buf == NULL)) {
> @@ -499,8 +535,8 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl,
> size_t size)
>
>                 if (pool->s.init_params.buf_init != NULL)
>                         (*pool->s.init_params.buf_init)
> -                               (buf->buf.handle.handle,
> -                                pool->s.init_params.buf_init_arg);
> +                       (buf->buf.handle.handle,
> +                        pool->s.init_params.buf_init_arg);
>         }
>
>         return odp_hdr_to_buf(&buf->buf);
> @@ -559,10 +595,10 @@ void odp_buffer_pool_print(odp_buffer_pool_t
> pool_hdl)
>                 pool->s.flags.has_name ? pool->s.name : "Unnamed Pool");
>         ODP_DBG(" pool type       %s\n",
>                 pool->s.params.buf_type == ODP_BUFFER_TYPE_RAW ? "raw" :
> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ?
> "packet" :
> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ?
> "timeout" :
> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
> -               "unknown"))));
> +               (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ?
> "packet" :
> +             (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ?
> "timeout" :
> +             (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
> +                  "unknown"))));
>         ODP_DBG(" pool storage    %sODP managed\n",
>                 pool->s.flags.user_supplied_shm ?
>                 "application provided, " : "");
> diff --git a/platform/linux-generic/odp_classification.c
> b/platform/linux-generic/odp_classification.c
> index eeb049a..21728ac 100644
> --- a/platform/linux-generic/odp_classification.c
> +++ b/platform/linux-generic/odp_classification.c
> @@ -53,8 +53,8 @@ int odp_classification_init_global(void)
>         int i;
>
>         cos_shm = odp_shm_reserve("shm_odp_cos_tbl",
> -                       sizeof(cos_tbl_t),
> -                       sizeof(cos_t), 0);
> +                                 sizeof(cos_tbl_t),
> +                                 sizeof(cos_t), 0);
>
>         if (cos_shm == ODP_SHM_INVALID) {
>                 ODP_ERR("shm allocation failed for shm_odp_cos_tbl");
> @@ -73,8 +73,8 @@ int odp_classification_init_global(void)
>         }
>
>         pmr_shm = odp_shm_reserve("shm_odp_pmr_tbl",
> -                       sizeof(pmr_tbl_t),
> -                       sizeof(pmr_t), 0);
> +                                 sizeof(pmr_tbl_t),
> +                                 sizeof(pmr_t), 0);
>
>         if (pmr_shm == ODP_SHM_INVALID) {
>                 ODP_ERR("shm allocation failed for shm_odp_pmr_tbl");
> @@ -93,8 +93,8 @@ int odp_classification_init_global(void)
>         }
>
>         pmr_set_shm = odp_shm_reserve("shm_odp_pmr_set_tbl",
> -                       sizeof(pmr_set_tbl_t),
> -                       sizeof(pmr_set_t), 0);
> +                                     sizeof(pmr_set_tbl_t),
> +                                     sizeof(pmr_set_t), 0);
>
>         if (pmr_set_shm == ODP_SHM_INVALID) {
>                 ODP_ERR("shm allocation failed for shm_odp_pmr_set_tbl");
> @@ -124,6 +124,32 @@ 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;
> @@ -604,7 +630,7 @@ int odp_pmr_match_set_destroy(odp_pmr_set_t pmr_set_id)
>  }
>
>  int odp_pktio_pmr_match_set_cos(odp_pmr_set_t pmr_set_id, odp_pktio_t
> src_pktio,
> -               odp_cos_t dst_cos)
> +                               odp_cos_t dst_cos)
>  {
>         uint8_t num_pmr;
>         pktio_entry_t *pktio_entry;
> @@ -829,7 +855,7 @@ int packet_classifier(odp_pktio_t pktio, odp_packet_t
> pkt)
>  }
>
>  cos_t *pktio_select_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
> -                      odp_packet_hdr_t *pkt_hdr)
> +                       odp_packet_hdr_t *pkt_hdr)
>  {
>         pmr_t *pmr;
>         cos_t *cos;
> 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..6b22023 100644
> --- a/platform/linux-generic/odp_init.c
> +++ b/platform/linux-generic/odp_init.c
> @@ -11,7 +11,7 @@
>
>
>  int odp_init_global(odp_init_t *params  ODP_UNUSED,
> -                       odp_platform_init_t *platform_params ODP_UNUSED)
> +                   odp_platform_init_t *platform_params ODP_UNUSED)
>  {
>         odp_system_info_init();
>
> @@ -64,7 +64,46 @@ 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..a815020 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)
>  {
> @@ -345,15 +364,15 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
>         switch (pktio_entry->s.type) {
>         case ODP_PKTIO_TYPE_SOCKET_BASIC:
>                 pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                          pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMSG:
>                 pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMAP:
>                 pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         default:
>                 pkts = -1;
> @@ -382,15 +401,15 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
>         switch (pktio_entry->s.type) {
>         case ODP_PKTIO_TYPE_SOCKET_BASIC:
>                 pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                          pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMSG:
>                 pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMAP:
>                 pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         default:
>                 pkts = -1;
> @@ -548,7 +567,7 @@ int pktin_deq_multi(queue_entry_t *qentry,
> odp_buffer_hdr_t *buf_hdr[], int num)
>         nbr = queue_deq_multi(qentry, buf_hdr, num);
>         if (odp_unlikely(nbr > num))
>                 ODP_ABORT("queue_deq_multi req: %d, returned %d\n",
> -                       num, nbr);
> +                         num, nbr);
>
>         /** queue already has number of requsted buffers,
>          *  do not do receive in that case.
> @@ -707,7 +726,7 @@ int odp_pktio_promisc_mode(odp_pktio_t id)
>  }
>
>  size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
> -                      size_t addr_size)
> +                         size_t addr_size)
>  {
>         pktio_entry_t *entry;
>
> 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..080edeb 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)
>  {
> @@ -331,8 +357,8 @@ static int schedule(odp_queue_t *out_queue,
> odp_buffer_t out_buf[],
>
>
>  static int schedule_loop(odp_queue_t *out_queue, uint64_t wait,
> -                         odp_buffer_t out_buf[],
> -                         unsigned int max_num, unsigned int max_deq)
> +                        odp_buffer_t out_buf[],
> +                        unsigned int max_num, unsigned int max_deq)
>  {
>         uint64_t start_cycle, cycle, diff;
>         int ret;
> 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
>
Mike Holmes Jan. 22, 2015, 9:16 p.m. UTC | #2
In the subject >> linux-generic: implement of odp_term_global.
It should not have punctuation at the end, also I think a slightly crisper
description would be
linux-generic: add implementation of odp_term_global

On 19 January 2015 at 06:34, Yan Songming <yan.songming@linaro.org> 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.
>

You mention a bug fix here in the description, I assume it is a bug that
would exist even if you were not implementing odp_term_global.
So in this case should there be two patches, the first fixes the bug and
the second implements  odp_term_global, if we have a good rationale why
that is not true maybe just some better explanation in the description
would be ok.

However the general comment here is that this is at least three patches
from the outset, because at a high level you are doing three things

1. fix bug
2. add term_local
3. add term global

It really could serve us better if there were patches in these three
categories (above) for each ODP logical area.
For example buffer_pool has two patches in that logical area, one for
term_local and one for term_global, and this repeats for the other logical
areas. This may sound like a lot, but the reason for this is that in a
little while when there is an issue found a bisect will come down to
logical change in a specific area of ODP and it will be easily fixed.  If
it is all one patch then we don't know if the issue is caused by buffers,
scheduling, the bug fix you made - we just won't know without a proper
debug session.

Unfortunately because this is termination code it touched everything at
once and yes that is a lot of small patches, it is the same problem Bill
and Petri have faced already, it should not be so bad once the API settle.
In this case I think three patches in the minimum.

Other comments in line below


> Signed-off-by: Yan Songming <yan.songming@linaro.org>
> ---
>  platform/linux-generic/include/odp_internal.h | 10 +++
>  platform/linux-generic/odp_buffer_pool.c      | 88
> +++++++++++++++++++--------
>  platform/linux-generic/odp_classification.c   | 42 ++++++++++---
>  platform/linux-generic/odp_crypto.c           | 12 ++++
>  platform/linux-generic/odp_init.c             | 43 ++++++++++++-
>  platform/linux-generic/odp_packet_io.c        | 35 ++++++++---
>  platform/linux-generic/odp_queue.c            | 24 ++++++++
>  platform/linux-generic/odp_schedule.c         | 34 +++++++++--
>  platform/linux-generic/odp_shared_memory.c    | 12 +++-
>  platform/linux-generic/odp_thread.c           | 13 ++++
>  10 files changed, 263 insertions(+), 50 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..85e99e2 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,13 +96,48 @@ 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;
> +}
>

The patch description does not say it implements term local, says it does
term_global.
Either the description should be improved and say it does two thing or it
should be two patches. The general rule is that a patch does a single thing
so this looks like a case for another patch.


> +

+
>

You add two spaces here and only one just above in the same hunk


>  /**
>   * Buffer pool creation
>   */
>
>  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
> -                                        odp_shm_t shm,
> -                                        odp_buffer_pool_param_t *params)
> +               odp_shm_t shm,
> +               odp_buffer_pool_param_t *params)
>  {
>         odp_buffer_pool_t pool_hdl = ODP_BUFFER_POOL_INVALID;
>         pool_entry_t *pool;
> @@ -127,8 +163,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>
>         /* Restriction for v1.0: No udata support */
>         uint32_t udata_stride = (init_params->udata_size > sizeof(void *))
> ?
> -               ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
> -               0;
> +
>  ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
> +                       0;
>
>         uint32_t blk_size, buf_stride;
>         uint32_t buf_align = params->buf_align;
> @@ -155,8 +191,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>                         blk_size = ODP_ALIGN_ROUNDUP(blk_size, buf_align);
>
>                 buf_stride = params->buf_type == ODP_BUFFER_TYPE_RAW ?
> -                       sizeof(odp_buffer_hdr_stride) :
> -                       sizeof(odp_timeout_hdr_stride);
> +                            sizeof(odp_buffer_hdr_stride) :
> +                            sizeof(odp_timeout_hdr_stride);
>                 break;
>
>         case ODP_BUFFER_TYPE_PACKET:
> @@ -167,16 +203,16 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>
>                 if (unsegmented)
>                         blk_size = ODP_ALIGN_ROUNDUP(
> -                               headroom + params->buf_size + tailroom,
> -                               buf_align);
> +                                  headroom + params->buf_size + tailroom,
> +                                          buf_align);
>                 else
>                         blk_size = ODP_ALIGN_ROUNDUP(
> -                               headroom + params->buf_size + tailroom,
> -                               ODP_CONFIG_PACKET_BUF_LEN_MIN);
> +                                  headroom + params->buf_size + tailroom,
> +                                          ODP_CONFIG_PACKET_BUF_LEN_MIN);
>
>                 buf_stride = params->buf_type == ODP_BUFFER_TYPE_PACKET ?
> -                       sizeof(odp_packet_hdr_stride) :
> -                       sizeof(odp_any_hdr_stride);
> +                            sizeof(odp_packet_hdr_stride) :
> +                            sizeof(odp_any_hdr_stride);
>                 break;
>
>         default:
> @@ -230,9 +266,9 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>                 udata_size = params->num_bufs * udata_stride;
>
>                 pool->s.pool_size = ODP_PAGE_SIZE_ROUNDUP(block_size +
> -                                                         pad_size +
> -                                                         mdata_size +
> -                                                         udata_size);
> +                                   pad_size +
> +                                   mdata_size +
> +                                   udata_size);
>
>                 if (shm == ODP_SHM_NULL) {
>                         shm = odp_shm_reserve(pool->s.name,
> @@ -274,7 +310,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>                 pool->s.flags.unsegmented = unsegmented;
>                 pool->s.flags.zeroized = zeroized;
>                 pool->s.seg_size = unsegmented ?
> -                       blk_size : ODP_CONFIG_PACKET_BUF_LEN_MIN;
> +                                  blk_size :
> ODP_CONFIG_PACKET_BUF_LEN_MIN;
>
>
>                 uint8_t *block_base_addr = pool->s.pool_base_addr;
> @@ -297,7 +333,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
> *name,
>
>                 uint8_t *buf = udata_base_addr - buf_stride;
>                 uint8_t *udat = udata_stride == 0 ? NULL :
> -                       block_base_addr - udata_stride;
> +                               block_base_addr - udata_stride;
>
>                 /* Init buffer common header and add to pool buffer
> freelist */
>                 do {
> @@ -407,7 +443,7 @@ int odp_buffer_pool_info(odp_buffer_pool_t pool_hdl,
>
>         info->name = pool->s.name;
>         info->shm  = pool->s.flags.user_supplied_shm ?
> -               pool->s.pool_shm : ODP_SHM_INVALID;
> +                    pool->s.pool_shm : ODP_SHM_INVALID;
>         info->params.buf_size  = pool->s.params.buf_size;
>         info->params.buf_align = pool->s.params.buf_align;
>         info->params.num_bufs  = pool->s.params.num_bufs;
> @@ -466,7 +502,7 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl,
> size_t size)
>
>         /* Try to satisfy request from the local cache */
>         buf = (odp_anybuf_t *)(void *)get_local_buf(&local_cache[pool_id],
> -                                                   &pool->s, totsize);
> +                       &pool->s, totsize);
>
>         /* If cache is empty, satisfy request from the pool */
>         if (odp_unlikely(buf == NULL)) {
> @@ -499,8 +535,8 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl,
> size_t size)
>
>                 if (pool->s.init_params.buf_init != NULL)
>                         (*pool->s.init_params.buf_init)
> -                               (buf->buf.handle.handle,
> -                                pool->s.init_params.buf_init_arg);
> +                       (buf->buf.handle.handle,
> +                        pool->s.init_params.buf_init_arg);
>         }
>
>         return odp_hdr_to_buf(&buf->buf);
> @@ -559,10 +595,10 @@ void odp_buffer_pool_print(odp_buffer_pool_t
> pool_hdl)
>                 pool->s.flags.has_name ? pool->s.name : "Unnamed Pool");
>         ODP_DBG(" pool type       %s\n",
>                 pool->s.params.buf_type == ODP_BUFFER_TYPE_RAW ? "raw" :
> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ?
> "packet" :
> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ?
> "timeout" :
> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
> -               "unknown"))));
> +               (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ?
> "packet" :
> +             (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ?
> "timeout" :
> +             (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
> +                  "unknown"))));
>         ODP_DBG(" pool storage    %sODP managed\n",
>                 pool->s.flags.user_supplied_shm ?
>                 "application provided, " : "");
> diff --git a/platform/linux-generic/odp_classification.c
> b/platform/linux-generic/odp_classification.c
> index eeb049a..21728ac 100644
> --- a/platform/linux-generic/odp_classification.c
> +++ b/platform/linux-generic/odp_classification.c
> @@ -53,8 +53,8 @@ int odp_classification_init_global(void)
>         int i;
>
>         cos_shm = odp_shm_reserve("shm_odp_cos_tbl",
> -                       sizeof(cos_tbl_t),
> -                       sizeof(cos_t), 0);
> +                                 sizeof(cos_tbl_t),
> +                                 sizeof(cos_t), 0);
>
>         if (cos_shm == ODP_SHM_INVALID) {
>                 ODP_ERR("shm allocation failed for shm_odp_cos_tbl");
> @@ -73,8 +73,8 @@ int odp_classification_init_global(void)
>         }
>
>         pmr_shm = odp_shm_reserve("shm_odp_pmr_tbl",
> -                       sizeof(pmr_tbl_t),
> -                       sizeof(pmr_t), 0);
> +                                 sizeof(pmr_tbl_t),
> +                                 sizeof(pmr_t), 0);
>
>         if (pmr_shm == ODP_SHM_INVALID) {
>                 ODP_ERR("shm allocation failed for shm_odp_pmr_tbl");
> @@ -93,8 +93,8 @@ int odp_classification_init_global(void)
>         }
>
>         pmr_set_shm = odp_shm_reserve("shm_odp_pmr_set_tbl",
> -                       sizeof(pmr_set_tbl_t),
> -                       sizeof(pmr_set_t), 0);
> +                                     sizeof(pmr_set_tbl_t),
> +                                     sizeof(pmr_set_t), 0);
>
>         if (pmr_set_shm == ODP_SHM_INVALID) {
>                 ODP_ERR("shm allocation failed for shm_odp_pmr_set_tbl");
> @@ -124,6 +124,32 @@ 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;
> @@ -604,7 +630,7 @@ int odp_pmr_match_set_destroy(odp_pmr_set_t pmr_set_id)
>  }
>
>  int odp_pktio_pmr_match_set_cos(odp_pmr_set_t pmr_set_id, odp_pktio_t
> src_pktio,
> -               odp_cos_t dst_cos)
> +                               odp_cos_t dst_cos)
>  {
>         uint8_t num_pmr;
>         pktio_entry_t *pktio_entry;
> @@ -829,7 +855,7 @@ int packet_classifier(odp_pktio_t pktio, odp_packet_t
> pkt)
>  }
>
>  cos_t *pktio_select_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
> -                      odp_packet_hdr_t *pkt_hdr)
> +                       odp_packet_hdr_t *pkt_hdr)
>  {
>         pmr_t *pmr;
>         cos_t *cos;
> 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..6b22023 100644
> --- a/platform/linux-generic/odp_init.c
> +++ b/platform/linux-generic/odp_init.c
> @@ -11,7 +11,7 @@
>
>
>  int odp_init_global(odp_init_t *params  ODP_UNUSED,
> -                       odp_platform_init_t *platform_params ODP_UNUSED)
> +                   odp_platform_init_t *platform_params ODP_UNUSED)
>  {
>         odp_system_info_init();
>
> @@ -64,7 +64,46 @@ 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..a815020 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)
>  {
> @@ -345,15 +364,15 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
>         switch (pktio_entry->s.type) {
>         case ODP_PKTIO_TYPE_SOCKET_BASIC:
>                 pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                          pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMSG:
>                 pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMAP:
>                 pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         default:
>                 pkts = -1;
> @@ -382,15 +401,15 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
>         switch (pktio_entry->s.type) {
>         case ODP_PKTIO_TYPE_SOCKET_BASIC:
>                 pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                          pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMSG:
>                 pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         case ODP_PKTIO_TYPE_SOCKET_MMAP:
>                 pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> -                               pkt_table, len);
> +                                         pkt_table, len);
>                 break;
>         default:
>                 pkts = -1;
> @@ -548,7 +567,7 @@ int pktin_deq_multi(queue_entry_t *qentry,
> odp_buffer_hdr_t *buf_hdr[], int num)
>         nbr = queue_deq_multi(qentry, buf_hdr, num);
>         if (odp_unlikely(nbr > num))
>                 ODP_ABORT("queue_deq_multi req: %d, returned %d\n",
> -                       num, nbr);
> +                         num, nbr);
>
>         /** queue already has number of requsted buffers,
>          *  do not do receive in that case.
> @@ -707,7 +726,7 @@ int odp_pktio_promisc_mode(odp_pktio_t id)
>  }
>
>  size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
> -                      size_t addr_size)
> +                         size_t addr_size)
>  {
>         pktio_entry_t *entry;
>
> 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..080edeb 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>
>

 not needed


>
>  /* 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)
>  {
> @@ -331,8 +357,8 @@ static int schedule(odp_queue_t *out_queue,
> odp_buffer_t out_buf[],
>
>
>  static int schedule_loop(odp_queue_t *out_queue, uint64_t wait,
> -                         odp_buffer_t out_buf[],
> -                         unsigned int max_num, unsigned int max_deq)
> +                        odp_buffer_t out_buf[],
> +                        unsigned int max_num, unsigned int max_deq)
>  {
>         uint64_t start_cycle, cycle, diff;
>         int ret;
> 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
>
Mike Holmes Jan. 22, 2015, 9:32 p.m. UTC | #3
Apologies, hooked this review to V1 not V2

On 22 January 2015 at 16:16, Mike Holmes <mike.holmes@linaro.org> wrote:

> In the subject >> linux-generic: implement of odp_term_global.
> It should not have punctuation at the end, also I think a slightly crisper
> description would be
> linux-generic: add implementation of odp_term_global
>
> On 19 January 2015 at 06:34, Yan Songming <yan.songming@linaro.org> 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.
>>
>
> You mention a bug fix here in the description, I assume it is a bug that
> would exist even if you were not implementing odp_term_global.
> So in this case should there be two patches, the first fixes the bug and
> the second implements  odp_term_global, if we have a good rationale why
> that is not true maybe just some better explanation in the description
> would be ok.
>
> However the general comment here is that this is at least three patches
> from the outset, because at a high level you are doing three things
>
> 1. fix bug
> 2. add term_local
> 3. add term global
>
> It really could serve us better if there were patches in these three
> categories (above) for each ODP logical area.
> For example buffer_pool has two patches in that logical area, one for
> term_local and one for term_global, and this repeats for the other logical
> areas. This may sound like a lot, but the reason for this is that in a
> little while when there is an issue found a bisect will come down to
> logical change in a specific area of ODP and it will be easily fixed.  If
> it is all one patch then we don't know if the issue is caused by buffers,
> scheduling, the bug fix you made - we just won't know without a proper
> debug session.
>
> Unfortunately because this is termination code it touched everything at
> once and yes that is a lot of small patches, it is the same problem Bill
> and Petri have faced already, it should not be so bad once the API settle.
> In this case I think three patches in the minimum.
>
> Other comments in line below
>
>
>> Signed-off-by: Yan Songming <yan.songming@linaro.org>
>> ---
>>  platform/linux-generic/include/odp_internal.h | 10 +++
>>  platform/linux-generic/odp_buffer_pool.c      | 88
>> +++++++++++++++++++--------
>>  platform/linux-generic/odp_classification.c   | 42 ++++++++++---
>>  platform/linux-generic/odp_crypto.c           | 12 ++++
>>  platform/linux-generic/odp_init.c             | 43 ++++++++++++-
>>  platform/linux-generic/odp_packet_io.c        | 35 ++++++++---
>>  platform/linux-generic/odp_queue.c            | 24 ++++++++
>>  platform/linux-generic/odp_schedule.c         | 34 +++++++++--
>>  platform/linux-generic/odp_shared_memory.c    | 12 +++-
>>  platform/linux-generic/odp_thread.c           | 13 ++++
>>  10 files changed, 263 insertions(+), 50 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..85e99e2 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,13 +96,48 @@ 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;
>> +}
>>
>
> The patch description does not say it implements term local, says it does
> term_global.
> Either the description should be improved and say it does two thing or it
> should be two patches. The general rule is that a patch does a single thing
> so this looks like a case for another patch.
>
>
>> +
>
> +
>>
>
> You add two spaces here and only one just above in the same hunk
>
>
>>  /**
>>   * Buffer pool creation
>>   */
>>
>>  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
>> -                                        odp_shm_t shm,
>> -                                        odp_buffer_pool_param_t *params)
>> +               odp_shm_t shm,
>> +               odp_buffer_pool_param_t *params)
>>  {
>>         odp_buffer_pool_t pool_hdl = ODP_BUFFER_POOL_INVALID;
>>         pool_entry_t *pool;
>> @@ -127,8 +163,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
>> *name,
>>
>>         /* Restriction for v1.0: No udata support */
>>         uint32_t udata_stride = (init_params->udata_size > sizeof(void
>> *)) ?
>> -               ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
>> -               0;
>> +
>>  ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
>> +                       0;
>>
>>         uint32_t blk_size, buf_stride;
>>         uint32_t buf_align = params->buf_align;
>> @@ -155,8 +191,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
>> *name,
>>                         blk_size = ODP_ALIGN_ROUNDUP(blk_size, buf_align);
>>
>>                 buf_stride = params->buf_type == ODP_BUFFER_TYPE_RAW ?
>> -                       sizeof(odp_buffer_hdr_stride) :
>> -                       sizeof(odp_timeout_hdr_stride);
>> +                            sizeof(odp_buffer_hdr_stride) :
>> +                            sizeof(odp_timeout_hdr_stride);
>>                 break;
>>
>>         case ODP_BUFFER_TYPE_PACKET:
>> @@ -167,16 +203,16 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
>> *name,
>>
>>                 if (unsegmented)
>>                         blk_size = ODP_ALIGN_ROUNDUP(
>> -                               headroom + params->buf_size + tailroom,
>> -                               buf_align);
>> +                                  headroom + params->buf_size + tailroom,
>> +                                          buf_align);
>>                 else
>>                         blk_size = ODP_ALIGN_ROUNDUP(
>> -                               headroom + params->buf_size + tailroom,
>> -                               ODP_CONFIG_PACKET_BUF_LEN_MIN);
>> +                                  headroom + params->buf_size + tailroom,
>> +                                          ODP_CONFIG_PACKET_BUF_LEN_MIN);
>>
>>                 buf_stride = params->buf_type == ODP_BUFFER_TYPE_PACKET ?
>> -                       sizeof(odp_packet_hdr_stride) :
>> -                       sizeof(odp_any_hdr_stride);
>> +                            sizeof(odp_packet_hdr_stride) :
>> +                            sizeof(odp_any_hdr_stride);
>>                 break;
>>
>>         default:
>> @@ -230,9 +266,9 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
>> *name,
>>                 udata_size = params->num_bufs * udata_stride;
>>
>>                 pool->s.pool_size = ODP_PAGE_SIZE_ROUNDUP(block_size +
>> -                                                         pad_size +
>> -                                                         mdata_size +
>> -                                                         udata_size);
>> +                                   pad_size +
>> +                                   mdata_size +
>> +                                   udata_size);
>>
>>                 if (shm == ODP_SHM_NULL) {
>>                         shm = odp_shm_reserve(pool->s.name,
>> @@ -274,7 +310,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
>> *name,
>>                 pool->s.flags.unsegmented = unsegmented;
>>                 pool->s.flags.zeroized = zeroized;
>>                 pool->s.seg_size = unsegmented ?
>> -                       blk_size : ODP_CONFIG_PACKET_BUF_LEN_MIN;
>> +                                  blk_size :
>> ODP_CONFIG_PACKET_BUF_LEN_MIN;
>>
>>
>>                 uint8_t *block_base_addr = pool->s.pool_base_addr;
>> @@ -297,7 +333,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char
>> *name,
>>
>>                 uint8_t *buf = udata_base_addr - buf_stride;
>>                 uint8_t *udat = udata_stride == 0 ? NULL :
>> -                       block_base_addr - udata_stride;
>> +                               block_base_addr - udata_stride;
>>
>>                 /* Init buffer common header and add to pool buffer
>> freelist */
>>                 do {
>> @@ -407,7 +443,7 @@ int odp_buffer_pool_info(odp_buffer_pool_t pool_hdl,
>>
>>         info->name = pool->s.name;
>>         info->shm  = pool->s.flags.user_supplied_shm ?
>> -               pool->s.pool_shm : ODP_SHM_INVALID;
>> +                    pool->s.pool_shm : ODP_SHM_INVALID;
>>         info->params.buf_size  = pool->s.params.buf_size;
>>         info->params.buf_align = pool->s.params.buf_align;
>>         info->params.num_bufs  = pool->s.params.num_bufs;
>> @@ -466,7 +502,7 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl,
>> size_t size)
>>
>>         /* Try to satisfy request from the local cache */
>>         buf = (odp_anybuf_t *)(void *)get_local_buf(&local_cache[pool_id],
>> -                                                   &pool->s, totsize);
>> +                       &pool->s, totsize);
>>
>>         /* If cache is empty, satisfy request from the pool */
>>         if (odp_unlikely(buf == NULL)) {
>> @@ -499,8 +535,8 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl,
>> size_t size)
>>
>>                 if (pool->s.init_params.buf_init != NULL)
>>                         (*pool->s.init_params.buf_init)
>> -                               (buf->buf.handle.handle,
>> -                                pool->s.init_params.buf_init_arg);
>> +                       (buf->buf.handle.handle,
>> +                        pool->s.init_params.buf_init_arg);
>>         }
>>
>>         return odp_hdr_to_buf(&buf->buf);
>> @@ -559,10 +595,10 @@ void odp_buffer_pool_print(odp_buffer_pool_t
>> pool_hdl)
>>                 pool->s.flags.has_name ? pool->s.name : "Unnamed Pool");
>>         ODP_DBG(" pool type       %s\n",
>>                 pool->s.params.buf_type == ODP_BUFFER_TYPE_RAW ? "raw" :
>> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ?
>> "packet" :
>> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ?
>> "timeout" :
>> -              (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
>> -               "unknown"))));
>> +               (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ?
>> "packet" :
>> +             (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ?
>> "timeout" :
>> +             (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
>> +                  "unknown"))));
>>         ODP_DBG(" pool storage    %sODP managed\n",
>>                 pool->s.flags.user_supplied_shm ?
>>                 "application provided, " : "");
>> diff --git a/platform/linux-generic/odp_classification.c
>> b/platform/linux-generic/odp_classification.c
>> index eeb049a..21728ac 100644
>> --- a/platform/linux-generic/odp_classification.c
>> +++ b/platform/linux-generic/odp_classification.c
>> @@ -53,8 +53,8 @@ int odp_classification_init_global(void)
>>         int i;
>>
>>         cos_shm = odp_shm_reserve("shm_odp_cos_tbl",
>> -                       sizeof(cos_tbl_t),
>> -                       sizeof(cos_t), 0);
>> +                                 sizeof(cos_tbl_t),
>> +                                 sizeof(cos_t), 0);
>>
>>         if (cos_shm == ODP_SHM_INVALID) {
>>                 ODP_ERR("shm allocation failed for shm_odp_cos_tbl");
>> @@ -73,8 +73,8 @@ int odp_classification_init_global(void)
>>         }
>>
>>         pmr_shm = odp_shm_reserve("shm_odp_pmr_tbl",
>> -                       sizeof(pmr_tbl_t),
>> -                       sizeof(pmr_t), 0);
>> +                                 sizeof(pmr_tbl_t),
>> +                                 sizeof(pmr_t), 0);
>>
>>         if (pmr_shm == ODP_SHM_INVALID) {
>>                 ODP_ERR("shm allocation failed for shm_odp_pmr_tbl");
>> @@ -93,8 +93,8 @@ int odp_classification_init_global(void)
>>         }
>>
>>         pmr_set_shm = odp_shm_reserve("shm_odp_pmr_set_tbl",
>> -                       sizeof(pmr_set_tbl_t),
>> -                       sizeof(pmr_set_t), 0);
>> +                                     sizeof(pmr_set_tbl_t),
>> +                                     sizeof(pmr_set_t), 0);
>>
>>         if (pmr_set_shm == ODP_SHM_INVALID) {
>>                 ODP_ERR("shm allocation failed for shm_odp_pmr_set_tbl");
>> @@ -124,6 +124,32 @@ 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;
>> @@ -604,7 +630,7 @@ int odp_pmr_match_set_destroy(odp_pmr_set_t
>> pmr_set_id)
>>  }
>>
>>  int odp_pktio_pmr_match_set_cos(odp_pmr_set_t pmr_set_id, odp_pktio_t
>> src_pktio,
>> -               odp_cos_t dst_cos)
>> +                               odp_cos_t dst_cos)
>>  {
>>         uint8_t num_pmr;
>>         pktio_entry_t *pktio_entry;
>> @@ -829,7 +855,7 @@ int packet_classifier(odp_pktio_t pktio, odp_packet_t
>> pkt)
>>  }
>>
>>  cos_t *pktio_select_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
>> -                      odp_packet_hdr_t *pkt_hdr)
>> +                       odp_packet_hdr_t *pkt_hdr)
>>  {
>>         pmr_t *pmr;
>>         cos_t *cos;
>> 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..6b22023 100644
>> --- a/platform/linux-generic/odp_init.c
>> +++ b/platform/linux-generic/odp_init.c
>> @@ -11,7 +11,7 @@
>>
>>
>>  int odp_init_global(odp_init_t *params  ODP_UNUSED,
>> -                       odp_platform_init_t *platform_params ODP_UNUSED)
>> +                   odp_platform_init_t *platform_params ODP_UNUSED)
>>  {
>>         odp_system_info_init();
>>
>> @@ -64,7 +64,46 @@ 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..a815020 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)
>>  {
>> @@ -345,15 +364,15 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t
>> pkt_table[], unsigned len)
>>         switch (pktio_entry->s.type) {
>>         case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>                 pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
>> -                               pkt_table, len);
>> +                                          pkt_table, len);
>>                 break;
>>         case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>                 pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
>> -                               pkt_table, len);
>> +                                         pkt_table, len);
>>                 break;
>>         case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>                 pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
>> -                               pkt_table, len);
>> +                                         pkt_table, len);
>>                 break;
>>         default:
>>                 pkts = -1;
>> @@ -382,15 +401,15 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t
>> pkt_table[], unsigned len)
>>         switch (pktio_entry->s.type) {
>>         case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>                 pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
>> -                               pkt_table, len);
>> +                                          pkt_table, len);
>>                 break;
>>         case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>                 pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
>> -                               pkt_table, len);
>> +                                         pkt_table, len);
>>                 break;
>>         case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>                 pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
>> -                               pkt_table, len);
>> +                                         pkt_table, len);
>>                 break;
>>         default:
>>                 pkts = -1;
>> @@ -548,7 +567,7 @@ int pktin_deq_multi(queue_entry_t *qentry,
>> odp_buffer_hdr_t *buf_hdr[], int num)
>>         nbr = queue_deq_multi(qentry, buf_hdr, num);
>>         if (odp_unlikely(nbr > num))
>>                 ODP_ABORT("queue_deq_multi req: %d, returned %d\n",
>> -                       num, nbr);
>> +                         num, nbr);
>>
>>         /** queue already has number of requsted buffers,
>>          *  do not do receive in that case.
>> @@ -707,7 +726,7 @@ int odp_pktio_promisc_mode(odp_pktio_t id)
>>  }
>>
>>  size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
>> -                      size_t addr_size)
>> +                         size_t addr_size)
>>  {
>>         pktio_entry_t *entry;
>>
>> 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..080edeb 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>
>>
>
>  not needed
>
>
>>
>>  /* 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)
>>  {
>> @@ -331,8 +357,8 @@ static int schedule(odp_queue_t *out_queue,
>> odp_buffer_t out_buf[],
>>
>>
>>  static int schedule_loop(odp_queue_t *out_queue, uint64_t wait,
>> -                         odp_buffer_t out_buf[],
>> -                         unsigned int max_num, unsigned int max_deq)
>> +                        odp_buffer_t out_buf[],
>> +                        unsigned int max_num, unsigned int max_deq)
>>  {
>>         uint64_t start_cycle, cycle, diff;
>>         int ret;
>> 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
>>
>
>
>
> --
> *Mike Holmes*
> Linaro  Sr Technical Manager
> 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..85e99e2 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,13 +96,48 @@  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
  */
 
 odp_buffer_pool_t odp_buffer_pool_create(const char *name,
-					 odp_shm_t shm,
-					 odp_buffer_pool_param_t *params)
+		odp_shm_t shm,
+		odp_buffer_pool_param_t *params)
 {
 	odp_buffer_pool_t pool_hdl = ODP_BUFFER_POOL_INVALID;
 	pool_entry_t *pool;
@@ -127,8 +163,8 @@  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
 
 	/* Restriction for v1.0: No udata support */
 	uint32_t udata_stride = (init_params->udata_size > sizeof(void *)) ?
-		ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
-		0;
+			ODP_CACHE_LINE_SIZE_ROUNDUP(init_params->udata_size) :
+			0;
 
 	uint32_t blk_size, buf_stride;
 	uint32_t buf_align = params->buf_align;
@@ -155,8 +191,8 @@  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
 			blk_size = ODP_ALIGN_ROUNDUP(blk_size, buf_align);
 
 		buf_stride = params->buf_type == ODP_BUFFER_TYPE_RAW ?
-			sizeof(odp_buffer_hdr_stride) :
-			sizeof(odp_timeout_hdr_stride);
+			     sizeof(odp_buffer_hdr_stride) :
+			     sizeof(odp_timeout_hdr_stride);
 		break;
 
 	case ODP_BUFFER_TYPE_PACKET:
@@ -167,16 +203,16 @@  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
 
 		if (unsegmented)
 			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf_size + tailroom,
-				buf_align);
+				   headroom + params->buf_size + tailroom,
+					   buf_align);
 		else
 			blk_size = ODP_ALIGN_ROUNDUP(
-				headroom + params->buf_size + tailroom,
-				ODP_CONFIG_PACKET_BUF_LEN_MIN);
+				   headroom + params->buf_size + tailroom,
+					   ODP_CONFIG_PACKET_BUF_LEN_MIN);
 
 		buf_stride = params->buf_type == ODP_BUFFER_TYPE_PACKET ?
-			sizeof(odp_packet_hdr_stride) :
-			sizeof(odp_any_hdr_stride);
+			     sizeof(odp_packet_hdr_stride) :
+			     sizeof(odp_any_hdr_stride);
 		break;
 
 	default:
@@ -230,9 +266,9 @@  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
 		udata_size = params->num_bufs * udata_stride;
 
 		pool->s.pool_size = ODP_PAGE_SIZE_ROUNDUP(block_size +
-							  pad_size +
-							  mdata_size +
-							  udata_size);
+				    pad_size +
+				    mdata_size +
+				    udata_size);
 
 		if (shm == ODP_SHM_NULL) {
 			shm = odp_shm_reserve(pool->s.name,
@@ -274,7 +310,7 @@  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
 		pool->s.flags.unsegmented = unsegmented;
 		pool->s.flags.zeroized = zeroized;
 		pool->s.seg_size = unsegmented ?
-			blk_size : ODP_CONFIG_PACKET_BUF_LEN_MIN;
+				   blk_size : ODP_CONFIG_PACKET_BUF_LEN_MIN;
 
 
 		uint8_t *block_base_addr = pool->s.pool_base_addr;
@@ -297,7 +333,7 @@  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
 
 		uint8_t *buf = udata_base_addr - buf_stride;
 		uint8_t *udat = udata_stride == 0 ? NULL :
-			block_base_addr - udata_stride;
+				block_base_addr - udata_stride;
 
 		/* Init buffer common header and add to pool buffer freelist */
 		do {
@@ -407,7 +443,7 @@  int odp_buffer_pool_info(odp_buffer_pool_t pool_hdl,
 
 	info->name = pool->s.name;
 	info->shm  = pool->s.flags.user_supplied_shm ?
-		pool->s.pool_shm : ODP_SHM_INVALID;
+		     pool->s.pool_shm : ODP_SHM_INVALID;
 	info->params.buf_size  = pool->s.params.buf_size;
 	info->params.buf_align = pool->s.params.buf_align;
 	info->params.num_bufs  = pool->s.params.num_bufs;
@@ -466,7 +502,7 @@  odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl, size_t size)
 
 	/* Try to satisfy request from the local cache */
 	buf = (odp_anybuf_t *)(void *)get_local_buf(&local_cache[pool_id],
-						    &pool->s, totsize);
+			&pool->s, totsize);
 
 	/* If cache is empty, satisfy request from the pool */
 	if (odp_unlikely(buf == NULL)) {
@@ -499,8 +535,8 @@  odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl, size_t size)
 
 		if (pool->s.init_params.buf_init != NULL)
 			(*pool->s.init_params.buf_init)
-				(buf->buf.handle.handle,
-				 pool->s.init_params.buf_init_arg);
+			(buf->buf.handle.handle,
+			 pool->s.init_params.buf_init_arg);
 	}
 
 	return odp_hdr_to_buf(&buf->buf);
@@ -559,10 +595,10 @@  void odp_buffer_pool_print(odp_buffer_pool_t pool_hdl)
 		pool->s.flags.has_name ? pool->s.name : "Unnamed Pool");
 	ODP_DBG(" pool type       %s\n",
 		pool->s.params.buf_type == ODP_BUFFER_TYPE_RAW ? "raw" :
-	       (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ? "packet" :
-	       (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ? "timeout" :
-	       (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
-		"unknown"))));
+		(pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ? "packet" :
+	      (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ? "timeout" :
+	      (pool->s.params.buf_type == ODP_BUFFER_TYPE_ANY ? "any" :
+		   "unknown"))));
 	ODP_DBG(" pool storage    %sODP managed\n",
 		pool->s.flags.user_supplied_shm ?
 		"application provided, " : "");
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index eeb049a..21728ac 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -53,8 +53,8 @@  int odp_classification_init_global(void)
 	int i;
 
 	cos_shm = odp_shm_reserve("shm_odp_cos_tbl",
-			sizeof(cos_tbl_t),
-			sizeof(cos_t), 0);
+				  sizeof(cos_tbl_t),
+				  sizeof(cos_t), 0);
 
 	if (cos_shm == ODP_SHM_INVALID) {
 		ODP_ERR("shm allocation failed for shm_odp_cos_tbl");
@@ -73,8 +73,8 @@  int odp_classification_init_global(void)
 	}
 
 	pmr_shm = odp_shm_reserve("shm_odp_pmr_tbl",
-			sizeof(pmr_tbl_t),
-			sizeof(pmr_t), 0);
+				  sizeof(pmr_tbl_t),
+				  sizeof(pmr_t), 0);
 
 	if (pmr_shm == ODP_SHM_INVALID) {
 		ODP_ERR("shm allocation failed for shm_odp_pmr_tbl");
@@ -93,8 +93,8 @@  int odp_classification_init_global(void)
 	}
 
 	pmr_set_shm = odp_shm_reserve("shm_odp_pmr_set_tbl",
-			sizeof(pmr_set_tbl_t),
-			sizeof(pmr_set_t), 0);
+				      sizeof(pmr_set_tbl_t),
+				      sizeof(pmr_set_t), 0);
 
 	if (pmr_set_shm == ODP_SHM_INVALID) {
 		ODP_ERR("shm allocation failed for shm_odp_pmr_set_tbl");
@@ -124,6 +124,32 @@  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;
@@ -604,7 +630,7 @@  int odp_pmr_match_set_destroy(odp_pmr_set_t pmr_set_id)
 }
 
 int odp_pktio_pmr_match_set_cos(odp_pmr_set_t pmr_set_id, odp_pktio_t src_pktio,
-		odp_cos_t dst_cos)
+				odp_cos_t dst_cos)
 {
 	uint8_t num_pmr;
 	pktio_entry_t *pktio_entry;
@@ -829,7 +855,7 @@  int packet_classifier(odp_pktio_t pktio, odp_packet_t pkt)
 }
 
 cos_t *pktio_select_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
-		       odp_packet_hdr_t *pkt_hdr)
+			odp_packet_hdr_t *pkt_hdr)
 {
 	pmr_t *pmr;
 	cos_t *cos;
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..6b22023 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -11,7 +11,7 @@ 
 
 
 int odp_init_global(odp_init_t *params  ODP_UNUSED,
-			odp_platform_init_t *platform_params ODP_UNUSED)
+		    odp_platform_init_t *platform_params ODP_UNUSED)
 {
 	odp_system_info_init();
 
@@ -64,7 +64,46 @@  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..a815020 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)
 {
@@ -345,15 +364,15 @@  int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
 	switch (pktio_entry->s.type) {
 	case ODP_PKTIO_TYPE_SOCKET_BASIC:
 		pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
-				pkt_table, len);
+					   pkt_table, len);
 		break;
 	case ODP_PKTIO_TYPE_SOCKET_MMSG:
 		pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
-				pkt_table, len);
+					  pkt_table, len);
 		break;
 	case ODP_PKTIO_TYPE_SOCKET_MMAP:
 		pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
-				pkt_table, len);
+					  pkt_table, len);
 		break;
 	default:
 		pkts = -1;
@@ -382,15 +401,15 @@  int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
 	switch (pktio_entry->s.type) {
 	case ODP_PKTIO_TYPE_SOCKET_BASIC:
 		pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
-				pkt_table, len);
+					   pkt_table, len);
 		break;
 	case ODP_PKTIO_TYPE_SOCKET_MMSG:
 		pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
-				pkt_table, len);
+					  pkt_table, len);
 		break;
 	case ODP_PKTIO_TYPE_SOCKET_MMAP:
 		pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
-				pkt_table, len);
+					  pkt_table, len);
 		break;
 	default:
 		pkts = -1;
@@ -548,7 +567,7 @@  int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num)
 	nbr = queue_deq_multi(qentry, buf_hdr, num);
 	if (odp_unlikely(nbr > num))
 		ODP_ABORT("queue_deq_multi req: %d, returned %d\n",
-			num, nbr);
+			  num, nbr);
 
 	/** queue already has number of requsted buffers,
 	 *  do not do receive in that case.
@@ -707,7 +726,7 @@  int odp_pktio_promisc_mode(odp_pktio_t id)
 }
 
 size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
-		       size_t addr_size)
+			  size_t addr_size)
 {
 	pktio_entry_t *entry;
 
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..080edeb 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)
 {
@@ -331,8 +357,8 @@  static int schedule(odp_queue_t *out_queue, odp_buffer_t out_buf[],
 
 
 static int schedule_loop(odp_queue_t *out_queue, uint64_t wait,
-			  odp_buffer_t out_buf[],
-			  unsigned int max_num, unsigned int max_deq)
+			 odp_buffer_t out_buf[],
+			 unsigned int max_num, unsigned int max_deq)
 {
 	uint64_t start_cycle, cycle, diff;
 	int ret;
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)
 {