OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

private.h
1 /*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2011 inria. All rights reserved.
4 * Copyright © 2009-2012 Université Bordeaux 1
5 * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6 *
7 * See COPYING in top-level directory.
8 */
9
10 /* Internal types and helpers. */
11
12 #ifndef HWLOC_PRIVATE_H
13 #define HWLOC_PRIVATE_H
14
15 #include <private/autogen/config.h>
16 #include <hwloc.h>
17 #include <hwloc/bitmap.h>
18 #include <private/debug.h>
19 #include <sys/types.h>
20 #ifdef HAVE_STDINT_H
21 #include <stdint.h>
22 #endif
23
24 #include <string.h>
25
26 #ifdef HWLOC_HAVE_ATTRIBUTE_FORMAT
27 # if HWLOC_HAVE_ATTRIBUTE_FORMAT
28 # define __hwloc_attribute_format(type, str, arg) __attribute__((__format__(type, str, arg)))
29 # else
30 # define __hwloc_attribute_format(type, str, arg)
31 # endif
32 #else
33 # define __hwloc_attribute_format(type, str, arg)
34 #endif
35
36 enum hwloc_ignore_type_e {
37 HWLOC_IGNORE_TYPE_NEVER = 0,
38 HWLOC_IGNORE_TYPE_KEEP_STRUCTURE,
39 HWLOC_IGNORE_TYPE_ALWAYS
40 };
41
42 #define HWLOC_DEPTH_MAX 128
43
44 typedef enum hwloc_backend_e {
45 HWLOC_BACKEND_NONE,
46 HWLOC_BACKEND_SYNTHETIC,
47 #ifdef HWLOC_LINUX_SYS
48 HWLOC_BACKEND_SYSFS,
49 #endif
50 HWLOC_BACKEND_XML,
51 /* This value is only here so that we can end the enum list without
52 a comma (thereby preventing compiler warnings) */
53 HWLOC_BACKEND_MAX
54 } hwloc_backend_t;
55
56 struct hwloc_topology {
57 unsigned nb_levels; /* Number of horizontal levels */
58 unsigned next_group_depth; /* Depth of the next Group object that we may create */
59 unsigned level_nbobjects[HWLOC_DEPTH_MAX]; /* Number of objects on each horizontal level */
60 struct hwloc_obj **levels[HWLOC_DEPTH_MAX]; /* Direct access to levels, levels[l = 0 .. nblevels-1][0..level_nbobjects[l]] */
61 unsigned long flags;
62 int type_depth[HWLOC_OBJ_TYPE_MAX];
63 enum hwloc_ignore_type_e ignored_types[HWLOC_OBJ_TYPE_MAX];
64 int is_thissystem;
65 int is_loaded;
66 hwloc_pid_t pid; /* Process ID the topology is view from, 0 for self */
67
68 unsigned bridge_nbobjects;
69 struct hwloc_obj **bridge_level;
70 struct hwloc_obj *first_bridge, *last_bridge;
71 unsigned pcidev_nbobjects;
72 struct hwloc_obj **pcidev_level;
73 struct hwloc_obj *first_pcidev, *last_pcidev;
74 unsigned osdev_nbobjects;
75 struct hwloc_obj **osdev_level;
76 struct hwloc_obj *first_osdev, *last_osdev;
77
78 int (*set_thisproc_cpubind)(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
79 int (*get_thisproc_cpubind)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
80 int (*set_thisthread_cpubind)(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
81 int (*get_thisthread_cpubind)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
82 int (*set_proc_cpubind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
83 int (*get_proc_cpubind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
84 #ifdef hwloc_thread_t
85 int (*set_thread_cpubind)(hwloc_topology_t topology, hwloc_thread_t tid, hwloc_const_cpuset_t set, int flags);
86 int (*get_thread_cpubind)(hwloc_topology_t topology, hwloc_thread_t tid, hwloc_cpuset_t set, int flags);
87 #endif
88
89 int (*get_thisproc_last_cpu_location)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
90 int (*get_thisthread_last_cpu_location)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
91 int (*get_proc_last_cpu_location)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
92
93 int (*set_thisproc_membind)(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
94 int (*get_thisproc_membind)(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
95 int (*set_thisthread_membind)(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
96 int (*get_thisthread_membind)(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
97 int (*set_proc_membind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
98 int (*get_proc_membind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
99 int (*set_area_membind)(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
100 int (*get_area_membind)(hwloc_topology_t topology, const void *addr, size_t len, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
101 /* This has to return the same kind of pointer as alloc_membind, so that free_membind can be used on it */
102 void *(*alloc)(hwloc_topology_t topology, size_t len);
103 /* alloc_membind has to always succeed if !(flags & HWLOC_MEMBIND_STRICT).
104 * see hwloc_alloc_or_fail which is convenient for that. */
105 void *(*alloc_membind)(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
106 int (*free_membind)(hwloc_topology_t topology, void *addr, size_t len);
107
108 struct hwloc_topology_support support;
109
110 struct hwloc_os_distances_s {
111 int nbobjs;
112 unsigned *indexes; /* array of OS indexes before we can convert them into objs. always available.
113 */
114 struct hwloc_obj **objs; /* array of objects, in the same order as above.
115 * either given (by a backend) together with the indexes array above.
116 * or build from the above indexes array when not given (by the user).
117 */
118 float *distances; /* distance matrices, ordered according to the above indexes/objs array.
119 * distance from i to j is stored in slot i*nbnodes+j.
120 * will be copied into the main logical-index-ordered distance at the end of the discovery.
121 */
122 int forced; /* set if the user forced a matrix to ignore the OS one */
123 } os_distances[HWLOC_OBJ_TYPE_MAX];
124
125 hwloc_backend_t backend_type;
126 union hwloc_backend_params_u {
127 #ifdef HWLOC_LINUX_SYS
128 struct hwloc_backend_params_sysfs_s {
129 /* sysfs backend parameters */
130 char *root_path; /* The path of the file system root, used when browsing, e.g., Linux' sysfs and procfs. */
131 int root_fd; /* The file descriptor for the file system root, used when browsing, e.g., Linux' sysfs and procfs. */
132 } sysfs;
133 #endif /* HWLOC_LINUX_SYS */
134 #if defined(HWLOC_OSF_SYS) || defined(HWLOC_COMPILE_PORTS)
135 struct hwloc_backend_params_osf {
136 int nbnodes;
137 } osf;
138 #endif /* HWLOC_OSF_SYS */
139 struct hwloc_backend_params_xml_s {
140 /* xml backend parameters */
141 #ifdef HWLOC_HAVE_LIBXML2
142 void *doc;
143 #endif /* HWLOC_HAVE_LIBXML2 */
144 char *buffer; /* only used when not using libxml2 */
145 } xml;
146 struct hwloc_backend_params_synthetic_s {
147 /* synthetic backend parameters */
148 #define HWLOC_SYNTHETIC_MAX_DEPTH 128
149 unsigned arity[HWLOC_SYNTHETIC_MAX_DEPTH];
150 hwloc_obj_type_t type[HWLOC_SYNTHETIC_MAX_DEPTH];
151 unsigned id[HWLOC_SYNTHETIC_MAX_DEPTH];
152 unsigned depth[HWLOC_SYNTHETIC_MAX_DEPTH]; /* For cache/misc */
153 } synthetic;
154 } backend_params;
155 };
156
157
158 extern void hwloc_setup_pu_level(struct hwloc_topology *topology, unsigned nb_pus);
159 extern int hwloc_get_sysctlbyname(const char *name, int64_t *n);
160 extern int hwloc_get_sysctl(int name[], unsigned namelen, int *n);
161 extern unsigned hwloc_fallback_nbprocessors(struct hwloc_topology *topology);
162
163 #if defined(HWLOC_LINUX_SYS)
164 extern void hwloc_look_linux(struct hwloc_topology *topology);
165 extern void hwloc_set_linux_hooks(struct hwloc_topology *topology);
166 extern int hwloc_backend_sysfs_init(struct hwloc_topology *topology, const char *fsroot_path);
167 extern void hwloc_backend_sysfs_exit(struct hwloc_topology *topology);
168 #endif /* HWLOC_LINUX_SYS */
169
170 extern int hwloc_backend_xml_init(struct hwloc_topology *topology, const char *xmlpath, const char *xmlbuffer, int buflen);
171 extern void hwloc_xml_check_distances(struct hwloc_topology *topology);
172 extern int hwloc_look_xml(struct hwloc_topology *topology);
173 extern void hwloc_backend_xml_exit(struct hwloc_topology *topology);
174
175 #ifdef HWLOC_SOLARIS_SYS
176 extern void hwloc_look_solaris(struct hwloc_topology *topology);
177 extern void hwloc_set_solaris_hooks(struct hwloc_topology *topology);
178 #endif /* HWLOC_SOLARIS_SYS */
179
180 #ifdef HWLOC_AIX_SYS
181 extern void hwloc_look_aix(struct hwloc_topology *topology);
182 extern void hwloc_set_aix_hooks(struct hwloc_topology *topology);
183 #endif /* HWLOC_AIX_SYS */
184
185 #ifdef HWLOC_OSF_SYS
186 extern void hwloc_look_osf(struct hwloc_topology *topology);
187 extern void hwloc_set_osf_hooks(struct hwloc_topology *topology);
188 #endif /* HWLOC_OSF_SYS */
189
190 #ifdef HWLOC_WIN_SYS
191 extern void hwloc_look_windows(struct hwloc_topology *topology);
192 extern void hwloc_set_windows_hooks(struct hwloc_topology *topology);
193 #endif /* HWLOC_WIN_SYS */
194
195 #ifdef HWLOC_DARWIN_SYS
196 extern void hwloc_look_darwin(struct hwloc_topology *topology);
197 extern void hwloc_set_darwin_hooks(struct hwloc_topology *topology);
198 #endif /* HWLOC_DARWIN_SYS */
199
200 #ifdef HWLOC_FREEBSD_SYS
201 extern void hwloc_look_freebsd(struct hwloc_topology *topology);
202 extern void hwloc_set_freebsd_hooks(struct hwloc_topology *topology);
203 #endif /* HWLOC_FREEBSD_SYS */
204
205 #ifdef HWLOC_HPUX_SYS
206 extern void hwloc_look_hpux(struct hwloc_topology *topology);
207 extern void hwloc_set_hpux_hooks(struct hwloc_topology *topology);
208 #endif /* HWLOC_HPUX_SYS */
209
210 extern void hwloc_look_x86(struct hwloc_topology *topology, unsigned nbprocs);
211
212 #ifdef HWLOC_HAVE_LIBPCI
213 extern void hwloc_look_libpci(struct hwloc_topology *topology);
214 #endif /* HWLOC_HAVE_LIBPCI */
215
216 extern int hwloc_backend_synthetic_init(struct hwloc_topology *topology, const char *description);
217 extern void hwloc_backend_synthetic_exit(struct hwloc_topology *topology);
218 extern void hwloc_look_synthetic (struct hwloc_topology *topology);
219
220 /*
221 * Add an object to the topology.
222 * It is sorted along the tree of other objects according to the inclusion of
223 * cpusets, to eventually be added as a child of the smallest object including
224 * this object.
225 *
226 * If the cpuset is empty, the type of the object (and maybe some attributes)
227 * must be enough to find where to insert the object. This is especially true
228 * for NUMA nodes with memory and no CPUs.
229 *
230 * The given object should not have children.
231 *
232 * This shall only be called before levels are built.
233 *
234 * In case of error, hwloc_report_os_error() is called.
235 */
236 extern void hwloc_insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t obj);
237
238 /* Error reporting */
239 typedef void (*hwloc_report_error_t)(const char * msg, int line);
240 extern void hwloc_report_os_error(const char * msg, int line);
241 extern int hwloc_hide_errors(void);
242 /*
243 * Add an object to the topology and specify which error callback to use
244 */
245 extern int hwloc__insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t obj, hwloc_report_error_t report_error);
246
247 /*
248 * Insert an object somewhere in the topology.
249 *
250 * It is added as the last child of the given parent.
251 * The cpuset is completely ignored, so strange objects such as I/O devices should
252 * preferably be inserted with this.
253 *
254 * The given object may have children.
255 *
256 * Remember to call topology_connect() afterwards to fix handy pointers.
257 */
258 extern void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj);
259
260 /* Insert uname-specific names/values in the object infos array */
261 extern void hwloc_add_uname_info(struct hwloc_topology *topology);
262
263 #ifdef HWLOC_INSIDE_LIBHWLOC
264 /** \brief Return a locally-allocated stringified bitmap for printf-like calls. */
265 static __hwloc_inline char *
266 hwloc_bitmap_printf_value(hwloc_const_bitmap_t bitmap)
267 {
268 char *buf;
269 hwloc_bitmap_asprintf(&buf, bitmap);
270 return buf;
271 }
272
273 static __hwloc_inline struct hwloc_obj *
274 hwloc_alloc_setup_object(hwloc_obj_type_t type, signed idx)
275 {
276 struct hwloc_obj *obj = malloc(sizeof(*obj));
277 memset(obj, 0, sizeof(*obj));
278 obj->type = type;
279 obj->os_index = idx;
280 obj->os_level = -1;
281 obj->attr = malloc(sizeof(*obj->attr));
282 memset(obj->attr, 0, sizeof(*obj->attr));
283 /* do not allocate the cpuset here, let the caller do it */
284 return obj;
285 }
286
287 extern void hwloc_free_unlinked_object(hwloc_obj_t obj);
288
289 #define hwloc_object_cpuset_from_array(l, _value, _array, _max) do { \
290 struct hwloc_obj *__l = (l); \
291 unsigned int *__a = (_array); \
292 int k; \
293 __l->cpuset = hwloc_bitmap_alloc(); \
294 for(k=0; k<_max; k++) \
295 if (__a[k] == _value) \
296 hwloc_bitmap_set(__l->cpuset, k); \
297 } while (0)
298
299 /* Configures an array of NUM objects of type TYPE with physical IDs OSPHYSIDS
300 * and for which processors have ID PROC_PHYSIDS, and add them to the topology.
301 * */
302 static __hwloc_inline void
303 hwloc_setup_level(int procid_max, unsigned num, unsigned *osphysids, unsigned *proc_physids, struct hwloc_topology *topology, hwloc_obj_type_t type)
304 {
305 struct hwloc_obj *obj;
306 unsigned j;
307
308 hwloc_debug("%d %s\n", num, hwloc_obj_type_string(type));
309
310 for (j = 0; j < num; j++)
311 {
312 obj = hwloc_alloc_setup_object(type, osphysids[j]);
313 hwloc_object_cpuset_from_array(obj, j, proc_physids, procid_max);
314 hwloc_debug_2args_bitmap("%s %d has cpuset %s\n",
315 hwloc_obj_type_string(type),
316 j, obj->cpuset);
317 hwloc_insert_object_by_cpuset(topology, obj);
318 }
319 hwloc_debug("%s", "\n");
320 }
321 #endif
322
323 /* This can be used for the alloc field to get allocated data that can be freed by free() */
324 void *hwloc_alloc_heap(hwloc_topology_t topology, size_t len);
325
326 /* This can be used for the alloc field to get allocated data that can be freed by munmap() */
327 void *hwloc_alloc_mmap(hwloc_topology_t topology, size_t len);
328
329 /* This can be used for the free_membind field to free data using free() */
330 int hwloc_free_heap(hwloc_topology_t topology, void *addr, size_t len);
331
332 /* This can be used for the free_membind field to free data using munmap() */
333 int hwloc_free_mmap(hwloc_topology_t topology, void *addr, size_t len);
334
335 /* Allocates unbound memory or fail, depending on whether STRICT is requested
336 * or not */
337 static __hwloc_inline void *
338 hwloc_alloc_or_fail(hwloc_topology_t topology, size_t len, int flags)
339 {
340 if (flags & HWLOC_MEMBIND_STRICT)
341 return NULL;
342 return hwloc_alloc(topology, len);
343 }
344
345 extern void hwloc_topology_distances_init(struct hwloc_topology *topology);
346 extern void hwloc_topology_distances_clear(struct hwloc_topology *topology);
347 extern void hwloc_topology_distances_destroy(struct hwloc_topology *topology);
348 extern void hwloc_topology__set_distance_matrix(struct hwloc_topology *topology, hwloc_obj_type_t type, unsigned nbobjs, unsigned *indexes, hwloc_obj_t *objs, float *distances, int force);
349 extern void hwloc_store_distances_from_env(struct hwloc_topology *topology);
350 extern void hwloc_convert_distances_indexes_into_objects(struct hwloc_topology *topology);
351 extern void hwloc_finalize_logical_distances(struct hwloc_topology *topology);
352 extern void hwloc_restrict_distances(struct hwloc_topology *topology, unsigned long flags);
353 extern void hwloc_free_logical_distances(struct hwloc_distances_s *dist);
354 extern void hwloc_group_by_distances(struct hwloc_topology *topology);
355
356 #endif /* HWLOC_PRIVATE_H */
hwloc_obj_type_string
HWLOC_DECLSPEC const char * hwloc_obj_type_string(hwloc_obj_type_t type) __hwloc_attribute_const
Return a stringified topology object type.
Definition: traversal.c:175
hwloc_obj::os_level
signed os_level
OS-provided physical level, -1 if unknown or meaningless.
Definition: hwloc.h:344
hwloc_obj::os_index
unsigned os_index
OS-provided physical index number.
Definition: hwloc.h:332
hwloc_distances_s
Distances between objects.
Definition: hwloc.h:522
hwloc_topology::hwloc_os_distances_s
Definition: private.h:110
HWLOC_MEMBIND_STRICT
Request strict binding from the OS.
Definition: hwloc.h:1574
hwloc_obj::type
hwloc_obj_type_t type
Type of object.
Definition: hwloc.h:331
HWLOC_OBJ_TYPE_MAX
Sentinel value.
Definition: hwloc.h:243
hwloc_obj::nodeset
hwloc_nodeset_t nodeset
NUMA nodes covered by this object or containing this object.
Definition: hwloc.h:409
hwloc_topology::hwloc_backend_params_u
Definition: private.h:126
hwloc_obj
Structure of a topology object.
Definition: hwloc.h:329
hwloc_bitmap_asprintf
HWLOC_DECLSPEC int hwloc_bitmap_asprintf(char **strp, hwloc_const_bitmap_t bitmap)
Stringify a bitmap into a newly allocated string.
hwloc_topology::hwloc_backend_params_u::hwloc_backend_params_xml_s
Definition: private.h:139
hwloc_topology::hwloc_backend_params_u::hwloc_backend_params_synthetic_s
Definition: private.h:146
bitmap.h
The bitmap API, for use in hwloc itself.
hwloc_alloc
HWLOC_DECLSPEC void * hwloc_alloc(hwloc_topology_t topology, size_t len)
Allocate some memory.
Definition: bind.c:487
hwloc_obj_type_t
hwloc_obj_type_t
Type of topology object.
Definition: hwloc.h:164
hwloc_obj::cpuset
hwloc_cpuset_t cpuset
CPUs covered by this object.
Definition: hwloc.h:366
hwloc_membind_policy_t
hwloc_membind_policy_t
Memory binding policy.
Definition: hwloc.h:1479
hwloc_obj::attr
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:337
hwloc_topology
Definition: private.h:56
hwloc_obj::distances
struct hwloc_distances_s ** distances
Distances between all objects at same depth below this object.
Definition: hwloc.h:453
hwloc_topology_support
Set of flags describing actual support for this topology.
Definition: hwloc.h:905
hwloc_bitmap_s
Definition: cpuset.c:38