• 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 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 
00031 #ifdef HWLOC_HAVE_CPU_SET
00032 
00033 
00046 static __hwloc_inline int
00047 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, 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 /* !CPU_ZERO_S */
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 /* !CPU_ZERO_S */
00064   return 0;
00065 }
00066 
00074 static __hwloc_inline int
00075 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, 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 /* !CPU_ZERO_S */
00093   /* sched.h does not support dynamic cpu_set_t (introduced in glibc 2.7),
00094    * assume we have a very old interface without CPU_COUNT (added in 2.6)
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 /* !CPU_ZERO_S */
00102   return 0;
00103 }
00104 
00108 #endif /* CPU_SET */
00109 
00110 
00111 #ifdef __cplusplus
00112 } /* extern "C" */
00113 #endif
00114 
00115 
00116 #endif /* HWLOC_GLIBC_SCHED_H */

Generated on Thu Dec 16 2010 06:44:16 for Hardware Locality (hwloc) by  doxygen 1.7.1