Coverage Report

Created: 2026-09-03 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hwloc/include/private/private.h
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: BSD-3-Clause
3
 * Copyright © 2009      CNRS
4
 * Copyright © 2009-2026 Inria.  All rights reserved.
5
 * Copyright © 2009-2012, 2020 Université Bordeaux
6
 * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
7
 * See COPYING in top-level directory.
8
 */
9
10
/* Internal types and helpers. */
11
12
13
#ifdef HWLOC_INSIDE_PLUGIN
14
/*
15
 * these declarations are internal only, they are not available to plugins
16
 * (many functions below are internal static symbols).
17
 */
18
#error This file should not be used in plugins
19
#endif
20
21
22
#ifndef HWLOC_PRIVATE_H
23
#define HWLOC_PRIVATE_H
24
25
#include "private/autogen/config.h"
26
#include "hwloc.h"
27
#include "hwloc/bitmap.h"
28
#include "private/components.h"
29
#include "private/misc.h"
30
31
#include <sys/types.h>
32
#ifdef HAVE_UNISTD_H
33
#include <unistd.h>
34
#endif
35
#ifdef HAVE_STDINT_H
36
#include <stdint.h>
37
#endif
38
#ifdef HAVE_SYS_UTSNAME_H
39
#include <sys/utsname.h>
40
#endif
41
#include <string.h>
42
43
#define HWLOC_TOPOLOGY_ABI 0x30000 /* version of the layout of struct topology */
44
45
struct hwloc_internal_location_s {
46
  enum hwloc_location_type_e type;
47
  union {
48
    struct {
49
      hwloc_obj_t obj; /* cached between refreshes */
50
      uint64_t gp_index;
51
      hwloc_obj_type_t type;
52
    } object; /* if type == HWLOC_LOCATION_TYPE_OBJECT */
53
    hwloc_cpuset_t cpuset; /* if type == HWLOC_LOCATION_TYPE_CPUSET */
54
  } location;
55
};
56
57
/*****************************************************
58
 * WARNING:
59
 * changes below in this structure (and its children)
60
 * should cause a bump of HWLOC_TOPOLOGY_ABI.
61
 *****************************************************/
