00001
00002
00003
00004
00005
00006
00007
00008
00019 #ifndef HWLOC_GLIBC_SCHED_H
00020 #define HWLOC_GLIBC_SCHED_H
00021
00022 #include <hwloc.h>
00023 #include <hwloc/helper.h>
00024 #include <assert.h>
00025
00026 #if !defined _GNU_SOURCE || !defined _SCHED_H || (!defined CPU_SETSIZE && !defined sched_priority)
00027 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h
00028 #endif
00029
00030
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034
00035
00036 #ifdef HWLOC_HAVE_CPU_SET
00037
00038
00051 static __hwloc_inline int
00052 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t hwlocset,
00053 cpu_set_t *schedset, size_t schedsetsize)
00054 {
00055 #ifdef CPU_ZERO_S
00056 unsigned cpu;
00057 CPU_ZERO_S(schedsetsize, schedset);
00058 hwloc_bitmap_foreach_begin(cpu, hwlocset)
00059 CPU_SET_S(cpu, schedsetsize, schedset);
00060 hwloc_bitmap_foreach_end();
00061 #else
00062 unsigned cpu;
00063 CPU_ZERO(schedset);
00064 assert(schedsetsize == sizeof(cpu_set_t));
00065 hwloc_bitmap_foreach_begin(cpu, hwlocset)
00066 CPU_SET(cpu, schedset);
00067 hwloc_bitmap_foreach_end();
00068 #endif
00069 return 0;
00070 }
00071
00079 static __hwloc_inline int
00080 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_cpuset_t hwlocset,
00081 const cpu_set_t *schedset, size_t schedsetsize)
00082 {
00083 int cpu;
00084 #ifdef CPU_ZERO_S
00085 int count;
00086 #endif
00087 hwloc_bitmap_zero(hwlocset);
00088 #ifdef CPU_ZERO_S
00089 count = CPU_COUNT_S(schedsetsize, schedset);
00090 cpu = 0;
00091 while (count) {
00092 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
00093 hwloc_bitmap_set(hwlocset, cpu);
00094 count--;
00095 }
00096 cpu++;
00097 }
00098 #else
00099
00100
00101
00102 assert(schedsetsize == sizeof(cpu_set_t));
00103 for(cpu=0; cpu<CPU_SETSIZE; cpu++)
00104 if (CPU_ISSET(cpu, schedset))
00105 hwloc_bitmap_set(hwlocset, cpu);
00106 #endif
00107 return 0;
00108 }
00109
00113 #endif
00114
00115
00116 #ifdef __cplusplus
00117 }
00118 #endif
00119
00120
00121 #endif