From 465e206216d789707d403d7d50488f95d29c02a3 Mon Sep 17 00:00:00 2001 From: Brian Barrett Date: Tue, 5 Jul 2005 22:15:35 +0000 Subject: [PATCH] * fill in some more of the chunk mamagement code (chunks == array of memory used for the rolling recv buffers for non-RDMA messages) This commit was SVN r6355. --- ompi/mca/btl/portals/src/btl_portals_recv.c | 55 ++++++++++++++ ompi/mca/btl/portals/src/btl_portals_recv.h | 84 +++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/ompi/mca/btl/portals/src/btl_portals_recv.c b/ompi/mca/btl/portals/src/btl_portals_recv.c index fe9140efcf..a8fabde6c5 100644 --- a/ompi/mca/btl/portals/src/btl_portals_recv.c +++ b/ompi/mca/btl/portals/src/btl_portals_recv.c @@ -44,3 +44,58 @@ mca_btl_portals_process_recv(mca_btl_portals_module_t *module, { return OMPI_SUCCESS; } + + +mca_btl_portals_recv_chunk_t* +mca_btl_portals_recv_chunk_init(mca_btl_portals_module_t *module) +{ + mca_btl_portals_recv_chunk_t *chunk; + + chunk = OBJ_NEW(mca_btl_portals_recv_chunk_t); + chunk->btl = module; + chunk->length = module->portals_recv_mds_size; + chunk->start = malloc(chunk->length); + if (chunk->start == NULL) return NULL; + + chunk->me_h = PTL_INVALID_HANDLE; + chunk->md_h = PTL_INVALID_HANDLE; + + chunk->full = false; + chunk->pending = 0; + + return chunk; +} + + +int +mca_btl_portals_recv_chunk_free(mca_btl_portals_recv_chunk_t *chunk) +{ + + if (PTL_INVALID_HANDLE != chunk->me_h) { + PtlMEUnlink(chunk->me_h); + chunk->me_h = PTL_INVALID_HANDLE; + } + + while (chunk->pending != 0) { + mca_btl_portals_component_progress(); + } + + if (PTL_INVALID_HANDLE != chunk->md_h) { + PtlMDUnlink(chunk->md_h); + chunk->md_h = PTL_INVALID_HANDLE; + } + + if (NULL != chunk->start) { + free(chunk->start); + chunk->start = NULL; + } + chunk->length = 0; + chunk->full = false; + + return OMPI_SUCCESS; +} + + +OBJ_CLASS_INSTANCE(mca_btl_portals_recv_chunk_t, + opal_list_item_t, + NULL, NULL); diff --git a/ompi/mca/btl/portals/src/btl_portals_recv.h b/ompi/mca/btl/portals/src/btl_portals_recv.h index 4e7fdf56b7..fb10de9d95 100644 --- a/ompi/mca/btl/portals/src/btl_portals_recv.h +++ b/ompi/mca/btl/portals/src/btl_portals_recv.h @@ -17,6 +17,23 @@ #ifndef MCA_BTL_PORTALS_RECV_H #define MCA_BTL_PORTALS_RECV_H +struct mca_btl_portals_recv_chunk_t { + opal_list_item_t base; + + mca_btl_portals_module_t *btl; + + void *start; + size_t length; + ptl_handle_me_t me_h; + ptl_handle_md_t md_h; + + volatile bool full; + volatile int32_t pending; +}; +typedef struct mca_btl_portals_recv_chunk_t mca_btl_portals_recv_chunk_t; +OBJ_CLASS_DECLARATION(mca_btl_portals_recv_chunk_t); + + int mca_btl_portals_recv_enable(mca_btl_portals_module_t *module); int mca_btl_portals_recv_disable(mca_btl_portals_module_t *module); @@ -24,5 +41,72 @@ int mca_btl_portals_recv_disable(mca_btl_portals_module_t *module); int mca_btl_portals_process_recv(mca_btl_portals_module_t *module, ptl_event_t *ev); +/** + * Create a chunk of memory for receiving send messages. Must call + * activate_chunk on the returned chunk of memory before it will be + * active with the POrtals library */ +mca_btl_portals_recv_chunk_t* +mca_btl_portals_recv_chunk_init(mca_btl_portals_module_t *module); + +/** + * Free a chunk of memory. Will remove the match entry, then progress + * Portals until the pending count is returned to 0. Will then free + * all resources associated with chunk. + */ +int mca_btl_portals_recv_chunk_free(mca_btl_portals_recv_chunk_t *chunk); + +/* + * activate a chunk. Chunks that are full (have gone inactive) can be + * re-activated with this call + */ +static inline int +mca_btl_portals_activate_chunk(mca_btl_portals_recv_chunk_t *chunk) +{ + int ret; + ptl_process_id_t proc = { PTL_NID_ANY, PTL_PID_ANY }; + ptl_md_t md; + + /* if we have pending operations, something very, very, very bad + has happened... */ + assert(chunk->pending == 0); + + if (NULL == chunk->start) return OMPI_ERROR; + + /* create match entry */ + ret = PtlMEAttach(chunk->btl->portals_ni_h, + BTL_PORTALS_SEND_TABLE_ID, + proc, + 0, /* match bits */ + 0, /* ignore bits */ + PTL_UNLINK, + PTL_INS_AFTER, + &(chunk->me_h)); + if (PTL_OK != ret) return OMPI_ERROR; + + /* and the memory descriptor */ + md.start = chunk->start; + md.length = chunk->length; + md.threshold = PTL_MD_THRESH_INF; + md.max_size = chunk->btl->super.btl_max_send_size; + md.options = PTL_MD_OP_PUT | PTL_MD_MAX_SIZE; + md.user_ptr = chunk; + md.eq_handle = chunk->btl->portals_eq_handles[MCA_BTL_PORTALS_EQ_RECV]; + + chunk->full = false; + + ret = PtlMDAttach(chunk->me_h, + md, + PTL_UNLINK, + &(chunk->md_h)); + if (PTL_OK != ret) { + PtlMEUnlink(chunk->me_h); + return OMPI_ERROR; + } + + OPAL_OUTPUT_VERBOSE((100, mca_btl_portals_component.portals_output, + "new receive buffer posted")); + + return OMPI_SUCCESS; +} #endif /* MCA_BTL_PORTALS_RECV_H */