| 1 | /* |
| 2 | * Copyright (c) 2013. Intel Corporation. All rights reserved. |
| 3 | * Copyright (c) 2006-2012. QLogic Corporation. All rights reserved. |
| 4 | * Copyright (c) 2003-2006, PathScale, Inc. All rights reserved. |
| 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the |
| 10 | * OpenIB.org BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 20 | * - Redistributions in binary form must reproduce the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer in the documentation and/or other materials |
| 23 | * provided with the distribution. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 | * SOFTWARE. |
| 33 | */ |
| 34 | |
| 35 | #ifndef PSM_MQ_H |
| 36 | #define PSM_MQ_H |
| 37 | |
| 38 | #include <psm.h> |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
| 44 | |
| 45 | |
| 46 | /* Initialize the MQ component for MQ communication |
| 47 | * |
| 48 | * This function provides the Matched Queue handle necessary to performa all |
| 49 | * Matched Queue communication operations. |
| 50 | * |
| 51 | * [in] ep Endpoint over which to initialize Matched Queue |
| 52 | * [in] tag_order_mask Order mask hint to let MQ know what bits of the send |
| 53 | * tag are required to maintain MQ message order. In |
| 54 | * MPI parlance, this mask sets the bits that store |
| 55 | * the context (or communicator ID). The user can |
| 56 | * choose to pass PSM_MQ_ORDERMASK_NONE or |
| 57 | * PSM_MQ_ORDERMASK_ALL to tell MQ to respectively |
| 58 | * provide no ordering guarantees or to provide |
| 59 | * ordering over all messages by ignoring the |
| 60 | * contexts of the send tags. |
| 61 | * [in] opts Set of options for Matched Queue |
| 62 | * [in] numopts Number of options passed |
| 63 | * [out] mq User-supplied storage to return the Matched Queue handle |
| 64 | * associated to the newly created Matched Queue. |
| 65 | * |
| 66 | * @remark This function can be called many times to retrieve the MQ handle |
| 67 | * associated to an endpoint, but options are only considered the first |
| 68 | * time the function is called. |
| 69 | * |
| 70 | * [post] The user obtains a handle to an instantiated Match Queue. |
| 71 | * |
| 72 | * The following error code is returned. Other errors are handled by the PSM |
| 73 | * error handler (psm_error_register_handler). |
| 74 | * |
| 75 | * [retval] PSM_OK A new Matched Queue has been instantiated across all the |
| 76 | * members of the group. |
| 77 | * |
| 78 | * @verbatim |
| 79 | * int try_open_endpoint_and_initialize_mq( |
| 80 | * psm_ep_t *ep, // endpoint handle |
| 81 | * psm_epid_t *epid, // unique endpoint ID |
| 82 | * psm_uuid_t job_uuid, // unique job uuid, for ep_open |
| 83 | * psm_mq_t *mq, // MQ handle initialized on endpoint 'ep' |
| 84 | * uint64_t communicator_bits) // Where we store our communicator or |
| 85 | * // context bits in the 64-bit tag. |
| 86 | * { |
| 87 | * // Simplifed open, see psm_ep_open documentation for more info |
| 88 | * psm_ep_open(job_uuid, |
| 89 | * NULL, // no options |
| 90 | * ep, epid); |
| 91 | * |
| 92 | * // We initialize a matched queue by telling PSM the bits that are |
| 93 | * // order-significant in the tag. Point-to-point ordering will not be |
| 94 | * // maintained between senders where the communicator bits are not the |
| 95 | * // same. |
| 96 | * psm_mq_init(ep, |
| 97 | * communicator_bits, |
| 98 | * NULL, // no other MQ options |
| 99 | * 0, // 0 options passed |
| 100 | * mq); // newly initialized matched Queue |
| 101 | * |
| 102 | * return 1; |
| 103 | * } |
| 104 | * @endverbatim |
| 105 | */ |
| 106 | psm_error_t |
| 107 | psm_mq_init(psm_ep_t ep, uint64_t tag_order_mask, |
| 108 | const struct psm_optkey *opts, int numopts, psm_mq_t *mq); |
| 109 | |
| 110 | #define PSM_MQ_ORDERMASK_NONE 0ULL |
| 111 | /* Used to initialize MQ and disable all MQ message ordering |
| 112 | * guarantees (this mask may prevent the use of MQ to maintain matched |
| 113 | * message envelope delivery required in MPI). */ |
| 114 | |
| 115 | #define PSM_MQ_ORDERMASK_ALL 0xffffffffffffffffULL |
| 116 | /* Used to initialize MQ with no message ordering hints, which forces |
| 117 | * MQ to maintain order over all messages */ |
| 118 | |
| 119 | /* Finalize (close) an MQ handle |
| 120 | * |
| 121 | * The following error code is returned. Other errors are handled by the PSM |
| 122 | * error handler (psm_error_register_handler). |
| 123 | * |
| 124 | * [retval] PSM_OK A given Matched Queue has been freed and use of the future |
| 125 | * use of the handle produces undefined results. |
| 126 | */ |
| 127 | psm_error_t |
| 128 | psm_mq_finalize(psm_mq_t mq); |
| 129 | |
| 130 | /* MQ Non-blocking operation status |
| 131 | * |
| 132 | * Message completion status for asynchronous communication operations. |
| 133 | * For wait and test functions, MQ fills in the structure upon completion. |
| 134 | * Upon completion, receive requests fill in every field of the status |
| 135 | * structure while send requests only return a valid error_code and context |
| 136 | * pointer. |
| 137 | */ |
| 138 | typedef |
| 139 | struct psm_mq_status { |
| 140 | uint64_t msg_tag; /* Sender's original message tag (receive reqs only) */ |
| 141 | uint32_t msg_length; /* Sender's original message length (receive reqs only) */ |
| 142 | uint32_t nbytes; /* Actual number of bytes transfered (receive reqs only) */ |
| 143 | psm_error_t error_code; /* MQ error code for communication operation */ |
| 144 | void *context; /* User-associated context for send or receive */ |
| 145 | } |
| 146 | psm_mq_status_t; |
| 147 | |
| 148 | /* PSM Communication handle (opaque) */ |
| 149 | typedef struct psm_mq_req *psm_mq_req_t; |
| 150 | |
| 151 | |
| 152 | |
| 153 | /* Get an MQ option (Deprecated. Use psm_getopt with PSM_COMPONENT_MQ) |
| 154 | * |
| 155 | * Function to retrieve the value of an MQ option. |
| 156 | * |
| 157 | * [in] mq Matched Queue handle |
| 158 | * [in] option Index of option to retrieve. Possible values are: |
| 159 | * * PSM_MQ_RNDV_IPATH_SZ |
| 160 | * * PSM_MQ_RNDV_SHM_SZ |
| 161 | * * PSM_MQ_MAX_SYSBUF_MBYTES |
| 162 | * |
| 163 | * [in] value Pointer to storage that can be used to store the value of |
| 164 | * the option to be set. It is up to the user to ensure that the |
| 165 | * pointer points to a memory location large enough to accomodate |
| 166 | * the value associated to the type. Each option documents the size |
| 167 | * associated to its value. |
| 168 | * |
| 169 | * [returns] PSM_OK if option could be retrieved. |
| 170 | * [returns] PSM_PARAM_ERR if the option is not a valid option number |
| 171 | */ |
| 172 | psm_error_t |
| 173 | psm_mq_getopt(psm_mq_t mq, int option, void *value); |
| 174 | |
| 175 | /* Set an MQ option (Deprecated. Use psm_setopt with PSM_COMPONENT_MQ) |
| 176 | * |
| 177 | * Function to set the value of an MQ option. |
| 178 | * |
| 179 | * [in] mq Matched Queue handle |
| 180 | * [in] option Index of option to retrieve. Possible values are: |
| 181 | * * PSM_MQ_RNDV_IPATH_SZ |
| 182 | * * PSM_MQ_RNDV_SHM_SZ |
| 183 | * * PSM_MQ_MAX_SYSBUF_MBYTES |
| 184 | * |
| 185 | * [in] value Pointer to storage that contains the value to be updated |
| 186 | * for the supplied option number. It is up to the user to |
| 187 | * ensure that the pointer points to a memory location with a |
| 188 | * correct size. |
| 189 | * |
| 190 | * [returns] PSM_OK if option could be retrieved. |
| 191 | * [returns] PSM_PARAM_ERR if the option is not a valid option number |
| 192 | * [returns] PSM_OPT_READONLY if the option to be set is a read-only option |
| 193 | * (currently no MQ options are read-only). |
| 194 | */ |
| 195 | psm_error_t |
| 196 | psm_mq_setopt(psm_mq_t mq, int option, const void *value); |
| 197 | |
| 198 | |
| 199 | |
| 200 | #define PSM_MQ_FLAG_SENDSYNC 0x01 |
| 201 | /* MQ Send Force synchronous send */ |
| 202 | |
| 203 | #define PSM_MQ_REQINVALID ((psm_mq_req_t)(NULL)) |
| 204 | /* MQ request completion value */ |
| 205 | |
| 206 | /* Post a receive to a Matched Queue with tag selection criteria |
| 207 | * |
| 208 | * Function to receive a non-blocking MQ message by providing a preposted |
| 209 | * buffer. For every MQ message received on a particular MQ, the tag and @c |
| 210 | * tagsel parameters are used against the incoming message's send tag as |
| 211 | * described in tagmatch. |
| 212 | * |
| 213 | * [in] mq Matched Queue Handle |
| 214 | * [in] rtag Receive tag |
| 215 | * [in] rtagsel Receive tag selector |
| 216 | * [in] flags Receive flags (None currently supported) |
| 217 | * [in] buf Receive buffer |
| 218 | * [in] len Receive buffer length |
| 219 | * [in] context User context pointer, available in psm_mq_status_t |
| 220 | * upon completion |
| 221 | * [out] req PSM MQ Request handle created by the preposted receive, to |
| 222 | * be used for explicitly controlling message receive |
| 223 | * completion. |
| 224 | * |
| 225 | * [post] The supplied receive buffer is given to MQ to match against incoming |
| 226 | * messages unless it is cancelled via psm_mq_cancel @e before any |
| 227 | * match occurs. |
| 228 | * |
| 229 | * The following error code is returned. Other errors are handled by the PSM |
| 230 | * error handler (psm_error_register_handler). |
| 231 | * |
| 232 | * [retval] PSM_OK The receive buffer has successfully been posted to the MQ. |
| 233 | */ |
| 234 | psm_error_t |
| 235 | psm_mq_irecv(psm_mq_t mq, uint64_t rtag, uint64_t rtagsel, uint32_t flags, |
| 236 | void *buf, uint32_t len, void *context, psm_mq_req_t *req); |
| 237 | |
| 238 | /* Send a blocking MQ message |
| 239 | * |
| 240 | * Function to send a blocking MQ message, whereby the message is locally |
| 241 | * complete and the source data can be modified upon return. |
| 242 | * |
| 243 | * [in] mq Matched Queue Handle |
| 244 | * [in] dest Destination EP address |
| 245 | * [in] flags Message flags, currently: |
| 246 | * * PSM_MQ_FLAG_SENDSYNC tells PSM to send the message |
| 247 | * synchronously, meaning that the message will not be sent until |
| 248 | * the receiver acknowledges that it has matched the send with a |
| 249 | * receive buffer. |
| 250 | * [in] stag Message Send Tag |
| 251 | * [in] buf Source buffer pointer |
| 252 | * [in] len Length of message starting at buf. |
| 253 | * |
| 254 | * [post] The source buffer is reusable and the send is locally complete. |
| 255 | * |
| 256 | * @note This send function has been implemented to best suit MPI_Send. |
| 257 | * |
| 258 | * The following error code is returned. Other errors are handled by the PSM |
| 259 | * error handler (psm_error_register_handler). |
| 260 | * |
| 261 | * [retval] PSM_OK The message has been successfully sent. |
| 262 | */ |
| 263 | psm_error_t |
| 264 | psm_mq_send(psm_mq_t mq, psm_epaddr_t dest, uint32_t flags, uint64_t stag, |
| 265 | const void *buf, uint32_t len); |
| 266 | |
| 267 | /* Send a non-blocking MQ message |
| 268 | * |
| 269 | * Function to initiate the send of a non-blocking MQ message, whereby the |
| 270 | * user guarantees that the source data will remain unmodified until the send |
| 271 | * is locally completed through a call such as psm_mq_wait or @ref |
| 272 | * psm_mq_test. |
| 273 | * |
| 274 | * [in] mq Matched Queue Handle |
| 275 | * [in] dest Destination EP address |
| 276 | * [in] flags Message flags, currently: |
| 277 | * * PSM_MQ_FLAG_SENDSYNC tells PSM to send the message |
| 278 | * synchronously, meaning that the message will not be sent until |
| 279 | * the receiver acknowledges that it has matched the send with a |
| 280 | * receive buffer. |
| 281 | * [in] stag Message Send Tag |
| 282 | * [in] buf Source buffer pointer |
| 283 | * [in] len Length of message starting at buf. |
| 284 | * [in] context Optional user-provided pointer available in @ref |
| 285 | * psm_mq_status_t when the send is locally completed. |
| 286 | * [out] req PSM MQ Request handle created by the non-blocking send, to |
| 287 | * be used for explicitly controlling message completion. |
| 288 | * |
| 289 | * [post] The source buffer is not reusable and the send is not locally complete |
| 290 | * until its request is completed by either psm_mq_test or @ref |
| 291 | * psm_mq_wait. |
| 292 | * |
| 293 | * @note This send function has been implemented to suit MPI_Isend. |
| 294 | * |
| 295 | * The following error code is returned. Other errors are handled by the PSM |
| 296 | * error handler (psm_error_register_handler). |
| 297 | * |
| 298 | * [retval] PSM_OK The message has been successfully initiated. |
| 299 | * |
| 300 | * @verbatim |
| 301 | * psm_mq_req_t |
| 302 | * non_blocking_send(const psm_mq_t mq, psm_epaddr_t dest_ep, |
| 303 | * const void *buf, uint32_t len, |
| 304 | * int context_id, int send_tag, const my_request_t *req) |
| 305 | * { |
| 306 | * psm_mq_req_t req_mq; |
| 307 | * // Set up our send tag, assume that "my_rank" is global and represents |
| 308 | * // the rank of this process in the job |
| 309 | * uint64_t tag = ( ((context_id & 0xffff) << 48) | |
| 310 | * ((my_rank & 0xffff) << 32) | |
| 311 | * ((send_tag & 0xffffffff)) ); |
| 312 | * |
| 313 | * psm_mq_isend(mq, dest_ep, |
| 314 | * 0, // no flags |
| 315 | * tag, |
| 316 | * buf, |
| 317 | * len, |
| 318 | * req, // this req is available in psm_mq_status_t when one |
| 319 | * // of the synchronization functions is called. |
| 320 | * &req_mq); |
| 321 | * return req_mq; |
| 322 | * } |
| 323 | * @endverbatim |
| 324 | */ |
| 325 | psm_error_t |
| 326 | psm_mq_isend(psm_mq_t mq, psm_epaddr_t dest, uint32_t flags, uint64_t stag, |
| 327 | const void *buf, uint32_t len, void *context, psm_mq_req_t *req); |
| 328 | |
| 329 | /* Try to Probe if a message is received to match tag selection |
| 330 | * criteria |
| 331 | * |
| 332 | * Function to verify if a message matching the supplied tag and tag selectors |
| 333 | * has been received. The function is not fully matched until the user |
| 334 | * provides a buffer with the successfully matching tag selection criteria |
| 335 | * through psm_mq_irecv. |
| 336 | * Probing for messages may be useful if the size of the |
| 337 | * message to be received is unknown, in which case its size will be |
| 338 | * available in the msg_length member of the returned status. |
| 339 | * |
| 340 | * [in] mq Matched Queue Handle |
| 341 | * [in] rtag Message receive tag |
| 342 | * [in] rtagsel Message receive tag selector |
| 343 | * [out] status Upon return, status is filled with information |
| 344 | * regarding the matching send. |
| 345 | * |
| 346 | * The following error codes are returned. Other errors are handled by the PSM |
| 347 | * error handler (psm_error_register_handler). |
| 348 | * |
| 349 | * [retval] PSM_OK The iprobe is successful and status is updated if non-NULL. |
| 350 | * [retval] PSM_MQ_NO_COMPLETIONS The iprobe is unsuccessful and status is unchaged. |
| 351 | */ |
| 352 | psm_error_t |
| 353 | psm_mq_iprobe(psm_mq_t mq, uint64_t rtag, uint64_t rtagsel, |
| 354 | psm_mq_status_t *status); |
| 355 | |
| 356 | /* Query for non-blocking requests ready for completion. |
| 357 | * |
| 358 | * Function to query a particular MQ for non-blocking requests that are ready |
| 359 | * for completion. Requests "ready for completion" are not actually considered |
| 360 | * complete by MQ until they are returned to the MQ library through @ref |
| 361 | * psm_mq_wait or psm_mq_test. |
| 362 | * |
| 363 | * If the user can deal with consuming request completions in the order in |
| 364 | * which they complete, this function can be used both for completions and for |
| 365 | * ensuring progress. The latter requirement is satisfied when the user |
| 366 | * peeks an empty completion queue as a side effect of always aggressively |
| 367 | * peeking and completing all an MQ's requests ready for completion. |
| 368 | * |
| 369 | * |
| 370 | * [in] mq Matched Queue Handle |
| 371 | * [in,out] req MQ non-blocking request |
| 372 | * [in] status Optional MQ status, can be NULL. |
| 373 | * |
| 374 | * [post] The user has ensured progress if the function returns @ref |
| 375 | * PSM_MQ_NO_COMPLETIONS |
| 376 | * |
| 377 | * The following error codes are returned. Other errors are handled by the PSM |
| 378 | * error handler (psm_error_register_handler). |
| 379 | * |
| 380 | * [retval] PSM_OK The peek is successful and req is updated with a request |
| 381 | * ready for completion. If status is non-NULL, it is also |
| 382 | * updated. |
| 383 | * |
| 384 | * [retval] PSM_MQ_NO_COMPLETIONS The peek is not successful, meaning that there are |
| 385 | * no further requests ready for completion. The |
| 386 | * contents of req and status remain |
| 387 | * unchanged. |
| 388 | * @verbatim |
| 389 | * // Example that uses ipeek_mq_ipeek to make progress instead of psm_poll |
| 390 | * // We return the amount of non-blocking requests that we've completed |
| 391 | * int main_progress_loop(psm_mq_t mq) |
| 392 | * { |
| 393 | * int num_completed = 0; |
| 394 | * psm_mq_req_t req; |
| 395 | * psm_mq_status_t status; |
| 396 | * psm_error_t err; |
| 397 | * my_request_t *myreq; |
| 398 | * |
| 399 | * do { |
| 400 | * err = psm_mq_ipeek(mq, &req, |
| 401 | * NULL); // No need for status in ipeek here |
| 402 | * if (err == PSM_MQ_NO_COMPLETIONS) |
| 403 | * return num_completed; |
| 404 | * else if (err != PSM_OK) |
| 405 | * goto errh; |
| 406 | * num_completed++; |
| 407 | * |
| 408 | * // We obtained 'req' at the head of the completion queue. We can |
| 409 | * // now free the request with PSM and obtain our original reques |
| 410 | * // from the status' context |
| 411 | * err = psm_mq_test(&req, // will be marked as invalid |
| 412 | * &status); // we need the status |
| 413 | * myreq = (my_request_t *) status.context; |
| 414 | * |
| 415 | * // handle the completion for myreq whether myreq is a posted receive |
| 416 | * // or a non-blocking send. |
| 417 | * } |
| 418 | * while (1); |
| 419 | * } |
| 420 | * @endverbatim */ |
| 421 | psm_error_t |
| 422 | psm_mq_ipeek(psm_mq_t mq, psm_mq_req_t *req, psm_mq_status_t *status); |
| 423 | |
| 424 | /* Wait until a non-blocking request completes |
| 425 | * |
| 426 | * Function to wait on requests created from either preposted receive buffers |
| 427 | * or non-blocking sends. This is the only blocking function in the MQ |
| 428 | * interface and will poll until the request is complete as per the progress |
| 429 | * semantics explained in mq_progress. |
| 430 | * |
| 431 | * [in,out] request MQ non-blocking request |
| 432 | * [out] status Updated if non-NULL when request successfully completes |
| 433 | * |
| 434 | * [pre] The user has obtained a valid MQ request by calling psm_mq_isend |
| 435 | * or psm_mq_irecv and passes a pointer to enough storage to write |
| 436 | * the output of a psm_mq_status_t or NULL if status is to be |
| 437 | * ignored. |
| 438 | * |
| 439 | * [pre] Since MQ will internally ensure progress while the user is |
| 440 | * suspended, the user need not ensure that progress is made prior to |
| 441 | * calling this function. |
| 442 | * |
| 443 | * [post] The request is assigned the value PSM_MQ_REQINVALID and all |
| 444 | * associated MQ request storage is released back to the MQ library. |
| 445 | * |
| 446 | * [remarks] |
| 447 | * * This function ensures progress on the endpoint as long as the request |
| 448 | * is incomplete. |
| 449 | * * status can be NULL, in which case no status is written upon |
| 450 | * completion. |
| 451 | * * If request is PSM_MQ_REQINVALID, the function returns |
| 452 | * immediately. |
| 453 | * |
| 454 | * The following error code is returned. Other errors are handled by the PSM |
| 455 | * error handler (psm_error_register_handler). |
| 456 | * |
| 457 | * [retval] PSM_OK The request is complete or the value of was |
| 458 | * PSM_MQ_REQINVALID. |
| 459 | * |
| 460 | */ |
| 461 | psm_error_t |
| 462 | psm_mq_wait(psm_mq_req_t *request, psm_mq_status_t *status); |
| 463 | |
| 464 | /* Test if a non-blocking request is complete |
| 465 | * |
| 466 | * Function to test requests created from either preposted receive buffers or |
| 467 | * non-blocking sends for completion. Unlike psm_mq_wait, this function |
| 468 | * tests request for completion and @e never ensures progress directly or |
| 469 | * indirectly. It is up to the user to employ some of the progress functions |
| 470 | * described in mq_progress to ensure progress if the user chooses to |
| 471 | * exclusively test requests for completion. |
| 472 | * |
| 473 | * Testing a request for completion @e never internally ensure progress in |
| 474 | * order to be useful to construct higher-level completion tests over arrays to |
| 475 | * test some, all or any request that has completed. For testing arrays of |
| 476 | * requests, it is preferable for performance reasons to only ensure progress |
| 477 | * once before testing a set of requests for completion. |
| 478 | * |
| 479 | * [in,out] request MQ non-blocking request |
| 480 | * [out] status Updated if non-NULL and the request successfully |
| 481 | * completes |
| 482 | * |
| 483 | * [pre] The user has obtained a valid MQ request by calling psm_mq_isend |
| 484 | * or psm_mq_irecv and passes a pointer to enough storage to write |
| 485 | * the output of a psm_mq_status_t or NULL if status is to be |
| 486 | * ignored. |
| 487 | * |
| 488 | * [pre] The user has ensured progress on the Matched Queue if @ref |
| 489 | * psm_mq_test is exclusively used for guaranteeing request completions. |
| 490 | * |
| 491 | * [post] If the request is complete, the request is assigned the value @ref |
| 492 | * PSM_MQ_REQINVALID and all associated MQ request storage is released |
| 493 | * back to the MQ library. If the request is incomplete, the contents of |
| 494 | * request is unchanged. |
| 495 | * |
| 496 | * [post] The user will ensure progress on the Matched Queue if @ref |
| 497 | * psm_mq_test is exclusively used for guaranteeing request completions. |
| 498 | * |
| 499 | * The following two errors are always returned. Other errors are handled by |
| 500 | * the PSM error handler (psm_error_register_handler). |
| 501 | * |
| 502 | * [retval] PSM_OK The request is complete and request is set to @ref |
| 503 | * PSM_MQ_REQINVALID or the value of was PSM_MQ_REQINVALID |
| 504 | * |
| 505 | * [retval] PSM_MQ_NO_COMPLETIONS The request is not complete and request is |
| 506 | * unchanged. |
| 507 | * |
| 508 | * @verbatim |
| 509 | * // Function that returns the first completed request in an array |
| 510 | * // of requests. |
| 511 | * void * |
| 512 | * user_testany(psm_mq_t mq, psm_mq_req_t *allreqs, int nreqs) |
| 513 | * { |
| 514 | * int i; |
| 515 | * void *context = NULL; |
| 516 | * |
| 517 | * // Ensure progress only once |
| 518 | * psm_poll(mq); |
| 519 | * |
| 520 | * // Test for at least one completion and return it's context |
| 521 | * psm_mq_status_t stat; |
| 522 | * for (i = 0; i < nreqs; i++) { |
| 523 | * if (psm_mq_test(&allreqs[i], &stat) == PSM_OK) { |
| 524 | * context = stat.context; |
| 525 | * break; |
| 526 | * } |
| 527 | * } |
| 528 | * return context; |
| 529 | * } |
| 530 | * @endverbatim |
| 531 | */ |
| 532 | psm_error_t |
| 533 | psm_mq_test(psm_mq_req_t *request, psm_mq_status_t *status); |
| 534 | |
| 535 | /* Cancel a preposted request |
| 536 | * |
| 537 | * Function to cancel a preposted receive request returned by @ref |
| 538 | * psm_mq_irecv. It is currently illegal to cancel a send request initiated |
| 539 | * with psm_mq_isend. |
| 540 | * |
| 541 | * [pre] The user has obtained a valid MQ request by calling psm_mq_isend |
| 542 | * or psm_mq_irecv and passes a pointer to enough storage to write |
| 543 | * the output of a psm_mq_status_t or NULL if status is to be |
| 544 | * ignored. |
| 545 | * |
| 546 | * [post] Whether the cancel is successful or not, the user returns the |
| 547 | * request to the library by way of psm_mq_test or @ref |
| 548 | * psm_mq_wait. |
| 549 | * |
| 550 | * Only the two following errors can be returned directly, without being |
| 551 | * handled by the error handler (psm_error_register_handler): |
| 552 | * |
| 553 | * [retval] PSM_OK The request could be successfully cancelled such that the |
| 554 | * preposted receive buffer could be removed from the preposted |
| 555 | * receive queue before a match occurred. The associated @c |
| 556 | * request remains unchanged and the user must still return |
| 557 | * the storage to the MQ library. |
| 558 | * |
| 559 | * [retval] PSM_MQ_NO_COMPLETIONS The request could not be successfully cancelled |
| 560 | * since the preposted receive buffer has already |
| 561 | * matched an incoming message. The request |
| 562 | * remains unchanged. |
| 563 | * |
| 564 | */ |
| 565 | psm_error_t |
| 566 | psm_mq_cancel(psm_mq_req_t *req); |
| 567 | |
| 568 | struct psm_mq_stats { |
| 569 | uint64_t rx_user_bytes;/* Bytes received into a matched user buffer */ |
| 570 | uint64_t rx_user_num; /* Messages received into a matched user buffer */ |
| 571 | uint64_t rx_sys_bytes; /* Bytes received into an unmatched system buffer */ |
| 572 | uint64_t rx_sys_num; /* Messages received into an unmatched system buffer */ |
| 573 | |
| 574 | uint64_t tx_num; /* Total Messages transmitted (shm and ipath) */ |
| 575 | uint64_t tx_eager_num; /* Messages transmitted eagerly */ |
| 576 | uint64_t tx_eager_bytes; /* Bytes transmitted eagerly */ |
| 577 | uint64_t tx_rndv_num; /* Messages transmitted using expected TID mechanism */ |
| 578 | uint64_t tx_rndv_bytes; /* Bytes transmitted using expected TID mechanism */ |
| 579 | uint64_t tx_shm_num; /* Messages transmitted (shm only) */ |
| 580 | uint64_t rx_shm_num; /* Messages received through shm */ |
| 581 | |
| 582 | uint64_t rx_sysbuf_num; /* Number of system buffers allocated */ |
| 583 | uint64_t rx_sysbuf_bytes; /* Bytes allcoated for system buffers */ |
| 584 | |
| 585 | uint64_t _reserved[16]; /* Internally reserved for future use */ |
| 586 | }; |
| 587 | |
| 588 | #define PSM_MQ_NUM_STATS 13 /* How many stats are currently used in psm_mq_stats */ |
| 589 | |
| 590 | typedef struct psm_mq_stats psm_mq_stats_t; |
| 591 | |
| 592 | /* Retrieve statistics from an instantied MQ */ |
| 593 | void |
| 594 | psm_mq_get_stats(psm_mq_t mq, psm_mq_stats_t *stats); |
| 595 | |
| 596 | |
| 597 | #ifdef __cplusplus |
| 598 | } /* extern "C" */ |
| 599 | #endif |
| 600 | #endif |