Hardware Locality (hwloc)
1.4.2
|
00001 /* 00002 * Copyright © 2009 CNRS 00003 * Copyright © 2009-2012 inria. All rights reserved. 00004 * Copyright © 2009-2011 Université Bordeaux 1 00005 * Copyright © 2011 Cisco Systems, Inc. All rights reserved. 00006 * See COPYING in top-level directory. 00007 */ 00008 00019 #ifndef HWLOC_GLIBC_SCHED_H 00020 #define HWLOC_GLIBC_SCHED_H 00021 00022 #include <hwloc.h> 00023 #include <hwloc/helper.h> 00024 #include <assert.h> 00025 00026 #if !defined _GNU_SOURCE || !defined _SCHED_H || (!defined CPU_SETSIZE && !defined sched_priority) 00027 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h 00028 #endif 00029 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 00035 00036 #ifdef HWLOC_HAVE_CPU_SET 00037 00038 00051 static inline int 00052 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology , hwloc_const_cpuset_t hwlocset, 00053 cpu_set_t *schedset, size_t schedsetsize) 00054 { 00055 #ifdef CPU_ZERO_S 00056 unsigned cpu; 00057 CPU_ZERO_S(schedsetsize, schedset); 00058 hwloc_bitmap_foreach_begin(cpu, hwlocset) 00059 CPU_SET_S(cpu, schedsetsize, schedset); 00060 hwloc_bitmap_foreach_end(); 00061 #else /* !CPU_ZERO_S */ 00062 unsigned cpu; 00063 CPU_ZERO(schedset); 00064 assert(schedsetsize == sizeof(cpu_set_t)); 00065 hwloc_bitmap_foreach_begin(cpu, hwlocset) 00066 CPU_SET(cpu, schedset); 00067 hwloc_bitmap_foreach_end(); 00068 #endif /* !CPU_ZERO_S */ 00069 return 0; 00070 } 00071 00079 static inline int 00080 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology , hwloc_cpuset_t hwlocset, 00081 const cpu_set_t *schedset, size_t schedsetsize) 00082 { 00083 int cpu; 00084 #ifdef CPU_ZERO_S 00085 int count; 00086 #endif 00087 hwloc_bitmap_zero(hwlocset); 00088 #ifdef CPU_ZERO_S 00089 count = CPU_COUNT_S(schedsetsize, schedset); 00090 cpu = 0; 00091 while (count) { 00092 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) { 00093 hwloc_bitmap_set(hwlocset, cpu); 00094 count--; 00095 } 00096 cpu++; 00097 } 00098 #else /* !CPU_ZERO_S */ 00099 /* sched.h does not support dynamic cpu_set_t (introduced in glibc 2.7), 00100 * assume we have a very old interface without CPU_COUNT (added in 2.6) 00101 */ 00102 assert(schedsetsize == sizeof(cpu_set_t)); 00103 for(cpu=0; cpu<CPU_SETSIZE; cpu++) 00104 if (CPU_ISSET(cpu, schedset)) 00105 hwloc_bitmap_set(hwlocset, cpu); 00106 #endif /* !CPU_ZERO_S */ 00107 return 0; 00108 } 00109 00113 #endif /* CPU_SET */ 00114 00115 00116 #ifdef __cplusplus 00117 } /* extern "C" */ 00118 #endif 00119 00120 00121 #endif /* HWLOC_GLIBC_SCHED_H */