Hardware Locality (hwloc) 1.5.1

- Main Page
- Related Pages
- Modules
- Data Structures

glibc-sched.h
1 /*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2012 inria. All rights reserved.
4 * Copyright © 2009-2011 Université Bordeaux 1
5 * Copyright © 2011 Cisco Systems, Inc. All rights reserved.
6 * See COPYING in top-level directory.
7 */
8
19 #ifndef HWLOC_GLIBC_SCHED_H
20 #define HWLOC_GLIBC_SCHED_H
21
22 #include <hwloc.h>
23 #include <hwloc/helper.h>
24 #include <assert.h>
25
26 #if !defined _GNU_SOURCE || !defined _SCHED_H || (!defined CPU_SETSIZE && !defined sched_priority)
27 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h
28 #endif
29
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35
36 #ifdef HWLOC_HAVE_CPU_SET
37
38
51 static inline int
52 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology , hwloc_const_cpuset_t hwlocset,
53 cpu_set_t *schedset, size_t schedsetsize)
54 {
55 #ifdef CPU_ZERO_S
56 unsigned cpu;
57 CPU_ZERO_S(schedsetsize, schedset);
58 hwloc_bitmap_foreach_begin(cpu, hwlocset)
59 CPU_SET_S(cpu, schedsetsize, schedset);
60 hwloc_bitmap_foreach_end();
61 #else /* !CPU_ZERO_S */
62 unsigned cpu;
63 CPU_ZERO(schedset);
64 assert(schedsetsize == sizeof(cpu_set_t));
65 hwloc_bitmap_foreach_begin(cpu, hwlocset)
66 CPU_SET(cpu, schedset);
67 hwloc_bitmap_foreach_end();
68 #endif /* !CPU_ZERO_S */
69 return 0;
70 }
71
79 static inline int
80 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology , hwloc_cpuset_t hwlocset,
81 const cpu_set_t *schedset, size_t schedsetsize)
82 {
83 int cpu;
84 #ifdef CPU_ZERO_S
85 int count;
86 #endif
87 hwloc_bitmap_zero(hwlocset);
88 #ifdef CPU_ZERO_S
89 count = CPU_COUNT_S(schedsetsize, schedset);
90 cpu = 0;
91 while (count) {
92 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
93 hwloc_bitmap_set(hwlocset, cpu);
94 count--;
95 }
96 cpu++;
97 }
98 #else /* !CPU_ZERO_S */
99 /* sched.h does not support dynamic cpu_set_t (introduced in glibc 2.7),
100 * assume we have a very old interface without CPU_COUNT (added in 2.6)
101 */
102 assert(schedsetsize == sizeof(cpu_set_t));
103 for(cpu=0; cpu<CPU_SETSIZE; cpu++)
104 if (CPU_ISSET(cpu, schedset))
105 hwloc_bitmap_set(hwlocset, cpu);
106 #endif /* !CPU_ZERO_S */
107 return 0;
108 }
109
113 #endif /* CPU_SET */
114
115
116 #ifdef __cplusplus
117 } /* extern "C" */
118 #endif
119
120
121 #endif /* HWLOC_GLIBC_SCHED_H */