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