Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v2.6.0

  |   Home   |   Support   |   FAQ   |  
glibc-sched.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2020 Inria. All rights reserved.
4  * Copyright © 2009-2011 Université Bordeaux
5  * Copyright © 2011 Cisco Systems, Inc. All rights reserved.
6  * See COPYING in top-level directory.
7  */
8 
17 #ifndef HWLOC_GLIBC_SCHED_H
18 #define HWLOC_GLIBC_SCHED_H
19 
20 #include "hwloc.h"
21 #include "hwloc/helper.h"
22 
23 #include <assert.h>
24 
25 #if !defined _GNU_SOURCE || (!defined _SCHED_H && !defined _SCHED_H_) || (!defined CPU_SETSIZE && !defined sched_priority)
26 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h
27 #endif
28 
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 
35 #ifdef HWLOC_HAVE_CPU_SET
36 
37 
56 static __hwloc_inline int
58  cpu_set_t *schedset, size_t schedsetsize)
59 {
60 #ifdef CPU_ZERO_S
61  unsigned cpu;
62  CPU_ZERO_S(schedsetsize, schedset);
63  hwloc_bitmap_foreach_begin(cpu, hwlocset)
64  CPU_SET_S(cpu, schedsetsize, schedset);
66 #else /* !CPU_ZERO_S */
67  unsigned cpu;
68  CPU_ZERO(schedset);
69  assert(schedsetsize == sizeof(cpu_set_t));
70  hwloc_bitmap_foreach_begin(cpu, hwlocset)
71  CPU_SET(cpu, schedset);
73 #endif /* !CPU_ZERO_S */
74  return 0;
75 }
76 
84 static __hwloc_inline int
85 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_cpuset_t hwlocset,
86  const cpu_set_t *schedset, size_t schedsetsize)
87 {
88  int cpu;
89 #ifdef CPU_ZERO_S
90  int count;
91 #endif
92  hwloc_bitmap_zero(hwlocset);
93 #ifdef CPU_ZERO_S
94  count = CPU_COUNT_S(schedsetsize, schedset);
95  cpu = 0;
96  while (count) {
97  if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
98  hwloc_bitmap_set(hwlocset, cpu);
99  count--;
100  }
101  cpu++;
102  }
103 #else /* !CPU_ZERO_S */
104  /* sched.h does not support dynamic cpu_set_t (introduced in glibc 2.7),
105  * assume we have a very old interface without CPU_COUNT (added in 2.6)
106  */
107  assert(schedsetsize == sizeof(cpu_set_t));
108  for(cpu=0; cpu<CPU_SETSIZE; cpu++)
109  if (CPU_ISSET(cpu, schedset))
110  hwloc_bitmap_set(hwlocset, cpu);
111 #endif /* !CPU_ZERO_S */
112  return 0;
113 }
114 
118 #endif /* CPU_SET */
119 
120 
121 #ifdef __cplusplus
122 } /* extern "C" */
123 #endif
124 
125 
126 #endif /* HWLOC_GLIBC_SCHED_H */
hwloc_const_bitmap_t hwloc_const_cpuset_t
A non-modifiable hwloc_cpuset_t.
Definition: hwloc.h:142
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
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:692
int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
#define hwloc_bitmap_foreach_begin(id, bitmap)
Loop macro iterating on bitmap bitmap.
Definition: bitmap.h:370
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
#define hwloc_bitmap_foreach_end()
End of loop macro iterating on a bitmap.
Definition: bitmap.h:384
static int hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology, hwloc_const_cpuset_t hwlocset, cpu_set_t *schedset, size_t schedsetsize)
Convert hwloc CPU set toposet into glibc sched affinity CPU set schedset.
Definition: glibc-sched.h:57
static int hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology, hwloc_cpuset_t hwlocset, const cpu_set_t *schedset, size_t schedsetsize)
Convert glibc sched affinity CPU set schedset into hwloc CPU set.
Definition: glibc-sched.h:85