62
63
enum hwloc_topology_state_e {
64
  HWLOC_TOPOLOGY_STATE_IS_THISSYSTEM = (1UL<<0),
65
  HWLOC_TOPOLOGY_STATE_IS_LOADED = (1UL<<1),
66
  HWLOC_TOPOLOGY_STATE_IS_LOADING = (1UL<<2),
67
  HWLOC_TOPOLOGY_STATE_IS_INIT = (1UL<<3)
68
};
69
70
struct hwloc_topology {
71
  unsigned topology_abi;
72
73
  unsigned nb_levels;         /* Number of horizontal levels */
74
  unsigned nb_levels_allocated;       /* Number of levels allocated and zeroed in level_nbobjects and levels below */
75
  unsigned *level_nbobjects;        /* Number of objects on each horizontal level */
76
  struct hwloc_obj ***levels;       /* Direct access to levels, levels[l = 0 .. nblevels-1][0..level_nbobjects[l]] */
77
  unsigned long flags;
78
  int type_depth[HWLOC_OBJ_TYPE_MAX];
79
  enum hwloc_type_filter_e type_filter[HWLOC_OBJ_TYPE_MAX];
80
  unsigned char is_xml;                                 /* shortcut to only component being XML */
81
  unsigned long state;                                  /* OR'ed enum hwloc_topology_state_e */
82
  unsigned long modified;                               /* >0 if objects were added/removed recently, which means a reconnect is needed,
83
                                                         * not inside "state" in case we want to store bits, numbers, etc.
84
                                                         */
85
  hwloc_pid_t pid;                                      /* Process ID the topology is view from, 0 for self */
86
  void *userdata;
87
  uint64_t next_gp_index;
88
89
  void *adopted_shmem_addr;
90
  size_t adopted_shmem_length;
91
92
#define HWLOC_NR_SLEVELS 6
93
#define HWLOC_SLEVEL_NUMANODE 0
94
#define HWLOC_SLEVEL_BRIDGE 1
95
#define HWLOC_SLEVEL_PCIDEV 2
96
#define HWLOC_SLEVEL_OSDEV 3
97
#define HWLOC_SLEVEL_MISC 4
98
#define HWLOC_SLEVEL_MEMCACHE 5
99
  /* order must match negative depth, it's asserted in setup_defaults() */
100
#define HWLOC_SLEVEL_FROM_DEPTH(x) (HWLOC_TYPE_DEPTH_NUMANODE-(x))
101
#define HWLOC_SLEVEL_TO_DEPTH(x) (HWLOC_TYPE_DEPTH_NUMANODE-(x))
102
  struct hwloc_special_level_s {
103
    unsigned nbobjs;
104
    struct hwloc_obj **objs;
105
    struct hwloc_obj *first, *last; /* Temporarily used while listing object before building the objs array */
106
  } slevels[HWLOC_NR_SLEVELS];
107
108
  hwloc_bitmap_t allowed_cpuset;
109
  hwloc_bitmap_t allowed_nodeset;
110
111
  struct hwloc_binding_hooks {
112
    /* These are actually rather OS hooks since some of them are not about binding */
113
    int (*set_thisproc_cpubind)(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
114
    int (*get_thisproc_cpubind)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
115
    int (*set_thisthread_cpubind)(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
116
    int (*get_thisthread_cpubind)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
117
    int (*set_proc_cpubind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
118
    int (*get_proc_cpubind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
119
#ifdef hwloc_thread_t
120
    int (*set_thread_cpubind)(hwloc_topology_t topology, hwloc_thread_t tid, hwloc_const_cpuset_t set, int flags);
121
    int (*get_thread_cpubind)(hwloc_topology_t topology, hwloc_thread_t tid, hwloc_cpuset_t set, int flags);
122
#endif
123
    /* x86 specific CPU binding that may only bind to a single PU or nothing.
124
     * Prototypes must match get/set_thisthread_cpubind() */
125
    int (*x86_set_cpubind)(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
126
    int (*x86_get_cpubind)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
127
128
    int (*get_thisproc_last_cpu_location)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
129
    int (*get_thisthread_last_cpu_location)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
130
    int (*get_proc_last_cpu_location)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
131
132
    int (*set_thisproc_membind)(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
133
    int (*get_thisproc_membind)(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
134
    int (*set_thisthread_membind)(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
135
    int (*get_thisthread_membind)(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
136
    int (*set_proc_membind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
137
    int (*get_proc_membind)(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
138
    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);
139
    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);
140
    int (*get_area_memlocation)(hwloc_topology_t topology, const void *addr, size_t len, hwloc_nodeset_t nodeset, int flags);
141
    /* This has to return the same kind of pointer as alloc_membind, so that free_membind can be used on it */
142
    void *(*alloc)(hwloc_topology_t topology, size_t len);
143
    /* alloc_membind has to always succeed if !(flags & HWLOC_MEMBIND_STRICT).
144
     * see hwloc_alloc_or_fail which is convenient for that.  */
145
    void *(*alloc_membind)(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
146
    int (*free_membind)(hwloc_topology_t topology, void *addr, size_t len);
147
148
    int (*get_allowed_resources)(hwloc_topology_t topology);
149
  } binding_hooks;
150
151
  struct hwloc_topology_support support;
152
153
  struct hwloc_infos_s infos;
154
155
  void (*userdata_export_cb)(void *reserved, struct hwloc_topology *topology, struct hwloc_obj *obj);
156
  void (*userdata_import_cb)(struct hwloc_topology *topology, struct hwloc_obj *obj, const char *name, const void *buffer, size_t length);
157
  int userdata_not_decoded;
158
159
  struct hwloc_internal_distances_s {
160
    char *name; /* FIXME: needs an API to set it from user */
161
162
    unsigned id; /* to match the container id field of public distances structure
163
      * not exported to XML, regenerated during _add()
164
      */
165
166
    /* if all objects have the same type, different_types is NULL and unique_type is valid.
167
     * otherwise unique_type is HWLOC_OBJ_TYPE_NONE and different_types contains individual objects types.
168
     */
169
    hwloc_obj_type_t unique_type;
170
    hwloc_obj_type_t *different_types;
171
172
    /* add union hwloc_obj_attr_u if we ever support groups */
173
    unsigned nbobjs;
174
    uint64_t *indexes; /* array of OS or GP indexes before we can convert them into objs.
175
      * OS indexes for distances covering only PUs or only NUMAnodes.
176
      */
177
#define HWLOC_DIST_TYPE_USE_OS_INDEX(_type) ((_type) == HWLOC_OBJ_PU || (_type == HWLOC_OBJ_NUMANODE))
178
    uint64_t *values; /* distance matrices, ordered according to the above indexes/objs array.
179
           * distance from i to j is stored in slot i*nbnodes+j.
180
           */
181
    unsigned long kind;
182
183
#define HWLOC_INTERNAL_DIST_FLAG_OBJS_VALID (1U<<0) /* if the objs array is valid below */
184
#define HWLOC_INTERNAL_DIST_FLAG_NOT_COMMITTED (1U<<1) /* if the distances isn't in the list yet */
185
    unsigned iflags;
186
187
    /* objects are currently stored in physical_index order */
188
    hwloc_obj_t *objs; /* array of objects */
189
190
    struct hwloc_internal_distances_s *prev, *next;
191
  } *first_dist, *last_dist;
192
  unsigned next_dist_id;
193
194
  /* memory attributes */
195
  unsigned nr_memattrs;
196
  struct hwloc_internal_memattr_s {
197
    /* memattr info */
198
    char *name; /* TODO unit is implicit, in the documentation of standard attributes, or in the name? */
199
    unsigned long flags;
200
#define HWLOC_IMATTR_FLAG_STATIC_NAME (1U<<0) /* no need to free name */
201
#define HWLOC_IMATTR_FLAG_CACHE_VALID (1U<<1) /* target and initiator are valid */
202
#define HWLOC_IMATTR_FLAG_CONVENIENCE (1U<<2) /* convenience attribute reporting values from non-memattr attributes (R/O and no actual targets stored) */
203
    unsigned iflags;
204
205
    /* array of values */
206
    unsigned nr_targets;
207
    struct hwloc_internal_memattr_target_s {
208
      /* target object */
209
      hwloc_obj_t obj; /* cached between refreshes */
210
      hwloc_obj_type_t type;
211
      unsigned os_index; /* only used temporarily during discovery when there's no obj/gp_index yet */
212
      hwloc_uint64_t gp_index;
213
214
      /* value if there are no initiator for this attr */
215
      hwloc_uint64_t noinitiator_value;
216
      /* initiators otherwise */
217
      unsigned nr_initiators;
218
      struct hwloc_internal_memattr_initiator_s {
219
        struct hwloc_internal_location_s initiator;
220
        hwloc_uint64_t value;
221
      } *initiators;
222
    } *targets;
223
  } *memattrs;
224
225
  /* memtiers */
226
  unsigned nr_memtiers;
227
  struct hwloc_internal_memtier_s {
228
    hwloc_nodeset_t nodeset;
229
    uint64_t local_bw_min, local_bw_max;
230
    uint64_t local_lat_min, local_lat_max;
231
    unsigned long kinds;
232
    struct hwloc_infos_s infos;
233
  } * memtiers;
234
235
  /* hybridcpus */
236
  unsigned nr_cpukinds;
237
  unsigned nr_cpukinds_allocated;
238
  struct hwloc_internal_cpukind_s {
239
    hwloc_cpuset_t cpuset;
240
#define HWLOC_CPUKIND_EFFICIENCY_UNKNOWN -1
241
    int efficiency;
242
    int forced_efficiency; /* returned by the hardware or OS if any */
243
    hwloc_uint64_t ranking_value; /* internal value for ranking */
244
    struct hwloc_infos_s infos;
245
  } *cpukinds;
246
247
  int grouping;
248
  int grouping_verbose;
249
  unsigned grouping_nbaccuracies;
250
  float grouping_accuracies[5];
251
  unsigned grouping_next_subkind;
252
253
  /* pci localities */
254
  /* FIXME: reuse for finding specific buses */
255
  /* FIXME: save to XML */
256
  struct hwloc_pci_locality_s {
257
    unsigned domain;
258
    unsigned bus_min;
259
    unsigned bus_max;
260
    hwloc_cpuset_t cpuset;
261
    hwloc_obj_t parent; /* may need to refreshed from cpuset on topology changes */
262
    struct hwloc_pci_locality_s *prev, *next;
263
  } *first_pci_locality, *last_pci_locality; /* contains unsorted forced localities first, then sorted real ones */
264
265
  /* list of enabled backends. */
266
  struct hwloc_backend * backends;
267
  struct hwloc_backend * get_pci_busid_cpuset_backend; /* first backend that provides get_pci_busid_cpuset() callback */
268
  unsigned backend_phases;
269
  unsigned backend_excluded_phases;
270
271
  /* memory allocator for topology objects */
272
  struct hwloc_tma * tma;
273
274
/*****************************************************
275
 * WARNING:
276
 * changes above in this structure (and its children)
277
 * should cause a bump of HWLOC_TOPOLOGY_ABI.
278
 *****************************************************/
279
280
  /*
281
   * temporary variables during discovery
282
   */
283
284
  /* set to 1 at the beginning of load() if the filter of any cpu cache type (L1 to L3i) is not NONE,
285
   * may be checked by backends before querying caches
286
   * (when they don't know the level of caches they are querying).
287
   */
288
  int want_some_cpu_caches;
289
290
  /* machine-wide memory.
291
   * temporarily stored there by OSes that only provide this without NUMA information,
292
   * and actually used later by the core.
293
   */
294
  struct hwloc_numanode_attr_s machine_memory;
295
296
  /* component blacklisting */
297
  unsigned nr_blacklisted_components;
298
  struct hwloc_topology_forced_component_s {
299
    struct hwloc_disc_component *component;
300
    unsigned phases;
301
  } *blacklisted_components;
302
};
303
304
extern void hwloc_alloc_root_sets(hwloc_obj_t root);
305
extern void hwloc_setup_pu_level(struct hwloc_topology *topology, unsigned nb_pus);
306
extern int hwloc_get_sysctlbyname(const char *name, int64_t *n);
307
extern int hwloc_get_sysctl(int name[], unsigned namelen, int64_t *n);
308
309
/* returns the number of CPU from the OS (only valid if thissystem) */
310
#define HWLOC_FALLBACK_NBPROCESSORS_INCLUDE_OFFLINE 1 /* by default we try to get only the online CPUs */
311
extern int hwloc_fallback_nbprocessors(unsigned flags);
312
/* returns the memory size from the OS (only valid if thissystem) */
313
extern int64_t hwloc_fallback_memsize(void);
314
315
extern int hwloc__object_cpusets_compare_first(hwloc_obj_t obj1, hwloc_obj_t obj2);
316
extern void hwloc__reorder_children(hwloc_obj_t parent);
317
318
extern void hwloc_topology_setup_defaults(struct hwloc_topology *topology);
319
extern void hwloc_topology_clear(struct hwloc_topology *topology);
320
321
#define _HWLOC_RECONNECT_FLAG_KEEPSTRUCTURE (1UL<<0)
322
extern int hwloc__reconnect(struct hwloc_topology *topology, unsigned long flags);
323
324
/* insert memory object as memory child of normal parent */
325
extern struct hwloc_obj * hwloc__attach_memory_object(struct hwloc_topology *topology, hwloc_obj_t parent,
326
                                                      hwloc_obj_t obj, const char *reason);
327
328
extern hwloc_obj_t hwloc_get_obj_by_type_and_gp_index(hwloc_topology_t topology, hwloc_obj_type_t type, uint64_t gp_index);
329
330
extern void hwloc_pci_init(struct hwloc_topology *topology);
331
extern void hwloc_pci_prepare(struct hwloc_topology *topology);
332
extern void hwloc_pci_refresh(struct hwloc_topology *topology);
333
extern int hwloc_pci_dup(hwloc_topology_t new, hwloc_topology_t old);
334
extern void hwloc_pci_exit(struct hwloc_topology *topology);
335
336
extern void hwloc_pci_xml_import_locality(struct hwloc_topology *topology, unsigned domain, unsigned bus_min, unsigned bus_max, hwloc_obj_t parent, hwloc_cpuset_t cpuset);
337
extern void hwloc_pci_xml_import_refresh_localities(struct hwloc_topology *topology);
338
339
extern int hwloc__add_info(struct hwloc_infos_s *infos, const char *name, const char *value);
340
extern int hwloc__replace_infos(struct hwloc_infos_s *infos, const char *name, const char *value);
341
extern int hwloc__remove_infos(struct hwloc_infos_s *infos, const char *name, const char *value);
342
extern int hwloc__move_infos(struct hwloc_infos_s *dst_infos, struct hwloc_infos_s *src_infos);
343
extern int hwloc__tma_dup_infos(struct hwloc_tma *tma, struct hwloc_infos_s *dst_infos, struct hwloc_infos_s *src_infos);
344
extern void hwloc__free_infos(struct hwloc_infos_s *infos);
345
static __hwloc_inline void hwloc__init_infos(struct hwloc_infos_s *infos)
346
0
{
347
0
  infos->array = NULL;
348
0
  infos->count = 0;
349
0
  infos->allocated = 0;
350
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc__init_infos
Unexecuted instantiation: base64.c:hwloc__init_infos
351
static __hwloc_inline void hwloc__init_infos_static(struct hwloc_infos_s *infos, unsigned count, struct hwloc_info_s *static_array)
352
0
{
353
0
  infos->array = static_array;
354
0
  infos->count = count;
355
0
  infos->allocated = 0; /* means we won't free */
356
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc__init_infos_static
Unexecuted instantiation: base64.c:hwloc__init_infos_static
357
358
/* set native OS binding hooks */
359
extern void hwloc_set_native_binding_hooks(struct hwloc_binding_hooks *hooks, struct hwloc_topology_support *support);
360
/* set either native OS binding hooks (if thissystem), or dummy ones */
361
extern void hwloc_set_binding_hooks(struct hwloc_topology *topology);
362
363
#if defined(HWLOC_LINUX_SYS)
364
extern void hwloc_set_linuxfs_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
365
#endif /* HWLOC_LINUX_SYS */
366
367
#ifdef HWLOC_SOLARIS_SYS
368
extern void hwloc_set_solaris_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
369
#endif /* HWLOC_SOLARIS_SYS */
370
371
#ifdef HWLOC_AIX_SYS
372
extern void hwloc_set_aix_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
373
#endif /* HWLOC_AIX_SYS */
374
375
#ifdef HWLOC_WIN_SYS
376
extern void hwloc_set_windows_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
377
#endif /* HWLOC_WIN_SYS */
378
379
#ifdef HWLOC_DARWIN_SYS
380
extern void hwloc_set_darwin_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
381
#endif /* HWLOC_DARWIN_SYS */
382
383
#ifdef HWLOC_FREEBSD_SYS
384
extern void hwloc_set_freebsd_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
385
#endif /* HWLOC_FREEBSD_SYS */
386
387
#ifdef HWLOC_NETBSD_SYS
388
extern void hwloc_set_netbsd_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
389
#endif /* HWLOC_NETBSD_SYS */
390
391
extern int hwloc_look_hardwired_fujitsu_k(struct hwloc_topology *topology);
392
extern int hwloc_look_hardwired_fujitsu_fx10(struct hwloc_topology *topology);
393
extern int hwloc_look_hardwired_fujitsu_fx100(struct hwloc_topology *topology);
394
395
/* Insert uname-specific names/values in the object infos array.
396
 * If cached_uname isn't NULL, it is used as a struct utsname instead of recalling uname.
397
 * Any field that starts with \0 is ignored.
398
 */
399
extern void hwloc_add_uname_info(struct hwloc_topology *topology, void *cached_uname);
400
401
/* Insert PageSizes topology info from legacy sysconf&co */
402
extern void hwloc_fallback_add_pagesize_info(struct hwloc_topology *topology);
403
404
#if (defined HWLOC_LINUX_SYS)
405
/* Linux may need more than a long when loading a 64bit sysfs dump (eg with 16GB pages) on a 32bit machine */
406
typedef uint64_t hwloc_pagesize_arrayelt_t;
407
#else
408
/* at least Solaris and FreeBSD want a size_t */
409
typedef size_t hwloc_pagesize_arrayelt_t;
410
#endif
411
412
/* Insert PageSizes topology info from the array of sizes */
413
extern int hwloc__add_pagesize_info_from_array(struct hwloc_topology *topology, hwloc_pagesize_arrayelt_t *sizes, unsigned nr);
414
415
/* Free obj and its attributes assuming it's not linked to a parent and doesn't have any child */
416
extern void hwloc_free_unlinked_object(hwloc_obj_t obj);
417
418
/* Free obj and its children, assuming it's not linked to a parent */
419
extern void hwloc_free_object_and_children(hwloc_obj_t obj);
420
421
/* Free obj, its next siblings, and their children, assuming they're not linked to a parent */
422
extern void hwloc_free_object_siblings_and_children(hwloc_obj_t obj);
423
424
/* This can be used for the alloc field to get allocated data that can be freed by free() */
425
void *hwloc_alloc_heap(hwloc_topology_t topology, size_t len);
426
427
/* This can be used for the alloc field to get allocated data that can be freed by munmap() */
428
void *hwloc_alloc_mmap(hwloc_topology_t topology, size_t len);
429
430
/* This can be used for the free_membind field to free data using free() */
431
int hwloc_free_heap(hwloc_topology_t topology, void *addr, size_t len);
432
433
/* This can be used for the free_membind field to free data using munmap() */
434
int hwloc_free_mmap(hwloc_topology_t topology, void *addr, size_t len);
435
436
/* Allocates unbound memory or fail, depending on whether STRICT is requested
437
 * or not */
438
static __hwloc_inline void *
439
hwloc_alloc_or_fail(hwloc_topology_t topology, size_t len, int flags)
440
0
{
441
0
  if (flags & HWLOC_MEMBIND_STRICT)
442
0
    return NULL;
443
0
  return hwloc_alloc(topology, len);
444
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_alloc_or_fail
Unexecuted instantiation: base64.c:hwloc_alloc_or_fail
445
446
extern void hwloc_internal_distances_init(hwloc_topology_t topology);
447
extern void hwloc_internal_distances_prepare(hwloc_topology_t topology);
448
extern void hwloc_internal_distances_destroy(hwloc_topology_t topology);
449
extern int hwloc_internal_distances_dup(hwloc_topology_t new, hwloc_topology_t old);
450
extern void hwloc_internal_distances_refresh(hwloc_topology_t topology);
451
extern void hwloc_internal_distances_invalidate_cached_objs(hwloc_topology_t topology);
452
453
/* these distances_add() functions are higher-level than those in hwloc/plugins.h
454
 * but they may change in the future, hence they are not exported to plugins.
455
 */
456
extern int hwloc_internal_distances_add_by_index(hwloc_topology_t topology, const char *name, hwloc_obj_type_t unique_type, hwloc_obj_type_t *different_types, unsigned nbobjs, uint64_t *indexes, uint64_t *values, unsigned long kind, unsigned long flags);
457
extern int hwloc_internal_distances_add(hwloc_topology_t topology, const char *name, unsigned nbobjs, hwloc_obj_t *objs, uint64_t *values, unsigned long kind, unsigned long flags);
458
459
extern void hwloc_internal_memattrs_init(hwloc_topology_t topology);
460
extern void hwloc_internal_memattrs_prepare(hwloc_topology_t topology);
461
extern void hwloc_internal_memattrs_destroy(hwloc_topology_t topology);
462
extern void hwloc_internal_memattrs_need_refresh(hwloc_topology_t topology);
463
extern void hwloc_internal_memattrs_refresh(hwloc_topology_t topology);
464
extern int hwloc_internal_memattrs_dup(hwloc_topology_t new, hwloc_topology_t old);
465
extern int hwloc_internal_memattr_set_value(hwloc_topology_t topology, hwloc_memattr_id_t id, hwloc_obj_type_t target_type, hwloc_uint64_t target_gp_index, unsigned target_os_index, struct hwloc_internal_location_s *initiator, hwloc_uint64_t value);
466
467
extern void hwloc_internal_memtiers_init(hwloc_topology_t topology);
468
extern int hwloc_internal_memtiers_build(hwloc_topology_t topology);
469
extern void hwloc_internal_memtiers_destroy(hwloc_topology_t topology);
470
extern int hwloc_internal_memtiers_dup(hwloc_topology_t new, hwloc_topology_t old);
471
extern int hwloc_internal_memtiers_restrict(struct hwloc_topology *topology);
472
extern int hwloc_internal_memtier_import(struct hwloc_topology *topology, unsigned long kinds, hwloc_bitmap_t nodeset, struct hwloc_infos_s *infos);
473
extern int hwloc_internal_memtier_v2xml_import(struct hwloc_topology *topology, char *subtype, hwloc_bitmap_t nodeset);
474
475
extern void hwloc_internal_cpukinds_init(hwloc_topology_t topology);
476
extern int hwloc_internal_cpukinds_rank(hwloc_topology_t topology);
477
extern void hwloc_internal_cpukinds_destroy(hwloc_topology_t topology);
478
extern int hwloc_internal_cpukinds_dup(hwloc_topology_t new, hwloc_topology_t old);
479
#define HWLOC_CPUKINDS_REGISTER_FLAG_OVERWRITE_FORCED_EFFICIENCY (1<<0)
480
extern int hwloc_internal_cpukinds_register(hwloc_topology_t topology, hwloc_cpuset_t cpuset, int forced_efficiency, const struct hwloc_infos_s *infos, unsigned long flags);
481
extern void hwloc_internal_cpukinds_restrict(hwloc_topology_t topology);
482
483
/* encode src buffer into target buffer.
484
 * targsize must be at least 4*((srclength+2)/3)+1.
485
 * target will be 0-terminated.
486
 */
487
extern int hwloc_encode_to_base64(const char *src, size_t srclength, char *target, size_t targsize);
488
/* decode src buffer into target buffer.
489
 * src is 0-terminated.
490
 * targsize must be at least srclength*3/4+1 (srclength not including \0)
491
 * but only srclength*3/4 characters will be meaningful
492
 * (the next one may be partially written during decoding, but it should be ignored).
493
 */
494
extern int hwloc_decode_from_base64(char const *src, char *target, size_t targsize);
495
496
/* On some systems, snprintf returns the size of written data, not the actually
497
 * required size. Sometimes it returns -1 on truncation too.
498
 * And sometimes it doesn't like NULL output buffers.
499
 * http://www.gnu.org/software/gnulib/manual/html_node/snprintf.html
500
 *
501
 * hwloc_snprintf behaves properly, but it's a bit overkill on the vast majority
502
 * of platforms, so don't enable it unless really needed.
503
 */
504
#ifdef HWLOC_HAVE_CORRECT_SNPRINTF
505
#define hwloc_snprintf snprintf
506
#else
507
extern int hwloc_snprintf(char *str, size_t size, const char *format, ...) __hwloc_attribute_format(printf, 3, 4);
508
#endif
509
510
/* uses HWLOC_OBJ_SNPRINTF_FLAG_ flags */
511
static __hwloc_inline int hwloc_memory_size_snprintf(char *buffer, size_t bufsize, unsigned long long size, unsigned long flags)
512
0
{
513
0
  /* no units */
514
0
  if (flags & HWLOC_OBJ_SNPRINTF_FLAG_NO_UNITS) {
515
0
    return snprintf(buffer, bufsize, "%llu", size);
516
0
  }
517
0
518
0
  /* old deprecated format (KiB value with KB units) */
519
0
  if (flags & HWLOC_OBJ_SNPRINTF_FLAG_OLD_VERBOSE) {
520
0
    return snprintf(buffer, bufsize, "%llu%s", ((size>>9)+1)>>1, "KB");
521
0
  }
522
0
523
0
  /* units 1000 */
524
0
  if (flags & HWLOC_OBJ_SNPRINTF_FLAG_UNITS_1000) {
525
0
    if (size < 10000000ULL) {
526
0
      return snprintf(buffer, bufsize, "%llu%s", ((size/500)+1)/2, "KB");
527
0
    } else if (size < 10000000000ULL) {
528
0
      return snprintf(buffer, bufsize, "%llu%s", ((size/500000)+1)/2, "MB");
529
0
    } else if (size < 10000000000000ULL) {
530
0
      return snprintf(buffer, bufsize, "%llu%s", ((size/500000000)+1)/2, "GB");
531
0
    } else {
532
0
      return snprintf(buffer, bufsize, "%llu%s", ((size/500000000000ULL)+1)/2, "TB");
533
0
    }
534
0
  }
535
0
536
0
  /* units 1024 */
537
0
  if (size < (10ULL<<20)) {
538
0
    return snprintf(buffer, bufsize, "%llu%s", ((size>>9)+1)>>1, "KiB");
539
0
  } else if (size < (10ULL<<30)) {
540
0
    return snprintf(buffer, bufsize, "%llu%s", ((size>>19)+1)>>1, "MiB");
541
0
  } else if (size < (10ULL<<40)) {
542
0
    return snprintf(buffer, bufsize, "%llu%s", ((size>>29)+1)>>1, "GiB");
543
0
  } else {
544
0
    return snprintf(buffer, bufsize, "%llu%s", ((size>>39)+1)>>1, "TiB");
545
0
  }
546
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_memory_size_snprintf
Unexecuted instantiation: base64.c:hwloc_memory_size_snprintf
547
548
/* Return the name of the currently running program, if supported.
549
 * If not NULL, must be freed by the caller.
550
 */
551
extern char * hwloc_progname(struct hwloc_topology *topology);
552
553
/* obj->attr->group.kind internal values.
554
 * the core will keep the smallest ones when merging two groups,
555
 * that's why user-given kinds are first.
556
 */
557
/* first, user-given groups, should remain as long as possible */
558
#define HWLOC_GROUP_KIND_USER       0 /* user-given, user may use subkind too */
559
#define HWLOC_GROUP_KIND_SYNTHETIC      10  /* subkind is group depth within synthetic description */
560
/* then, hardware-specific groups */
561
#define HWLOC_GROUP_KIND_INTEL_KNL_SUBNUMA_CLUSTER  100 /* no subkind */
562
#define HWLOC_GROUP_KIND_INTEL_EXTTOPOENUM_UNKNOWN  101 /* subkind is unknown level */
563
#define HWLOC_GROUP_KIND_INTEL_MODULE     102 /* no subkind */
564
#define HWLOC_GROUP_KIND_INTEL_TILE     103 /* no subkind */
565
#define HWLOC_GROUP_KIND_INTEL_DIE      104 /* no subkind */
566
#define HWLOC_GROUP_KIND_S390_BOOK      110 /* subkind 0 is book, subkind 1 is drawer (group of books) */
567
#define HWLOC_GROUP_KIND_AMD_COMPUTE_UNIT   120 /* no subkind */
568
#define HWLOC_GROUP_KIND_AMD_COMPLEX                    121     /* no subkind */
569
/* then, OS-specific groups */
570
#define HWLOC_GROUP_KIND_SOLARIS_PG_HW_PERF   200 /* subkind is group width */
571
#define HWLOC_GROUP_KIND_AIX_SDL_UNKNOWN    210 /* subkind is SDL level */
572
#define HWLOC_GROUP_KIND_WINDOWS_PROCESSOR_GROUP  220 /* no subkind */
573
#define HWLOC_GROUP_KIND_WINDOWS_RELATIONSHIP_UNKNOWN 221 /* no subkind */
574
#define HWLOC_GROUP_KIND_LINUX_CLUSTER                  222     /* no subkind */
575
/* distance groups */
576
#define HWLOC_GROUP_KIND_DISTANCE     900 /* subkind is round of adding these groups during distance based grouping */
577
/* finally, hwloc-specific groups required to insert something else, should disappear as soon as possible */
578
#define HWLOC_GROUP_KIND_IO       1000  /* no subkind */
579
#define HWLOC_GROUP_KIND_MEMORY       1001  /* no subkind */
580
581
/* memory allocator for topology objects */
582
struct hwloc_tma {
583
  void * (*malloc)(struct hwloc_tma *, size_t);
584
  void *data;
585
  int dontfree; /* when set, free() or realloc() cannot be used, and tma->malloc() cannot fail */
586
};
587
588
static __hwloc_inline void *
589
hwloc_tma_malloc(struct hwloc_tma *tma,
590
     size_t size)
591
0
{
592
0
  if (tma) {
593
0
    return tma->malloc(tma, size);
594
0
  } else {
595
0
    return malloc(size);
596
0
  }
597
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_tma_malloc
Unexecuted instantiation: base64.c:hwloc_tma_malloc
598
599
static __hwloc_inline void *
600
hwloc_tma_calloc(struct hwloc_tma *tma,
601
     size_t size)
602
0
{
603
0
  char *ptr = hwloc_tma_malloc(tma, size);
604
0
  if (ptr)
605
0
    memset(ptr, 0, size);
606
0
  return ptr;
607
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_tma_calloc
Unexecuted instantiation: base64.c:hwloc_tma_calloc
608
609
static __hwloc_inline char *
610
hwloc_tma_strdup(struct hwloc_tma *tma,
611
     const char *src)
612
0
{
613
0
  size_t len = strlen(src);
614
0
  char *ptr = hwloc_tma_malloc(tma, len+1);
615
0
  if (ptr)
616
0
    memcpy(ptr, src, len+1);
617
0
  return ptr;
618
0
}
Unexecuted instantiation: hwloc_fuzzer.c:hwloc_tma_strdup
Unexecuted instantiation: base64.c:hwloc_tma_strdup
619
620
/* bitmap allocator to be used inside hwloc */
621
extern hwloc_bitmap_t hwloc_bitmap_tma_dup(struct hwloc_tma *tma, hwloc_const_bitmap_t old);
622
623
extern int hwloc__topology_dup(hwloc_topology_t *newp, hwloc_topology_t old, struct hwloc_tma *tma);
624
extern void hwloc__topology_disadopt(hwloc_topology_t  topology);
625
626
#endif /* HWLOC_PRIVATE_H */