We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ac16fbb + e59638d commit 967876eCopy full SHA for 967876e
src/shims/hw_config.h
@@ -87,7 +87,17 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
87
case _dispatch_hw_config_physical_cpus:
88
return sysconf(_SC_NPROCESSORS_CONF);
89
case _dispatch_hw_config_active_cpus:
90
- return sysconf(_SC_NPROCESSORS_ONLN);
+ {
91
+#ifdef __USE_GNU
92
+ // Prefer pthread_getaffinity_np because it considers
93
+ // scheduler cpu affinity. This matters if the program
94
+ // is restricted to a subset of the online cpus (eg via numactl).
95
+ cpu_set_t cpuset;
96
+ if (pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) == 0)
97
+ return CPU_COUNT(&cpuset);
98
+#endif
99
+ return sysconf(_SC_NPROCESSORS_ONLN);
100
+ }
101
}
102
#else
103
const char *name = NULL;
0 commit comments