Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.3.3

  |   Home   |   Support   |   FAQ   |  
glibc-sched.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2010 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 
17 #ifndef HWLOC_GLIBC_SCHED_H
18 #define HWLOC_GLIBC_SCHED_H
19 
20 #include <hwloc.h>
21 #include <hwloc/helper.h>
22 #include <assert.h>
23 
24 #if !defined _GNU_SOURCE || !defined _SCHED_H || (!defined CPU_SETSIZE && !defined sched_priority)
25 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h
26 #endif
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
34 #ifdef HWLOC_HAVE_CPU_SET
35 
36 
49 static inline int
51  cpu_set_t *schedset, size_t schedsetsize)
52 {
53 #ifdef CPU_ZERO_S
54  unsigned cpu;
55  CPU_ZERO_S(schedsetsize, schedset);
56  hwloc_bitmap_foreach_begin(cpu, hwlocset)
57  CPU_SET_S(cpu, schedsetsize, schedset);
59 #else /* !CPU_ZERO_S */
60  unsigned cpu;
61  CPU_ZERO(schedset);
62  assert(schedsetsize == sizeof(cpu_set_t));
63  hwloc_bitmap_foreach_begin(cpu, hwlocset)
64  CPU_SET(cpu, schedset);
66 #endif /* !CPU_ZERO_S */
67  return 0;
68 }
69 
77 static inline int
79  const cpu_set_t *schedset, size_t schedsetsize)
80 {
81 #ifdef CPU_ZERO_S
82  int cpu, count;
83 #endif
84  hwloc_bitmap_zero(hwlocset);
85 #ifdef CPU_ZERO_S
86  count = CPU_COUNT_S(schedsetsize, schedset);
87  cpu = 0;
88  while (count) {
89  if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
90  hwloc_bitmap_set(hwlocset, cpu);
91  count--;
92  }
93  cpu++;
94  }
95 #else /* !CPU_ZERO_S */
96  /* sched.h does not support dynamic cpu_set_t (introduced in glibc 2.7),
97  * assume we have a very old interface without CPU_COUNT (added in 2.6)
98  */
99  int cpu;
100  assert(schedsetsize == sizeof(cpu_set_t));
101  for(cpu=0; cpu<CPU_SETSIZE; cpu++)
102  if (CPU_ISSET(cpu, schedset))
103  hwloc_bitmap_set(hwlocset, cpu);
104 #endif /* !CPU_ZERO_S */
105  return 0;
106 }
107 
111 #endif /* CPU_SET */
112 
113 
114 #ifdef __cplusplus
115 } /* extern "C" */
116 #endif
117 
118 
119 #endif /* HWLOC_GLIBC_SCHED_H */