Skip to content

Commit 69f04b2

Browse files
committed
tests/get_cpu_location: disable an assert on process-wide cpu-location when there are unexpected threads
qemu-user led us to add an env-var to disable some checks (see commit de60938). The actual problem is an expected threads in a process (launched by qemu-user). Detect such cases on Linux by looking in /proc/self/task/ and auto-disable those asserts. The env-var is still available for now, may be useful later if the same problem ever occurs on !Linux. Thanks to Ludovic Courtes for the help. Signed-off-by: Brice Goglin <[email protected]>
1 parent 91cc2c1 commit 69f04b2

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/hwloc/hwloc_get_last_cpu_location.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/*
2-
* Copyright © 2011-2019 Inria. All rights reserved.
2+
* Copyright © 2011-2020 Inria. All rights reserved.
33
* Copyright © 2011 Université Bordeaux. All rights reserved.
44
* See COPYING in top-level directory.
55
*/
66

77
#include <stdio.h>
88
#include <stdlib.h>
99
#include <string.h>
10+
#include <unistd.h>
11+
#include <sys/types.h>
12+
#include <sys/stat.h>
1013
#include <errno.h>
1114

1215
#include "hwloc.h"
@@ -59,12 +62,29 @@ static int checkall(hwloc_const_cpuset_t set)
5962
return 0;
6063
}
6164

65+
static int has_unexpected_threads(void)
66+
{
67+
#ifdef HWLOC_LINUX_SYS
68+
struct stat stbuf;
69+
int err = stat("/proc/self/task", &stbuf);
70+
if (!err && stbuf.st_nlink > 3) {
71+
printf("program has multiple threads, disabling process-wide binding/cpulocation checks.\n");
72+
return 1;
73+
}
74+
#endif
75+
/* if the problem ever occurs on !Linux,
76+
* we'll use HWLOC_TEST_DONTCHECK_PROC_CPULOCATION=1 until detecting it here
77+
*/
78+
return 0;
79+
}
80+
6281
int main(void)
6382
{
6483
unsigned depth;
6584
hwloc_obj_t obj;
6685

67-
checkprocincluded = (NULL == getenv("HWLOC_TEST_DONTCHECK_PROC_CPULOCATION"));
86+
checkprocincluded = !has_unexpected_threads()
87+
&& getenv("HWLOC_TEST_DONTCHECK_PROC_CPULOCATION") == NULL;
6888

6989
hwloc_topology_init(&topology);
7090
hwloc_topology_load(topology);

0 commit comments

Comments
 (0)