Hardware Locality (hwloc) 1.1.2
|
00001 /* 00002 * Copyright © 2009 CNRS 00003 * Copyright © 2009-2011 INRIA. All rights reserved. 00004 * Copyright © 2009-2011 Université Bordeaux 1 00005 * See COPYING in top-level directory. 00006 */ 00007 00016 #ifndef HWLOC_GLIBC_SCHED_H 00017 #define HWLOC_GLIBC_SCHED_H 00018 00019 #include <hwloc.h> 00020 #include <hwloc/helper.h> 00021 #include <assert.h> 00022 00023 #if !defined _GNU_SOURCE || !defined _SCHED_H || !defined CPU_SETSIZE 00024 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h 00025 #endif 00026 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 00033 #ifdef HWLOC_HAVE_CPU_SET 00034 00035 00048 static inline int 00049 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology , hwloc_const_cpuset_t hwlocset, 00050 cpu_set_t *schedset, size_t schedsetsize) 00051 { 00052 #ifdef CPU_ZERO_S 00053 unsigned cpu; 00054 CPU_ZERO_S(schedsetsize, schedset); 00055 hwloc_bitmap_foreach_begin(cpu, hwlocset) 00056 CPU_SET_S(cpu, schedsetsize, schedset); 00057 hwloc_bitmap_foreach_end(); 00058 #else /* !CPU_ZERO_S */ 00059 unsigned cpu; 00060 CPU_ZERO(schedset); 00061 assert(schedsetsize == sizeof(cpu_set_t)); 00062 hwloc_bitmap_foreach_begin(cpu, hwlocset) 00063 CPU_SET(cpu, schedset); 00064 hwloc_bitmap_foreach_end(); 00065 #endif /* !CPU_ZERO_S */ 00066 return 0; 00067 } 00068 00076 static inline int 00077 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology , hwloc_cpuset_t hwlocset, 00078 const cpu_set_t *schedset, size_t schedsetsize) 00079 { 00080 hwloc_bitmap_zero(hwlocset); 00081 #ifdef CPU_ZERO_S 00082 int cpu, count; 00083 count = CPU_COUNT_S(schedsetsize, schedset); 00084 cpu = 0; 00085 while (count) { 00086 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) { 00087 hwloc_bitmap_set(hwlocset, cpu); 00088 count--; 00089 } 00090 cpu++; 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++) 00099 if (CPU_ISSET(cpu, schedset)) 00100 hwloc_bitmap_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 */