diff mbox series

[API-NEXT,v2,4/4] linux-gen: shm: implement odp_shm_print

Message ID 1508752817-11952-5-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v2,1/4] api: shm: style clean up | expand

Commit Message

Github ODP bot Oct. 23, 2017, 10 a.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Implement the new block level debug print function.

Signed-off-by: Petri Savolainen <petri.savolainen@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: ec6510b33e8b96d6d6670efb9dc3c9101baed6c6
 ** Merge commit sha: fe0769b6e9387bbfabf68b538ec83a685f406da0
 **/
 platform/linux-generic/_ishm.c                  | 49 +++++++++++++++++++++++++
 platform/linux-generic/include/_ishm_internal.h |  1 +
 platform/linux-generic/odp_shared_memory.c      |  5 +++
 test/validation/api/shmem/shmem.c               |  2 +
 4 files changed, 57 insertions(+)
diff mbox series

Patch

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/validation/api/shmem/shmem.c b/test/validation/api/shmem/shmem.c
index 08587940c..d5335afa9 100644
--- a/test/validation/api/shmem/shmem.c
+++ b/test/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));
 }