Skip to content

Commit

Permalink
tests/get_cpu_location: disable an assert on process-wide cpu-locatio…
Browse files Browse the repository at this point in the history
…n 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 <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Mar 28, 2020
1 parent 91cc2c1 commit 69f04b2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tests/hwloc/hwloc_get_last_cpu_location.c
@@ -1,12 +1,15 @@
/*
* Copyright © 2011-2019 Inria. All rights reserved.
* Copyright © 2011-2020 Inria. All rights reserved.
* Copyright © 2011 Université Bordeaux. All rights reserved.
* See COPYING in top-level directory.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

#include "hwloc.h"
Expand Down Expand Up @@ -59,12 +62,29 @@ static int checkall(hwloc_const_cpuset_t set)
return 0;
}

static int has_unexpected_threads(void)
{
#ifdef HWLOC_LINUX_SYS
struct stat stbuf;
int err = stat("/proc/self/task", &stbuf);
if (!err && stbuf.st_nlink > 3) {
printf("program has multiple threads, disabling process-wide binding/cpulocation checks.\n");
return 1;
}
#endif
/* if the problem ever occurs on !Linux,
* we'll use HWLOC_TEST_DONTCHECK_PROC_CPULOCATION=1 until detecting it here
*/
return 0;
}

int main(void)
{
unsigned depth;
hwloc_obj_t obj;

checkprocincluded = (NULL == getenv("HWLOC_TEST_DONTCHECK_PROC_CPULOCATION"));
checkprocincluded = !has_unexpected_threads()
&& getenv("HWLOC_TEST_DONTCHECK_PROC_CPULOCATION") == NULL;

hwloc_topology_init(&topology);
hwloc_topology_load(topology);
Expand Down

0 comments on commit 69f04b2

Please sign in to comment.