Go to the documentation of this file.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 #include <assert.h>
00020
00021 #if !defined _GNU_SOURCE || !defined _SCHED_H
00022 #error sched.h must be included with _GNU_SOURCE defined
00023 #endif
00024
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00030
00031 #ifdef HWLOC_HAVE_CPU_SET
00032
00033
00046 static inline int
00047 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology , hwloc_const_cpuset_t hwlocset,
00048 cpu_set_t *schedset, size_t schedsetsize)
00049 {
00050 #ifdef CPU_ZERO_S
00051 unsigned cpu;
00052 CPU_ZERO_S(schedsetsize, schedset);
00053 hwloc_cpuset_foreach_begin(cpu, hwlocset)
00054 CPU_SET_S(cpu, schedsetsize, schedset);
00055 hwloc_cpuset_foreach_end();
00056 #else
00057 unsigned cpu;
00058 CPU_ZERO(schedset);
00059 assert(schedsetsize == sizeof(cpu_set_t));
00060 hwloc_cpuset_foreach_begin(cpu, hwlocset)
00061 CPU_SET(cpu, schedset);
00062 hwloc_cpuset_foreach_end();
00063 #endif
00064 return 0;
00065 }
00066
00074 static inline int
00075 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology , hwloc_cpuset_t hwlocset,
00076 const cpu_set_t *schedset, size_t schedsetsize)
00077 {
00078 hwloc_cpuset_zero(hwlocset);
00079 #ifdef CPU_ZERO_S
00080 int cpu, count;
00081 count = CPU_COUNT_S(schedsetsize, schedset);
00082 cpu = 0;
00083 while (count) {
00084 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
00085 hwloc_cpuset_set(hwlocset, cpu);
00086 count--;
00087 }
00088 cpu++;
00089 if (cpu > HWLOC_NBMAXCPUS)
00090 break;
00091 }
00092 #else
00093
00094
00095
00096 int cpu;
00097 assert(schedsetsize == sizeof(cpu_set_t));
00098 for(cpu=0; cpu<CPU_SETSIZE && cpu<HWLOC_NBMAXCPUS; cpu++)
00099 if (CPU_ISSET(cpu, schedset))
00100 hwloc_cpuset_set(hwlocset, cpu);
00101 #endif
00102 return 0;
00103 }
00104
00108 #endif
00109
00110
00111 #ifdef __cplusplus
00112 }
00113 #endif
00114
00115
00116 #endif