Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v2.3.0

  |   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 
20 #include <numa.h>
21 
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 
54 static __hwloc_inline int
56  unsigned long *mask, unsigned long *maxnode)
57 {
58  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
59  unsigned long outmaxnode = -1;
60  hwloc_obj_t node = NULL;
61 
62  /* round-up to the next ulong and clear all bytes */
63  *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
64  memset(mask, 0, *maxnode/8);
65 
66  while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL) {
67  if (node->os_index >= *maxnode)
68  continue;
69  mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
70  if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
71  outmaxnode = node->os_index;
72  }
73 
74  *maxnode = outmaxnode+1;
75  return 0;
76 }
77 
88 static __hwloc_inline int
90  unsigned long *mask, unsigned long *maxnode)
91 {
92  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
93  unsigned long outmaxnode = -1;
94  hwloc_obj_t node = NULL;
95 
96  /* round-up to the next ulong and clear all bytes */
97  *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
98  memset(mask, 0, *maxnode/8);
99 
100  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL) {
101  if (node->os_index >= *maxnode)
102  continue;
103  if (!hwloc_bitmap_isset(nodeset, node->os_index))
104  continue;
105  mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
106  if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
107  outmaxnode = node->os_index;
108  }
109 
110  *maxnode = outmaxnode+1;
111  return 0;
112 }
113 
123 static __hwloc_inline int
125  const unsigned long *mask, unsigned long maxnode)
126 {
127  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
128  hwloc_obj_t node = NULL;
129  hwloc_bitmap_zero(cpuset);
130  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
131  if (node->os_index < maxnode
132  && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
133  hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
134  return 0;
135 }
136 
146 static __hwloc_inline int
148  const unsigned long *mask, unsigned long maxnode)
149 {
150  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
151  hwloc_obj_t node = NULL;
152  hwloc_bitmap_zero(nodeset);
153  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
154  if (node->os_index < maxnode
155  && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
156  hwloc_bitmap_set(nodeset, node->os_index);
157  return 0;
158 }
159 
189 static __hwloc_inline struct bitmask *
190 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset) __hwloc_attribute_malloc;
191 static __hwloc_inline struct bitmask *
193 {
194  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
195  hwloc_obj_t node = NULL;
196  struct bitmask *bitmask = numa_allocate_cpumask();
197  if (!bitmask)
198  return NULL;
199  while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL)
200  if (node->attr->numanode.local_memory)
201  numa_bitmask_setbit(bitmask, node->os_index);
202  return bitmask;
203 }
204 
214 static __hwloc_inline struct bitmask *
215 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset) __hwloc_attribute_malloc;
216 static __hwloc_inline struct bitmask *
218 {
219  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
220  hwloc_obj_t node = NULL;
221  struct bitmask *bitmask = numa_allocate_cpumask();
222  if (!bitmask)
223  return NULL;
224  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
225  if (hwloc_bitmap_isset(nodeset, node->os_index) && node->attr->numanode.local_memory)
226  numa_bitmask_setbit(bitmask, node->os_index);
227  return bitmask;
228 }
229 
235 static __hwloc_inline int
237  const struct bitmask *bitmask)
238 {
239  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
240  hwloc_obj_t node = NULL;
241  hwloc_bitmap_zero(cpuset);
242  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
243  if (numa_bitmask_isbitset(bitmask, node->os_index))
244  hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
245  return 0;
246 }
247 
253 static __hwloc_inline int
255  const struct bitmask *bitmask)
256 {
257  int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
258  hwloc_obj_t node = NULL;
259  hwloc_bitmap_zero(nodeset);
260  while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
261  if (numa_bitmask_isbitset(bitmask, node->os_index))
262  hwloc_bitmap_set(nodeset, node->os_index);
263  return 0;
264 }
265 
269 #ifdef __cplusplus
270 } /* extern "C" */
271 #endif
272 
273 
274 #endif /* HWLOC_LINUX_NUMA_H */
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:147
hwloc_cpuset_t cpuset
CPUs covered by this object.
Definition: hwloc.h:511
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:254
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:691
hwloc_const_bitmap_t hwloc_const_nodeset_t
A non-modifiable hwloc_nodeset_t.
Definition: hwloc.h:160
struct hwloc_obj_attr_u::hwloc_numanode_attr_s numanode
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:217
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
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:140
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 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:192
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:157
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:414
@ HWLOC_OBJ_NUMANODE
NUMA node. An object that contains memory that is directly and byte-accessible to the host processors...
Definition: hwloc.h:236
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:124
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.
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:55
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:236
hwloc_uint64_t local_memory
Local memory (in bytes)
Definition: hwloc.h:601
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
Structure of a topology object.
Definition: hwloc.h:395
int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id)
Test whether index id is part of bitmap bitmap.
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:89
int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
unsigned os_index
OS-provided physical index number. It is not guaranteed unique across the entire machine,...
Definition: hwloc.h:400
hwloc_const_bitmap_t hwloc_const_cpuset_t
A non-modifiable hwloc_cpuset_t.
Definition: hwloc.h:142