diff --git a/ompi/datatype/Makefile.am b/ompi/datatype/Makefile.am index 643e8147fdd..aa059568e68 100644 --- a/ompi/datatype/Makefile.am +++ b/ompi/datatype/Makefile.am @@ -41,6 +41,7 @@ libdatatype_la_SOURCES = \ ompi_datatype_create_subarray.c \ ompi_datatype_external.c \ ompi_datatype_external32.c \ + ompi_datatype_lookup_by_opal_id.c \ ompi_datatype_match_size.c \ ompi_datatype_module.c \ ompi_datatype_sndrcv.c \ diff --git a/ompi/datatype/ompi_datatype.h b/ompi/datatype/ompi_datatype.h index 0c77079b916..004832c3312 100644 --- a/ompi/datatype/ompi_datatype.h +++ b/ompi/datatype/ompi_datatype.h @@ -295,6 +295,8 @@ ompi_datatype_copy_content_same_ddt( const ompi_datatype_t* type, size_t count, return 0; } +OMPI_DECLSPEC ompi_datatype_t* ompi_datatype_lookup_by_opal_id( uint16_t opal_id ); + OMPI_DECLSPEC const ompi_datatype_t* ompi_datatype_match_size( int size, uint16_t datakind, uint16_t datalang ); /* diff --git a/ompi/datatype/ompi_datatype_lookup_by_opal_id.c b/ompi/datatype/ompi_datatype_lookup_by_opal_id.c new file mode 100644 index 00000000000..6c77069fe9c --- /dev/null +++ b/ompi/datatype/ompi_datatype_lookup_by_opal_id.c @@ -0,0 +1,28 @@ +/* -*- Mode: C; c-basic-offset:4 ; -*- */ +/* + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "ompi_config.h" +#include "ompi/datatype/ompi_datatype.h" +#include "ompi/datatype/ompi_datatype_internal.h" + + +ompi_datatype_t* ompi_datatype_lookup_by_opal_id( uint16_t opal_id ) +{ + int32_t i; + const ompi_datatype_t* datatype = NULL; + + for (int j = 0 ; j < OMPI_DATATYPE_MPI_MAX_PREDEFINED ; ++j) { + if (ompi_datatype_basicDatatypes[j]->super.id == opal_id) { + datatype = (ompi_datatype_t *) ompi_datatype_basicDatatypes[j]; + break; + } + } + + return datatype; +} diff --git a/ompi/include/mpi.h.in b/ompi/include/mpi.h.in index 15025e73391..52d92d7bbdd 100644 --- a/ompi/include/mpi.h.in +++ b/ompi/include/mpi.h.in @@ -454,8 +454,8 @@ typedef struct ompi_mpit_cvar_handle_t *MPI_T_cvar_handle; typedef struct mca_base_pvar_handle_t *MPI_T_pvar_handle; typedef struct mca_base_pvar_session_t *MPI_T_pvar_session; typedef struct ompi_instance_t *MPI_Session; -typedef unsigned long *MPI_T_event_instance; -typedef unsigned long *MPI_T_event_registration; +typedef struct mca_base_raised_event_t *MPI_T_event_instance; +typedef struct mca_base_event_registration_t *MPI_T_event_registration; /* * MPI_Status diff --git a/ompi/mca/osc/rdma/osc_rdma.h b/ompi/mca/osc/rdma/osc_rdma.h index b18d2d7c4d0..d9070083262 100644 --- a/ompi/mca/osc/rdma/osc_rdma.h +++ b/ompi/mca/osc/rdma/osc_rdma.h @@ -57,6 +57,34 @@ #include "osc_rdma_peer.h" #include "opal_stdint.h" +#include "opal/mca/base/mca_base_event.h" + +enum { + OMPI_OSC_RDMA_EVENT_LOCK_ACQUIRED, + OMPI_OSC_RDMA_EVENT_LOCK_RELEASED, + OMPI_OSC_RDMA_EVENT_PUT_STARTED, + OMPI_OSC_RDMA_EVENT_PUT_COMPLETE, + OMPI_OSC_RDMA_EVENT_GET_STARTED, + OMPI_OSC_RDMA_EVENT_GET_COMPLETE, + OMPI_OSC_RDMA_EVENT_FLUSH_STARTED, + OMPI_OSC_RDMA_EVENT_FLUSH_COMPLETE, + OMPI_OSC_RDMA_EVENT_PSCW_EXPOSE_START, + OMPI_OSC_RDMA_EVENT_PSCW_EXPOSE_COMPLETE, + OMPI_OSC_RDMA_EVENT_PSCW_ACCESS_START, + OMPI_OSC_RDMA_EVENT_PSCW_ACCESS_COMPLETE, + OMPI_OSC_RDMA_EVENT_FENCE, + OMPI_OSC_RDMA_EVENT_MAX, +}; + +struct mca_osc_rdma_rdma_event_t { + int target; + uint64_t address; + uint64_t size; +}; + +typedef struct mca_osc_rdma_rdma_event_t mca_osc_rdma_rdma_event_t; + +extern mca_base_event_list_item_t mca_osc_rdma_events[]; #define RANK_ARRAY_COUNT(module) ((ompi_comm_size ((module)->comm) + (module)->node_count - 1) / (module)->node_count) diff --git a/ompi/mca/osc/rdma/osc_rdma_active_target.c b/ompi/mca/osc/rdma/osc_rdma_active_target.c index 9858151fa67..564777593bd 100644 --- a/ompi/mca/osc/rdma/osc_rdma_active_target.c +++ b/ompi/mca/osc/rdma/osc_rdma_active_target.c @@ -182,6 +182,8 @@ static void ompi_osc_rdma_handle_post (ompi_osc_rdma_module_t *module, int rank, rank, (int) (npeers - state->num_post_msgs - 1)); /* an atomic is not really necessary as this function is currently used but it doesn't hurt */ ompi_osc_rdma_counter_add (&state->num_post_msgs, 1); + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_PSCW_ACCESS_START].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &rank); return; } } @@ -307,6 +309,9 @@ int ompi_osc_rdma_post_atomic (ompi_group_t *group, int mpi_assert, ompi_win_t * return OMPI_SUCCESS; } + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_PSCW_EXPOSE_START].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, NULL); + /* translate group ranks into the communicator */ peers = ompi_osc_rdma_get_peers (module, module->pw_group); if (OPAL_UNLIKELY(NULL == peers)) { @@ -394,6 +399,8 @@ int ompi_osc_rdma_start_atomic (ompi_group_t *group, int mpi_assert, ompi_win_t "from %d processes", peer->rank, (int) (group_size - state->num_post_msgs - 1)); opal_list_remove_item (&module->pending_posts, &pending_post->super); OBJ_RELEASE(pending_post); + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_PSCW_ACCESS_START].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &peer->rank); ompi_osc_rdma_counter_add (&state->num_post_msgs, 1); break; } @@ -464,6 +471,9 @@ int ompi_osc_rdma_complete_atomic (ompi_win_t *win) ompi_osc_rdma_peer_t *peer = peers[i]; intptr_t target = (intptr_t) peer->state + offsetof (ompi_osc_rdma_state_t, num_complete_msgs); + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_PSCW_ACCESS_COMPLETE].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &peer->rank); + if (!ompi_osc_rdma_peer_local_state (peer)) { ret = ompi_osc_rdma_lock_btl_op (module, peer, target, MCA_BTL_ATOMIC_ADD, 1, true); assert (OMPI_SUCCESS == ret); @@ -507,6 +517,9 @@ int ompi_osc_rdma_wait_atomic (ompi_win_t *win) opal_atomic_mb (); } + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_PSCW_EXPOSE_COMPLETE].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, NULL); + OPAL_THREAD_LOCK(&module->lock); group = module->pw_group; module->pw_group = NULL; @@ -556,6 +569,9 @@ int ompi_osc_rdma_test_atomic (ompi_win_t *win, int *flag) module->pw_group = NULL; OPAL_THREAD_UNLOCK(&(module->lock)); + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_PSCW_EXPOSE_COMPLETE].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, NULL); + OBJ_RELEASE(group); OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "test complete. returning flag: true"); diff --git a/ompi/mca/osc/rdma/osc_rdma_comm.c b/ompi/mca/osc/rdma/osc_rdma_comm.c index 9b519e36eaf..2ab3a2b1f46 100644 --- a/ompi/mca/osc/rdma/osc_rdma_comm.c +++ b/ompi/mca/osc/rdma/osc_rdma_comm.c @@ -15,8 +15,7 @@ * $HEADER$ */ -#include "ompi_config.h" - +#include "osc_rdma.h" #include "osc_rdma_comm.h" #include "osc_rdma_frag.h" #include "osc_rdma_sync.h" @@ -461,6 +460,9 @@ static int ompi_osc_rdma_put_real (ompi_osc_rdma_sync_t *sync, ompi_osc_rdma_pee OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "initiating btl put of %lu bytes to remote address %" PRIx64 ", sync " "object %p...", (unsigned long) size, target_address, (void *) sync); + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_PUT_STARTED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &((mca_osc_rdma_rdma_event_t){.target = peer->rank, .address = target_address, .size = size})); + /* flag outstanding rma requests */ ompi_osc_rdma_sync_rdma_inc (sync); @@ -725,6 +727,9 @@ static int ompi_osc_rdma_get_contig (ompi_osc_rdma_sync_t *sync, ompi_osc_rdma_p ompi_osc_rdma_sync_rdma_inc (sync); } + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_GET_STARTED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &((mca_osc_rdma_rdma_event_t){.target = peer->rank, .address = source_address, .size = size})); + do { ret = ompi_osc_rdma_btl_get(module, peer->data_btl_index, peer->data_endpoint, ptr, aligned_source_base, local_handle, source_handle, diff --git a/ompi/mca/osc/rdma/osc_rdma_component.c b/ompi/mca/osc/rdma/osc_rdma_component.c index a7a005a8afe..7e285e9a148 100644 --- a/ompi/mca/osc/rdma/osc_rdma_component.c +++ b/ompi/mca/osc/rdma/osc_rdma_component.c @@ -85,6 +85,87 @@ static const char* ompi_osc_rdma_set_no_lock_info(opal_infosubscriber_t *obj, co static char *ompi_osc_rdma_full_connectivity_btls; +static char *mca_osc_rdma_target_element[] = { + "target", NULL, +}; + +static opal_datatype_t *mca_osc_rdma_rdma_event_types[] = { + &ompi_mpi_int.dt.super, &ompi_mpi_int64_t.dt.super, &ompi_mpi_int64_t.dt.super, +}; + +static char *mca_osc_rdma_rdma_event_elements[] = { + "target", "address", "size_bytes", NULL, +}; + +static unsigned long mca_osc_rdma_rdma_event_offsets[] = { + offsetof (mca_osc_rdma_rdma_event_t, target), offsetof (mca_osc_rdma_rdma_event_t, address), + offsetof (mca_osc_rdma_rdma_event_t, size), +}; + +mca_base_event_list_item_t mca_osc_rdma_events[] = { + [OMPI_OSC_RDMA_EVENT_LOCK_ACQUIRED] = {.name = "lock_acquired", .desc = "Passive-target lock aquired", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_LOCK_RELEASED] = {.name = "lock_released", .desc = "Passive-target lock released", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_PUT_STARTED] = {.name = "put_started", .desc = "Put started to target. Complete event may not exist.", + .verbosity = OPAL_INFO_LVL_5, .datatypes = mca_osc_rdma_rdma_event_types, + .offsets = mca_osc_rdma_rdma_event_offsets, .num_datatypes = 3, + .elements = mca_osc_rdma_rdma_event_elements, .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_PUT_COMPLETE] = {.name = "put_complete", .desc = "Put completed on target", + .verbosity = OPAL_INFO_LVL_5, .datatypes = mca_osc_rdma_rdma_event_types, + .offsets = mca_osc_rdma_rdma_event_offsets, .num_datatypes = 3, + .elements = mca_osc_rdma_rdma_event_elements, .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_GET_STARTED] = {.name = "get_started", .desc = "Get started to target. Complete event may not exist.", + .verbosity = OPAL_INFO_LVL_5, .datatypes = mca_osc_rdma_rdma_event_types, + .offsets = mca_osc_rdma_rdma_event_offsets, .num_datatypes = 3, + .elements = mca_osc_rdma_rdma_event_elements, .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_GET_COMPLETE] = {.name = "get_complete", .desc = "Get completed on target", + .verbosity = OPAL_INFO_LVL_5, .datatypes = mca_osc_rdma_rdma_event_types, + .offsets = mca_osc_rdma_rdma_event_offsets, .num_datatypes = 3, + .elements = mca_osc_rdma_rdma_event_elements, .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_FLUSH_STARTED] = {.name = "flush_started", .desc = "Flush started on target", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_FLUSH_COMPLETE] = {.name = "flush_complete", .desc = "Flush complete on target", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_PSCW_EXPOSE_START] = {.name = "pscw_expose_start", .desc = "PSCW exposure started", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 0, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_PSCW_EXPOSE_COMPLETE] = {.name = "pscw_expose_complete", .desc = "PSCW exposure complete", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 0, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_PSCW_ACCESS_START] = {.name = "pscw_access_start", .desc = "PSCW access epoch started", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_PSCW_ACCESS_COMPLETE] = {.name = "pscw_access_complete", .desc = "PSCW access epoch complete", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_int.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_osc_rdma_target_element, + .bind = MCA_BASE_VAR_BIND_MPI_WIN}, + + [OMPI_OSC_RDMA_EVENT_FENCE] = {.name = "fence", .desc = "Fence called", .verbosity = OPAL_INFO_LVL_5, .bind = MCA_BASE_VAR_BIND_MPI_WIN}, +}; + static const mca_base_var_enum_value_t ompi_osc_rdma_locking_modes[] = { {.value = OMPI_OSC_RDMA_LOCKING_TWO_LEVEL, .string = "two_level"}, {.value = OMPI_OSC_RDMA_LOCKING_ON_DEMAND, .string = "on_demand"}, @@ -305,6 +386,8 @@ static int ompi_osc_rdma_component_register (void) ompi_osc_rdma_pvar_read, NULL, NULL, (void *) (intptr_t) offsetof (ompi_osc_rdma_module_t, get_retry_count)); + mca_base_component_event_register_list (&mca_osc_rdma_component.super.osc_version, mca_osc_rdma_events, OMPI_OSC_RDMA_EVENT_MAX); + return OMPI_SUCCESS; } diff --git a/ompi/mca/osc/rdma/osc_rdma_passive_target.c b/ompi/mca/osc/rdma/osc_rdma_passive_target.c index 8154c8da176..8676792c955 100644 --- a/ompi/mca/osc/rdma/osc_rdma_passive_target.c +++ b/ompi/mca/osc/rdma/osc_rdma_passive_target.c @@ -56,9 +56,15 @@ int ompi_osc_rdma_flush (int target, struct ompi_win_t *win) } OPAL_THREAD_UNLOCK(&module->lock); + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_FLUSH_STARTED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &target); + /* finish all outstanding fragments */ ompi_osc_rdma_sync_rdma_complete (lock); + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_FLUSH_COMPLETE].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &target); + OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "flush on target %d complete", target); return OMPI_SUCCESS; @@ -85,6 +91,9 @@ int ompi_osc_rdma_flush_all (struct ompi_win_t *win) ompi_osc_rdma_sync_rdma_complete (&module->all_sync); } + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_FLUSH_STARTED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &(int) {-1}); + /* flush all locks */ ret = opal_hash_table_get_first_key_uint32 (&module->outstanding_locks, &key, (void **) &lock, &node); while (OPAL_SUCCESS == ret) { @@ -94,6 +103,9 @@ int ompi_osc_rdma_flush_all (struct ompi_win_t *win) node, &node); } + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_FLUSH_COMPLETE].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &(int) {-1}); + OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "flush_all complete"); return OPAL_SUCCESS; @@ -159,6 +171,9 @@ static inline int ompi_osc_rdma_lock_atomic_internal (ompi_osc_rdma_module_t *mo } while (1); } + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_LOCK_ACQUIRED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &peer->rank); + return OMPI_SUCCESS; } @@ -183,6 +198,10 @@ static inline int ompi_osc_rdma_unlock_atomic_internal (ompi_osc_rdma_module_t * peer->flags &= ~OMPI_OSC_RDMA_PEER_DEMAND_LOCKED; } + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_LOCK_RELEASED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &peer->rank); + + return OMPI_SUCCESS; } @@ -355,6 +374,9 @@ int ompi_osc_rdma_lock_all_atomic (int mpi_assert, struct ompi_win_t *win) ret = ompi_osc_rdma_lock_acquire_shared (module, module->leader, 0x0000000100000000UL, offsetof(ompi_osc_rdma_state_t, global_lock), 0x00000000ffffffffUL); + + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_LOCK_ACQUIRED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &(int) {-1}); } else { /* always lock myself */ ret = ompi_osc_rdma_demand_lock_peer (module, module->my_peer); @@ -410,6 +432,9 @@ int ompi_osc_rdma_unlock_all_atomic (struct ompi_win_t *win) /* decrement the master lock shared count */ (void) ompi_osc_rdma_lock_release_shared (module, module->leader, -0x0000000100000000UL, offsetof (ompi_osc_rdma_state_t, global_lock)); + + MCA_BASE_EVENT_RAISE(mca_osc_rdma_events[OMPI_OSC_RDMA_EVENT_LOCK_RELEASED].event, MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + module->win, NULL, &(int) {-1}); } } diff --git a/ompi/mca/pml/ob1/pml_ob1.c b/ompi/mca/pml/ob1/pml_ob1.c index e0516d16fe0..65ffb343e4e 100644 --- a/ompi/mca/pml/ob1/pml_ob1.c +++ b/ompi/mca/pml/ob1/pml_ob1.c @@ -14,7 +14,7 @@ * Copyright (c) 2006-2008 University of Houston. All rights reserved. * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved * Copyright (c) 2011 Sandia National Laboratories. All rights reserved. - * Copyright (c) 2011-2015 Los Alamos National Security, LLC. All rights + * Copyright (c) 2011-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015 FUJITSU LIMITED. All rights reserved. @@ -305,8 +305,8 @@ int mca_pml_ob1_add_comm(ompi_communicator_t* comm) * figure out if the messages are not received in the correct * order (if multiple network interfaces). */ - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_MSG_ARRIVED, comm, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_MESSAGE_ARRIVED].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, hdr); /* There is no matching to be done, and no lock to be held on the communicator as * we know at this point that the communicator has not yet been returned to the user. @@ -322,8 +322,8 @@ int mca_pml_ob1_add_comm(ompi_communicator_t* comm) #else custom_match_umq_append(pml_comm->umq, hdr->hdr_tag, hdr->hdr_src, frag); #endif - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_MSG_INSERT_IN_UNEX_Q, comm, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_UNEX_INSERT].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, hdr); continue; } @@ -337,8 +337,9 @@ int mca_pml_ob1_add_comm(ompi_communicator_t* comm) #else custom_match_umq_append(pml_comm->umq, hdr->hdr_tag, hdr->hdr_src, frag); #endif - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_MSG_INSERT_IN_UNEX_Q, comm, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_UNEX_INSERT].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, hdr); + /* And now the ugly part. As some fragments can be inserted in the cant_match list, * every time we successfully add a fragment in the unexpected list we have to make * sure the next one is not in the cant_match. Otherwise, we will endup in a deadlock diff --git a/ompi/mca/pml/ob1/pml_ob1.h b/ompi/mca/pml/ob1/pml_ob1.h index a0091793ab4..00e113babca 100644 --- a/ompi/mca/pml/ob1/pml_ob1.h +++ b/ompi/mca/pml/ob1/pml_ob1.h @@ -44,6 +44,7 @@ #include "ompi/proc/proc.h" #include "opal/mca/allocator/base/base.h" #include "ompi/runtime/mpiruntime.h" +#include "opal/mca/base/mca_base_event.h" BEGIN_C_DECLS @@ -91,6 +92,34 @@ struct mca_pml_ob1_t { }; typedef struct mca_pml_ob1_t mca_pml_ob1_t; +enum { + MCA_PML_OB1_EVENT_MESSAGE_ARRIVED, + MCA_PML_OB1_EVENT_SEARCH_POSTED_BEGIN, + MCA_PML_OB1_EVENT_SEARCH_POSTED_END, + MCA_PML_OB1_EVENT_SEARCH_UNEX_BEGIN, + MCA_PML_OB1_EVENT_SEARCH_UNEX_END, + MCA_PML_OB1_EVENT_POSTED_INSERT, + MCA_PML_OB1_EVENT_POSTED_REMOVE, + MCA_PML_OB1_EVENT_UNEX_INSERT, + MCA_PML_OB1_EVENT_UNEX_REMOVE, + MCA_PML_OB1_EVENT_TRANSFER_BEGIN, + MCA_PML_OB1_EVENT_TRANSFER, + MCA_PML_OB1_EVENT_TRANSFER_END, + MCA_PML_OB1_EVENT_RECEIVE_CANCELED, + MCA_PML_OB1_EVENT_REQUEST_FREE, + MCA_PML_OB1_EVENT_REQUEST_ACTIVATE, + MCA_PML_OB1_EVENT_REQUEST_COMPLETE, + MCA_PML_OB1_EVENT_MAX, +}; + +extern mca_base_event_list_item_t mca_pml_ob1_events[]; + +struct mca_pml_ob1_transfer_event_t { + void *request; + int64_t length; +}; +typedef struct mca_pml_ob1_transfer_event_t mca_pml_ob1_transfer_event_t; + extern mca_pml_ob1_t mca_pml_ob1; extern int mca_pml_ob1_output; extern bool mca_pml_ob1_matching_protection; diff --git a/ompi/mca/pml/ob1/pml_ob1_component.c b/ompi/mca/pml/ob1/pml_ob1_component.c index 74786121e4f..6a9b5d1f01f 100644 --- a/ompi/mca/pml/ob1/pml_ob1_component.c +++ b/ompi/mca/pml/ob1/pml_ob1_component.c @@ -12,7 +12,7 @@ * All rights reserved. * Copyright (c) 2007-2010 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved - * Copyright (c) 2013-2017 Los Alamos National Security, LLC. All rights + * Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2018 Sandia National Laboratories * All rights reserved. @@ -64,6 +64,110 @@ static int mca_pml_ob1_verbose = 0; bool mca_pml_ob1_matching_protection = false; int mca_pml_ob1_accelerator_events_max = 400; +static opal_datatype_t *mca_pml_ob1_match_hdr_types[] = { + &ompi_mpi_int16_t.dt.super, &ompi_mpi_int32_t.dt.super, + &ompi_mpi_int32_t.dt.super, &ompi_mpi_int16_t.dt.super, +}; + +static opal_datatype_t *mca_pml_ob1_request_size_types[] = { + &ompi_mpi_aint.dt.super, &ompi_mpi_int64_t.dt.super, +}; + +static unsigned long mca_pml_ob1_match_hdr_offsets[] = { + offsetof (mca_pml_ob1_match_hdr_t, hdr_ctx), offsetof (mca_pml_ob1_match_hdr_t, hdr_src), + offsetof (mca_pml_ob1_match_hdr_t, hdr_tag), offsetof (mca_pml_ob1_match_hdr_t, hdr_seq), +}; + +static unsigned long mca_pml_ob1_request_size_offsets[] = { + offsetof (mca_pml_ob1_transfer_event_t, request), offsetof (mca_pml_ob1_transfer_event_t, length), +}; + +static char *mca_pml_ob1_match_hdr_names[] = { + "context id", "source", "tag", "sequence number", NULL, +}; + +static char *mca_pml_ob1_request_element[] = { + "request", NULL, +}; + +static char *mca_pml_ob1_request_size_elements[] = { + "request", "length", NULL, +}; + + +mca_base_event_list_item_t mca_pml_ob1_events[] = { + [MCA_PML_OB1_EVENT_MESSAGE_ARRIVED] = {.name = "message_arrived", .desc = "Message arrived for match", + .verbosity = OPAL_INFO_LVL_5, .datatypes = mca_pml_ob1_match_hdr_types, + .offsets = mca_pml_ob1_match_hdr_offsets, .num_datatypes = 4, + .elements = mca_pml_ob1_match_hdr_names, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_SEARCH_POSTED_BEGIN] = {.name = "search_posted_begin", .desc = "Begin searching posted message queue", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &mca_pml_ob1_match_hdr_types[1], + .offsets = &mca_pml_ob1_match_hdr_offsets[1], .num_datatypes = 3, + .elements = &mca_pml_ob1_match_hdr_names[1], .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_SEARCH_POSTED_END] = {.name = "search_posted_end", .desc = "Finished searching posted message queue", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &mca_pml_ob1_match_hdr_types[1], + .offsets = &mca_pml_ob1_match_hdr_offsets[1], .num_datatypes = 3, + .elements = &mca_pml_ob1_match_hdr_names[1], .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_SEARCH_UNEX_BEGIN] = {.name = "search_unexpected_begin", .desc = "Begin searching unexpected message queue", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_pml_ob1_request_element, + .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_SEARCH_UNEX_END] = {.name = "search_unexpected_end", .desc = "Finished searching unexpected message queue", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_pml_ob1_request_element, + .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_POSTED_INSERT] = {.name = "posted_insert", .desc = "Added request to the posted message queue", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_pml_ob1_request_element, + .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_POSTED_REMOVE] = {.name = "posted_remove", .desc = "Remove request from the posted message queue", + .verbosity = OPAL_INFO_LVL_5, .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, + .offsets = &(unsigned long) {0}, .num_datatypes = 1, .elements = mca_pml_ob1_request_element, + .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_UNEX_INSERT] = {.name = "unex_insert", .desc = "Unexpected message inserted in queue", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &mca_pml_ob1_match_hdr_types[1], .offsets = &mca_pml_ob1_match_hdr_offsets[1], + .num_datatypes = 2, .elements = &mca_pml_ob1_match_hdr_names[1], .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_UNEX_REMOVE] = {.name = "unex_remove", .desc = "Unexpected message removed from queue", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &mca_pml_ob1_match_hdr_types[1], .offsets = &mca_pml_ob1_match_hdr_offsets[1], + .num_datatypes = 2, .elements = &mca_pml_ob1_match_hdr_names[1], .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_TRANSFER_BEGIN] = {.name = "transfer_begin", .desc = "Transfer has begun", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, .offsets = &(unsigned long) {0}, .num_datatypes = 1, + .elements = mca_pml_ob1_request_element, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_TRANSFER] = {.name = "transfer", .desc = "Transfer event", .verbosity = OPAL_INFO_LVL_5, + .datatypes = mca_pml_ob1_request_size_types, .offsets = mca_pml_ob1_request_size_offsets, .num_datatypes = 2, + .elements = mca_pml_ob1_request_size_elements, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_TRANSFER_END] = {.name = "transfer_end", .desc = "Transfer has completed", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, .offsets = &(unsigned long) {0}, .num_datatypes = 1, + .elements = mca_pml_ob1_request_element, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_RECEIVE_CANCELED] = {.name = "cancel", .desc = "Receive request canceled", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, .offsets = &(unsigned long) {0}, .num_datatypes = 1, + .elements = mca_pml_ob1_request_element, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_REQUEST_FREE] = {.name = "free", .desc = "Request object freed", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, .offsets = &(unsigned long) {0}, .num_datatypes = 1, + .elements = mca_pml_ob1_request_element, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_REQUEST_ACTIVATE] = {.name = "request_activate", .desc = "Request activated", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, .offsets = &(unsigned long) {0}, .num_datatypes = 1, + .elements = mca_pml_ob1_request_element, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, + + [MCA_PML_OB1_EVENT_REQUEST_COMPLETE] = {.name = "request_complete", .desc = "Request completed", .verbosity = OPAL_INFO_LVL_5, + .datatypes = &(opal_datatype_t *) {&ompi_mpi_aint.dt.super}, .offsets = &(unsigned long) {0}, .num_datatypes = 1, + .elements = mca_pml_ob1_request_element, .bind = MCA_BASE_VAR_BIND_MPI_COMM}, +}; + mca_pml_base_component_2_1_0_t mca_pml_ob1_component = { /* First, the mca_base_component_t struct containing meta information about the component itself */ @@ -243,11 +347,7 @@ static int mca_pml_ob1_component_register(void) MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS, mca_pml_ob1_get_posted_recvq_size, NULL, mca_pml_ob1_comm_size_notify, NULL); - mca_pml_ob1_accelerator_events_max = 400; - (void) mca_base_component_var_register(&mca_pml_ob1_component.pmlm_version, "accelerator_events_max", - "Number of events created by the ob1 component internally", - MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, - MCA_BASE_VAR_SCOPE_READONLY, &mca_pml_ob1_accelerator_events_max); + mca_base_component_event_register_list (&mca_pml_ob1_component.pmlm_version, mca_pml_ob1_events, MCA_PML_OB1_EVENT_MAX); return OMPI_SUCCESS; } diff --git a/ompi/mca/pml/ob1/pml_ob1_irecv.c b/ompi/mca/pml/ob1/pml_ob1_irecv.c index 4ccb8ea00f2..d3207bd40a8 100644 --- a/ompi/mca/pml/ob1/pml_ob1_irecv.c +++ b/ompi/mca/pml/ob1/pml_ob1_irecv.c @@ -10,7 +10,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 Sandia National Laboratories. All rights reserved. @@ -60,9 +60,8 @@ int mca_pml_ob1_irecv_init(void *addr, addr, count, datatype, src, tag, comm, true); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &((recvreq)->req_recv.req_base), - PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &recvreq); /* Work around a leak in start by marking this request as complete. The * problem occurred because we do not have a way to differentiate an @@ -92,9 +91,8 @@ int mca_pml_ob1_irecv(void *addr, addr, count, datatype, src, tag, comm, false); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &((recvreq)->req_recv.req_base), - PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &recvreq); MCA_PML_OB1_RECV_REQUEST_START(recvreq); *request = (ompi_request_t *) recvreq; @@ -128,9 +126,8 @@ int mca_pml_ob1_recv(void *addr, MCA_PML_OB1_RECV_REQUEST_INIT(recvreq, addr, count, datatype, src, tag, comm, false); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &(recvreq->req_recv.req_base), - PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &recvreq); MCA_PML_OB1_RECV_REQUEST_START(recvreq); ompi_request_wait_completion(&recvreq->req_recv.req_base.req_ompi); @@ -221,9 +218,8 @@ mca_pml_ob1_imrecv( void *buf, src, tag, comm, false); OBJ_RELEASE(comm); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &((recvreq)->req_recv.req_base), - PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &recvreq); /* init/re-init the request */ recvreq->req_lock = 0; @@ -314,9 +310,8 @@ mca_pml_ob1_mrecv( void *buf, src, tag, comm, false); OBJ_RELEASE(comm); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &((recvreq)->req_recv.req_base), - PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &recvreq); /* init/re-init the request */ recvreq->req_lock = 0; diff --git a/ompi/mca/pml/ob1/pml_ob1_isend.c b/ompi/mca/pml/ob1/pml_ob1_isend.c index b3e1741a239..42eefb9964b 100644 --- a/ompi/mca/pml/ob1/pml_ob1_isend.c +++ b/ompi/mca/pml/ob1/pml_ob1_isend.c @@ -10,7 +10,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights + * Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2014-2021 Cisco Systems, Inc. All rights reserved * Copyright (c) 2015 Research Organization for Information Science @@ -61,9 +61,8 @@ int mca_pml_ob1_isend_init(const void *buf, MCA_PML_OB1_SEND_REQUEST_INIT(sendreq, buf, count, datatype, dst, tag, comm, sendmode, true, ob1_proc); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &(sendreq)->req_send.req_base, - PERUSE_SEND); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &sendreq); /* Work around a leak in start by marking this request as complete. The * problem occurred because we do not have a way to differentiate an @@ -207,9 +206,8 @@ int mca_pml_ob1_isend(const void *buf, dst, tag, comm, sendmode, false, ob1_proc); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &(sendreq)->req_send.req_base, - PERUSE_SEND); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &sendreq); MCA_PML_OB1_SEND_REQUEST_START_W_SEQ(sendreq, endpoint, seqn, rc); *request = (ompi_request_t *) sendreq; @@ -318,9 +316,8 @@ int mca_pml_ob1_send(const void *buf, MCA_PML_OB1_SEND_REQUEST_INIT(sendreq, buf, count, datatype, dst, tag, comm, sendmode, false, ob1_proc); - PERUSE_TRACE_COMM_EVENT (PERUSE_COMM_REQ_ACTIVATE, - &sendreq->req_send.req_base, - PERUSE_SEND); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_ACTIVATE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, comm, NULL, &sendreq); MCA_PML_OB1_SEND_REQUEST_START_W_SEQ(sendreq, endpoint, seqn, rc); if (OPAL_LIKELY(rc == OMPI_SUCCESS)) { diff --git a/ompi/mca/pml/ob1/pml_ob1_recvfrag.c b/ompi/mca/pml/ob1/pml_ob1_recvfrag.c index a3db1458938..e68cb16ed3c 100644 --- a/ompi/mca/pml/ob1/pml_ob1_recvfrag.c +++ b/ompi/mca/pml/ob1/pml_ob1_recvfrag.c @@ -1,3 +1,4 @@ + /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana @@ -13,7 +14,7 @@ * Copyright (c) 2008 UT-Battelle, LLC. All rights reserved. * Copyright (c) 2006-2008 University of Houston. All rights reserved. * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights + * Copyright (c) 2012-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. @@ -494,8 +495,8 @@ void mca_pml_ob1_recv_frag_callback_match (mca_btl_base_module_t *btl, * figure out if the messages are not received in the correct * order (if multiple network interfaces). */ - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_MSG_ARRIVED, comm_ptr, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_MESSAGE_ARRIVED].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm_ptr, NULL, (void *)hdr); /* get next expected message sequence number - if threaded * run, lock to make sure that if another thread is processing @@ -541,8 +542,8 @@ void mca_pml_ob1_recv_frag_callback_match (mca_btl_base_module_t *btl, * received in the correct sequence. Otherwise, we delay the event * generation until we reach the correct sequence number. */ - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_SEARCH_POSTED_Q_BEGIN, comm_ptr, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_SEARCH_POSTED_BEGIN].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm_ptr, NULL, (void *)hdr); match = match_one(btl, hdr, segments, num_segments, comm_ptr, proc, NULL); @@ -550,8 +551,8 @@ void mca_pml_ob1_recv_frag_callback_match (mca_btl_base_module_t *btl, * before going into check_cantmatch_for_match so we can make * a difference for the searching time for all messages. */ - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_SEARCH_POSTED_Q_END, comm_ptr, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_SEARCH_POSTED_END].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm_ptr, NULL, (void *)hdr); /* release matching lock before processing fragment */ OB1_MATCHING_UNLOCK(&comm->matching_lock); @@ -897,8 +898,9 @@ static mca_pml_ob1_recv_request_t *match_incomming(const mca_pml_ob1_match_hdr_t req_tag = (*match)->req_recv.req_base.req_tag; if(req_tag == tag || (req_tag == OMPI_ANY_TAG && tag >= 0)) { opal_list_remove_item(queue, (opal_list_item_t*)(*match)); - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_REQ_REMOVE_FROM_POSTED_Q, - &((*match)->req_recv.req_base), PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_POSTED_REMOVE].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + (*match)->req_recv.req_base.req_comm, NULL, (void *)match); return *match; } @@ -925,8 +927,9 @@ static mca_pml_ob1_recv_request_t *match_incomming_no_any_source (const mca_pml_ if (req_tag == tag || (req_tag == OMPI_ANY_TAG && tag >= 0)) { opal_list_remove_item (&proc->specific_receives, (opal_list_item_t *) recv_req); - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_REQ_REMOVE_FROM_POSTED_Q, - &(recv_req->req_recv.req_base), PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_POSTED_REMOVE].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + recv_req->req_recv.req_base.req_comm, NULL, (void *)&recv_req); return recv_req; } } @@ -992,8 +995,9 @@ static mca_pml_ob1_recv_request_t *match_one (mca_btl_base_module_t *btl, return NULL; } - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_MSG_MATCH_POSTED_REQ, - &(match->req_recv.req_base), PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_POSTED_REMOVE].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + match->req_recv.req_base.req_comm, NULL, (void *)&match); SPC_TIMER_STOP(OMPI_SPC_MATCH_TIME, &timer); return match; } @@ -1009,9 +1013,10 @@ static mca_pml_ob1_recv_request_t *match_one (mca_btl_base_module_t *btl, SPC_RECORD(OMPI_SPC_UNEXPECTED, 1); SPC_RECORD(OMPI_SPC_UNEXPECTED_IN_QUEUE, 1); SPC_UPDATE_WATERMARK(OMPI_SPC_MAX_UNEXPECTED_IN_QUEUE, OMPI_SPC_UNEXPECTED_IN_QUEUE); - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_MSG_INSERT_IN_UNEX_Q, comm_ptr, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); - SPC_TIMER_STOP(OMPI_SPC_MATCH_TIME, &timer); + + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_UNEX_INSERT].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, (void *)hdr); + SPC_TIMER_STOP(OMPI_SPC_MATCH_TIME, &timer); return NULL; } while(true); } @@ -1084,8 +1089,8 @@ static int mca_pml_ob1_recv_frag_match (mca_btl_base_module_t *btl, * figure out if the messages are not received in the correct * order (if multiple network interfaces). */ - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_MSG_ARRIVED, comm_ptr, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_MESSAGE_ARRIVED].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm_ptr, NULL, (void *)hdr); /* get next expected message sequence number - if threaded * run, lock to make sure that if another thread is processing @@ -1180,8 +1185,8 @@ mca_pml_ob1_recv_frag_match_proc (mca_btl_base_module_t *btl, * received in the correct sequence. Otherwise, we delay the event * generation until we reach the correct sequence number. */ - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_SEARCH_POSTED_Q_BEGIN, comm_ptr, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_SEARCH_POSTED_BEGIN].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm_ptr, NULL, (void *)hdr); match = match_one(btl, hdr, segments, num_segments, comm_ptr, proc, frag); @@ -1189,8 +1194,8 @@ mca_pml_ob1_recv_frag_match_proc (mca_btl_base_module_t *btl, * before going into check_cantmatch_for_match we can make a * difference for the searching time for all messages. */ - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_SEARCH_POSTED_Q_END, comm_ptr, - hdr->hdr_src, hdr->hdr_tag, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_SEARCH_POSTED_END].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm_ptr, NULL, (void *)hdr); /* release matching lock before processing fragment */ OB1_MATCHING_UNLOCK(&comm->matching_lock); diff --git a/ompi/mca/pml/ob1/pml_ob1_recvreq.c b/ompi/mca/pml/ob1/pml_ob1_recvreq.c index 57aba677a8a..a028ad59a5f 100644 --- a/ompi/mca/pml/ob1/pml_ob1_recvreq.c +++ b/ompi/mca/pml/ob1/pml_ob1_recvreq.c @@ -13,7 +13,7 @@ * Copyright (c) 2008 UT-Battelle, LLC. All rights reserved. * Copyright (c) 2011 Sandia National Laboratories. All rights reserved. * Copyright (c) 2012-2015 NVIDIA Corporation. All rights reserved. - * Copyright (c) 2011-2017 Los Alamos National Security, LLC. All rights + * Copyright (c) 2011-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2012 FUJITSU LIMITED. All rights reserved. * Copyright (c) 2014-2016 Research Organization for Information Science @@ -74,8 +74,9 @@ static int mca_pml_ob1_recv_request_free(struct ompi_request_t** request) assert (false == recvreq->req_recv.req_base.req_free_called); recvreq->req_recv.req_base.req_free_called = true; - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_NOTIFY, - &(recvreq->req_recv.req_base), PERUSE_RECV ); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_FREE].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + recvreq->req_recv.req_base.req_comm, NULL, &recvreq); if (recvreq->req_recv.req_base.req_pml_complete) { /* make buffer defined when the request is completed, @@ -148,6 +149,10 @@ static int mca_pml_ob1_recv_request_cancel(struct ompi_request_t* ompi_request, return OMPI_SUCCESS; #endif /*OPAL_ENABLE_FT_MPI*/ } + + void *req = &(request->req_recv.req_base); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_RECEIVE_CANCELED].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, &req); /** * As now the PML is done with this request we have to force the pml_complete * to true. Otherwise, the request will never be freed. @@ -449,6 +454,7 @@ static void mca_pml_ob1_rget_completion (mca_btl_base_module_t* btl, struct mca_ static int mca_pml_ob1_recv_request_put_frag (mca_pml_ob1_rdma_frag_t *frag) { mca_pml_ob1_recv_request_t *recvreq = (mca_pml_ob1_recv_request_t *) frag->rdma_req; + ompi_communicator_t *comm = recvreq->req_recv.req_base.req_comm; #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT ompi_proc_t* proc = (ompi_proc_t*)recvreq->req_recv.req_base.req_proc; #endif @@ -488,9 +494,10 @@ static int mca_pml_ob1_recv_request_put_frag (mca_pml_ob1_rdma_frag_t *frag) recvreq->req_ack_sent = true; - PERUSE_TRACE_COMM_OMPI_EVENT( PERUSE_COMM_REQ_XFER_CONTINUE, - &(recvreq->req_recv.req_base), frag->rdma_length, - PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, + &((mca_pml_ob1_transfer_event_t) {.request = recvreq, .length = frag->rdma_length})); + /* send rdma request to peer */ rc = mca_bml_base_send (bml_btl, ctl, MCA_PML_OB1_HDR_TYPE_PUT); @@ -529,9 +536,9 @@ int mca_pml_ob1_recv_request_get_frag (mca_pml_ob1_rdma_frag_t *frag) local_handle = recvreq->local_handle; } - PERUSE_TRACE_COMM_OMPI_EVENT(PERUSE_COMM_REQ_XFER_CONTINUE, - &(((mca_pml_ob1_recv_request_t *) frag->rdma_req)->req_recv.req_base), - frag->rdma_length, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, recvreq->req_recv.req_base.req_comm, NULL, + &((mca_pml_ob1_transfer_event_t){.request = frag->rdma_req, .length = frag->rdma_length})); /* queue up get request */ rc = mca_bml_base_get (bml_btl, frag->local_address, frag->remote_address, local_handle, @@ -546,9 +553,6 @@ int mca_pml_ob1_recv_request_get_frag (mca_pml_ob1_rdma_frag_t *frag) return OMPI_SUCCESS; } - - - /* * Update the recv request status to reflect the number of bytes * received and actually delivered to the application. @@ -1116,16 +1120,15 @@ static inline void append_recv_req_to_queue(opal_list_t *queue, { opal_list_append(queue, (opal_list_item_t*)req); -#if OMPI_WANT_PERUSE /** * We don't want to generate this kind of event for MPI_Probe. */ if (req->req_recv.req_base.req_type != MCA_PML_REQUEST_PROBE && req->req_recv.req_base.req_type != MCA_PML_REQUEST_MPROBE) { - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_REQ_INSERT_IN_POSTED_Q, - &(req->req_recv.req_base), PERUSE_RECV); + ompi_communicator_t *comm = req->req_recv.req_base.req_comm; + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_POSTED_INSERT].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, &req); } -#endif } /* @@ -1288,8 +1291,8 @@ void mca_pml_ob1_recv_req_start(mca_pml_ob1_recv_request_t *req) * The laps of time between the ACTIVATE event and the SEARCH_UNEX one include * the cost of the request lock. */ - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_SEARCH_UNEX_Q_BEGIN, - &(req->req_recv.req_base), PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_SEARCH_UNEX_BEGIN].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, &req); /* assign sequence number */ req->req_recv.req_base.req_sequence = ob1_comm->recv_sequence++; @@ -1348,8 +1351,8 @@ void mca_pml_ob1_recv_req_start(mca_pml_ob1_recv_request_t *req) } if(OPAL_UNLIKELY(NULL == frag)) { - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_SEARCH_UNEX_Q_END, - &(req->req_recv.req_base), PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_SEARCH_UNEX_END].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, &req); /* We didn't find any matches. Record this irecv so we can match it when the message comes in. */ if(OPAL_LIKELY(req->req_recv.req_base.req_type != MCA_PML_REQUEST_IPROBE && @@ -1365,18 +1368,13 @@ void mca_pml_ob1_recv_req_start(mca_pml_ob1_recv_request_t *req) OB1_MATCHING_UNLOCK(&ob1_comm->matching_lock); } else { if(OPAL_LIKELY(!IS_PROB_REQ(req))) { - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_REQ_MATCH_UNEX, - &(req->req_recv.req_base), PERUSE_RECV); - hdr = (mca_pml_ob1_hdr_t*)frag->segments->seg_addr.pval; - PERUSE_TRACE_MSG_EVENT(PERUSE_COMM_MSG_REMOVE_FROM_UNEX_Q, - req->req_recv.req_base.req_comm, - hdr->hdr_match.hdr_src, - hdr->hdr_match.hdr_tag, - PERUSE_RECV); - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_SEARCH_UNEX_Q_END, - &(req->req_recv.req_base), PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_UNEX_REMOVE].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, &hdr->hdr_match); + + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_SEARCH_UNEX_END].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, comm, NULL, &req); #if MCA_PML_OB1_CUSTOM_MATCH custom_match_umq_remove_hold(req->req_recv.req_base.req_comm->c_pml_comm->umq, hold_prev, hold_elem, hold_index); diff --git a/ompi/mca/pml/ob1/pml_ob1_recvreq.h b/ompi/mca/pml/ob1/pml_ob1_recvreq.h index 402d3f4dcec..e2e6389ff89 100644 --- a/ompi/mca/pml/ob1/pml_ob1_recvreq.h +++ b/ompi/mca/pml/ob1/pml_ob1_recvreq.h @@ -124,8 +124,9 @@ do { \ */ #define MCA_PML_OB1_RECV_REQUEST_MPI_COMPLETE( recvreq ) \ do { \ - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_COMPLETE, \ - &(recvreq->req_recv.req_base), PERUSE_RECV ); \ + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_COMPLETE].event, \ + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, \ + (recvreq)->req_recv.req_base.req_comm, NULL, &(recvreq)); \ ompi_request_complete( &(recvreq->req_recv.req_base.req_ompi), true ); \ } while (0) @@ -162,8 +163,9 @@ recv_request_pml_complete(mca_pml_ob1_recv_request_t *recvreq) if(false == recvreq->req_recv.req_base.req_pml_complete){ if(recvreq->req_recv.req_bytes_packed > 0) { - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_XFER_END, - &recvreq->req_recv.req_base, PERUSE_RECV ); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER_END].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + recvreq->req_recv.req_base.req_comm, NULL, &recvreq); } for(i = 0; i < recvreq->req_rdma_cnt; i++) { @@ -258,8 +260,9 @@ static inline void recv_req_matched(mca_pml_ob1_recv_request_t *req, prepare_recv_req_converter(req); } #endif /* OPAL_ENABLE_HETEROGENEOUS_SUPPORT */ - PERUSE_TRACE_COMM_EVENT(PERUSE_COMM_REQ_XFER_BEGIN, - &req->req_recv.req_base, PERUSE_RECV); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER_BEGIN].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + req->req_recv.req_base.req_comm, NULL, &req); } } @@ -268,7 +271,7 @@ static inline void recv_req_matched(mca_pml_ob1_recv_request_t *req, * */ -#define MCA_PML_OB1_RECV_REQUEST_UNPACK( request, \ +#define MCA_PML_OB1_RECV_REQUEST_UNPACK( req, \ segments, \ num_segments, \ seg_offset, \ @@ -277,7 +280,7 @@ static inline void recv_req_matched(mca_pml_ob1_recv_request_t *req, bytes_delivered) \ do { \ bytes_delivered = 0; \ - if(request->req_recv.req_bytes_packed > 0) { \ + if((req)->req_recv.req_bytes_packed > 0) { \ struct iovec iov[MCA_BTL_DES_MAX_SEGMENTS]; \ uint32_t iov_count = 0; \ size_t max_data = bytes_received; \ @@ -295,18 +298,21 @@ do { offset = 0; \ } \ } \ - OPAL_THREAD_LOCK(&request->lock); \ - PERUSE_TRACE_COMM_OMPI_EVENT (PERUSE_COMM_REQ_XFER_CONTINUE, \ - &(request->req_recv.req_base), max_data, \ - PERUSE_RECV); \ - opal_convertor_set_position( &(request->req_recv.req_base.req_convertor), \ + OPAL_THREAD_LOCK(&(req)->lock); \ + \ + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER].event, \ + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, \ + (req)->req_recv.req_base.req_comm, NULL, \ + &((mca_pml_ob1_transfer_event_t){.request = req, .length = max_data})); \ + \ + opal_convertor_set_position( &((req)->req_recv.req_base.req_convertor), \ &data_offset ); \ - opal_convertor_unpack( &(request)->req_recv.req_base.req_convertor, \ + opal_convertor_unpack( &(req)->req_recv.req_base.req_convertor, \ iov, \ &iov_count, \ &max_data ); \ bytes_delivered = max_data; \ - OPAL_THREAD_UNLOCK(&request->lock); \ + OPAL_THREAD_UNLOCK(&(req)->lock); \ } \ } while (0) diff --git a/ompi/mca/pml/ob1/pml_ob1_sendreq.c b/ompi/mca/pml/ob1/pml_ob1_sendreq.c index 0dd246917c0..5691ef6fc4b 100644 --- a/ompi/mca/pml/ob1/pml_ob1_sendreq.c +++ b/ompi/mca/pml/ob1/pml_ob1_sendreq.c @@ -13,7 +13,7 @@ * Copyright (c) 2008 UT-Battelle, LLC. All rights reserved. * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012 NVIDIA Corporation. All rights reserved. - * Copyright (c) 2012-2016 Los Alamos National Security, LLC. All rights + * Copyright (c) 2012-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2016 Research Organization for Information Science @@ -107,8 +107,9 @@ static int mca_pml_ob1_send_request_free(struct ompi_request_t** request) if(false == sendreq->req_send.req_base.req_free_called) { sendreq->req_send.req_base.req_free_called = true; - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_NOTIFY, - &(sendreq->req_send.req_base), PERUSE_SEND ); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_FREE].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + sendreq->req_send.req_base.req_comm, NULL, &sendreq); if (sendreq->req_send.req_base.req_pml_complete) { /* make buffer defined when the request is completed, @@ -208,8 +209,10 @@ mca_pml_ob1_match_completion_free_request( mca_bml_base_btl_t* bml_btl, mca_pml_ob1_send_request_t* sendreq ) { if( sendreq->req_send.req_bytes_packed > 0 ) { - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_XFER_BEGIN, - &(sendreq->req_send.req_base), PERUSE_SEND ); + void *req = &(sendreq->req_send.req_base); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER_BEGIN].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + sendreq->req_send.req_base.req_comm, NULL, &req); } /* signal request completion */ @@ -253,8 +256,10 @@ mca_pml_ob1_rndv_completion_request( mca_bml_base_btl_t* bml_btl, size_t req_bytes_delivered ) { if( sendreq->req_send.req_bytes_packed > 0 ) { - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_XFER_BEGIN, - &(sendreq->req_send.req_base), PERUSE_SEND ); + void *req = &(sendreq->req_send.req_base); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER_BEGIN].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + sendreq->req_send.req_base.req_comm, NULL, &req); } OPAL_THREAD_ADD_FETCH_SIZE_T(&sendreq->req_bytes_delivered, req_bytes_delivered); @@ -908,8 +913,10 @@ int mca_pml_ob1_send_request_start_rdma( mca_pml_ob1_send_request_t* sendreq, * sent the GET message ... */ if( sendreq->req_send.req_bytes_packed > 0 ) { - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_XFER_BEGIN, - &(sendreq->req_send.req_base), PERUSE_SEND ); + void *req = &(sendreq->req_send.req_base); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER_BEGIN].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + sendreq->req_send.req_base.req_comm, NULL, &req); } /* send */ @@ -1216,10 +1223,10 @@ mca_pml_ob1_send_request_schedule_once(mca_pml_ob1_send_request_t* sendreq) ob1_hdr_hton(hdr, MCA_PML_OB1_HDR_TYPE_FRAG, sendreq->req_send.req_base.req_proc); -#if OMPI_WANT_PERUSE - PERUSE_TRACE_COMM_OMPI_EVENT(PERUSE_COMM_REQ_XFER_CONTINUE, - &(sendreq->req_send.req_base), size, PERUSE_SEND); -#endif /* OMPI_WANT_PERUSE */ + void *req = &(sendreq->req_send.req_base); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + sendreq->req_send.req_base.req_comm, NULL, &req); /* At this point, check to see if the BTL is doing an asynchronous * copy. This would have been initiated in the mca_bml_base_prepare_src @@ -1376,8 +1383,10 @@ int mca_pml_ob1_send_request_put_frag( mca_pml_ob1_rdma_frag_t *frag ) } } - PERUSE_TRACE_COMM_OMPI_EVENT( PERUSE_COMM_REQ_XFER_CONTINUE, - &(((mca_pml_ob1_send_request_t*)frag->rdma_req)->req_send.req_base), frag->rdma_length, PERUSE_SEND ); + void *req = &(((mca_pml_ob1_send_request_t*)frag->rdma_req)->req_send.req_base); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER].event, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + sendreq->req_send.req_base.req_comm, NULL, &req); rc = mca_bml_base_put (bml_btl, frag->local_address, frag->remote_address, local_handle, (mca_btl_base_registration_handle_t *) frag->remote_handle, frag->rdma_length, diff --git a/ompi/mca/pml/ob1/pml_ob1_sendreq.h b/ompi/mca/pml/ob1/pml_ob1_sendreq.h index 1d50ecc033d..34f1be96f18 100644 --- a/ompi/mca/pml/ob1/pml_ob1_sendreq.h +++ b/ompi/mca/pml/ob1/pml_ob1_sendreq.h @@ -211,8 +211,9 @@ do { (sendreq)->req_send.req_base.req_tag; \ (sendreq)->req_send.req_base.req_ompi.req_status._ucount = \ (sendreq)->req_send.req_bytes_packed; \ - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_COMPLETE, \ - &(sendreq->req_send.req_base), PERUSE_SEND); \ + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_REQUEST_COMPLETE].event, \ + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, \ + (sendreq)->req_send.req_base.req_comm, NULL, &(sendreq)); \ \ ompi_request_complete( &((sendreq)->req_send.req_base.req_ompi), (with_signal) ); \ } while(0) @@ -260,8 +261,9 @@ send_request_pml_complete(mca_pml_ob1_send_request_t *sendreq) { if(false == sendreq->req_send.req_base.req_pml_complete) { if(sendreq->req_send.req_bytes_packed > 0) { - PERUSE_TRACE_COMM_EVENT( PERUSE_COMM_REQ_XFER_END, - &(sendreq->req_send.req_base), PERUSE_SEND); + MCA_BASE_EVENT_RAISE (mca_pml_ob1_events[MCA_PML_OB1_EVENT_TRANSFER_END].event, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + sendreq->req_send.req_base.req_comm, NULL, &sendreq); } /* return mpool resources */ diff --git a/ompi/mpi/tool/event_callback_get_info.c b/ompi/mpi/tool/event_callback_get_info.c index 92519a13aac..2e3baf5a5dc 100644 --- a/ompi/mpi/tool/event_callback_get_info.c +++ b/ompi/mpi/tool/event_callback_get_info.c @@ -29,10 +29,25 @@ int MPI_T_event_callback_get_info (MPI_T_event_registration event_registration, MPI_T_cb_safety cb_safety, MPI_Info *info_used) { + ompi_info_t *info; + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; -} + info = OBJ_NEW(ompi_info_t); + if (NULL == info) { + return ompit_opal_to_mpit_error(OMPI_ERR_OUT_OF_RESOURCE); + } + /* mca_base_cb_safety_t and MPI_T_cb_safety must be kept in sync for this to work */ + ret = mca_base_event_callback_get_info (event_registration, (mca_base_cb_safety_t) cb_safety, &info->super); + if (OPAL_SUCCESS != ret) { + OBJ_RELEASE(info); + } else { + *info_used = info; + } + + return ompit_opal_to_mpit_error(ret); +} diff --git a/ompi/mpi/tool/event_callback_set_info.c b/ompi/mpi/tool/event_callback_set_info.c index 5f78d2c92de..bc22ba65ede 100644 --- a/ompi/mpi/tool/event_callback_set_info.c +++ b/ompi/mpi/tool/event_callback_set_info.c @@ -28,9 +28,14 @@ int MPI_T_event_callback_set_info (MPI_T_event_registration event_registration, MPI_T_cb_safety cb_safety, MPI_Info info) { + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + /* mca_base_cb_safety_t and MPI_T_cb_safety must be kept in sync for this to work */ + ret = mca_base_event_callback_set_info (event_registration, (mca_base_cb_safety_t) cb_safety, &info->super); + + return ompit_opal_to_mpit_error(ret); } diff --git a/ompi/mpi/tool/event_copy.c b/ompi/mpi/tool/event_copy.c index f0c64bad822..3e9881b9043 100644 --- a/ompi/mpi/tool/event_copy.c +++ b/ompi/mpi/tool/event_copy.c @@ -31,5 +31,6 @@ int MPI_T_event_copy (MPI_T_event_instance event, void *buffer) return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + mca_base_event_copy (event, buffer); + return MPI_SUCCESS; } diff --git a/ompi/mpi/tool/event_get_index.c b/ompi/mpi/tool/event_get_index.c index 0c0ec50cf39..af0ad83ebc1 100644 --- a/ompi/mpi/tool/event_get_index.c +++ b/ompi/mpi/tool/event_get_index.c @@ -25,6 +25,8 @@ int MPI_T_event_get_index (const char *name, int *event_index) { + mca_base_event_t *event = NULL; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } @@ -33,5 +35,14 @@ int MPI_T_event_get_index (const char *name, int *event_index) return MPI_ERR_ARG; } - return MPI_T_ERR_INVALID_NAME; + ompi_mpit_lock (); + (void) mca_base_event_get_by_fullname (name, &event); + ompi_mpit_unlock (); + + if (NULL == event) { + return MPI_T_ERR_INVALID_NAME; + } + + *event_index = event->event_index; + return MPI_SUCCESS; } diff --git a/ompi/mpi/tool/event_get_info.c b/ompi/mpi/tool/event_get_info.c index f7fd9134379..60f772e8eeb 100644 --- a/ompi/mpi/tool/event_get_info.c +++ b/ompi/mpi/tool/event_get_info.c @@ -30,9 +30,95 @@ int MPI_T_event_get_info (int event_index, char *name, int *name_len, MPI_T_enum *enumtype, MPI_Info *info, char *desc, int *desc_len, int *bind) { + mca_base_event_t * const event; + int ret, max_datatypes = 0, current_displacement = 0; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_INDEX; + ompi_mpit_lock (); + + /* Find the performance variable. mca_base_event_get() handles the + bounds checking. */ + ret = mca_base_event_get_by_index (event_index, (mca_base_event_t **) &event); + if (OMPI_SUCCESS != ret) { + goto fn_fail; + } + + /* Check the variable binding is something sane */ + if (event->event_bind > MPI_T_BIND_MPI_INFO || event->event_bind < MPI_T_BIND_NO_OBJECT) { + /* This variable specified an invalid binding (not an MPI object). */ + ret = MPI_T_ERR_INVALID_INDEX; + goto fn_fail; + } + + /* Copy name and description */ + mpit_copy_string (name, name_len, event->event_name); + mpit_copy_string (desc, desc_len, event->event_description); + + // num_elements is INOUT + // + // Can query number of datatypes, returned in num_elements + // if array_of_datatypes or displacements are NULL, just return data_type_count. + // Otherwise, if array_of_datatypes or displacements are not NULL, use num_elements + // as maximum datatypes or displacements returned. + // + // Unless the user passes the NULL pointer for num_elements, + // the function returns the number of elements required for this event type. + // + // If the number of elements used by the event type is larger than the value of num_elements + // provided by the user, the number of datatype handles and displacements returned in the + // corresponding arrays is truncated to the value of num_elements passed in by the user. + + max_datatypes = 0; + if (num_elements) { + if (NULL != array_of_datatypes || NULL != array_of_displacements) { + if (*num_elements < (int) (event->event_datatype_count)) { + max_datatypes = *num_elements; + } else { + max_datatypes = event->event_datatype_count; + } + } + *num_elements = event->event_datatype_count; + } + + if (max_datatypes) { + if (array_of_datatypes) { + for (int i = 0 ; i < max_datatypes ; i++) { + + array_of_datatypes[i] = ompi_datatype_lookup_by_opal_id(event->event_datatypes[i]->id); + } + } + + if (array_of_displacements) { + for (int i = 0 ; i < max_datatypes ; i++) { + array_of_displacements[i] = (MPI_Aint) current_displacement; + current_displacement += event->event_datatypes[i]->size; + } + } + + *num_elements = max_datatypes; + } + + if (NULL != verbosity) { + *verbosity = event->event_verbosity; + } + + if (NULL != enumtype) { + *enumtype = event->event_enumerator ? (MPI_T_enum) event->event_enumerator : MPI_T_ENUM_NULL; + } + + if (NULL != bind) { + *bind = event->event_bind; + } + + if (NULL != info) { + *info = OBJ_NEW(ompi_info_t); + } + +fn_fail: + ompi_mpit_unlock (); + + return ret; } diff --git a/ompi/mpi/tool/event_get_num.c b/ompi/mpi/tool/event_get_num.c index 0b27caa60fc..48d49c5f01c 100644 --- a/ompi/mpi/tool/event_get_num.c +++ b/ompi/mpi/tool/event_get_num.c @@ -33,6 +33,5 @@ int MPI_T_event_get_num (int *num_event) return MPI_ERR_ARG; } - *num_event = 0; - return MPI_SUCCESS; + return mca_base_event_get_count (num_event); } diff --git a/ompi/mpi/tool/event_get_source.c b/ompi/mpi/tool/event_get_source.c index 7ec12af587e..6273900907b 100644 --- a/ompi/mpi/tool/event_get_source.c +++ b/ompi/mpi/tool/event_get_source.c @@ -30,5 +30,6 @@ int MPI_T_event_get_source (MPI_T_event_instance event, int *source_index) return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + mca_base_event_get_source (event, source_index); + return MPI_SUCCESS; } diff --git a/ompi/mpi/tool/event_get_timestamp.c b/ompi/mpi/tool/event_get_timestamp.c index 34fd49d5075..ff0b61df759 100644 --- a/ompi/mpi/tool/event_get_timestamp.c +++ b/ompi/mpi/tool/event_get_timestamp.c @@ -26,9 +26,15 @@ int MPI_T_event_get_timestamp (MPI_T_event_instance event, MPI_Count *event_time) { + uint64_t mca_time; + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + ret = mca_base_event_get_time (event, &mca_time); + *event_time = (MPI_Count) mca_time; + + return ompit_opal_to_mpit_error (ret); } diff --git a/ompi/mpi/tool/event_handle_alloc.c b/ompi/mpi/tool/event_handle_alloc.c index 0768cf2f879..7fdf1b5715e 100644 --- a/ompi/mpi/tool/event_handle_alloc.c +++ b/ompi/mpi/tool/event_handle_alloc.c @@ -27,9 +27,33 @@ int MPI_T_event_handle_alloc (int event_index, void *obj_handle, MPI_Info info, MPI_T_event_registration *event_registration) { + mca_base_event_t * const event; + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_INDEX; + ompi_mpit_lock (); + + /* Find the event. mca_base_event_get_by_index() handles the + bounds checking. */ + ret = mca_base_event_get_by_index (event_index, (mca_base_event_t **) &event); + if (OMPI_SUCCESS != ret) { + goto fn_fail; + } + + /* Check the event binding is something sane */ + if (event->event_bind > MPI_T_BIND_MPI_INFO || event->event_bind < MPI_T_BIND_NO_OBJECT) { + /* This event specified an invalid binding (not an MPI object). */ + ret = MPI_T_ERR_INVALID_INDEX; + goto fn_fail; + } + + ret = mca_base_event_registration_alloc (event, obj_handle, &info->super, event_registration); + +fn_fail: + ompi_mpit_unlock (); + + return ompit_opal_to_mpit_error(ret); } diff --git a/ompi/mpi/tool/event_handle_free.c b/ompi/mpi/tool/event_handle_free.c index 7fb756b3938..fcd6c620463 100644 --- a/ompi/mpi/tool/event_handle_free.c +++ b/ompi/mpi/tool/event_handle_free.c @@ -28,9 +28,23 @@ int MPI_T_event_handle_free (MPI_T_event_registration event_registration, void *user_data, MPI_T_event_free_cb_function free_cb_function) { + int ret = MPI_SUCCESS; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + ompi_mpit_lock (); + + /* Check that this is a valid handle */ + if (MPI_T_EVENT_REGISTRATION_NULL == event_registration) { + ret = MPI_T_ERR_INVALID_HANDLE; + } else { + mca_base_event_registration_free (event_registration, + (mca_base_event_registration_free_cb_fn_t) free_cb_function); + } + + ompi_mpit_unlock (); + + return ret; } diff --git a/ompi/mpi/tool/event_handle_get_info.c b/ompi/mpi/tool/event_handle_get_info.c index 2009d67b1ef..bb1a29a672a 100644 --- a/ompi/mpi/tool/event_handle_get_info.c +++ b/ompi/mpi/tool/event_handle_get_info.c @@ -28,9 +28,24 @@ int MPI_T_event_handle_get_info (MPI_T_event_registration event_registration, MPI_Info *info_used) { + ompi_info_t *info; + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + info = OBJ_NEW(ompi_info_t); + if (NULL == info) { + return ompit_opal_to_mpit_error(OMPI_ERR_OUT_OF_RESOURCE); + } + + ret = mca_base_event_handle_get_info (event_registration, &info->super); + if (OPAL_SUCCESS != ret) { + OBJ_RELEASE(info); + } else { + *info_used = info; + } + + return ompit_opal_to_mpit_error(ret); } diff --git a/ompi/mpi/tool/event_handle_set_info.c b/ompi/mpi/tool/event_handle_set_info.c index 0c35e27d2a1..7f6f2253485 100644 --- a/ompi/mpi/tool/event_handle_set_info.c +++ b/ompi/mpi/tool/event_handle_set_info.c @@ -28,9 +28,13 @@ int MPI_T_event_handle_set_info (MPI_T_event_registration event_registration, MPI_Info info) { + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + ret = mca_base_event_handle_set_info (event_registration, &info->super); + + return ompit_opal_to_mpit_error(ret); } diff --git a/ompi/mpi/tool/event_read.c b/ompi/mpi/tool/event_read.c index e16d3e33f50..5d550ee6738 100644 --- a/ompi/mpi/tool/event_read.c +++ b/ompi/mpi/tool/event_read.c @@ -26,9 +26,13 @@ int MPI_T_event_read (MPI_T_event_instance event, int element_index, void *buffer) { + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + ret = mca_base_event_read (event, element_index, buffer); + + return ompit_opal_to_mpit_error (ret); } diff --git a/ompi/mpi/tool/event_register_callback.c b/ompi/mpi/tool/event_register_callback.c index 4550fabe520..399ab119b25 100644 --- a/ompi/mpi/tool/event_register_callback.c +++ b/ompi/mpi/tool/event_register_callback.c @@ -28,9 +28,18 @@ int MPI_T_event_register_callback (MPI_T_event_registration event_registration, MPI_T_cb_safety cb_safety, MPI_Info info, void *user_data, MPI_T_event_cb_function event_cb_function) { + int ret; + if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + ompi_mpit_lock (); + + ret = mca_base_event_register_callback (event_registration, (mca_base_cb_safety_t) cb_safety, + &info->super, user_data, (mca_base_event_cb_fn_t) event_cb_function); + + ompi_mpit_unlock (); + + return ompit_opal_to_mpit_error(ret); } diff --git a/ompi/mpi/tool/event_set_dropped_handler.c b/ompi/mpi/tool/event_set_dropped_handler.c index fe15695abb8..63f666d1320 100644 --- a/ompi/mpi/tool/event_set_dropped_handler.c +++ b/ompi/mpi/tool/event_set_dropped_handler.c @@ -31,5 +31,16 @@ int MPI_T_event_set_dropped_handler (MPI_T_event_registration handle, MPI_T_even return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_HANDLE; + /* Check that this is a valid handle */ + if (MPI_T_EVENT_REGISTRATION_NULL == handle) { + return MPI_T_ERR_INVALID_HANDLE; + } + + ompi_mpit_lock (); + + mca_base_event_registration_set_dropped_handler (handle, (mca_base_event_dropped_cb_fn_t) dropped_cb_function); + + ompi_mpit_unlock (); + + return MPI_SUCCESS; } diff --git a/ompi/mpi/tool/mpit-internal.h b/ompi/mpi/tool/mpit-internal.h index 4ee3d9e92a3..7c0a7907989 100644 --- a/ompi/mpi/tool/mpit-internal.h +++ b/ompi/mpi/tool/mpit-internal.h @@ -1,6 +1,6 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights + * Copyright (c) 2011-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2011 UT-Battelle, LLC. All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. @@ -15,11 +15,10 @@ #ifndef MPIT_INTERNAL_H #define MPIT_INTERNAL_H +#include "ompi/include/ompi_config.h" #include "opal/util/string_copy.h" #include "opal/mca/base/mca_base_var.h" -#include "opal/mca/base/mca_base_pvar.h" - -#include "ompi/include/ompi_config.h" +#include "opal/mca/base/mca_base_event.h" #include "ompi/runtime/params.h" #include "ompi/communicator/communicator.h" #include "ompi/constants.h" diff --git a/ompi/mpi/tool/source_get_info.c b/ompi/mpi/tool/source_get_info.c index 94017246fa2..b6057d9668f 100644 --- a/ompi/mpi/tool/source_get_info.c +++ b/ompi/mpi/tool/source_get_info.c @@ -23,12 +23,54 @@ #define MPI_T_source_get_info PMPI_T_source_get_info #endif -int MPI_T_source_get_info (int source_index, char *name, int *name_len, char *desc, int *desc_len, MPI_T_source_order *ordering, +int MPI_T_source_get_info (int source_id, char *name, int *name_len, char *desc, int *desc_len, MPI_T_source_order *ordering, MPI_Count *ticks_per_second, MPI_Count *max_timestamp, MPI_Info *info) { + mca_base_source_t *source; if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } - return MPI_T_ERR_INVALID_INDEX; + ompi_mpit_lock (); + source = mca_base_source_get (source_id); + ompi_mpit_unlock (); + if (OPAL_UNLIKELY(NULL == source)) { + return MPI_T_ERR_INVALID_INDEX; + } + + if (NULL == name && name_len) { + *name_len = strlen(source->source_name); + } + + if (name && name_len) { + strncpy (name, source->source_name, *name_len); + *name_len = strlen (name); + } + + if (NULL == desc && desc_len) { + *desc_len = strlen(source->source_description); + } + + if (desc && desc_len) { + strncpy (desc, source->source_description, *desc_len); + *desc_len = strlen (desc); + } + + if (ordering) { + *ordering = source->source_ordered; + } + + if (ticks_per_second) { + *ticks_per_second = source->source_ticks; + } + + if (max_timestamp) { + *max_timestamp = SIZE_MAX; + } + + if (NULL != info && *info) { + *info = OBJ_NEW(ompi_info_t); + } + + return MPI_SUCCESS; } diff --git a/ompi/mpi/tool/source_get_num.c b/ompi/mpi/tool/source_get_num.c index 6b31862ff27..c4b456755da 100644 --- a/ompi/mpi/tool/source_get_num.c +++ b/ompi/mpi/tool/source_get_num.c @@ -33,6 +33,5 @@ int MPI_T_source_get_num (int *num_source) return MPI_ERR_ARG; } - *num_source = 0; - return MPI_SUCCESS; + return mca_base_source_get_count (num_source); } diff --git a/ompi/mpi/tool/source_get_timestamp.c b/ompi/mpi/tool/source_get_timestamp.c index 02a4303d286..4347a93ce00 100644 --- a/ompi/mpi/tool/source_get_timestamp.c +++ b/ompi/mpi/tool/source_get_timestamp.c @@ -23,8 +23,9 @@ #define MPI_T_source_get_timestamp PMPI_T_source_get_timestamp #endif -int MPI_T_source_get_timestamp (int source_index, MPI_Count *timestamp) +int MPI_T_source_get_timestamp (int source_id, MPI_Count *timestamp) { + mca_base_source_t *source; if (!mpit_is_initialized ()) { return MPI_T_ERR_NOT_INITIALIZED; } @@ -33,5 +34,14 @@ int MPI_T_source_get_timestamp (int source_index, MPI_Count *timestamp) return MPI_ERR_ARG; } - return MPI_T_ERR_INVALID_INDEX; + ompi_mpit_lock (); + source = mca_base_source_get (source_id); + ompi_mpit_unlock (); + if (OPAL_UNLIKELY(NULL == source)) { + return MPI_T_ERR_INVALID_INDEX; + } + + *timestamp = (MPI_Count)source->source_time (); + + return MPI_SUCCESS; } diff --git a/opal/mca/base/Makefile.am b/opal/mca/base/Makefile.am index 2e4cd3f2f3f..903b9fd6716 100644 --- a/opal/mca/base/Makefile.am +++ b/opal/mca/base/Makefile.am @@ -10,6 +10,8 @@ # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. # Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights +# reserved. # Copyright (c) 2020 Google LLC. All rights reserved. # $COPYRIGHT$ # @@ -39,7 +41,9 @@ headers = \ mca_base_var_enum.h \ mca_base_var_group.h \ mca_base_vari.h \ - mca_base_framework.h + mca_base_framework.h \ + mca_base_event.h \ + mca_base_source.h # Library @@ -62,7 +66,9 @@ libmca_base_la_SOURCES = \ mca_base_var_group.c \ mca_base_parse_paramfile.c \ mca_base_components_register.c \ - mca_base_framework.c + mca_base_framework.c \ + mca_base_event.c \ + mca_base_source.c # Conditionally install the header files diff --git a/opal/mca/base/mca_base_event.c b/opal/mca/base/mca_base_event.c new file mode 100644 index 00000000000..567501627c8 --- /dev/null +++ b/opal/mca/base/mca_base_event.c @@ -0,0 +1,653 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2015 Bull SAS. All rights reserved. + * Copyright (c) 2015 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. + * Copyright (c) 2018-2019 Triad National Security, LLC. All rights + * reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "mca_base_event.h" +#include "mca_base_vari.h" + +#include +#include +#include + +#include "opal/class/opal_pointer_array.h" +#include "opal/class/opal_hash_table.h" +#include "opal/mca/threads/thread_usage.h" + +static opal_hash_table_t mca_base_event_index_hash; +static opal_pointer_array_t registered_events; +static bool mca_base_event_initialized = false; +static int event_count = 0; +static opal_mutex_t mca_base_event_lock = OPAL_MUTEX_STATIC_INIT; + +static int mca_base_event_get_by_index_internal (int index, mca_base_event_t **event, bool invalidok); +static int mca_base_event_get_by_fullname_internal (const char *full_name, mca_base_event_t **event, bool invalidok); +static int mca_base_event_get_by_name_internal (const char *project, const char *framework, const char *component, const char *name, + mca_base_event_t **event, bool invalidok); + +/***************************************************************************************************/ + +int mca_base_event_init (void) +{ + int ret = OPAL_SUCCESS; + + OPAL_THREAD_LOCK(&mca_base_event_lock); + if (false == mca_base_event_initialized) { + mca_base_event_initialized = true; + + OBJ_CONSTRUCT(®istered_events, opal_pointer_array_t); + opal_pointer_array_init(®istered_events, 128, 2048, 128); + + OBJ_CONSTRUCT(&mca_base_event_index_hash, opal_hash_table_t); + ret = opal_hash_table_init (&mca_base_event_index_hash, 1024); + if (OPAL_SUCCESS != ret) { + mca_base_event_initialized = false; + OBJ_DESTRUCT(®istered_events); + OBJ_DESTRUCT(&mca_base_event_index_hash); + } + } + OPAL_THREAD_UNLOCK(&mca_base_event_lock); + + return ret; +} + +int mca_base_event_finalize (void) +{ + int i; + + OPAL_THREAD_LOCK(&mca_base_event_lock); + if (true == mca_base_event_initialized) { + mca_base_event_initialized = false; + + for (i = 0 ; i < event_count ; ++i) { + mca_base_event_t *event = opal_pointer_array_get_item (®istered_events, i); + if (event) { + OBJ_RELEASE(event); + } + } + + event_count = 0; + + OBJ_DESTRUCT(®istered_events); + OBJ_DESTRUCT(&mca_base_event_index_hash); + } + OPAL_THREAD_UNLOCK(&mca_base_event_lock); + + return OPAL_SUCCESS; +} + +/***************************************************************************************************/ + + +/** lookup functions */ + +static int mca_base_event_get_by_fullname_internal (const char *full_name, mca_base_event_t **event, bool invalidok) +{ + void *tmp; + int rc; + + rc = opal_hash_table_get_value_ptr (&mca_base_event_index_hash, full_name, strlen (full_name), + &tmp); + if (OPAL_SUCCESS != rc) { + return rc; + } + + return mca_base_event_get_by_index_internal ((int)(uintptr_t) tmp, event, invalidok); +} + +int mca_base_event_get_by_fullname (const char *full_name, mca_base_event_t **event) +{ + return mca_base_event_get_by_fullname_internal (full_name, event, false); +} + +static int mca_base_event_get_by_name_internal (const char *project, const char *framework, const char *component, const char *name, + mca_base_event_t **event, bool invalidok) +{ + char *full_name; + int ret; + + ret = mca_base_var_generate_full_name4 (project, framework, component, name, &full_name); + if (OPAL_SUCCESS != ret) { + return OPAL_ERROR; + } + + ret = mca_base_event_get_by_fullname_internal (full_name, event, invalidok); + free (full_name); + + return ret; +} + +int mca_base_event_get_by_name (const char *project, const char *framework, const char *component, const char *name, + mca_base_event_t **event) +{ + return mca_base_event_get_by_name_internal (project, framework, component, name, event, false); +} + +int mca_base_registration_get_event (mca_base_event_registration_t *registration, mca_base_event_t **event) +{ + if (OPAL_UNLIKELY(NULL == registration)) { + return OPAL_ERR_BAD_PARAM; + } + + *event = registration->event; + + return OPAL_SUCCESS; +} + +static int mca_base_event_get_by_index_internal (int index, mca_base_event_t **event, bool invalidok) +{ + if (0 > index || index >= event_count) { + return OPAL_ERR_VALUE_OUT_OF_BOUNDS; + } + + *event = opal_pointer_array_get_item (®istered_events, index); + + /* variables should never be removed per MPI 3.0 ยง 14.3.7 */ + assert (*event); + + if (((*event)->event_flags & MCA_BASE_EVENT_FLAG_INVALID) && !invalidok) { + *event = NULL; + return OPAL_ERR_VALUE_OUT_OF_BOUNDS; + } + + return OPAL_SUCCESS; +} + +int mca_base_event_get_by_index (int index, mca_base_event_t **event) +{ + return mca_base_event_get_by_index_internal (index, (mca_base_event_t **) event, false); +} + +/***************************************************************************************************/ + +int mca_base_event_get_count (int *count) +{ + *count = event_count; + return OPAL_SUCCESS; +} + +int mca_base_event_register (const char *project, const char *framework, const char *component, const char *name, + const char *description, mca_base_var_info_lvl_t verbosity, opal_datatype_t **datatypes, + unsigned long *offsets, size_t num_datatypes, mca_base_var_enum_t *enumerator, int bind, + int source, uint32_t flags, mca_base_notify_fn_t notify, void *ctx, mca_base_event_t **event_out) +{ + int ret, group_index; + mca_base_event_t *event; + + /* ensure the caller did not set an invalid flag */ + assert (!(flags & (MCA_BASE_EVENT_FLAG_IWG-1))); + + /* update this assert if more MPIT verbosity levels are added */ + assert (verbosity >= OPAL_INFO_LVL_1 && verbosity <= OPAL_INFO_LVL_9); + + flags &= ~MCA_BASE_EVENT_FLAG_INVALID; + + /* check if this variable is already registered */ + ret = mca_base_event_get_by_name (project, framework, component, name, &event); + if (OPAL_SUCCESS > ret) { + /* find/register an MCA parameter group for this performance variable */ + group_index = mca_base_var_group_register (project, framework, component, NULL); + if (-1 > group_index) { + return group_index; + } + + /* create a new parameter entry */ + event = OBJ_NEW(mca_base_event_t); + if (NULL == event) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + + do { + /* generate the variable's full name */ + ret = mca_base_var_generate_full_name4 (project, framework, component, name, &event->event_name); + if (OPAL_SUCCESS != ret) { + ret = OPAL_ERR_OUT_OF_RESOURCE; + break; + } + + if (NULL != description) { + event->event_description = strdup(description); + if (NULL == event->event_description) { + ret = OPAL_ERR_OUT_OF_RESOURCE; + break; + } + } + + event->event_index = opal_pointer_array_add (®istered_events, event); + if (0 > event->event_index) { + ret = OPAL_ERR_OUT_OF_RESOURCE; + break; + } + + /* add this performance variable to the MCA variable group */ + if (0 <= group_index) { + ret = mca_base_var_group_add_event (group_index, event->event_index); + if (0 > ret) { + break; + } + } + + opal_hash_table_set_value_ptr (&mca_base_event_index_hash, event->event_name, strlen (event->event_name), + (void *)(uintptr_t) event->event_index); + + event_count++; + ret = OPAL_SUCCESS; + } while (0); + + if (OPAL_SUCCESS != ret) { + OBJ_RELEASE(event); + return ret; + } + + event->event_group_index = group_index; + } + + event->event_verbosity = verbosity; + event->event_source = mca_base_source_get (source); + + if (event->event_enumerator) { + OBJ_RELEASE(event->event_enumerator); + } + + event->event_enumerator = enumerator; + if (enumerator) { + OBJ_RETAIN(enumerator); + } + + event->event_bind = bind; + event->event_flags = flags; + event->event_ctx = ctx; + + event->event_datatypes = calloc (num_datatypes, sizeof (event->event_datatypes[0])); + event->event_offsets = calloc (num_datatypes, sizeof (event->event_offsets[0])); + if (NULL == event->event_datatypes || NULL == event->event_offsets) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + + memcpy (event->event_datatypes, datatypes, num_datatypes * sizeof (event->event_datatypes[0])); + memcpy (event->event_offsets, offsets, num_datatypes * sizeof (event->event_offsets[0])); + + event->event_datatype_count = num_datatypes; + + if (event_out) { + *event_out = event; + } + + return OPAL_SUCCESS; +} + +int mca_base_component_event_register (const mca_base_component_t *component, const char *name, + const char *description, mca_base_var_info_lvl_t verbosity, opal_datatype_t **datatypes, + unsigned long *offsets, size_t num_datatypes, mca_base_var_enum_t *enumerator, int bind, + int source, uint32_t flags, mca_base_notify_fn_t notify, void *ctx, mca_base_event_t **event_out) +{ + /* invalidate this variable if the component's group is deregistered */ + return mca_base_event_register (component->mca_project_name, component->mca_type_name, component->mca_component_name, + name, description, verbosity, datatypes, offsets, num_datatypes, enumerator, bind, + source, flags | MCA_BASE_EVENT_FLAG_IWG, notify, ctx, event_out); +} + +int mca_base_component_event_register_list (const mca_base_component_t *component, mca_base_event_list_item_t *list, int count) +{ + mca_base_var_enum_t *new_enum = NULL; + int ret; + + for (int i = 0 ; i < count ; ++i) { + mca_base_event_list_item_t *item = list + i; + if (NULL != item->elements && NULL != item->elements[0]) { + char *full_name; + ret = mca_base_var_generate_full_name4 (component->mca_project_name, component->mca_type_name, component->mca_component_name, + item->name, &full_name); + if (OPAL_SUCCESS != ret) { + return OPAL_ERROR; + } + + mca_base_var_enum_create_simple (full_name, item->elements, &new_enum); + } + + ret = mca_base_event_register (component->mca_project_name, component->mca_type_name, component->mca_component_name, + item->name, item->desc, item->verbosity, item->datatypes, item->offsets, item->num_datatypes, + new_enum, item->bind, item->source, item->flags | MCA_BASE_EVENT_FLAG_IWG, + item->notify, item->ctx, &item->event); + + if (new_enum) { + OBJ_RELEASE(new_enum); + } + + if (OPAL_SUCCESS != ret) { + return ret; + } + + new_enum = NULL; + } + + return OPAL_SUCCESS; +} + + +int mca_base_event_mark_invalid (mca_base_event_t *event) +{ + event->event_flags |= MCA_BASE_PVAR_FLAG_INVALID; + + return OPAL_SUCCESS; +} + +int mca_base_event_registration_alloc (mca_base_event_t *event, void *obj_registration, opal_info_t *info, + mca_base_event_registration_t **registration) +{ + mca_base_event_registration_t *event_registration = NULL; + + if (0 == event->event_bind) { + /* ignore binding object */ + obj_registration = NULL; + } else if (0 != event->event_bind && NULL == obj_registration) { + /* this is an application error. what is the correct error code? */ + return OPAL_ERR_BAD_PARAM; + } + + /* allocate and initialize the registration */ + event_registration = OBJ_NEW(mca_base_event_registration_t); + if (NULL == event_registration) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + + event_registration->obj_registration = (NULL == obj_registration ? NULL : *(void**)obj_registration); + event_registration->event = event; + event_registration->obj_registration = obj_registration; + + *registration = event_registration; + opal_list_append (&event->event_bound_registrations, &event_registration->super); + + return OPAL_SUCCESS; +} + +int mca_base_event_handle_set_info (mca_base_event_registration_t *registration, opal_info_t *info) +{ + /* nothing to do at this time */ + return OPAL_SUCCESS; +} + +int mca_base_event_handle_get_info (mca_base_event_registration_t *registration, opal_info_t *info_used) +{ + /* nothing to do at this time */ + return OPAL_SUCCESS; +} + +int mca_base_event_register_callback (mca_base_event_registration_t *registration, mca_base_cb_safety_t cb_safety, + opal_info_t *info, void *user_data, mca_base_event_cb_fn_t event_cbfn) +{ + if (cb_safety >= MCA_BASE_CB_SAFETY_MAX || cb_safety < 0) { + return OPAL_ERR_BAD_PARAM; + } + + registration->user_data[cb_safety] = user_data; + /* ensure the user data is commited before setting the callback function */ + opal_atomic_wmb(); + opal_atomic_swap_ptr ((opal_atomic_intptr_t *) (registration->event_cbs + cb_safety), (intptr_t) event_cbfn); + + return OPAL_SUCCESS; +} + +int mca_base_event_callback_set_info (mca_base_event_registration_t *registration, mca_base_cb_safety_t cb_safety, + opal_info_t *info) +{ + /* nothing to do */ + return OPAL_SUCCESS; +} + +int mca_base_event_callback_get_info (mca_base_event_registration_t *registration, mca_base_cb_safety_t cb_safety, + opal_info_t *info_used) +{ + /* nothing to do */ + return OPAL_SUCCESS; +} + +void mca_base_event_registration_free (mca_base_event_registration_t *registration, mca_base_event_registration_free_cb_fn_t cbfn) +{ + registration->free_cb = cbfn; + OBJ_RELEASE(registration); +} + +int mca_base_event_dump(int index, char ***out, mca_base_var_dump_type_t output_type) +{ + const char *framework, *component, *full_name; + mca_base_var_group_t *group; + int line = 0, line_count; + mca_base_event_t *event; + int ret, enum_count = 0; + char *tmp; + + ret = mca_base_event_get_by_index (index, &event); + if (OPAL_SUCCESS != ret) { + return ret; + } + + ret = mca_base_var_group_get_internal (event->event_group_index, &group, true); + if (OPAL_SUCCESS != ret) { + return ret; + } + + framework = group->group_framework; + component = group->group_component ? group->group_component : "base"; + full_name = event->event_name; + + if (NULL != event->event_enumerator) { + (void) event->event_enumerator->get_count(event->event_enumerator, &enum_count); + } + + if (MCA_BASE_VAR_DUMP_PARSABLE == output_type) { + line_count = 2 + !!(event->event_description) + enum_count + event->event_datatype_count; + + *out = (char **) calloc (line_count + 1, sizeof (char *)); + if (NULL == *out) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + + /* build the message*/ + (void)asprintf(&tmp, "mca:%s:%s:event:%s:", framework, component, full_name); + + (void)asprintf(out[0] + line++, "%snum_datatypes:%lu", tmp, (unsigned long) event->event_datatype_count); + for (size_t i = 0 ; i < event->event_datatype_count ; ++i) { + (void)asprintf(out[0] + line++, "%sdatatypes:%lu:%s", tmp, (unsigned long) i, event->event_datatypes[i]->name); + } + + /* if it has a help message, output the help message */ + if (event->event_description) { + (void)asprintf(out[0] + line++, "%shelp:%s", tmp, event->event_description); + } + + if (NULL != event->event_enumerator) { + for (int i = 0 ; i < enum_count ; ++i) { + const char *enum_string = NULL; + int enum_value; + + ret = event->event_enumerator->get_value (event->event_enumerator, i, &enum_value, + &enum_string); + if (OPAL_SUCCESS != ret) { + continue; + } + + (void)asprintf(out[0] + line++, "%senumerator:element:%d:%s", tmp, enum_value, enum_string); + } + } + + free(tmp); // release tmp storage + } else { + /* there will be at most three lines in the pretty print case */ + *out = (char **) calloc (4, sizeof (char *)); + if (NULL == *out) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + + (void)asprintf (out[0] + line++, "event \"%s\" (datatype count: %ld)", full_name, + (long) event->event_datatype_count); + + if (event->event_description) { + (void)asprintf(out[0] + line++, "%s", event->event_description); + } + + if (NULL != event->event_enumerator) { + char *values; + + ret = event->event_enumerator->dump(event->event_enumerator, &values, MCA_BASE_VAR_ENUM_DUMP_READABLE); + if (OPAL_SUCCESS == ret) { + (void)asprintf (out[0] + line++, "Elements: %s", values); + free (values); + } + } + } + + return OPAL_SUCCESS; +} + +void MCA_BASE_EVENT_RAISE_internal (mca_base_event_t *event, mca_base_cb_safety_t cb_safety, void *obj, mca_base_source_t *source, void *data) +{ + mca_base_raised_event_t revent = {.re_timestamp = source ? source->source_time () : event->event_source->source_time (), + .re_source = source ? source->source_index : event->event_source->source_index, + .re_data = data, .re_event = event}; + mca_base_event_registration_t *registration; + + OPAL_LIST_FOREACH(registration, &event->event_bound_registrations, mca_base_event_registration_t) { + if (registration->obj_registration != obj) { + continue; + } + + for (mca_base_cb_safety_t i = cb_safety ; i < MCA_BASE_CB_SAFETY_MAX ; ++i) { + mca_base_event_cb_fn_t cb = registration->event_cbs[i]; + + if (NULL == cb) { + continue; + } + + /* call only the least restrictive callback allowed by the raise */ + cb (&revent, registration, cb_safety, registration->user_data[i]); + break; + } + } +} + +/* mca_base_event_t class */ +static void mca_base_event_contructor (mca_base_event_t *event) +{ + memset ((char *) event + sizeof (event->super), 0, sizeof (*event) - sizeof (event->super)); + OBJ_CONSTRUCT(&event->event_bound_registrations, opal_list_t); +} + +static void mca_base_event_destructor (mca_base_event_t *event) +{ + free (event->event_name); + free (event->event_description); + + if (NULL != event->event_enumerator) { + OBJ_RELEASE(event->event_enumerator); + } + + free (event->event_datatypes); + + OBJ_DESTRUCT(&event->event_bound_registrations); +} + +OBJ_CLASS_INSTANCE(mca_base_event_t, opal_object_t, mca_base_event_contructor, mca_base_event_destructor); + +/* mca_base_event_registration_t class */ +static void mca_base_event_registration_constructor (mca_base_event_registration_t *registration) +{ + memset ((char *) registration + sizeof (registration->super), 0, sizeof (*registration) - sizeof (registration->super)); +} + +static void mca_base_event_registration_destructor (mca_base_event_registration_t *registration) +{ + /* remove this registration from the event's list */ + if (registration->event) { + opal_list_remove_item (®istration->event->event_bound_registrations, ®istration->super); + } + + if (registration->free_cb) { + registration->free_cb (registration, MCA_BASE_CB_REQUIRE_NONE, registration->user_data); + } +} + +OBJ_CLASS_INSTANCE(mca_base_event_registration_t, opal_list_item_t, mca_base_event_registration_constructor, + mca_base_event_registration_destructor); + + +/* query functions */ +int mca_base_event_get_time (mca_base_raised_event_t *revent, uint64_t *event_time) +{ + *event_time = revent->re_timestamp; + return OPAL_SUCCESS; +} + +void mca_base_event_get_source (mca_base_raised_event_t *revent, int *source_index) +{ + *source_index = revent->re_source; +} + +int mca_base_event_read (mca_base_raised_event_t *revent, unsigned int element_index, void *buffer) +{ + mca_base_event_t *event = revent->re_event; + + if (element_index > event->event_datatype_count) { + return OPAL_ERR_VALUE_OUT_OF_BOUNDS; + } + + memcpy (buffer, revent->re_data + event->event_offsets[element_index], event->event_datatypes[element_index]->size); + + return OPAL_SUCCESS; +} + +void mca_base_event_copy (mca_base_raised_event_t *revent, void *buffer) +{ + mca_base_event_t *event = revent->re_event; + uint8_t *buffer_ptr = (uint8_t *)buffer; + + for (size_t i = 0 ; i < event->event_datatype_count ; ++i) { + if (buffer) { + memcpy (buffer_ptr, revent->re_data + event->event_offsets[i], event->event_datatypes[i]->size); + buffer_ptr += event->event_datatypes[i]->size; + } + } +} + +int mca_base_event_read_some (mca_base_raised_event_t *revent, void *array_of_buffers[]) +{ + mca_base_event_t *event = revent->re_event; + + for (size_t i = 0 ; i < event->event_datatype_count ; ++i) { + if (array_of_buffers[i]) { + memcpy (array_of_buffers[i], revent->re_data + event->event_offsets[i], event->event_datatypes[i]->size); + } + } + + return OPAL_SUCCESS; +} + +int mca_base_event_read_all (mca_base_raised_event_t *revent, void *array_of_buffers[]) +{ + mca_base_event_t *event = revent->re_event; + + for (size_t i = 0 ; i < event->event_datatype_count ; ++i) { + memcpy (array_of_buffers[i], revent->re_data + event->event_offsets[i], event->event_datatypes[i]->size); + } + + return OPAL_SUCCESS; +} + +void mca_base_event_registration_set_dropped_handler (mca_base_event_registration_t *registration, mca_base_event_dropped_cb_fn_t cbfn) +{ + registration->dropped_cb = cbfn; +} diff --git a/opal/mca/base/mca_base_event.h b/opal/mca/base/mca_base_event.h new file mode 100644 index 00000000000..bc270798887 --- /dev/null +++ b/opal/mca/base/mca_base_event.h @@ -0,0 +1,225 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2018-2019 Triad National Security, LLC. All rights + * reserved. + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#if !defined(MCA_BASE_EVENT_H) +#define MCA_BASE_EVENT_H + +#include "opal/datatype/opal_datatype.h" +#include "opal/util/info.h" +#include "mca_base_pvar.h" +#include "mca_base_source.h" + +struct mca_base_event_t; +struct mca_base_event_registration_t; +struct mca_base_raised_event_t; + +/* + * These flags are used when registering a new event. + */ +typedef enum { + /** This variable should be marked as invalid when the containing + group is deregistered (IWG = "invalidate with group"). This + flag is set automatically when you register a variable with + mca_base_component_pvvar_register(), but can also be set + manually when you register a variable with + mca_base_pvar_register(). Analogous to the + MCA_BASE_VAR_FLAG_DWG flag. */ + MCA_BASE_EVENT_FLAG_IWG = 0x040, + /** This variable has been marked as invalid. This flag is ignored + by mca_base_pvar_register(). */ + MCA_BASE_EVENT_FLAG_INVALID = 0x400, +} mca_base_event_flag_t; + +/** + * @basic Callback safety levels + * + * Values are set in configure.ac for consistency with mpi.h + */ +typedef enum { + MCA_BASE_CB_REQUIRE_NONE = OPAL_MCA_BASE_CB_REQUIRE_NONE, + MCA_BASE_CB_REQUIRE_MPI_RESTRICTED = OPAL_MCA_BASE_CB_REQUIRE_MPI_RESTRICTED, + MCA_BASE_CB_REQUIRE_THREAD_SAFE = OPAL_MCA_BASE_CB_REQUIRE_THREAD_SAFE, + MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE = OPAL_MCA_BASE_CB_REQUIRE_ASYNC_SIGNAL_SAFE, + MCA_BASE_CB_SAFETY_MAX, +} mca_base_cb_safety_t; + +typedef void (*mca_base_event_cb_fn_t) (struct mca_base_raised_event_t *event, struct mca_base_event_registration_t *registration, + mca_base_cb_safety_t cb_safety, void *user_data); + +typedef void (*mca_base_event_registration_free_cb_fn_t) (struct mca_base_event_registration_t *registration, + mca_base_cb_safety_t cb_safety, void *user_data); + +typedef void (*mca_base_event_dropped_cb_fn_t) (int count, struct mca_base_event_registration_t *registration, + mca_base_cb_safety_t cb_safety, void *user_data); + +typedef struct mca_base_raised_event_t { + struct mca_base_event_t *re_event; + int re_source; + uint64_t re_timestamp; + int8_t *re_data; +} mca_base_raised_event_t; + +typedef struct mca_base_event_t { + /** Make this an opal object */ + opal_object_t super; + + /** Variable index */ + int event_index; + + /** Full name of the variable: form is framework_component_name */ + char *event_name; + + /** Description of this performance variable */ + char *event_description; + + /** MCA variable group this variable is associated with */ + int event_group_index; + + /** Verbosity level of this variable */ + mca_base_var_info_lvl_t event_verbosity; + + /** Event datatypes */ + opal_datatype_t **event_datatypes; + + /** Event offsets */ + unsigned long *event_offsets; + + /** Size of the event_datatypes array */ + size_t event_datatype_count; + + /** Enumerator for integer values */ + mca_base_var_enum_t *event_enumerator; + + /** Type of object to which this variable must be bound or MCA_BASE_VAR_BIND_NO_OBJECT */ + int event_bind; + + /** event source (may be NULL) */ + mca_base_source_t *event_source; + + /** Flags for this variable */ + uint32_t event_flags; + + /** Notify the creator of this variable of a new/deleted handle. This callback can + * be used to turn on/off code that is needed for the event but may reduce performance + * in the case where there are no active event listeners. */ + mca_base_notify_fn_t event_notify; + + /** Context of this variable */ + void *event_ctx; + + /** List of bound event registrations. NOTE: The items in this list are + offsetof(mca_base_pvar_registration_t, list2) into a pvar registration. */ + opal_list_t event_bound_registrations; +} mca_base_event_t; + +OBJ_CLASS_DECLARATION(mca_base_event_t); + +typedef struct mca_base_event_list_item_t { + const char *name; + const char *desc; + mca_base_var_info_lvl_t verbosity; + opal_datatype_t **datatypes; + unsigned long *offsets; + size_t num_datatypes; + char **elements; + int bind; + int source; + uint32_t flags; + mca_base_notify_fn_t notify; + void *ctx; + mca_base_event_t *event; +} mca_base_event_list_item_t; + +typedef struct mca_base_event_registration_t { + opal_list_item_t super; + + /** associated event */ + mca_base_event_t *event; + + /** user callback to trigger on event */ + mca_base_event_cb_fn_t event_cbs[MCA_BASE_CB_SAFETY_MAX]; + + /** user callback to trigger when an event was dropped */ + mca_base_event_dropped_cb_fn_t dropped_cb; + + /** free callback */ + mca_base_event_registration_free_cb_fn_t free_cb; + + /** user data specified when this registration was created */ + void *user_data[MCA_BASE_CB_SAFETY_MAX]; + + /** bound object registration */ + void *obj_registration; +} mca_base_event_registration_t; + +OBJ_CLASS_DECLARATION(mca_base_event_registration_t); + +OPAL_DECLSPEC int mca_base_event_init (void); +OPAL_DECLSPEC int mca_base_event_finalize (void); + +OPAL_DECLSPEC int mca_base_event_get_count (int *count); +OPAL_DECLSPEC int mca_base_event_mark_invalid (mca_base_event_t *event); +OPAL_DECLSPEC int mca_base_event_dump(int index, char ***out, mca_base_var_dump_type_t output_type); + +OPAL_DECLSPEC int mca_base_event_register (const char *project, const char *framework, const char *component, const char *name, + const char *description, mca_base_var_info_lvl_t verbosity, opal_datatype_t **datatypes, + unsigned long *offsets, size_t num_datatypes, mca_base_var_enum_t *enumerator, int bind, + int source, uint32_t flags, mca_base_notify_fn_t notify, void *ctx, mca_base_event_t **event_out); + +OPAL_DECLSPEC int mca_base_component_event_register (const mca_base_component_t *component, const char *name, + const char *description, mca_base_var_info_lvl_t verbosity, opal_datatype_t **datatypes, + unsigned long *offsets, size_t num_datatypes, mca_base_var_enum_t *enumerator, int bind, + int source, uint32_t flags, mca_base_notify_fn_t notify, void *ctx, mca_base_event_t **event_out); + +OPAL_DECLSPEC int mca_base_component_event_register_list (const mca_base_component_t *component, mca_base_event_list_item_t *list, int count); + +OPAL_DECLSPEC void MCA_BASE_EVENT_RAISE_internal (mca_base_event_t *event, mca_base_cb_safety_t cb_safety, void *obj, mca_base_source_t *source, + void *data); + +#define MCA_BASE_EVENT_RAISE(eventp, cb_safety, obj, source, data) \ + do { \ + if (OPAL_UNLIKELY(0 != opal_list_get_size (&(eventp)->event_bound_registrations))) { \ + /* at least one registration is bound to this event. raise the event with the user code */ \ + MCA_BASE_EVENT_RAISE_internal (eventp, cb_safety, obj, source, data); \ + } \ + } while (0); + +OPAL_DECLSPEC int mca_base_event_registration_alloc (mca_base_event_t *event, void *obj_registration, opal_info_t *info, + mca_base_event_registration_t **registration); +OPAL_DECLSPEC int mca_base_event_register_callback (mca_base_event_registration_t *registration, mca_base_cb_safety_t cb_safety, + opal_info_t *info, void *user_data, mca_base_event_cb_fn_t event_cbfn); + +OPAL_DECLSPEC void mca_base_event_registration_free (mca_base_event_registration_t *registration, mca_base_event_registration_free_cb_fn_t cbfn); + +OPAL_DECLSPEC void mca_base_event_registration_set_dropped_handler (mca_base_event_registration_t *registration, mca_base_event_dropped_cb_fn_t cbfn); + +OPAL_DECLSPEC int mca_base_event_get_by_index (int index, mca_base_event_t **event); +OPAL_DECLSPEC int mca_base_event_get_by_name (const char *project, const char *framework, const char *component, const char *name, + mca_base_event_t **event); +OPAL_DECLSPEC int mca_base_registration_get_event (mca_base_event_registration_t *registration, mca_base_event_t **event); +OPAL_DECLSPEC int mca_base_event_get_by_fullname (const char *full_name, mca_base_event_t **event); + +OPAL_DECLSPEC int mca_base_event_get_time (mca_base_raised_event_t *revent, uint64_t *event_time); +OPAL_DECLSPEC void mca_base_event_get_source (mca_base_raised_event_t *revent, int *source_index); +OPAL_DECLSPEC int mca_base_event_read (mca_base_raised_event_t *revent, unsigned int element_index, void *buffer); +OPAL_DECLSPEC void mca_base_event_copy (mca_base_raised_event_t *revent, void *buffer); +OPAL_DECLSPEC int mca_base_event_read_some (mca_base_raised_event_t *revent, void *array_of_buffers[]); +OPAL_DECLSPEC int mca_base_event_read_all (mca_base_raised_event_t *revent, void *array_of_buffers[]); + +OPAL_DECLSPEC int mca_base_event_handle_set_info (mca_base_event_registration_t *registration, opal_info_t *info); +OPAL_DECLSPEC int mca_base_event_handle_get_info (mca_base_event_registration_t *registration, opal_info_t *info_used); +OPAL_DECLSPEC int mca_base_event_callback_set_info (mca_base_event_registration_t *registration, mca_base_cb_safety_t cb_safety, + opal_info_t *info); +OPAL_DECLSPEC int mca_base_event_callback_get_info (mca_base_event_registration_t *registration, mca_base_cb_safety_t cb_safety, + opal_info_t *info_used); + +#endif /* !defined(MCA_BASE_EVENT_H) */ diff --git a/opal/mca/base/mca_base_source.c b/opal/mca/base/mca_base_source.c new file mode 100644 index 00000000000..8b8b4fdb6b1 --- /dev/null +++ b/opal/mca/base/mca_base_source.c @@ -0,0 +1,276 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights + * reserved. + * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2015 Bull SAS. All rights reserved. + * Copyright (c) 2015 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "mca_base_source.h" +#include "mca_base_vari.h" + +#include +#include +#include + +#include "opal/class/opal_pointer_array.h" +#include "opal/class/opal_hash_table.h" +#include "opal/util/clock_gettime.h" + +static opal_pointer_array_t registered_sources; +static bool mca_base_source_initialized = false; +static int source_count; + +static opal_mutex_t mca_base_source_lock = OPAL_MUTEX_STATIC_INIT; + +int mca_base_source_default_source = -1; + +static uint64_t mca_base_source_default_time_source (void) +{ + uint64_t time_value; + struct timespec current; + + (void)opal_clock_gettime(¤t); + time_value = 1000000000ul * current.tv_sec + current.tv_nsec; + + return time_value; +} + +static uint64_t mca_base_source_default_time_source_ticks (void) +{ + struct timespec spec; + if (OPAL_LIKELY(0 == opal_clock_getres(&spec))){ + return (uint64_t)(spec.tv_sec + spec.tv_nsec); + } else { + /* guess */ + return 1000000; + } +} + +/***************************************************************************************************/ + +int mca_base_source_init (void) +{ + int ret = OPAL_SUCCESS; + + OPAL_THREAD_LOCK(&mca_base_source_lock); + + if (false == mca_base_source_initialized) { + mca_base_source_initialized = true; + + OBJ_CONSTRUCT(®istered_sources, opal_pointer_array_t); + opal_pointer_array_init(®istered_sources, 16, 512, 16); + + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + + /* mca_base_source_register will use lock */ + mca_base_source_default_source = mca_base_source_register ("opal", "mca", "base", "default_source", + "Default source for MCA events", true, + mca_base_source_default_time_source, + mca_base_source_default_time_source_ticks ()); + + } + else + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + + return ret; +} + +int mca_base_source_finalize (void) +{ + int i; + + OPAL_THREAD_LOCK(&mca_base_source_lock); + if (true == mca_base_source_initialized) { + for (i = 0 ; i < source_count ; ++i) { + mca_base_source_t *source = opal_pointer_array_get_item (®istered_sources, i); + if (source) { + OBJ_RELEASE(source); + } + } + + source_count = 0; + + OBJ_DESTRUCT(®istered_sources); + mca_base_source_initialized = false; + } + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + + return OPAL_SUCCESS; +} + +/***************************************************************************************************/ + +mca_base_source_t *mca_base_source_get (int source_index) +{ + mca_base_source_t *ret; + + OPAL_THREAD_LOCK(&mca_base_source_lock); + + ret = opal_pointer_array_get_item (®istered_sources, source_index); + + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + + return ret; +} + +int mca_base_source_set_time_source (int source_index, mca_base_source_time_fn_t time_source, uint64_t time_ticks) +{ + /* Uses source lock/unlock */ + mca_base_source_t *source = mca_base_source_get (source_index); + + if (NULL == source) { + return OPAL_ERR_NOT_FOUND; + } + + OPAL_THREAD_LOCK(&mca_base_source_lock); + + if (!time_source) { + time_source = mca_base_source_default_time_source; + time_ticks = mca_base_source_default_time_source_ticks (); + } + + source->source_time = time_source; + source->source_ticks = time_ticks; + + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + + return OPAL_SUCCESS; +} + +/***************************************************************************************************/ + +int mca_base_source_get_count (int *count) +{ + OPAL_THREAD_LOCK(&mca_base_source_lock); + + *count = source_count; + + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + + return OPAL_SUCCESS; +} + +/* This function should be under mca_base_source_lock. */ +/* Due to this being called only from mca_base_source_register() currently, */ +/* and that is under such lock, there aren't any locks here. */ +/* This should be considered if this needs to be called from somewhere else. */ +static inline int mca_base_source_get_by_name (const char *name, mca_base_source_t **source_out) +{ + /* there are expected to be a relatively small number of sources so a linear search should be fine */ + for (int i = 0 ; i < source_count ; ++i) { + mca_base_source_t *source = opal_pointer_array_get_item (®istered_sources, i); + if (NULL != source && 0 == strcmp (name, source->source_name)) { + if (source) { + *source_out = source; + } + + return OPAL_SUCCESS; + } + } + + return OPAL_ERR_NOT_FOUND; +} + +int mca_base_source_register (const char *project, const char *framework, const char *component, const char *name, + const char *description, bool ordered, mca_base_source_time_fn_t source_time, uint64_t source_ticks) +{ + mca_base_source_t *source; + char *source_name; + int ret; + + OPAL_THREAD_LOCK(&mca_base_source_lock); + + /* generate the variable's full name */ + ret = mca_base_var_generate_full_name4 (NULL, framework, component, name, &source_name); + if (OPAL_SUCCESS != ret) { + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + return ret; + } + + + /* check if this variable is already registered */ + ret = mca_base_source_get_by_name (source_name, &source); + if (OPAL_SUCCESS > ret) { + /* create a new parameter entry */ + source = OBJ_NEW(mca_base_source_t); + if (NULL == source) { + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + return OPAL_ERR_OUT_OF_RESOURCE; + } + + do { + source->source_name = source_name; + + if (NULL != description) { + source->source_description = strdup(description); + if (NULL == source->source_description) { + ret = OPAL_ERR_OUT_OF_RESOURCE; + break; + } + } + + source->source_index = opal_pointer_array_add (®istered_sources, source); + if (0 > source->source_index) { + ret = OPAL_ERR_OUT_OF_RESOURCE; + break; + } + + source_count++; + ret = OPAL_SUCCESS; + } while (0); + + if (OPAL_SUCCESS != ret) { + OBJ_RELEASE(source); + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + return ret; + } + } else { + free (source_name); + } + + source->source_ordered = ordered; + if (NULL == source_time) { + source_time = mca_base_source_default_time_source; + source_ticks = mca_base_source_default_time_source_ticks (); + } + + source->source_time = source_time; + source->source_ticks = source_ticks; + + OPAL_THREAD_UNLOCK(&mca_base_source_lock); + + return OPAL_SUCCESS; +} +int mca_base_component_source_register (const mca_base_component_t *component, const char *name, const char *description, bool ordered, + mca_base_source_time_fn_t source_time, uint64_t source_ticks) +{ + /* invalidate this variable if the component's group is deregistered */ + return mca_base_source_register (component->mca_project_name, component->mca_type_name, component->mca_component_name, + name, description, ordered, source_time, source_ticks); +} + +/* mca_base_source_t class */ +static void mca_base_source_constructor (mca_base_source_t *source) +{ + memset ((char *) source + sizeof (source->super), 0, sizeof (*source) - sizeof (source->super)); +} + +static void mca_base_source_destructor (mca_base_source_t *source) +{ + free (source->source_name); + source->source_name = NULL; + free (source->source_description); + source->source_description = NULL; +} + +OBJ_CLASS_INSTANCE(mca_base_source_t, opal_object_t, mca_base_source_constructor, mca_base_source_destructor); diff --git a/opal/mca/base/mca_base_source.h b/opal/mca/base/mca_base_source.h new file mode 100644 index 00000000000..62a156746f7 --- /dev/null +++ b/opal/mca/base/mca_base_source.h @@ -0,0 +1,68 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ +/* + * Copyright (c) 2018 Los Alamos National Security, LLC. All rights + * reserved. + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#if !defined(MCA_BASE_SOURCE_H) +#define MCA_BASE_SOURCE_H + +#include "opal/datatype/opal_datatype.h" +#include "mca_base_pvar.h" + +enum { + /* default source */ + MCA_BASE_SOURCE_DEFAULT_SOURCE, +}; + +typedef uint64_t (*mca_base_source_time_fn_t) (void); + +typedef struct mca_base_source_t { + /** Make this an opal object */ + opal_object_t super; + + /** Source index */ + int source_index; + + /** Source ordering */ + bool source_ordered; + + /** Full name of the variable: form is framework_component_name */ + char *source_name; + + /** Description of this performance variable */ + char *source_description; + + /** Time source (never NULL) */ + mca_base_source_time_fn_t source_time; + + /** Time source ticks per second */ + uint64_t source_ticks; +} mca_base_source_t; + +OBJ_CLASS_DECLARATION(mca_base_source_t); + +extern int mca_base_source_default_source; + +OPAL_DECLSPEC int mca_base_source_init (void); +OPAL_DECLSPEC int mca_base_source_finalize (void); + +OPAL_DECLSPEC int mca_base_source_get_count (int *count); + +OPAL_DECLSPEC int mca_base_source_dump(int index, char ***out, mca_base_var_dump_type_t output_type); + +OPAL_DECLSPEC int mca_base_source_register (const char *project, const char *framework, const char *component, const char *name, + const char *description, bool ordered, mca_base_source_time_fn_t source_time, uint64_t source_ticks); + +OPAL_DECLSPEC int mca_base_component_source_register (const mca_base_component_t *component, const char *name, const char *description, + bool ordered, mca_base_source_time_fn_t source_time, uint64_t source_ticks); + +OPAL_DECLSPEC int mca_base_source_set_time_source (int source_index, mca_base_source_time_fn_t time_source, uint64_t time_ticks); + +OPAL_DECLSPEC mca_base_source_t *mca_base_source_get (int source_index); + +#endif /* !defined(MCA_BASE_SOURCE_H) */ diff --git a/opal/mca/base/mca_base_var.c b/opal/mca/base/mca_base_var.c index b9860c6ed1e..f604ab0cb3b 100644 --- a/opal/mca/base/mca_base_var.c +++ b/opal/mca/base/mca_base_var.c @@ -279,6 +279,16 @@ int mca_base_var_init(void) cwd = strdup("."); } + ret = mca_base_source_init (); + if (OPAL_SUCCESS != ret) { + return ret; + } + + ret = mca_base_event_init (); + if (OPAL_SUCCESS != ret) { + return ret; + } + /* Set this before we register the parameter, below */ mca_base_var_initialized = true; diff --git a/opal/mca/base/mca_base_var_enum.c b/opal/mca/base/mca_base_var_enum.c index a6d89da5f20..8868d8c8aec 100644 --- a/opal/mca/base/mca_base_var_enum.c +++ b/opal/mca/base/mca_base_var_enum.c @@ -429,6 +429,43 @@ int mca_base_var_enum_create(const char *name, const mca_base_var_enum_value_t * return OPAL_SUCCESS; } +int mca_base_var_enum_create_simple (const char *name, char * const strings[], mca_base_var_enum_t **enumerator) +{ + mca_base_var_enum_t *new_enum; + int i; + + *enumerator = NULL; + + new_enum = OBJ_NEW(mca_base_var_enum_t); + if (NULL == new_enum) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + + new_enum->enum_name = strdup (name); + if (NULL == new_enum->enum_name) { + return OPAL_ERR_OUT_OF_RESOURCE; + } + + for (i = 0 ; strings[i] ; ++i); + new_enum->enum_value_count = i; + + /* make a copy of the values */ + new_enum->enum_values = calloc (new_enum->enum_value_count + 1, sizeof (*new_enum->enum_values)); + if (NULL == new_enum->enum_values) { + OBJ_RELEASE(new_enum); + return OPAL_ERR_OUT_OF_RESOURCE; + } + + for (i = 0 ; i < new_enum->enum_value_count ; ++i) { + new_enum->enum_values[i].value = i; + new_enum->enum_values[i].string = strdup (strings[i]); + } + + *enumerator = new_enum; + + return OPAL_SUCCESS; +} + int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_value_flag_t *flags, mca_base_var_enum_flag_t **enumerator) { diff --git a/opal/mca/base/mca_base_var_enum.h b/opal/mca/base/mca_base_var_enum.h index 7fdfa8e64f0..89aa7b9e7bf 100644 --- a/opal/mca/base/mca_base_var_enum.h +++ b/opal/mca/base/mca_base_var_enum.h @@ -221,6 +221,9 @@ OPAL_DECLSPEC int mca_base_var_enum_create(const char *name, const mca_base_var_enum_value_t values[], mca_base_var_enum_t **enumerator); +OPAL_DECLSPEC int mca_base_var_enum_create_simple (const char *name, char * const strings[], + mca_base_var_enum_t **enumerator); + /** * Create a new default flag enumerator * diff --git a/opal/mca/base/mca_base_var_group.c b/opal/mca/base/mca_base_var_group.c index 732df663e98..de27a7723c9 100644 --- a/opal/mca/base/mca_base_var_group.c +++ b/opal/mca/base/mca_base_var_group.c @@ -11,7 +11,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2008-2013 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights + * Copyright (c) 2012-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. @@ -42,6 +42,10 @@ #include "opal/mca/base/mca_base_pvar.h" #include "opal/mca/base/mca_base_vari.h" #include "opal/mca/mca.h" +#include "opal/mca/base/mca_base_event.h" +#include "opal/constants.h" +#include "opal/util/output.h" +#include "opal/util/opal_environ.h" #include "opal/runtime/opal.h" #include "opal/util/opal_environ.h" #include "opal/util/output.h" @@ -58,6 +62,8 @@ static void mca_base_var_group_destructor(mca_base_var_group_t *group); OBJ_CLASS_INSTANCE(mca_base_var_group_t, opal_object_t, mca_base_var_group_constructor, mca_base_var_group_destructor); +static opal_mutex_t mca_base_var_group_lock = OPAL_MUTEX_STATIC_INIT; + int mca_base_var_group_init(void) { int ret; @@ -78,7 +84,9 @@ int mca_base_var_group_init(void) } mca_base_var_group_initialized = true; + OPAL_THREAD_LOCK(&mca_base_var_group_lock); mca_base_var_group_count = 0; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); } return OPAL_SUCCESS; @@ -99,7 +107,9 @@ int mca_base_var_group_finalize(void) } OBJ_DESTRUCT(&mca_base_var_groups); OBJ_DESTRUCT(&mca_base_var_group_index_hash); + OPAL_THREAD_LOCK(&mca_base_var_group_lock); mca_base_var_group_count = 0; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); mca_base_var_group_initialized = false; } @@ -164,6 +174,7 @@ static bool compare_strings(const char *str1, const char *str2) static int group_find_linear(const char *project_name, const char *framework_name, const char *component_name, bool invalidok) { + OPAL_THREAD_LOCK(&mca_base_var_group_lock); for (int i = 0; i < mca_base_var_group_count; ++i) { mca_base_var_group_t *group; @@ -175,9 +186,11 @@ static int group_find_linear(const char *project_name, const char *framework_nam if (compare_strings(project_name, group->group_project) && compare_strings(framework_name, group->group_framework) && compare_strings(component_name, group->group_component)) { + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); return i; } } + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); return OPAL_ERR_NOT_FOUND; } @@ -237,7 +250,9 @@ static int group_register(const char *project_name, const char *framework_name, return ret; } group->group_isvalid = true; + OPAL_THREAD_LOCK(&mca_base_var_group_lock); mca_base_var_groups_timestamp++; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); /* group already exists. return it's index */ return group_id; @@ -301,8 +316,10 @@ static int group_register(const char *project_name, const char *framework_name, opal_hash_table_set_value_ptr(&mca_base_var_group_index_hash, group->group_full_name, strlen(group->group_full_name), (void *) (uintptr_t) group_id); + OPAL_THREAD_LOCK(&mca_base_var_group_lock); mca_base_var_group_count++; mca_base_var_groups_timestamp++; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); if (0 <= parent_id) { mca_base_var_group_t *parent_group; @@ -379,6 +396,21 @@ int mca_base_var_group_deregister(int group_index) opal_value_array_set_size(&group->group_enums, 0); + /* deregister all events */ + size = opal_value_array_get_size(&group->group_events); + params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_events, int); + + for (int i = 0 ; i < size ; ++i) { + mca_base_event_t *event; + + ret = mca_base_event_get_by_index (params[i], &event); + if (OPAL_SUCCESS != ret || !(event->event_flags & MCA_BASE_EVENT_FLAG_IWG)) { + continue; + } + + (void) mca_base_event_mark_invalid (event); + } + size = opal_value_array_get_size(&group->group_subgroups); subgroups = OPAL_VALUE_ARRAY_GET_BASE(&group->group_subgroups, int); for (int i = 0; i < size; ++i) { @@ -387,7 +419,9 @@ int mca_base_var_group_deregister(int group_index) /* ordering of variables and subgroups must be the same if the * group is re-registered */ + OPAL_THREAD_LOCK(&mca_base_var_group_lock); mca_base_var_groups_timestamp++; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); return OPAL_SUCCESS; } @@ -426,7 +460,9 @@ int mca_base_var_group_add_var(const int group_index, const int param_index) return ret; } + OPAL_THREAD_LOCK(&mca_base_var_group_lock); mca_base_var_groups_timestamp++; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); /* return the group index */ return (int) opal_value_array_get_size(&group->group_vars) - 1; @@ -455,7 +491,9 @@ int mca_base_var_group_add_pvar(const int group_index, const int param_index) return ret; } + OPAL_THREAD_LOCK(&mca_base_var_group_lock); mca_base_var_groups_timestamp++; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); /* return the group index */ return (int) opal_value_array_get_size(&group->group_pvars) - 1; @@ -488,7 +526,39 @@ int mca_base_var_group_add_enum(const int group_index, const void *storage) return (int) opal_value_array_get_size(&group->group_enums) - 1; } -int mca_base_var_group_get(const int group_index, const mca_base_var_group_t **group) +int mca_base_var_group_add_event (const int group_index, const int event_index) +{ + mca_base_var_group_t *group; + int size, i, ret; + int *params; + + ret = mca_base_var_group_get_internal (group_index, &group, false); + if (OPAL_SUCCESS != ret) { + return ret; + } + + size = opal_value_array_get_size(&group->group_events); + params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_events, int); + for (i = 0 ; i < size ; ++i) { + if (params[i] == event_index) { + return i; + } + } + + if (OPAL_SUCCESS != + (ret = opal_value_array_append_item (&group->group_events, &event_index))) { + return ret; + } + + OPAL_THREAD_LOCK(&mca_base_var_group_lock); + mca_base_var_groups_timestamp++; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); + + /* return the group index */ + return (int) opal_value_array_get_size (&group->group_events) - 1; +} + +int mca_base_var_group_get (const int group_index, const mca_base_var_group_t **group) { return mca_base_var_group_get_internal(group_index, (mca_base_var_group_t **) group, false); } @@ -531,7 +601,10 @@ static void mca_base_var_group_constructor(mca_base_var_group_t *group) opal_value_array_init(&group->group_pvars, sizeof(int)); OBJ_CONSTRUCT(&group->group_enums, opal_value_array_t); - opal_value_array_init(&group->group_enums, sizeof(void *)); + opal_value_array_init (&group->group_enums, sizeof(void *)); + + OBJ_CONSTRUCT(&group->group_events, opal_value_array_t); + opal_value_array_init (&group->group_events, sizeof(int)); } static void mca_base_var_group_destructor(mca_base_var_group_t *group) @@ -555,14 +628,25 @@ static void mca_base_var_group_destructor(mca_base_var_group_t *group) OBJ_DESTRUCT(&group->group_vars); OBJ_DESTRUCT(&group->group_pvars); OBJ_DESTRUCT(&group->group_enums); + OBJ_DESTRUCT(&group->group_events); } int mca_base_var_group_get_count(void) { - return mca_base_var_group_count; + int ret; + + OPAL_THREAD_LOCK(&mca_base_var_group_lock); + ret = mca_base_var_group_count; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); + return ret; } int mca_base_var_group_get_stamp(void) { - return mca_base_var_groups_timestamp; + int ret; + + OPAL_THREAD_LOCK(&mca_base_var_group_lock); + ret = mca_base_var_groups_timestamp; + OPAL_THREAD_UNLOCK(&mca_base_var_group_lock); + return ret; } diff --git a/opal/mca/base/mca_base_var_group.h b/opal/mca/base/mca_base_var_group.h index 71261b16940..bbba7a685e3 100644 --- a/opal/mca/base/mca_base_var_group.h +++ b/opal/mca/base/mca_base_var_group.h @@ -57,6 +57,9 @@ struct mca_base_var_group_t { /** Pointer array of group enums */ opal_value_array_t group_enums; + + /** Pointer array of group events */ + opal_value_array_t group_events; }; typedef struct mca_base_var_group_t mca_base_var_group_t; diff --git a/opal/mca/base/mca_base_vari.h b/opal/mca/base/mca_base_vari.h index cc89842fdd8..b5a2acad4a5 100644 --- a/opal/mca/base/mca_base_vari.h +++ b/opal/mca/base/mca_base_vari.h @@ -11,7 +11,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights + * Copyright (c) 2012-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. @@ -48,6 +48,8 @@ #include "opal/class/opal_value_array.h" #include "opal/mca/base/mca_base_pvar.h" #include "opal/mca/base/mca_base_var.h" +#include "opal/mca/base/mca_base_source.h" +#include "opal/mca/base/mca_base_event.h" BEGIN_C_DECLS @@ -147,6 +149,13 @@ OPAL_DECLSPEC int mca_base_var_group_add_pvar(const int group_index, const int p */ OPAL_DECLSPEC int mca_base_var_group_add_enum(const int group_index, const void *storage); +/** + * \internal + * + * Add an event to a group + */ +OPAL_DECLSPEC int mca_base_var_group_add_event (const int group_index, const int event_index); + /** * \internal * diff --git a/opal/runtime/opal_info_support.c b/opal/runtime/opal_info_support.c index e167451d67f..7f6a455b29b 100644 --- a/opal/runtime/opal_info_support.c +++ b/opal/runtime/opal_info_support.c @@ -11,7 +11,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2010-2016 Los Alamos National Security, LLC. All rights + * Copyright (c) 2010-2018 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2011-2012 University of Houston. All rights reserved. * Copyright (c) 2016-2017 Intel, Inc. All rights reserved. @@ -50,6 +50,9 @@ #include "opal/util/output.h" #include "opal/util/printf.h" #include "opal/util/show_help.h" +#include "opal/runtime/opal.h" +#include "opal/mca/base/mca_base_pvar.h" +#include "opal/mca/base/mca_base_event.h" #include "opal/include/opal/frameworks.h" @@ -667,6 +670,7 @@ static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, { const int *variables, *groups; const mca_base_pvar_t *pvar; + mca_base_event_t *event; const char *group_component; const mca_base_var_t *var; char **strings, *message; @@ -804,6 +808,52 @@ static void opal_info_show_mca_group_params(const mca_base_var_group_t *group, free(strings); } + variables = OPAL_VALUE_ARRAY_GET_BASE(&group->group_events, const int); + count = opal_value_array_get_size((opal_value_array_t *)&group->group_events); + + for (i = 0 ; i < count ; ++i) { + ret = mca_base_event_get_by_index (variables[i], &event); + if (OPAL_SUCCESS != ret || max_level < event->event_verbosity) { + continue; + } + + if (opal_info_pretty && curr_group != group) { + asprintf(&message, "MCA%s %s%s", requested ? "" : " (-)", + group->group_framework, + component_msg ? component_msg : ""); + opal_info_out(message, message, "---------------------------------------------------"); + free(message); + curr_group = group; + } + + ret = mca_base_event_dump (variables[i], &strings, !opal_info_pretty ? MCA_BASE_VAR_DUMP_PARSABLE : MCA_BASE_VAR_DUMP_READABLE); + if (OPAL_SUCCESS != ret) { + continue; + } + + for (j = 0 ; strings[j] ; ++j) { + if (0 == j && opal_info_pretty) { + asprintf (&message, "MCA%s %s%s", requested ? "" : " (-)", + group->group_framework, + component_msg ? component_msg : ""); + opal_info_out(message, message, strings[j]); + free(message); + } else { + opal_info_out("", "", strings[j]); + } + free(strings[j]); + } + if (!opal_info_pretty) { + /* generate an entry indicating whether this variable is disabled or not. if the + * format in mca_base_var/pvar/event.c changes this needs to be changed as well */ + asprintf (&message, "mca:%s:%s:event:%s:disabled:%s", group->group_framework, + group_component, event->event_name, requested ? "false" : "true"); + opal_info_out("", "", message); + free (message); + } + free(strings); + } + groups = OPAL_VALUE_ARRAY_GET_BASE(&group->group_subgroups, const int); count = opal_value_array_get_size((opal_value_array_t *) &group->group_subgroups);