- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List

# glibc-sched.h

    00001 /*
    00002  * Copyright © 2009 CNRS, INRIA, Université Bordeaux 1
    00003  * See COPYING in top-level directory.
    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 #ifdef HWLOC_HAVE_CPU_SET
    00026
    00027
    00040 static __hwloc_inline int
    00041 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t hwlocset,
    00042                                     cpu_set_t *schedset, size_t schedsetsize)
    00043 {
    00044 #ifdef CPU_ZERO_S
    00045   unsigned cpu;
    00046   CPU_ZERO_S(schedsetsize, schedset);
    00047   hwloc_cpuset_foreach_begin(cpu, hwlocset)
    00048     CPU_SET_S(cpu, schedsetsize, schedset);
    00049   hwloc_cpuset_foreach_end();
    00050 #else /* !CPU_ZERO_S */
    00051   unsigned cpu;
    00052   CPU_ZERO(schedset);
    00053   assert(schedsetsize == sizeof(cpu_set_t));
    00054   hwloc_cpuset_foreach_begin(cpu, hwlocset)
    00055     CPU_SET(cpu, schedset);
    00056   hwloc_cpuset_foreach_end();
    00057 #endif /* !CPU_ZERO_S */
    00058   return 0;
    00059 }
    00060
    00068 static __hwloc_inline int
    00069 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_cpuset_t hwlocset,
    00070                                        const cpu_set_t *schedset, size_t schedsetsize)
    00071 {
    00072   hwloc_cpuset_zero(hwlocset);
    00073 #ifdef CPU_ZERO_S
    00074   int cpu, count;
    00075   count = CPU_COUNT_S(schedsetsize, schedset);
    00076   cpu = 0;
    00077   while (count) {
    00078     if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
    00079       hwloc_cpuset_set(hwlocset, cpu);
    00080       count--;
    00081     }
    00082     cpu++;
    00083     if (cpu > HWLOC_NBMAXCPUS)
    00084       break;
    00085   }
    00086 #else /* !CPU_ZERO_S */
    00087   /* sched.h does not support dynamic cpu_set_t (introduced in glibc 2.7),
    00088    * assume we have a very old interface without CPU_COUNT (added in 2.6)
    00089    */
    00090   int cpu;
    00091   assert(schedsetsize == sizeof(cpu_set_t));
    00092   for(cpu=0; cpu<CPU_SETSIZE && cpu<HWLOC_NBMAXCPUS; cpu++)
    00093     if (CPU_ISSET(cpu, schedset))
    00094       hwloc_cpuset_set(hwlocset, cpu);
    00095 #endif /* !CPU_ZERO_S */
    00096   return 0;
    00097 }
    00098
    00102 #endif /* CPU_SET */
    00103
    00104 #endif /* HWLOC_GLIBC_SCHED_H */