Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v2.0.4

  |   Home   |   Support   |   FAQ   |  
linux-libnuma.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2017 Inria. All rights reserved.
4  * Copyright © 2009-2010, 2012 Université Bordeaux
5  * See COPYING in top-level directory.
6  */
7 
15 #ifndef HWLOC_LINUX_LIBNUMA_H
16 #define HWLOC_LINUX_LIBNUMA_H
17 
18 #include <hwloc.h>
19 #include <numa.h>
20 
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 
53 static __hwloc_inline int
55  unsigned long *mask, unsigned long *maxnode)
56 {
57  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
58  unsigned long outmaxnode = -1;
59  hwloc_obj_t node = NULL;
60 
61  /* round-up to the next ulong and clear all bytes */
62  *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
63  memset(mask, 0, *maxnode/8);
64 
65  while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL) {
66  if (node->os_index >= *maxnode)
67  continue;
68  mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
69  if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
70  outmaxnode = node->os_index;
71  }
72 
73  *maxnode = outmaxnode+1;
74  return 0;
75 }
76 
87 static __hwloc_inline int
89  unsigned long *mask, unsigned long *maxnode)
90 {
91  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
92  unsigned long outmaxnode = -1;
93  hwloc_obj_t node = NULL;
94 
95  /* round-up to the next ulong and clear all bytes */
96  *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
97  memset(mask, 0, *maxnode/8);
98 
99  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL) {
100  if (node->os_index >= *maxnode)
101  continue;
102  if (!hwloc_bitmap_isset(nodeset, node->os_index))
103  continue;
104  mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
105  if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
106  outmaxnode = node->os_index;
107  }
108 
109  *maxnode = outmaxnode+1;
110  return 0;
111 }
112 
122 static __hwloc_inline int
124  const unsigned long *mask, unsigned long maxnode)
125 {
126  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
127  hwloc_obj_t node = NULL;
128  hwloc_bitmap_zero(cpuset);
129  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
130  if (node->os_index < maxnode
131  && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
132  hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
133  return 0;
134 }
135 
145 static __hwloc_inline int
147  const unsigned long *mask, unsigned long maxnode)
148 {
149  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
150  hwloc_obj_t node = NULL;
151  hwloc_bitmap_zero(nodeset);
152  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
153  if (node->os_index < maxnode
154  && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
155  hwloc_bitmap_set(nodeset, node->os_index);
156  return 0;
157 }
158 
188 static __hwloc_inline struct bitmask *
189 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset) __hwloc_attribute_malloc;
190 static __hwloc_inline struct bitmask *
192 {
193  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
194  hwloc_obj_t node = NULL;
195  struct bitmask *bitmask = numa_allocate_cpumask();
196  if (!bitmask)
197  return NULL;
198  while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL)
199  if (node->attr->numanode.local_memory)
200  numa_bitmask_setbit(bitmask, node->os_index);
201  return bitmask;
202 }
203 
213 static __hwloc_inline struct bitmask *
214 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset) __hwloc_attribute_malloc;
215 static __hwloc_inline struct bitmask *
217 {
218  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
219  hwloc_obj_t node = NULL;
220  struct bitmask *bitmask = numa_allocate_cpumask();
221  if (!bitmask)
222  return NULL;
223  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
224  if (hwloc_bitmap_isset(nodeset, node->os_index) && node->attr->numanode.local_memory)
225  numa_bitmask_setbit(bitmask, node->os_index);
226  return bitmask;
227 }
228 
234 static __hwloc_inline int
236  const struct bitmask *bitmask)
237 {
238  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
239  hwloc_obj_t node = NULL;
240  hwloc_bitmap_zero(cpuset);
241  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
242  if (numa_bitmask_isbitset(bitmask, node->os_index))
243  hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
244  return 0;
245 }
246 
252 static __hwloc_inline int
254  const struct bitmask *bitmask)
255 {
256  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
257  hwloc_obj_t node = NULL;
258  hwloc_bitmap_zero(nodeset);
259  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
260  if (numa_bitmask_isbitset(bitmask, node->os_index))
261  hwloc_bitmap_set(nodeset, node->os_index);
262  return 0;
263 }
264 
268 #ifdef __cplusplus
269 } /* extern "C" */
270 #endif
271 
272 
273 #endif /* HWLOC_LINUX_NUMA_H */
static hwloc_obj_t hwloc_get_next_obj_by_depth(hwloc_topology_t topology, int depth, hwloc_obj_t prev)
Returns the next object at depth depth.
struct hwloc_obj_attr_u::hwloc_numanode_attr_s numanode
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:637
hwloc_const_bitmap_t hwloc_const_cpuset_t
A non-modifiable hwloc_cpuset_t.
Definition: hwloc.h:141
static int hwloc_cpuset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_cpuset_t cpuset, const unsigned long *mask, unsigned long maxnode)
Convert the array of unsigned long mask into hwloc CPU set.
Definition: linux-libnuma.h:123
hwloc_bitmap_t hwloc_nodeset_t
A node set is a bitmap whose bits are set according to NUMA memory node physical OS indexes...
Definition: hwloc.h:156
int hwloc_bitmap_or(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Or bitmaps bitmap1 and bitmap2 and store the result in bitmap res.
static int hwloc_cpuset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset, unsigned long *mask, unsigned long *maxnode)
Convert hwloc CPU set cpuset into the array of unsigned long mask.
Definition: linux-libnuma.h:54
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:376
static int hwloc_nodeset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_nodeset_t nodeset, const unsigned long *mask, unsigned long maxnode)
Convert the array of unsigned long mask into hwloc NUMA node set.
Definition: linux-libnuma.h:146
int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
static struct bitmask * hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset)
Convert hwloc NUMA node set nodeset into the returned libnuma bitmask.
Definition: linux-libnuma.h:216
static struct bitmask * hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset)
Convert hwloc CPU set cpuset into the returned libnuma bitmask.
Definition: linux-libnuma.h:191
unsigned os_index
OS-provided physical index number. It is not guaranteed unique across the entire machine, except for PUs and NUMA nodes. Set to HWLOC_UNKNOWN_INDEX if unknown or irrelevant for this object.
Definition: hwloc.h:362
Structure of a topology object.
Definition: hwloc.h:357
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
hwloc_cpuset_t cpuset
CPUs covered by this object.
Definition: hwloc.h:467
hwloc_bitmap_t hwloc_cpuset_t
A CPU set is a bitmap whose bits are set according to CPU physical OS indexes.
Definition: hwloc.h:139
hwloc_const_bitmap_t hwloc_const_nodeset_t
A non-modifiable hwloc_nodeset_t.
Definition: hwloc.h:159
NUMA node. An object that contains memory that is directly and byte-accessible to the host processors...
Definition: hwloc.h:230
static int hwloc_cpuset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_cpuset_t cpuset, const struct bitmask *bitmask)
Convert libnuma bitmask bitmask into hwloc CPU set cpuset.
Definition: linux-libnuma.h:235
static hwloc_obj_t hwloc_get_next_obj_covering_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth, hwloc_obj_t prev)
Iterate through same-depth objects covering at least CPU set set.
Definition: helper.h:321
static int hwloc_nodeset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, unsigned long *mask, unsigned long *maxnode)
Convert hwloc NUMA node set nodeset into the array of unsigned long mask.
Definition: linux-libnuma.h:88
hwloc_uint64_t local_memory
Local memory (in bytes)
Definition: hwloc.h:555
static int hwloc_nodeset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_nodeset_t nodeset, const struct bitmask *bitmask)
Convert libnuma bitmask bitmask into hwloc NUMA node set nodeset.
Definition: linux-libnuma.h:253
int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id)
Test whether index id is part of bitmap bitmap.