00001
00002
00003
00004
00005
00014 #ifndef HWLOC_GLIBC_SCHED_H
00015 #define HWLOC_GLIBC_SCHED_H
00016
00017 #include <hwloc.h>
00018 #include <hwloc/helper.h>
00019
00020 #if !defined _GNU_SOURCE || !defined _SCHED_H
00021 #error sched.h must be included with _GNU_SOURCE defined
00022 #endif
00023
00024 #ifdef HWLOC_HAVE_CPU_SET
00025
00026
00039 static inline void
00040 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology, hwloc_cpuset_t hwlocset,
00041 cpu_set_t *schedset, size_t schedsetsize)
00042 {
00043 #ifdef CPU_ZERO_S
00044 unsigned cpu;
00045 CPU_ZERO_S(schedsetsize, schedset);
00046 hwloc_cpuset_foreach_begin(cpu, hwlocset)
00047 CPU_SET_S(cpu, schedsetsize, schedset);
00048 hwloc_cpuset_foreach_end();
00049 #else
00050 unsigned cpu;
00051 CPU_ZERO(schedset);
00052 assert(schedsetsize == sizeof(cpu_set_t));
00053 hwloc_cpuset_foreach_begin(cpu, hwlocset)
00054 CPU_SET(cpu, schedset);
00055 hwloc_cpuset_foreach_end();
00056 #endif
00057 }
00058
00066 static inline hwloc_cpuset_t
00067 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology,
00068 const cpu_set_t *schedset, size_t schedsetsize)
00069 {
00070 hwloc_cpuset_t hwlocset = hwloc_cpuset_alloc();
00071 #ifdef CPU_ZERO_S
00072 int cpu, count;
00073 count = CPU_COUNT_S(schedsetsize, schedset);
00074 cpu = 0;
00075 while (count) {
00076 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
00077 hwloc_cpuset_set(hwlocset, cpu);
00078 count--;
00079 }
00080 cpu++;
00081 if (cpu > HWLOC_NBMAXCPUS)
00082 break;
00083 }
00084 #else
00085
00086
00087
00088 int cpu;
00089 assert(schedsetsize == sizeof(cpu_set_t));
00090 for(cpu=0; cpu<CPU_SETSIZE && cpu<HWLOC_NBMAXCPUS; cpu++)
00091 if (CPU_ISSET(cpu, schedset))
00092 hwloc_cpuset_set(hwlocset, cpu);
00093 #endif
00094 return hwlocset;
00095 }
00096
00100 #endif
00101
00102 #endif