From: Petri Savolainen <petri.savolai...@linaro.org>

Implement the new block level debug print function.

Signed-off-by: Petri Savolainen <petri.savolai...@linaro.org>
---
/** Email created from pull request 246 (psavol:next-shm-print)
 ** https://github.com/Linaro/odp/pull/246
 ** Patch: https://github.com/Linaro/odp/pull/246.patch
 ** Base sha: e3108af2f0b58c2ceca422b418439bba5de04b11
 ** Merge commit sha: d02ca128bb3e497ed54c1224b5bd9d9f707870b3
 **/
 platform/linux-generic/_ishm.c                  | 49 +++++++++++++++++++++++++
 platform/linux-generic/include/_ishm_internal.h |  1 +
 platform/linux-generic/odp_shared_memory.c      |  5 +++
 test/common_plat/validation/api/shmem/shmem.c   |  2 +
 4 files changed, 57 insertions(+)

diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c
index e7a6c2357..238efb81a 100644
--- a/platform/linux-generic/_ishm.c
+++ b/platform/linux-generic/_ishm.c
@@ -1837,3 +1837,52 @@ int _odp_ishm_status(const char *title)
        odp_spinlock_unlock(&ishm_tbl->lock);
        return nb_blocks;
 }
+
+void _odp_ishm_print(int block_index)
+{
+       ishm_block_t *block;
+       const char *str;
+
+       odp_spinlock_lock(&ishm_tbl->lock);
+
+       if ((block_index < 0) ||
+           (block_index >= ISHM_MAX_NB_BLOCKS) ||
+           (ishm_tbl->block[block_index].len == 0)) {
+               odp_spinlock_unlock(&ishm_tbl->lock);
+               ODP_ERR("Request for info on an invalid block\n");
+               return;
+       }
+
+       block = &ishm_tbl->block[block_index];
+
+       ODP_PRINT("\nSHM block info\n--------------\n");
+       ODP_PRINT(" name:       %s\n",   block->name);
+       ODP_PRINT(" file:       %s\n",   block->filename);
+       ODP_PRINT(" expt:       %s\n",   block->exptname);
+       ODP_PRINT(" user_flags: 0x%x\n", block->user_flags);
+       ODP_PRINT(" flags:      0x%x\n", block->flags);
+       ODP_PRINT(" user_len:   %lu\n",  block->user_len);
+       ODP_PRINT(" start:      %p\n",   block->start);
+       ODP_PRINT(" len:        %lu\n",  block->len);
+
+       switch (block->huge) {
+       case HUGE:
+               str = "huge";
+               break;
+       case NORMAL:
+               str = "normal";
+               break;
+       case EXTERNAL:
+               str = "external";
+               break;
+       default:
+               str = "??";
+       }
+
+       ODP_PRINT(" page type:  %s\n", str);
+       ODP_PRINT(" seq:        %lu\n",  block->seq);
+       ODP_PRINT(" refcnt:     %lu\n",  block->refcnt);
+       ODP_PRINT("\n");
+
+       odp_spinlock_unlock(&ishm_tbl->lock);
+}
diff --git a/platform/linux-generic/include/_ishm_internal.h 
b/platform/linux-generic/include/_ishm_internal.h
index 005d6b551..34068bc0c 100644
--- a/platform/linux-generic/include/_ishm_internal.h
+++ b/platform/linux-generic/include/_ishm_internal.h
@@ -45,6 +45,7 @@ void *_odp_ishm_address(int block_index);
 int   _odp_ishm_info(int block_index, _odp_ishm_info_t *info);
 int   _odp_ishm_status(const char *title);
 int _odp_ishm_cleanup_files(const char *dirpath);
+void _odp_ishm_print(int block_index);
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/odp_shared_memory.c 
b/platform/linux-generic/odp_shared_memory.c
index ccd25c8c8..aabecd9b0 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -116,6 +116,11 @@ void odp_shm_print_all(void)
        _odp_ishm_status("Memory allocation status:");
 }
 
+void odp_shm_print(odp_shm_t shm)
+{
+       _odp_ishm_print(from_handle(shm));
+}
+
 uint64_t odp_shm_to_u64(odp_shm_t hdl)
 {
        return _odp_pri(hdl);
diff --git a/test/common_plat/validation/api/shmem/shmem.c 
b/test/common_plat/validation/api/shmem/shmem.c
index 08587940c..d5335afa9 100644
--- a/test/common_plat/validation/api/shmem/shmem.c
+++ b/test/common_plat/validation/api/shmem/shmem.c
@@ -152,6 +152,8 @@ void shmem_test_basic(void)
        odp_cunit_thread_create(run_test_basic_thread, &thrdarg);
        CU_ASSERT(odp_cunit_thread_exit(&thrdarg) >= 0);
 
+       odp_shm_print(shm);
+
        CU_ASSERT(0 == odp_shm_free(shm));
 }
 

Reply via email to