forked from cornelisnetworks/opa-psm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psm2_am.h
411 lines (379 loc) · 17.9 KB
/
psm2_am.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) 2015 Intel Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Contact Information:
Intel Corporation, www.intel.com
BSD LICENSE
Copyright(c) 2015 Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 2003-2014 Intel Corporation. All rights reserved. */
#ifndef PSM2_AM_H
#define PSM2_AM_H
#include <stddef.h>
#include <stdint.h>
#include <psm2.h>
#ifdef __cplusplus
extern "C" {
#endif
/*!
* @file psm2_am.h
* @brief PSM2 Active Message.
*
* @page psm2_am Active Message Interface
*
* PSM2 implements an Active Message (AM) component that lives alongside the
* Matched Queues (MQ) component. The active message interface essentially
* provides a remote procedure call mechanism. A PSM2 process can generate a
* request to run an active message handler on a remote PSM2 process
* identified by its end-point address (epaddr). End-point address values
* are returned by PSM2 when connecting end-points using the psm2_ep_connect()
* function.
*
* An AM handler may make local state updates, and may generate at most
* one reply to be returned to the original requestor. This reply will cause
* a handler to be run on that requestor. The requestor handler may make
* local state updates but is not allowed to reply nor request in that handler
* context. A request or reply can convey a small number of in-line arguments
* plus a short amount of data. A tight bound is placed on the number of
* in-line arguments to allow them to be packed into a header. A bound is
* placed on the size of the data payload so that the request or reply can
* be sent as a single packet within the MTU of the underlying communication
* transport. Longer payloads must be synthesized on top of the provided
* short request/reply mechanism by fragmentation and reassembly, or
* transported by some other means.
*
* Handlers are run in the process context of the targeted PSM2 process,
* either in its main thread of execution or in a progress thread. A handler
* may therefore be executed concurrently with the main thread of execution
* of the PSM2 process. PSM2 ensures that its own state is protected against this
* concurrent execution. However, a handler must make its own arrangements to
* protect its own state. Alternatively, the PSM2 progress thread can be
* disabled using the PSM_RCVTHREAD environment variable if this is too
* onerous for the handler.
*
* PSM2 has an active progress model and requires that the PSM2 library is
* called in order to make progress. This can be achieved using the psm2_poll()
* function. A PSM2 implementatation may provide passive progress through some
* other mechanism (e.g. a receive thread), but a PSM2 consumer must not assume
* this and must arrange to make active progress through calls into the PSM
* library. Note that the PSM2 AM interface is not MTsafe, same as the other PSM
* interfaces, and that MTsafety must be provided by the consumer if required.
*
* The order in which AM requests are issued by an initiator to a particular
* target defines the order in which those AM requests will be executed on
* that target. Therefore the AM implementation will maintain the order
* of handler executions on a flow, and this also applies when progress
* threads are used. For multiple initiators issuing requests to a particular
* target, the handler executions will be interleaved in some sequentially
* consistent ordering.
*/
/*! @defgroup am PSM2 Active Message
*
* @{
*/
/** @brief Datatype for an index representing an active message handler */
typedef uint32_t psm2_handler_t;
/** @brief Datatype for a token for an active message handler.*/
typedef void *psm2_am_token_t;
/* PSM2 AM flags
* These flags may be combined using bitwise-or.
*/
#define PSM2_AM_FLAG_NONE 0 /**< No other PSM2 AM flags are needed. */
#define PSM2_AM_FLAG_ASYNC 1 /**< No need to copy source data. */
#define PSM2_AM_FLAG_NOREPLY 2 /**< The handler for this AM request is
guaranteed not to generate a reply. */
/** @brief The psm2_amarg type represents the type of an AM argument. This is
* a 64-bit type and is broken down into four 16-bit fields, two 32-bit
* fields or one 64-bit field for the convenience of code using the PSM2 AM
* interface.
*/
typedef
struct psm2_amarg {
union {
struct {
uint16_t u16w3;
uint16_t u16w2;
uint16_t u16w1;
uint16_t u16w0;
};
struct {
uint32_t u32w1;
uint32_t u32w0;
};
uint64_t u64w0;
uint64_t u64;
};
} psm2_amarg_t;
/** @brief The AM handler function type
*
* psm2_am_handler_fm_t is the datatype for an AM handler. PSM2 AM will call-back
* into an AM handler using this function prototype. The parameters and result
* of these handler functions are described here.
*
* @param[in] token This is an opaque token value passed into a handler.
* A request handler may send at most one reply back to the
* original requestor, and must pass this value as the token
* parameter to the psm2_am_reply_short() function. A reply
* handler is also passed a token value, but must not attempt
* to reply.
* @param[in] args A pointer to the arguments provided to this handler.
* @param[in] nargs The number of arguments.
* @param[in] src A pointer to the data payload provided to this handler.
* @param[in] len The length of the data payload in bytes.
*
* @returns 0 The handler should always return a result of 0.
*/
typedef
int (*psm2_am_handler_fn_t) (psm2_am_token_t token,
psm2_amarg_t *args, int nargs,
void *src, uint32_t len);
/** @brief Type for a completion call-back handler.
*
* A completion handler can be specified to give a call-back on the initiation
* side that an AM request or reply has completed on the target side. The
* call-back has a context pointer which is provided along with the call-back
* function pointer when the initiator generates the request or reply. This
* approach will typically give higher performance than using an AM request or
* reply to achieve the same effect, though note that no additional information
* can be passed from the target side back to the initiator side with the
* completion handler approach.
*
* @param[in] context A context pointer.
* @returns void This handler has no return result.
*/
typedef
void (*psm2_am_completion_fn_t) (void *context);
/** @brief Register AM call-back handlers at the specified end-point.
*
* This function is used to register an array of handlers, and may be called
* multiple times to register additonal handlers. The maximum number of
* handlers that can be registered is limited to the max_handlers value
* returned by psm2_am_get_parameters(). Handlers are associated with a PSM
* end-point. The handlers are allocated index numbers in the the handler table
* for that end-point. The allocated index for the handler function in
* handlers[i] is returned in handlers_idx[i] for i in (0, num_handlers]. These
* handler index values are used in the psm2_am_request_short() and
* psm2_am_reply_short() functions.
*
* @param[in] ep End-point value
* @param[in] handlers Array of handler functions
* @param[in] num_handlers Number of handlers (sizes the handlers and
* handlers_idx arrays)
* @param[out] handlers_idx Used to return handler index mapping table
*
* @returns PSM2_OK Indicates success
* @returns PSM2_EP_NO_RESOURCES Insufficient slots in the AM handler table
*/
psm2_error_t psm2_am_register_handlers(psm2_ep_t ep,
const psm2_am_handler_fn_t *
handlers, int num_handlers,
int *handlers_idx);
/** @brief Generate an AM request.
*
* This function generates an AM request causing an AM handler function to be
* called in the PSM2 process associated with the specified end-point address.
* The number of arguments is limited to max_nargs and the payload length in
* bytes to max_request_short returned by the psm2_am_get_parameters() function.
* If arguments are not required, set the number of arguments to 0 and the
* argument pointer will not be dereferenced. If payload is not required, set
* the payload size to 0 and the payload pointer will not be dereferenced.
*
* Optionally a completion function and completion context pointer can be
* provided, and a local call-back will be made to that function passing in
* that context pointer once remote execution of the handler has completed. If
* the completion call-back is not required, the handler should be specified as
* NULL and the pointer value will not be used.
*
* The allowed flags are any combination of the following combined with
* bitwise-or:
* PSM2_AM_FLAG_NONE - No flags
* PSM2_AM_FLAG_ASYNC - Indicates no need to copy source data
* PSM2_AM_FLAG_NOREPLY - The handler for this AM request is guaranteed not to
* generate a reply
*
* The PSM2 AM implementation will not dereference the args pointer after return
* from this function. If PSM2_AM_FLAG_ASYNC is not provided, the PSM2 AM
* implementation will not dereference the src pointer after return from this
* function. This may require the implementation to take a copy of the payload
* if the request cannot be issued immediately. However, if PSM2_AM_FLAG_ASYNC
* is provided then a copy will not be taken and the PSM2 AM implementation
* retains ownership of the payload src memory until the request is locally
* complete. Local completion can be determined using the completion handler
* call-back, or through an AM handler associated with an AM reply.
*
* The PSM2_AM_FLAG_NOREPLY flag indicates ahead of time to the AM handler that
* a reply will not be generated. Use of this flag is optional, but it may
* enable a performance optimization in this case by indicating that reply
* state is not required.
*
* @param[in] epaddr End-point address to run handler on
* @param[in] handler Index of handler to run
* @param[in] args Array of arguments to be provided to the handler
* @param[in] nargs Number of arguments to be provided to the handler
* @param[in] src Pointer to the payload to be delivered to the handler
* @param[in] len Length of the payload in bytes
* @param[in] flags These are PSM2 AM flags and may be combined together with
* bitwise-or
* @param[in] completion_fn The completion function to called locally when
* remote handler is complete
* @param[in] completion_ctxt User-provided context pointer to be passed to the
* completion handler
*
* @returns PSM2_OK indicates success.
*/
psm2_error_t
psm2_am_request_short(psm2_epaddr_t epaddr, psm2_handler_t handler,
psm2_amarg_t *args, int nargs, void *src,
size_t len, int flags,
psm2_am_completion_fn_t completion_fn,
void *completion_ctxt);
/** @brief Generate an AM reply.
*
* This function may only be called from an AM handler called due to an AM
* request. If the AM request uses the PSM2_AM_FLAG_NOREPLY flag, the AM
* handler must not call this function. Otherwise, the AM request handler may
* call psm2_am_reply_short() at most once, and must pass in the token value
* that it received in its own handler call-back.
*
* This function generates an AM reply causing an AM handler function to be
* called in the PSM2 process associated with the specified end-point address.
* The number of arguments is limited to max_nargs and the payload length in
* bytes to max_reply_short returned by the psm2_am_get_parameters() function.
* If arguments are not required, set the number of arguments to 0 and the
* argument pointer will not be dereferenced. If payload is not required, set
* the payload size to 0 and the payload pointer will not be dereferenced.
*
* Optionally a completion function and completion context pointer can be
* provided, and a local call-back will be made to that function passing in
* that context pointer once remote execution of the handler has completed. If
* the completion call-back is not required, the handler should be specified as
* NULL and the pointer value will not be used.
*
* The allowed flags are any combination of the following combined with
* bitwise-or:
* PSM2_AM_FLAG_NONE - No flags
* PSM2_AM_FLAG_ASYNC - Indicates no need to copy source data
*
* The PSM2 AM implementation will not dereference the args pointer after return
* from this function. If PSM2_AM_FLAG_ASYNC is not provided, the PSM2 AM
* implementation will not dereference the src pointer after return from this
* function. This may require the implementation to take a copy of the payload
* if the reply cannot be issued immediately. However, if PSM2_AM_FLAG_ASYNC is
* provided then a copy will not be taken and the PSM2 AM implementation retains
* ownership of the payload src memory until the reply is locally complete.
* Local completion can be determined using the completion handler call-back.
*
* @param[in] token Token value provided to the AM handler that is generating
* the reply.
* @param[in] handler Index of handler to run
* @param[in] args Array of arguments to be provided to the handler
* @param[in] nargs Number of arguments to be provided to the handler
* @param[in] src Pointer to the payload to be delivered to the handler
* @param[in] len Length of the payload in bytes
* @param[in] flags These are PSM2 AM flags and may be combined together with
* bitwise-or
* @param[in] completion_fn The completion function to called locally when
* remote handler is complete
* @param[in] completion_ctxt User-provided context pointer to be passed to the
* completion handler
*
* @returns PSM2_OK indicates success.
*/
psm2_error_t
psm2_am_reply_short(psm2_am_token_t token, psm2_handler_t handler,
psm2_amarg_t *args, int nargs, void *src,
size_t len, int flags,
psm2_am_completion_fn_t completion_fn,
void *completion_ctxt);
/** @brief Return the source end-point address for a token.
*
* This function is used to obtain the epaddr object representing the message
* initiator from a token passed by PSM2 to a message handler.
*
* @param[in] token Token value provided to the AM handler that is generating
* the reply.
* @param[out] epaddr_out Pointer to the where the epaddr should be returned.
*
* @returns PSM2_OK indicates success.
* @returns PSM2_PARAM_ERR token is invalid or epaddr_out is NULL.
*/
psm2_error_t psm2_am_get_source(psm2_am_token_t token,
psm2_epaddr_t *epaddr_out);
/** @brief AM parameters
*
* This structure is used to return PSM2 AM implementation-specific parameter
* values back to the caller of the psm2_am_get_parameters() function. This
* API also specifies the minimum values for these parameters that an
* implementation must at least provide:
* max_handlers >= 64,
* max_nargs >= 2,
* max_request_short >= 256 and
* max_reply_short >= 256.
*/
struct psm2_am_parameters {
/** Maximum number of handlers that can be registered. */
uint32_t max_handlers;
/** Maximum number of arguments to an AM handler. */
uint32_t max_nargs;
/** Maximum number of bytes in a request payload. */
uint32_t max_request_short;
/** Maximum number of bytes in a reply payload. */
uint32_t max_reply_short;
};
/** @brief Get the AM parameter values
*
* This function retrieves the implementation-specific AM parameter values for
* the specified end-point.
*
* @param[in] ep The end-point value returned by psm2_ep_open().
* @param[out] parameters Pointer to the struct where the parameters will be
* returned.
* @param[in] sizeof_parameters_in The size in bytes of the struct provided by
* the caller.
* @param[out] sizeof_parameters_out The size in bytes of the struct returned
* by PSM.
*
* @returns PSM2_OK indicates success.
*/
psm2_error_t
psm2_am_get_parameters(psm2_ep_t ep,
struct psm2_am_parameters *parameters,
size_t sizeof_parameters_in,
size_t *sizeof_parameters_out);
/*! @} */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif