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