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