root/ompi/peruse/peruse.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. PERUSE_Init
  2. PERUSE_Query_supported_events
  3. PERUSE_Query_event
  4. PERUSE_Query_event_name
  5. PERUSE_Query_environment
  6. PERUSE_Query_queue_event_scope
  7. PERUSE_Event_comm_register
  8. PERUSE_Event_activate
  9. PERUSE_Event_deactivate
  10. PERUSE_Event_release
  11. PERUSE_Event_comm_callback_set
  12. PERUSE_Event_comm_callback_get
  13. PERUSE_Event_get
  14. PERUSE_Event_object_get
  15. PERUSE_Event_propagate

   1 /*
   2  * Copyright (c) 2004-2006 The University of Tennessee and The University
   3  *                         of Tennessee Research Foundation.  All rights
   4  *                         reserved.
   5  * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
   6  *                         University of Stuttgart.  All rights reserved.
   7  * Copyright (c) 2018      Cisco Systems, Inc.  All rights reserved
   8  * $COPYRIGHT$
   9  *
  10  * Additional copyrights may follow
  11  *
  12  * $HEADER$
  13  */
  14 
  15 #include "ompi_config.h"
  16 #  include <string.h>
  17 #include "mpi.h"
  18 #include "ompi/peruse/peruse.h"
  19 #include "ompi/peruse/peruse-internal.h"
  20 #include "ompi/communicator/communicator.h"
  21 #include "ompi/runtime/params.h"
  22 
  23 /*
  24  * Data
  25  */
  26 
  27 typedef struct {
  28     const char* name;
  29     const int   id;
  30 } peruse_event_associations_t;
  31 
  32 /**
  33  * The associations between the peruse event name and id. This array
  34  * should be ended by the tuple {NULL, PERUSE_CUSTOM_EVENT}.
  35  */
  36 static const peruse_event_associations_t PERUSE_events[] = {
  37     /* Point-to-point request events */
  38     { "PERUSE_COMM_REQ_ACTIVATE", PERUSE_COMM_REQ_ACTIVATE },
  39     { "PERUSE_COMM_REQ_MATCH_UNEX", PERUSE_COMM_REQ_MATCH_UNEX },
  40     { "PERUSE_COMM_REQ_INSERT_IN_POSTED_Q", PERUSE_COMM_REQ_INSERT_IN_POSTED_Q },
  41     { "PERUSE_COMM_REQ_REMOVE_FROM_POSTED_Q", PERUSE_COMM_REQ_REMOVE_FROM_POSTED_Q },
  42     { "PERUSE_COMM_REQ_XFER_BEGIN", PERUSE_COMM_REQ_XFER_BEGIN },
  43     { "PERUSE_COMM_REQ_XFER_CONTINUE", PERUSE_COMM_REQ_XFER_CONTINUE },
  44     { "PERUSE_COMM_REQ_XFER_END", PERUSE_COMM_REQ_XFER_END },
  45     { "PERUSE_COMM_REQ_COMPLETE", PERUSE_COMM_REQ_COMPLETE },
  46     { "PERUSE_COMM_REQ_NOTIFY", PERUSE_COMM_REQ_NOTIFY },
  47     { "PERUSE_COMM_MSG_ARRIVED", PERUSE_COMM_MSG_ARRIVED },
  48     { "PERUSE_COMM_MSG_INSERT_IN_UNEX_Q", PERUSE_COMM_MSG_INSERT_IN_UNEX_Q },
  49     { "PERUSE_COMM_MSG_REMOVE_FROM_UNEX_Q", PERUSE_COMM_MSG_REMOVE_FROM_UNEX_Q },
  50     { "PERUSE_COMM_MSG_MATCH_POSTED_REQ", PERUSE_COMM_MSG_MATCH_POSTED_REQ },
  51 
  52     /* Queue events*/
  53     { "PERUSE_COMM_SEARCH_POSTED_Q_BEGIN", PERUSE_COMM_SEARCH_POSTED_Q_BEGIN },
  54     { "PERUSE_COMM_SEARCH_POSTED_Q_END", PERUSE_COMM_SEARCH_POSTED_Q_END },
  55     { "PERUSE_COMM_SEARCH_UNEX_Q_BEGIN", PERUSE_COMM_SEARCH_UNEX_Q_BEGIN },
  56     { "PERUSE_COMM_SEARCH_UNEX_Q_END", PERUSE_COMM_SEARCH_UNEX_Q_END },
  57     { "PERUSE_CUSTOM_EVENT", PERUSE_CUSTOM_EVENT }
  58 };
  59 
  60 const int PERUSE_num_events = (sizeof(PERUSE_events) / sizeof(peruse_event_associations_t));
  61 
  62 /*
  63  * PERUSE user-callable function
  64  */
  65 int PERUSE_Init (void)
  66 {
  67     if (MPI_PARAM_CHECK) {
  68         int32_t state = ompi_mpi_state;
  69         if (state < OMPI_MPI_STATE_INIT_COMPLETED ||
  70             state >= OMPI_MPI_STATE_FINALIZE_STARTED) {
  71             return PERUSE_ERR_INIT;
  72         }
  73     }
  74     ompi_peruse_init ();
  75     return PERUSE_SUCCESS;
  76 }
  77 
  78 
  79 /* Query all implemented events */
  80 int PERUSE_Query_supported_events (int* num_supported,
  81                                    char*** event_names,
  82                                    int** events)
  83 {
  84     int i;
  85     *num_supported = PERUSE_num_events;
  86 
  87     *event_names = (char**) malloc (PERUSE_num_events * sizeof (char *));
  88     *events = (int*) malloc (PERUSE_num_events * sizeof (int));
  89 
  90     for (i = 0; i < PERUSE_num_events; i++) {
  91         (*event_names)[i] = strdup (PERUSE_events[i].name);
  92         (*events)[i] = PERUSE_events[i].id;
  93     }
  94 
  95     return PERUSE_SUCCESS;
  96 }
  97 
  98 
  99 /* Query supported events */
 100 int PERUSE_Query_event (const char* event_name, int* event)
 101 {
 102     int i;
 103 
 104     for( i = 0; i < PERUSE_num_events; i++ ) {
 105         if( !strcmp (event_name, PERUSE_events[i].name) ) {
 106             *event = PERUSE_events[i].id;
 107             return PERUSE_SUCCESS;
 108         }
 109     }
 110     return PERUSE_ERR_EVENT;
 111 }
 112 
 113 
 114 /* Query event name */
 115 int PERUSE_Query_event_name (int event, char** event_name)
 116 {
 117     if (event < 0 || event > PERUSE_num_events ||
 118         NULL == PERUSE_events[event].name)
 119         return PERUSE_EVENT_INVALID;
 120 
 121     *event_name = strdup(PERUSE_events[event].name);
 122     return PERUSE_SUCCESS;
 123 }
 124 
 125 
 126 /* Get environment variables that affect MPI library behavior */
 127 int PERUSE_Query_environment (int * env_size, char *** env)
 128 {
 129     /* XXX tbd */
 130     return PERUSE_SUCCESS;
 131 }
 132 
 133 /* Query the scope of queue metrics - global or per communicator */
 134 int PERUSE_Query_queue_event_scope (int * scope)
 135 {
 136     *scope = PERUSE_PER_COMM;
 137 
 138     return PERUSE_SUCCESS;
 139 }
 140 
 141 
 142 /*
 143  * II. Events, objects initialization and manipulation
 144  */
 145 /* Initialize event associated with an MPI communicator */
 146 int PERUSE_Event_comm_register (int                       event,
 147                                 MPI_Comm                  comm,
 148                                 peruse_comm_callback_f *  callback_fn,
 149                                 void *                    param,
 150                                 peruse_event_h *          event_h)
 151 {
 152     ompi_peruse_handle_t * handle;
 153     if (MPI_PARAM_CHECK) {
 154         OMPI_ERR_PERUSE_INIT_FINALIZE;
 155 
 156         if( (event < 0) || (event > PERUSE_num_events) ||
 157             (NULL == PERUSE_events[event].name) )
 158             return PERUSE_ERR_EVENT;
 159 
 160         if( (MPI_COMM_NULL == comm) || ompi_comm_invalid (comm) )
 161             return PERUSE_ERR_COMM;
 162 
 163         if (NULL == callback_fn)
 164             return PERUSE_ERR_GENERIC;
 165 
 166         if (NULL == event_h)
 167             return PERUSE_ERR_EVENT_HANDLE;
 168     }
 169 
 170     handle = OBJ_NEW (ompi_peruse_handle_t);
 171 
 172     /*
 173      * Initialize the newly created handle to the default inactive state.
 174      */
 175     handle->active = 0;
 176     handle->event = event;
 177     handle->type = PERUSE_TYPE_COMM;
 178     handle->comm = comm;
 179     handle->fn = (ompi_peruse_callback_f*) callback_fn;
 180     handle->param = param;
 181 
 182     /*
 183      * Update the information on the handle on the communicator
 184      */
 185     OPAL_THREAD_LOCK (&comm->c_lock);
 186     if( NULL == comm->c_peruse_handles ) {
 187         comm->c_peruse_handles = (ompi_peruse_handle_t**)calloc( PERUSE_num_events, sizeof(ompi_peruse_handle_t*) );
 188     }
 189     OPAL_THREAD_UNLOCK (&comm->c_lock);
 190     comm->c_peruse_handles[event] = handle;
 191 
 192     *event_h = handle;
 193     return PERUSE_SUCCESS;
 194 }
 195 
 196 
 197 /* Start collecting data (activate event) */
 198 int PERUSE_Event_activate (peruse_event_h event_h)
 199 {
 200     ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
 201 
 202     if (MPI_PARAM_CHECK) {
 203         OMPI_ERR_PERUSE_INIT_FINALIZE;
 204 
 205         if (PERUSE_EVENT_HANDLE_NULL == event_h)
 206             return PERUSE_ERR_EVENT_HANDLE;
 207     }
 208 
 209     OPAL_THREAD_LOCK (&handle->lock);
 210     handle->active = 1;
 211     OPAL_THREAD_UNLOCK (&handle->lock);
 212     return PERUSE_SUCCESS;
 213 }
 214 
 215 
 216 /* Stop collecting data (deactivate event) */
 217 int PERUSE_Event_deactivate (peruse_event_h event_h)
 218 {
 219     ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
 220 
 221     if (MPI_PARAM_CHECK) {
 222         OMPI_ERR_PERUSE_INIT_FINALIZE;
 223 
 224         if (PERUSE_EVENT_HANDLE_NULL == event_h)
 225             return PERUSE_ERR_EVENT_HANDLE;
 226     }
 227 
 228     OPAL_THREAD_LOCK (&handle->lock);
 229     handle->active = 0;
 230     OPAL_THREAD_UNLOCK (&handle->lock);
 231     return PERUSE_SUCCESS;
 232 }
 233 
 234 
 235 /* Free event handle */
 236 int PERUSE_Event_release (peruse_event_h * event_h)
 237 {
 238     if (MPI_PARAM_CHECK) {
 239         OMPI_ERR_PERUSE_INIT_FINALIZE;
 240 
 241         if (PERUSE_EVENT_HANDLE_NULL == event_h)
 242             return PERUSE_ERR_EVENT_HANDLE;
 243     }
 244     /*
 245      * XXX
 246      */
 247     *event_h = PERUSE_EVENT_HANDLE_NULL;
 248     return PERUSE_SUCCESS;
 249 }
 250 
 251 #define PERUSE_MPI_PARAM_CHECK(obj_upper,obj_lower )                  \
 252     if (MPI_PARAM_CHECK) {                                            \
 253         OMPI_ERR_PERUSE_INIT_FINALIZE;                                \
 254                                                                       \
 255         if (PERUSE_EVENT_HANDLE_NULL == event_h ||                    \
 256             ((ompi_peruse_handle_t*)event_h)->active ||               \
 257             ((ompi_peruse_handle_t*)event_h)->type !=                 \
 258                 PERUSE_TYPE_ ## obj_upper)                            \
 259             return PERUSE_ERR_EVENT_HANDLE;                           \
 260                                                                       \
 261         if (NULL == callback_fn)                                      \
 262             return PERUSE_ERR_PARAMETER;                              \
 263         /*                                                            \
 264          * XXX whether the underlying MPI-object has been freed!??    \
 265         if (ompi_ ## obj_lower ## _invalid (                          \
 266               ((ompi_peruse_handle_t*)event_h)->obj_lower))           \
 267             return PERUSE_ERR_MPI_OBJECT;                             \
 268          */                                                           \
 269     }                                                                 \
 270 
 271 /* Set a new comm callback */
 272 int PERUSE_Event_comm_callback_set (peruse_event_h           event_h,
 273                                     peruse_comm_callback_f*  callback_fn,
 274                                     void*                    param)
 275 {
 276     ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
 277 
 278     PERUSE_MPI_PARAM_CHECK (COMM, comm);
 279 
 280     OPAL_THREAD_LOCK (&handle->lock);
 281     handle->fn = (ompi_peruse_callback_f*) callback_fn;
 282     handle->param = param;
 283     OPAL_THREAD_UNLOCK (&handle->lock);
 284 
 285     return PERUSE_SUCCESS;
 286 }
 287 
 288 /* Get the current comm callback */
 289 int PERUSE_Event_comm_callback_get (peruse_event_h           event_h,
 290                                     peruse_comm_callback_f** callback_fn,
 291                                     void**                   param)
 292 {
 293     ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
 294 
 295     PERUSE_MPI_PARAM_CHECK (COMM, comm);
 296 
 297     OPAL_THREAD_LOCK (&handle->lock);
 298     *callback_fn = (peruse_comm_callback_f*) handle->fn;
 299     *param = handle->param;
 300     OPAL_THREAD_UNLOCK (&handle->lock);
 301 
 302     return PERUSE_SUCCESS;
 303 }
 304 
 305 /* Obtain event descriptor from an event handle (reverse lookup) */
 306 int PERUSE_Event_get (peruse_event_h event_h, int* event)
 307 {
 308     if (MPI_PARAM_CHECK) {
 309         OMPI_ERR_PERUSE_INIT_FINALIZE;
 310 
 311         if (NULL == event_h)
 312             return PERUSE_ERR_EVENT_HANDLE;
 313 
 314         if (NULL == event)
 315             return PERUSE_ERR_PARAMETER;
 316     }
 317 
 318     *event = ((ompi_peruse_handle_t*)event_h)->event;
 319     return PERUSE_SUCCESS;
 320 }
 321 
 322 
 323 /* Obtain MPI object associated with event handle */
 324 int PERUSE_Event_object_get (peruse_event_h event_h, void** mpi_object)
 325 {
 326     ompi_peruse_handle_t* p = (ompi_peruse_handle_t*)event_h;
 327 
 328     if (MPI_PARAM_CHECK) {
 329         OMPI_ERR_PERUSE_INIT_FINALIZE;
 330 
 331         if (NULL == event_h)
 332             return PERUSE_ERR_EVENT_HANDLE;
 333 
 334         if (NULL == mpi_object)
 335             return PERUSE_ERR_PARAMETER;
 336     }
 337 
 338     switch (p->type) {
 339         case PERUSE_TYPE_COMM:
 340             *mpi_object = p->comm;
 341             return PERUSE_SUCCESS;
 342     }
 343     return PERUSE_ERR_GENERIC;
 344 }
 345 
 346 
 347 /* Propagation mode */
 348 int PERUSE_Event_propagate (peruse_event_h event_h, int mode)
 349 {
 350     return PERUSE_SUCCESS;
 351 }

/* [<][>][^][v][top][bottom][index][help] */