Honor cgroup/cpuset constraints when enumerating cpus

This commit is contained in:
Martin Kroeker
2017-07-11 18:27:33 +02:00
committed by GitHub
parent 482015f8d6
commit 29fc429d9a
2 changed files with 98 additions and 26 deletions

View File

@@ -175,7 +175,44 @@ int get_num_procs(void);
#else
int get_num_procs(void) {
static int nums = 0;
cpu_set_t *cpusetp;
size_t size;
int ret;
int i,n;
if (!nums) nums = sysconf(_SC_NPROCESSORS_CONF);
#if !defined(OS_LINUX)
return nums;
#endif
#if !defined(__GLIBC_PREREQ)
return nums;
#endif
#if !__GLIBC_PREREQ(2, 3)
return nums;
#endif
#if !__GLIBC_PREREQ(2, 7)
ret = sched_getaffinity(0,sizeof(cpu_set_t), cpusetp);
if (ret!=0) return nums;
n=0;
#if !__GLIBC_PREREQ(2, 6)
for (i=0;i<nums;i++)
if (CPU_ISSET(i,cpusetp)) n++;
nums=n;
#else
nums = CPU_COUNT(sizeof(cpu_set_t),cpusetp);
#endif
return nums;
#endif
cpusetp = CPU_ALLOC(nums);
if (cpusetp == NULL) return nums;
size = CPU_ALLOC_SIZE(nums);
ret = sched_getaffinity(0,size,cpusetp);
if (ret!=0) return nums;
nums = CPU_COUNT_S(size,cpusetp);
CPU_FREE(cpusetp);
return nums;
}
#endif
@@ -1015,7 +1052,7 @@ void *blas_memory_alloc(int procpos){
mypos = WhereAmI();
position = mypos;
while (position >= NUM_BUFFERS) position >>= 1;
while (position > NUM_BUFFERS) position >>= 1;
do {
if (!memory[position].used && (memory[position].pos == mypos)) {
@@ -1164,8 +1201,8 @@ void blas_memory_free(void *free_area){
position = 0;
LOCK_COMMAND(&alloc_lock);
while ((position < NUM_BUFFERS) && (memory[position].addr != free_area))
position++;
while ((memory[position].addr != free_area)
&& (position < NUM_BUFFERS)) position++;
if (memory[position].addr != free_area) goto error;
@@ -1479,30 +1516,12 @@ static int on_process_term(void)
#else
#pragma comment(linker, "/INCLUDE:__tls_used")
#endif
#ifdef _WIN64
#pragma const_seg(".CRT$XLB")
#else
#pragma data_seg(push, old_seg)
#pragma data_seg(".CRT$XLB")
#endif
static void (APIENTRY *dll_callback)(HINSTANCE h, DWORD ul_reason_for_call, PVOID pv) = DllMain;
#ifdef _WIN64
#pragma const_seg()
#else
#pragma data_seg()
#endif
#ifdef _WIN64
#pragma const_seg(".CRT$XTU")
#else
#pragma data_seg(".CRT$XTU")
#endif
static int(*p_process_term)(void) = on_process_term;
#ifdef _WIN64
#pragma const_seg()
#else
#pragma data_seg()
#endif
#pragma data_seg(pop, old_seg)
#endif
#if (defined(C_PGI) || (!defined(C_SUN) && defined(F_INTERFACE_SUN))) && (defined(ARCH_X86) || defined(ARCH_X86_64))