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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/**
* Copyright (C) Mellanox Technologies Ltd. 2001-2015. ALL RIGHTS RESERVED.
* Copyright (C) Advanced Micro Devices, Inc. 2019. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
/**
* @brief Memory event types
*/
typedef enum ucm_event_type ucm_event_type_t;
/**
* @brief MMAP hook modes
*/
typedef enum ucm_mmap_hook_mode ucm_mmap_hook_mode_t;
/**
* @brief UCM module unload prevent mode
*/
typedef enum ucm_module_unload_prevent_mode ucm_module_unload_prevent_mode_t;
/**
* @brief Memory event parameters and result.
*/
typedef union ucm_event ucm_event_t;
/**
* @brief Global UCM configuration.
*
* Can be safely modified before using UCM functions.
*/
typedef struct ucm_global_config ucm_global_config_t;
/*
* Global UCM configuration to be set externally.
* @deprecated replaced by @ref ucm_library_init.
*/
extern ucm_global_config_t ucm_global_opts;
/**
* @brief Memory event callback.
*
* This type describes a callback which handles memory events in the current process.
*
* @param [in] event_type Type of the event being fired. see @ref ucm_event_type_t.
* @param [inout] event Event information. This structure can be updated by
* this callback, as described below.
* @param [in] arg User-defined argument as passed to @ref ucm_set_event_handler.
*
*
* Events are dispatched in order of callback priority (low to high).
*
* The fields of the relevant part of the union are initialized as follows:
* - "result" - to an invalid erroneous return value (depends on the specific event).
* - the rest - to the input parameters of the event.
*
* The callback is allowed to modify the fields, and those modifications will
* be passed to the next callback. Also, the callback is allowed to modify the
* result, but **only if it's currently invalid**. A valid result indicates that
* a previous callback already performed the requested memory operation, so a
* callback should **refrain from actions with side-effects** in this case.
*
* If the result is still invalid after all callbacks are called, the parameters,
* possibly modified by the callbacks, will be passed to the original handler.
*
*
* Important Note: The callback must not call any memory allocation routines, or
* anything which may trigger or wait for memory allocation, because it
* may lead to deadlock or infinite recursion.
*
* @todo describe use cases
*
*/
typedef void ;
/**
* Initialize UCM library and set its configuration.
*
* @param [in] ucm_opts UCM library global configuration. If NULL, default
* configuration is applied.
*
* @note Calling this function more than once in the same process has no effect.
*/
void ;
/**
* @brief Install a handler for memory events.
*
* @param [in] events Bit-mask of events to handle.
* @param [in] priority Priority value which defines the order in which event
* callbacks are called.
* < 0 - called before the original implementation,
* >= 0 - called after the original implementation.
* @param [in] cb Event-handling callback.
* @param [in] arg User-defined argument for the callback.
*
* @note If UCM_EVENT_FLAG_NO_INSTALL flag is passed in @a events argument,
* only @cb handler will be registered for @a events. No memory
* events/hooks will be installed.
*
* @return Status code.
*/
ucs_status_t ;
/**
* @brief Remove a handler for memory events.
*
* @param [in] events Which events to remove. The handler is removed
* completely when all its events are removed.
* @param [in] cb Event-handling callback.
* @param [in] arg User-defined argument for the callback.
*/
void ;
/**
* @brief Add memory events to the external events list.
*
* When the event is set to be external, it means that user is responsible for
* handling it. So, setting a handler for external event will not trigger
* installing of UCM memory hooks (if they were not installed before). In this
* case the corresponding UCM function needs to be invoked to trigger event
* handlers.
* Usage example is when the user disables UCM memory hooks (he may have its
* own hooks, like Open MPI), but it wants to use some UCM based functionality,
* e.g. IB registration cache. IB registration cache needs to be notified about
* UCM_EVENT_VM_UNMAPPED events, therefore it adds specific handler for it.
* In this case user needs to declare UCM_EVENT_VM_UNMAPPED event as external
* and explicitly call ucm_vm_munmap() when some memory release operation
* occurs.
*
* @param [in] events Bit-mask of events which are supposed to be handled
* externally.
*
* @note To take an effect, the event should be set external prior to adding
* event handlers for it.
*/
void ;
/**
* @brief Remove memory events from the external events list.
*
* When the event is removed from the external events list, any subsequent call
* to ucm_set_event_handler() for that event will trigger installing of UCM
* memory hooks (if they are enabled and were not installed before).
*
* @param [in] events Which events to remove from the external events list.
*/
void ;
/**
* @brief Test event handlers
*
* This routine checks if event handlers are called when corresponding system API
* is invoked.
*
* @param [in] events Bit-mask of events which are supposed to be handled
* externally.
*
* @return Status code.
*/
ucs_status_t ;
/**
* @brief Test event external handlers
*
* This routine checks if external events, as set by @ref ucm_set_external_event,
* are actually being reported (by calling APIs such as @ref ucm_vm_munmap).
*
* @param [in] events Bit-mask of events which are supposed to be handled
* externally.
*
* @return Status code.
*/
ucs_status_t ;
/**
* @brief Call the original implementation of @ref mmap without triggering events.
*/
void *;
/**
* @brief Call the original implementation of @ref munmap without triggering events.
*/
int ;
/**
* @brief Call the original implementation of @ref mremap without triggering events.
*/
void *;
/**
* @brief Call the original implementation of @ref shmat without triggering events.
*/
void *;
/**
* @brief Call the original implementation of @ref shmdt without triggering events.
*/
int ;
/**
* @brief Call the original implementation of @ref sbrk without triggering events.
*/
void *;
/**
* @brief Call the original implementation of @ref brk without triggering events.
*/
int ;
/**
* @brief Call the original implementation of @ref madvise without triggering events.
*/
int ;
/**
* @brief Call the original implementation of @ref mmap and all handlers
* associated with it.
*/
void *;
/**
* @brief Call the original implementation of @ref munmap and all handlers
* associated with it.
*/
int ;
/**
* @brief Call the handlers registered for aggregated VM_MMAP event.
*/
void ;
/**
* @brief Call the handlers registered for aggregated VM_MUNMAP event.
*/
void ;
/**
* @brief Call the original implementation of @ref mremap and all handlers
* associated with it.
*/
void *;
/**
* @brief Call the original implementation of @ref shmat and all handlers
* associated with it.
*/
void *;
/**
* @brief Call the original implementation of @ref shmdt and all handlers
* associated with it.
*/
int ;
/**
* @brief Call the original implementation of @ref sbrk and all handlers
* associated with it.
*/
void *;
/**
* @brief Call the original implementation of @ref brk and all handlers
* associated with it.
*/
int ;
/**
* @brief Call the original implementation of @ref madvise and all handlers
* associated with it.
*/
int ;
/**
* @brief Call the original implementation of @ref dlopen and all handlers
* associated with it.
*/
void *;