From 04ec0a8dcfe5d08864b6b6699a6a5e5af424dc7e Mon Sep 17 00:00:00 2001 From: Alex Mikheev Date: Tue, 10 Jan 2017 14:21:36 +0200 Subject: [PATCH 1/3] oshmem: spml: add memory allocation hook The hook is called from memheap when memory range is going to be allocated by smalloc(), realloc() and others. ucx spml uses this hook to call ucp_mem_advise in order to speedup non blocking memory mapping. Signed-off-by: Alex Mikheev (cherry picked from commit 986ca000f8398a00be07ccaf1ab4f7a0c84e69d9) --- oshmem/mca/memheap/buddy/memheap_buddy.c | 2 +- .../mca/memheap/ptmalloc/memheap_ptmalloc.c | 3 ++ oshmem/mca/spml/base/base.h | 1 + oshmem/mca/spml/base/spml_base.c | 4 +++ oshmem/mca/spml/ikrit/spml_ikrit.c | 1 + oshmem/mca/spml/spml.h | 11 +++++++ oshmem/mca/spml/ucx/spml_ucx.c | 30 ++++++++++++++++++- oshmem/mca/spml/ucx/spml_ucx.h | 2 ++ oshmem/mca/spml/yoda/spml_yoda.c | 1 + 9 files changed, 53 insertions(+), 2 deletions(-) diff --git a/oshmem/mca/memheap/buddy/memheap_buddy.c b/oshmem/mca/memheap/buddy/memheap_buddy.c index c7715f4dd1d..b3f4ca1df90 100644 --- a/oshmem/mca/memheap/buddy/memheap_buddy.c +++ b/oshmem/mca/memheap/buddy/memheap_buddy.c @@ -469,7 +469,7 @@ static int _do_alloc(uint32_t order, } *p_buff = (void*) addr; - /* no barrier because it is not required by spec! */ + MCA_SPML_CALL(memuse_hook(addr, 1<mem_h, ¶ms); + if (UCS_OK != status) { + SPML_ERROR("ucp_mem_advise failed addr %p len %llu", + addr, (unsigned long long)length); + } +} + sshmem_mkey_t *mca_spml_ucx_register(void* addr, size_t size, uint64_t shmid, diff --git a/oshmem/mca/spml/ucx/spml_ucx.h b/oshmem/mca/spml/ucx/spml_ucx.h index 4b248e026a3..b524031d3f2 100644 --- a/oshmem/mca/spml/ucx/spml_ucx.h +++ b/oshmem/mca/spml/ucx/spml_ucx.h @@ -108,6 +108,8 @@ extern sshmem_mkey_t *mca_spml_ucx_register(void* addr, int *count); extern int mca_spml_ucx_deregister(sshmem_mkey_t *mkeys); +extern void mca_spml_ucx_memuse_hook(void *addr, size_t length); + extern void mca_spml_ucx_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t segno, int pe, int tr_id); extern void mca_spml_ucx_rmkey_free(sshmem_mkey_t *mkey); diff --git a/oshmem/mca/spml/yoda/spml_yoda.c b/oshmem/mca/spml/yoda/spml_yoda.c index 68e8b5acf49..91dbf138ed2 100644 --- a/oshmem/mca/spml/yoda/spml_yoda.c +++ b/oshmem/mca/spml/yoda/spml_yoda.c @@ -65,6 +65,7 @@ mca_spml_yoda_module_t mca_spml_yoda = { mca_spml_yoda_fence, mca_spml_base_rmkey_unpack, mca_spml_base_rmkey_free, + mca_spml_base_memuse_hook, (void *)&mca_spml_yoda } From cf74c5de613f49c02c37f8de92f68a1f62bd37ab Mon Sep 17 00:00:00 2001 From: Alex Mikheev Date: Sun, 29 Jan 2017 10:28:24 +0200 Subject: [PATCH 2/3] oshmem: spml ucx: on error print ucx error string Signed-off-by: Alex Mikheev (cherry picked from commit 9da9e6260dbd6578710bdeab41f6871834cad0d0) --- oshmem/mca/spml/ucx/spml_ucx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/oshmem/mca/spml/ucx/spml_ucx.c b/oshmem/mca/spml/ucx/spml_ucx.c index 986a798cc9b..90a10f1169f 100644 --- a/oshmem/mca/spml/ucx/spml_ucx.c +++ b/oshmem/mca/spml/ucx/spml_ucx.c @@ -288,7 +288,7 @@ int mca_spml_ucx_add_procs(ompi_proc_t **procs, size_t nprocs) &ep_params, &mca_spml_ucx.ucp_peers[i].ucp_conn); if (UCS_OK != err) { - SPML_ERROR("ucp_ep_create failed!!!\n"); + SPML_ERROR("ucp_ep_create failed: %s\n", ucs_status_string(err)); goto error2; } OSHMEM_PROC_DATA(procs[i])->num_transports = 1; @@ -371,7 +371,7 @@ void mca_spml_ucx_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t segno, int pe, int mkey->u.data, &ucx_mkey->rkey); if (UCS_OK != err) { - SPML_ERROR("failed to unpack rkey"); + SPML_ERROR("failed to unpack rkey: %s", ucs_status_string(err)); goto error_fatal; } @@ -407,8 +407,8 @@ void mca_spml_ucx_memuse_hook(void *addr, size_t length) status = ucp_mem_advise(mca_spml_ucx.ucp_context, ucx_mkey->mem_h, ¶ms); if (UCS_OK != status) { - SPML_ERROR("ucp_mem_advise failed addr %p len %llu", - addr, (unsigned long long)length); + SPML_ERROR("ucp_mem_advise failed addr %p len %llu : %s", + addr, (unsigned long long)length, ucs_status_string(status)); } } @@ -567,7 +567,7 @@ int mca_spml_ucx_fence(void) err = ucp_worker_flush(mca_spml_ucx.ucp_worker); if (UCS_OK != err) { - SPML_ERROR("fence failed"); + SPML_ERROR("fence failed: %s", ucs_status_string(err)); oshmem_shmem_abort(-1); return OSHMEM_ERROR; } @@ -580,7 +580,7 @@ int mca_spml_ucx_quiet(void) err = ucp_worker_flush(mca_spml_ucx.ucp_worker); if (UCS_OK != err) { - SPML_ERROR("fence failed"); + SPML_ERROR("fence failed: %s", ucs_status_string(err)); oshmem_shmem_abort(-1); return OSHMEM_ERROR; } From a422154a141f0be5b92d2b6c26d7b2b4176dfe18 Mon Sep 17 00:00:00 2001 From: Alex Mikheev Date: Sun, 29 Jan 2017 16:28:19 +0200 Subject: [PATCH 3/3] oshmem: mem use hook: apply code review fixes Signed-off-by: Alex Mikheev --- oshmem/mca/memheap/buddy/memheap_buddy.c | 2 +- oshmem/mca/spml/ucx/spml_ucx.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/oshmem/mca/memheap/buddy/memheap_buddy.c b/oshmem/mca/memheap/buddy/memheap_buddy.c index b3f4ca1df90..c6f0fdc5642 100644 --- a/oshmem/mca/memheap/buddy/memheap_buddy.c +++ b/oshmem/mca/memheap/buddy/memheap_buddy.c @@ -469,7 +469,7 @@ static int _do_alloc(uint32_t order, } *p_buff = (void*) addr; - MCA_SPML_CALL(memuse_hook(addr, 1<num_transports = 1; @@ -386,8 +386,8 @@ void mca_spml_ucx_rmkey_unpack(sshmem_mkey_t *mkey, uint32_t segno, int pe, int void mca_spml_ucx_memuse_hook(void *addr, size_t length) { - int my_pe = oshmem_my_proc_id(); - spml_ucx_mkey_t *ucx_mkey; + int my_pe; + spml_ucx_mkey_t *ucx_mkey; ucp_mem_advise_params_t params; ucs_status_t status; @@ -395,6 +395,7 @@ void mca_spml_ucx_memuse_hook(void *addr, size_t length) return; } + my_pe = oshmem_my_proc_id(); ucx_mkey = &mca_spml_ucx.ucp_peers[my_pe].mkeys[HEAP_SEG_INDEX].key; params.field_mask = UCP_MEM_ADVISE_PARAM_FIELD_ADDRESS | @@ -567,7 +568,7 @@ int mca_spml_ucx_fence(void) err = ucp_worker_flush(mca_spml_ucx.ucp_worker); if (UCS_OK != err) { - SPML_ERROR("fence failed: %s", ucs_status_string(err)); + SPML_ERROR("fence failed: %s", ucs_status_string(err)); oshmem_shmem_abort(-1); return OSHMEM_ERROR; } @@ -580,7 +581,7 @@ int mca_spml_ucx_quiet(void) err = ucp_worker_flush(mca_spml_ucx.ucp_worker); if (UCS_OK != err) { - SPML_ERROR("fence failed: %s", ucs_status_string(err)); + SPML_ERROR("fence failed: %s", ucs_status_string(err)); oshmem_shmem_abort(-1); return OSHMEM_ERROR; }