1 /**
2 * Copyright (C) Mellanox Technologies Ltd. 2001-2014. ALL RIGHTS RESERVED.
3 *
4 * See file LICENSE for terms.
5 */
6
7 #ifndef UCT_MD_H_
8 #define UCT_MD_H_
9
10 #ifdef HAVE_CONFIG_H
11 # include "config.h"
12 #endif
13
14 #include "uct_component.h"
15
16 #include <uct/api/uct.h>
17 #include <ucs/config/parser.h>
18 #include <string.h>
19
20
21 typedef struct uct_md_rcache_config {
22 size_t alignment; /**< Force address alignment */
23 unsigned event_prio; /**< Memory events priority */
24 double overhead; /**< Lookup overhead estimation */
25 } uct_md_rcache_config_t;
26
27
28 extern ucs_config_field_t uct_md_config_rcache_table[];
29
30 /**
31 * "Base" structure which defines MD configuration options.
32 * Specific MDs extend this structure.
33 */
34 struct uct_md_config {
35 /* C standard prohibits empty structures */
36 char __dummy;
37 };
38
39
40 typedef void (*uct_md_close_func_t)(uct_md_h md);
41
42 typedef ucs_status_t (*uct_md_query_func_t)(uct_md_h md,
43 uct_md_attr_t *md_attr);
44
45 typedef ucs_status_t (*uct_md_mem_alloc_func_t)(uct_md_h md,
46 size_t *length_p,
47 void **address_p,
48 unsigned flags,
49 const char *alloc_name,
50 uct_mem_h *memh_p);
51
52 typedef ucs_status_t (*uct_md_mem_free_func_t)(uct_md_h md, uct_mem_h memh);
53
54 typedef ucs_status_t (*uct_md_mem_advise_func_t)(uct_md_h md,
55 uct_mem_h memh,
56 void *addr,
57 size_t length,
58 unsigned advice);
59
60 typedef ucs_status_t (*uct_md_mem_reg_func_t)(uct_md_h md, void *address,
61 size_t length,
62 unsigned flags,
63 uct_mem_h *memh_p);
64
65 typedef ucs_status_t (*uct_md_mem_dereg_func_t)(uct_md_h md, uct_mem_h memh);
66
67 typedef ucs_status_t (*uct_md_mem_query_func_t)(uct_md_h md,
68 const void *addr,
69 const size_t length,
70 uct_md_mem_attr_t *mem_attr_p);
71
72 typedef ucs_status_t (*uct_md_mkey_pack_func_t)(uct_md_h md, uct_mem_h memh,
73 void *rkey_buffer);
74
75 typedef int (*uct_md_is_sockaddr_accessible_func_t)(uct_md_h md,
76 const ucs_sock_addr_t *sockaddr,
77 uct_sockaddr_accessibility_t mode);
78
79 typedef ucs_status_t (*uct_md_detect_memory_type_func_t)(uct_md_h md,
80 const void *addr,
81 size_t length,
82 ucs_memory_type_t *mem_type_p);
83
84
85 /**
86 * Memory domain operations
87 */
88 struct uct_md_ops {
89 uct_md_close_func_t close;
90 uct_md_query_func_t query;
91 uct_md_mem_alloc_func_t mem_alloc;
92 uct_md_mem_free_func_t mem_free;
93 uct_md_mem_advise_func_t mem_advise;
94 uct_md_mem_reg_func_t mem_reg;
95 uct_md_mem_dereg_func_t mem_dereg;
96 uct_md_mem_query_func_t mem_query;
97 uct_md_mkey_pack_func_t mkey_pack;
98 uct_md_is_sockaddr_accessible_func_t is_sockaddr_accessible;
99 uct_md_detect_memory_type_func_t detect_memory_type;
100 };
101
102
103 /**
104 * Memory domain
105 */
106 struct uct_md {
107 uct_md_ops_t *ops;
108 uct_component_t *component;
109 };
110
111
112 #define UCT_MD_DEFAULT_CONFIG_INITIALIZER \
113 { \
114 .name = "Default memory domain", \
115 .prefix = "", \
116 .table = uct_md_config_table, \
117 .size = sizeof(uct_md_config_t), \
118 }
119
120
121 static UCS_F_ALWAYS_INLINE void*
uct_md_fill_md_name(uct_md_h md,void * buffer)122 uct_md_fill_md_name(uct_md_h md, void *buffer)
123 {
124 #if ENABLE_DEBUG_DATA
125 memcpy(buffer, md->component->name, UCT_COMPONENT_NAME_MAX);
126 return (char*)buffer + UCT_COMPONENT_NAME_MAX;
127 #else
128 return buffer;
129 #endif
130 }
131
132 /*
133 * Base implementation of query_md_resources(), which returns a single md
134 * resource whose name is identical to component name.
135 */
136 ucs_status_t
137 uct_md_query_single_md_resource(uct_component_t *component,
138 uct_md_resource_desc_t **resources_p,
139 unsigned *num_resources_p);
140
141 ucs_status_t
142 uct_md_query_empty_md_resource(uct_md_resource_desc_t **resources_p,
143 unsigned *num_resources_p);
144
145 /**
146 * @brief Dummy function
147 * Dummy function to emulate unpacking a remote key buffer to handle.
148 *
149 */
150 ucs_status_t uct_md_stub_rkey_unpack(uct_component_t *component,
151 const void *rkey_buffer, uct_rkey_t *rkey_p,
152 void **handle_p);
153
154 extern ucs_config_field_t uct_md_config_table[];
155
156 #endif
157