File indexing completed on 2025-01-18 10:01:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef HWLOC_GLIBC_SCHED_H
0018 #define HWLOC_GLIBC_SCHED_H
0019
0020 #include "hwloc.h"
0021 #include "hwloc/helper.h"
0022
0023 #include <assert.h>
0024
0025 #if !defined _GNU_SOURCE || (!defined _SCHED_H && !defined _SCHED_H_) || (!defined CPU_SETSIZE && !defined sched_priority)
0026 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h
0027 #endif
0028
0029
0030 #ifdef __cplusplus
0031 extern "C" {
0032 #endif
0033
0034
0035 #ifdef HWLOC_HAVE_CPU_SET
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 static __hwloc_inline int
0059 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t hwlocset,
0060 cpu_set_t *schedset, size_t schedsetsize)
0061 {
0062 #ifdef CPU_ZERO_S
0063 unsigned cpu;
0064 CPU_ZERO_S(schedsetsize, schedset);
0065 hwloc_bitmap_foreach_begin(cpu, hwlocset)
0066 CPU_SET_S(cpu, schedsetsize, schedset);
0067 hwloc_bitmap_foreach_end();
0068 #else
0069 unsigned cpu;
0070 CPU_ZERO(schedset);
0071 assert(schedsetsize == sizeof(cpu_set_t));
0072 hwloc_bitmap_foreach_begin(cpu, hwlocset)
0073 CPU_SET(cpu, schedset);
0074 hwloc_bitmap_foreach_end();
0075 #endif
0076 return 0;
0077 }
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 static __hwloc_inline int
0090 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_cpuset_t hwlocset,
0091 const cpu_set_t *schedset, size_t schedsetsize)
0092 {
0093 int cpu;
0094 #ifdef CPU_ZERO_S
0095 int count;
0096 #endif
0097 hwloc_bitmap_zero(hwlocset);
0098 #ifdef CPU_ZERO_S
0099 count = CPU_COUNT_S(schedsetsize, schedset);
0100 cpu = 0;
0101 while (count) {
0102 if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
0103 if (hwloc_bitmap_set(hwlocset, cpu) < 0)
0104 return -1;
0105 count--;
0106 }
0107 cpu++;
0108 }
0109 #else
0110
0111
0112
0113 assert(schedsetsize == sizeof(cpu_set_t));
0114 for(cpu=0; cpu<CPU_SETSIZE; cpu++)
0115 if (CPU_ISSET(cpu, schedset))
0116 if (hwloc_bitmap_set(hwlocset, cpu) < 0)
0117 return -1;
0118 #endif
0119 return 0;
0120 }
0121
0122
0123
0124
0125 #endif
0126
0127
0128 #ifdef __cplusplus
0129 }
0130 #endif
0131
0132
0133 #endif