File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 17
17
#include <locale.h>
18
18
#include <nl_types.h>
19
19
#include <pthread.h>
20
+ #include <sched.h>
20
21
#include <stddef.h>
21
22
#include <stdint.h>
22
23
#include <stdio.h>
@@ -789,7 +790,12 @@ static long bfs_sched_getaffinity(size_t size) {
789
790
790
791
long ret = -1 ;
791
792
if (sched_getaffinity (0 , size , pset ) == 0 ) {
793
+ # ifdef CPU_COUNT_S
792
794
ret = CPU_COUNT_S (size , pset );
795
+ # else
796
+ bfs_assert (size <= sizeof (set ));
797
+ ret = CPU_COUNT (pset );
798
+ # endif
793
799
}
794
800
795
801
if (pset != & set ) {
@@ -805,15 +811,21 @@ long nproc(void) {
805
811
#if BFS_HAS_SCHED_GETAFFINITY
806
812
size_t size = sizeof (cpu_set_t );
807
813
do {
808
- // sched_getaffinity(2) says:
814
+ ret = bfs_sched_getaffinity (size );
815
+
816
+ # ifdef CPU_COUNT_S
817
+ // On Linux, sched_getaffinity(2) says:
809
818
//
810
819
// When working on systems with large kernel CPU affinity masks, one must
811
820
// dynamically allocate the mask argument (see CPU_ALLOC(3)). Currently,
812
821
// the only way to do this is by probing for the size of the required mask
813
822
// using sched_getaffinity() calls with increasing mask sizes (until the
814
823
// call does not fail with the error EINVAL).
815
- ret = bfs_sched_getaffinity (size );
816
824
size *= 2 ;
825
+ # else
826
+ // No support for dynamically-sized CPU masks
827
+ break ;
828
+ # endif
817
829
} while (ret < 0 && errno == EINVAL );
818
830
#endif
819
831
You can’t perform that action at this time.
0 commit comments