00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00042 #ifndef TOPOLOGY_GLIBC_SCHED_H
00043 #define TOPOLOGY_GLIBC_SCHED_H
00044
00045 #include <topology.h>
00046 #include <topology/helper.h>
00047
00048 #if !defined _GNU_SOURCE || !defined _SCHED_H
00049 #error sched.h must be included with _GNU_SOURCE defined
00050 #endif
00051
00052 #ifdef CPU_SET
00053
00054
00067 static __inline__ void
00068 topo_cpuset_to_glibc_sched_affinity(topo_topology_t topology, const topo_cpuset_t *toposet,
00069 cpu_set_t *schedset, size_t schedsetsize)
00070 {
00071 #ifdef CPU_ZERO_S
00072 unsigned cpu;
00073 CPU_ZERO_S(schedsetsize, schedset);
00074 topo_cpuset_foreach_begin(cpu, toposet)
00075 CPU_SET_S(cpu, schedsetsize, schedset);
00076 topo_cpuset_foreach_end();
00077 #else
00078 unsigned cpu;
00079 CPU_ZERO(schedset);
00080 assert(schedsetsize == sizeof(cpu_set_t));
00081 topo_cpuset_foreach_begin(cpu, toposet)
00082 CPU_SET(cpu, schedset);
00083 topo_cpuset_foreach_end();
00084 #endif
00085 }
00086
00094 static __inline__ void
00095 topo_cpuset_from_glibc_sched_affinity(topo_topology_t topology, topo_cpuset_t *toposet,
00096 const cpu_set_t *schedset, size_t schedsetsize)
00097 {
00098 #ifdef CPU_ZERO_S
00099 int cpu, count;
00100 topo_cpuset_zero(toposet);
00101 count = CPU_COUNT_S(schedsetsize, schedset);
00102 cpu = 0;
00103 while (count) {
00104 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
00105 topo_cpuset_set(toposet, cpu);
00106 count--;
00107 }
00108 cpu++;
00109 if (cpu > TOPO_NBMAXCPUS)
00110 break;
00111 }
00112 #else
00113
00114
00115
00116 int cpu;
00117 assert(schedsetsize == sizeof(cpu_set_t));
00118 for(cpu=0; cpu<CPU_SETSIZE && cpu<TOPO_NBMAXCPUS; cpu++)
00119 if (CPU_ISSET(cpu, schedset))
00120 topo_cpuset_set(toposet, cpu);
00121 #endif
00122 }
00123
00127 #endif
00128
00129 #endif