Mercury
na.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Argonne National Laboratory, Department of Energy,
3  *                    UChicago Argonne, LLC and The HDF Group.
4  * All rights reserved.
5  *
6  * The full copyright notice, including terms governing use, modification,
7  * and redistribution, is contained in the COPYING file that can be
8  * found at the root of the source code distribution tree.
9  */
10 
11 #ifndef NA_H
12 #define NA_H
13 
14 #include "na_config.h"
15 
16 #include <limits.h>
17 
18 typedef struct na_class na_class_t; /* Opaque NA class */
19 typedef struct na_context na_context_t; /* Opaque NA execution context */
20 typedef void *na_addr_t; /* Abstract NA address */
21 typedef na_uint64_t na_size_t; /* Size */
22 typedef na_uint32_t na_tag_t; /* Tag */
23 typedef void *na_op_id_t; /* Abstract operation id */
24 
25 typedef void *na_mem_handle_t; /* Abstract memory handle */
26 typedef na_uint64_t na_offset_t; /* Offset */
27 
28 /* Segment */
29 struct na_segment {
30  na_ptr_t address; /* Address of the segment */
31  na_size_t size; /* Size of the segment in bytes */
32 };
33 
34 /* Constant values */
35 #define NA_ADDR_NULL ((na_addr_t)0)
36 #define NA_OP_ID_NULL ((na_op_id_t)0)
37 #define NA_OP_ID_IGNORE ((na_op_id_t *)1)
38 #define NA_MEM_HANDLE_NULL ((na_mem_handle_t)0)
39 
40 /* Max timeout */
41 #define NA_MAX_IDLE_TIME (3600*1000)
42 
43 /* Tag upper bound
44  * NB. This is not the user tag limit but only the limit imposed by the type */
45 #define NA_TAG_UB UINT_MAX
46 
47 /* Max len used for strings that represent an addr */
48 #define NA_MAX_ADDR_LEN 256
49 
50 /* The memory attributes associated with the memory handle
51  * can be defined as read/write or read only */
52 #define NA_MEM_READWRITE 0x00
53 #define NA_MEM_READ_ONLY 0x01
54 
55 /* Error return codes:
56  * Functions return 0 for success or NA_XXX_ERROR for failure */
57 typedef enum na_return {
58  NA_SUCCESS, /* operation succeeded */
59  NA_CANCELED, /* operation was canceled */
60  NA_TIMEOUT, /* reached timeout */
61  NA_INVALID_PARAM, /* invalid parameter */
62  NA_SIZE_ERROR, /* message size error */
63  NA_ALIGNMENT_ERROR, /* alignment error */
64  NA_PERMISSION_ERROR, /* read/write permission error */
65  NA_NOMEM_ERROR, /* no memory error */
66  NA_PROTOCOL_ERROR /* unknown error reported from the protocol layer */
67 } na_return_t;
68 
69 /* Callback operation type */
70 typedef enum na_cb_type {
78 } na_cb_type_t;
79 
80 /* Callback info structs */
83 };
84 
89 };
90 
91 /* Callback info struct */
92 struct na_cb_info {
93  void *arg; /* User data */
94  na_return_t ret; /* Return value */
95  na_cb_type_t type; /* Callback type */
96  union { /* Union of callback info structures */
99  } info;
100 };
101 
102 /* Callback type */
103 typedef na_return_t (*na_cb_t)(const struct na_cb_info *callback_info);
104 
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108 
119 NA_EXPORT na_class_t *
121  const char *info_string,
122  na_bool_t listen
123  ) NA_WARN_UNUSED_RESULT;
124 
132 NA_EXPORT na_return_t
135  );
136 
144 NA_EXPORT na_context_t *
146  na_class_t *na_class
147  );
148 
157 NA_EXPORT na_return_t
159  na_class_t *na_class,
160  na_context_t *context
161  );
162 
177 NA_EXPORT na_return_t
179  na_class_t *na_class,
180  na_context_t *context,
181  na_cb_t callback,
182  void *arg,
183  const char *name,
184  na_op_id_t *op_id
185  );
186 
197 NA_EXPORT na_return_t
199  na_class_t *na_class,
200  const char *name,
201  na_addr_t *addr
202  );
203 
212 NA_EXPORT na_return_t
214  na_class_t *na_class,
215  na_addr_t addr
216  );
217 
226 NA_EXPORT na_return_t
228  na_class_t *na_class,
229  na_addr_t *addr
230  );
231 
243 NA_EXPORT na_return_t
245  na_class_t *na_class,
246  na_addr_t addr,
247  na_addr_t *new_addr
248  );
249 
258 NA_EXPORT na_bool_t
260  na_class_t *na_class,
261  na_addr_t addr
262  );
263 
276 NA_EXPORT na_return_t
278  na_class_t *na_class,
279  char *buf,
280  na_size_t buf_size,
281  na_addr_t addr
282  );
283 
292 NA_EXPORT na_size_t
294  na_class_t *na_class
295  ) NA_WARN_UNUSED_RESULT;
296 
305 NA_EXPORT na_size_t
307  na_class_t *na_class
308  ) NA_WARN_UNUSED_RESULT;
309 
318 NA_EXPORT na_tag_t
320  na_class_t *na_class
321  ) NA_WARN_UNUSED_RESULT;
322 
342 NA_EXPORT na_return_t
344  na_class_t *na_class,
345  na_context_t *context,
346  na_cb_t callback,
347  void *arg,
348  const void *buf,
349  na_size_t buf_size,
350  na_addr_t dest,
351  na_tag_t tag,
352  na_op_id_t *op_id
353  );
354 
370 NA_EXPORT na_return_t
372  na_class_t *na_class,
373  na_context_t *context,
374  na_cb_t callback,
375  void *arg,
376  void *buf,
377  na_size_t buf_size,
378  na_op_id_t *op_id
379  );
380 
399 NA_EXPORT na_return_t
401  na_class_t *na_class,
402  na_context_t *context,
403  na_cb_t callback,
404  void *arg,
405  const void *buf,
406  na_size_t buf_size,
407  na_addr_t dest,
408  na_tag_t tag,
409  na_op_id_t *op_id
410  );
411 
427 NA_EXPORT na_return_t
429  na_class_t *na_class,
430  na_context_t *context,
431  na_cb_t callback,
432  void *arg,
433  void *buf,
434  na_size_t buf_size,
435  na_addr_t source,
436  na_tag_t tag,
437  na_op_id_t *op_id
438  );
439 
457 NA_EXPORT na_return_t
459  na_class_t *na_class,
460  void *buf,
461  na_size_t buf_size,
462  unsigned long flags,
463  na_mem_handle_t *mem_handle
464  );
465 
485 NA_EXPORT na_return_t
487  na_class_t *na_class,
488  struct na_segment *segments,
489  na_size_t segment_count,
490  unsigned long flags,
491  na_mem_handle_t *mem_handle
492  );
493 
502 NA_EXPORT na_return_t
504  na_class_t *na_class,
505  na_mem_handle_t mem_handle
506  );
507 
518 NA_EXPORT na_return_t
520  na_class_t *na_class,
521  na_mem_handle_t mem_handle
522  );
523 
532 NA_EXPORT na_return_t
534  na_class_t *na_class,
535  na_mem_handle_t mem_handle
536  );
537 
546 NA_EXPORT na_size_t
548  na_class_t *na_class,
549  na_mem_handle_t mem_handle
550  ) NA_WARN_UNUSED_RESULT;
551 
568 NA_EXPORT na_return_t
570  na_class_t *na_class,
571  void *buf,
572  na_size_t buf_size,
573  na_mem_handle_t mem_handle
574  );
575 
586 NA_EXPORT na_return_t
588  na_class_t *na_class,
589  na_mem_handle_t *mem_handle,
590  const void *buf,
591  na_size_t buf_size
592  );
593 
614 NA_EXPORT na_return_t
615 NA_Put(
616  na_class_t *na_class,
617  na_context_t *context,
618  na_cb_t callback,
619  void *arg,
620  na_mem_handle_t local_mem_handle,
621  na_offset_t local_offset,
622  na_mem_handle_t remote_mem_handle,
623  na_offset_t remote_offset,
624  na_size_t data_size,
625  na_addr_t remote_addr,
626  na_op_id_t *op_id
627  );
628 
646 NA_EXPORT na_return_t
647 NA_Get(
648  na_class_t *na_class,
649  na_context_t *context,
650  na_cb_t callback,
651  void *arg,
652  na_mem_handle_t local_mem_handle,
653  na_offset_t local_offset,
654  na_mem_handle_t remote_mem_handle,
655  na_offset_t remote_offset,
656  na_size_t data_size,
657  na_addr_t remote_addr,
658  na_op_id_t *op_id
659  );
660 
674 NA_EXPORT na_return_t
676  na_class_t *na_class,
677  na_context_t *context,
678  unsigned int timeout
679  );
680 
693 NA_EXPORT na_return_t
694 NA_Trigger(
695  na_context_t *context,
696  unsigned int timeout,
697  unsigned int max_count,
698  unsigned int *actual_count
699  );
700 
710 NA_EXPORT na_return_t
711 NA_Cancel(
712  na_class_t *na_class,
713  na_context_t *context,
714  na_op_id_t op_id
715  );
716 
724 NA_EXPORT const char *
726  na_return_t errnum
727  ) NA_WARN_UNUSED_RESULT;
728 
729 #ifdef __cplusplus
730 }
731 #endif
732 
733 #endif /* NA_H */
na_ptr_t address
Definition: na.h:30
NA_EXPORT na_return_t NA_Addr_to_string(na_class_t *na_class, char *buf, na_size_t buf_size, na_addr_t addr)
Convert an addr to a string (returned string includes the terminating null byte '\0').
Definition: na.h:58
NA_EXPORT na_return_t NA_Progress(na_class_t *na_class, na_context_t *context, unsigned int timeout)
Try to progress communication for at most timeout until timeout reached or any completion has occurre...
NA_EXPORT na_return_t NA_Msg_recv_unexpected(na_class_t *na_class, na_context_t *context, na_cb_t callback, void *arg, void *buf, na_size_t buf_size, na_op_id_t *op_id)
Receive an unexpected message.
struct na_cb_info_lookup lookup
Definition: na.h:97
NA_EXPORT na_class_t * NA_Initialize(const char *info_string, na_bool_t listen) NA_WARN_UNUSED_RESULT
Initialize the network abstraction layer.
void * arg
Definition: na.h:93
void * na_addr_t
Definition: na.h:20
NA_EXPORT na_return_t NA_Addr_lookup(na_class_t *na_class, na_context_t *context, na_cb_t callback, void *arg, const char *name, na_op_id_t *op_id)
Lookup an addr from a peer address/name.
na_size_t actual_buf_size
Definition: na.h:86
NA_EXPORT na_return_t NA_Mem_register(na_class_t *na_class, na_mem_handle_t mem_handle)
Register memory for RMA operations.
enum na_return na_return_t
NA_EXPORT na_return_t NA_Get(na_class_t *na_class, na_context_t *context, na_cb_t callback, void *arg, na_mem_handle_t local_mem_handle, na_offset_t local_offset, na_mem_handle_t remote_mem_handle, na_offset_t remote_offset, na_size_t data_size, na_addr_t remote_addr, na_op_id_t *op_id)
Get data from remote target.
struct na_cb_info_recv_unexpected recv_unexpected
Definition: na.h:98
NA_EXPORT na_return_t NA_Context_destroy(na_class_t *na_class, na_context_t *context)
Destroy a context created by using NA_Context_create().
NA_EXPORT na_return_t NA_Cancel(na_class_t *na_class, na_context_t *context, na_op_id_t op_id)
Cancel an ongoing operation.
na_uint64_t na_size_t
Definition: na.h:21
NA_EXPORT na_return_t NA_Msg_recv_expected(na_class_t *na_class, na_context_t *context, na_cb_t callback, void *arg, void *buf, na_size_t buf_size, na_addr_t source, na_tag_t tag, na_op_id_t *op_id)
Receive an expected message from source.
Definition: na.h:92
enum na_cb_type na_cb_type_t
NA_EXPORT na_return_t NA_Mem_handle_free(na_class_t *na_class, na_mem_handle_t mem_handle)
Free memory handle.
NA_EXPORT na_return_t NA_Addr_self(na_class_t *na_class, na_addr_t *addr)
Access self address.
na_cb_type_t type
Definition: na.h:95
NA_EXPORT na_return_t NA_Finalize(na_class_t *na_class)
Finalize the network abstraction layer.
Definition: na.h:60
NA_EXPORT na_context_t * NA_Context_create(na_class_t *na_class)
Create a new context.
NA_EXPORT na_return_t NA_Mem_handle_serialize(na_class_t *na_class, void *buf, na_size_t buf_size, na_mem_handle_t mem_handle)
Serialize memory handle into a buffer.
NA_EXPORT na_size_t NA_Mem_handle_get_serialize_size(na_class_t *na_class, na_mem_handle_t mem_handle) NA_WARN_UNUSED_RESULT
Get size required to serialize handle.
na_addr_t addr
Definition: na.h:82
NA_EXPORT const char * NA_Error_to_string(na_return_t errnum) NA_WARN_UNUSED_RESULT
Convert error return code to string (null terminated).
NA_EXPORT na_return_t NA_Mem_handle_deserialize(na_class_t *na_class, na_mem_handle_t *mem_handle, const void *buf, na_size_t buf_size)
Deserialize memory handle from buffer.
Definition: na.h:77
NA_EXPORT na_return_t NA_Mem_deregister(na_class_t *na_class, na_mem_handle_t mem_handle)
Unregister memory.
Definition: na.h:59
NA_EXPORT na_return_t NA_Msg_send_expected(na_class_t *na_class, na_context_t *context, na_cb_t callback, void *arg, const void *buf, na_size_t buf_size, na_addr_t dest, na_tag_t tag, na_op_id_t *op_id)
Send an expected message to dest.
NA_EXPORT na_return_t NA_Addr_free(na_class_t *na_class, na_addr_t addr)
Free the addr from the list of peers.
na_return
Definition: na.h:57
na_size_t size
Definition: na.h:31
Definition: na.h:29
NA_EXPORT na_size_t NA_Msg_get_max_unexpected_size(na_class_t *na_class) NA_WARN_UNUSED_RESULT
Get the maximum size of messages supported by unexpected send/recv.
void * na_mem_handle_t
Definition: na.h:25
NA_EXPORT na_return_t NA_Msg_send_unexpected(na_class_t *na_class, na_context_t *context, na_cb_t callback, void *arg, const void *buf, na_size_t buf_size, na_addr_t dest, na_tag_t tag, na_op_id_t *op_id)
Send an unexpected message to dest.
na_uint64_t na_offset_t
Definition: na.h:26
NA_EXPORT na_return_t NA_Addr_lookup_wait(na_class_t *na_class, const char *name, na_addr_t *addr)
For compatibility, temporarily provide this routine, which waits until addr is returned.
na_return_t ret
Definition: na.h:94
na_return_t(* na_cb_t)(const struct na_cb_info *callback_info)
Definition: na.h:103
void * na_op_id_t
Definition: na.h:23
NA_EXPORT na_return_t NA_Mem_handle_create_segments(na_class_t *na_class, struct na_segment *segments, na_size_t segment_count, unsigned long flags, na_mem_handle_t *mem_handle)
Create memory handle for RMA operations.
union na_cb_info::@0 info
na_addr_t source
Definition: na.h:87
NA_EXPORT na_return_t NA_Put(na_class_t *na_class, na_context_t *context, na_cb_t callback, void *arg, na_mem_handle_t local_mem_handle, na_offset_t local_offset, na_mem_handle_t remote_mem_handle, na_offset_t remote_offset, na_size_t data_size, na_addr_t remote_addr, na_op_id_t *op_id)
Put data to remote target.
NA_EXPORT na_return_t NA_Mem_handle_create(na_class_t *na_class, void *buf, na_size_t buf_size, unsigned long flags, na_mem_handle_t *mem_handle)
Create memory handle for RMA operations.
na_cb_type
Definition: na.h:70
Definition: na.h:76
NA_EXPORT na_return_t NA_Trigger(na_context_t *context, unsigned int timeout, unsigned int max_count, unsigned int *actual_count)
Execute at most max_count callbacks.
NA_EXPORT na_return_t NA_Addr_dup(na_class_t *na_class, na_addr_t addr, na_addr_t *new_addr)
Duplicate an existing NA abstract address.
NA_EXPORT na_bool_t NA_Addr_is_self(na_class_t *na_class, na_addr_t addr)
Test whether address is self or not.
na_uint32_t na_tag_t
Definition: na.h:22
NA_EXPORT na_size_t NA_Msg_get_max_expected_size(na_class_t *na_class) NA_WARN_UNUSED_RESULT
Get the maximum size of messages supported by expected send/recv.
NA_EXPORT na_tag_t NA_Msg_get_max_tag(na_class_t *na_class) NA_WARN_UNUSED_RESULT
Get the maximum tag value that can be used by send/recv.