diff options
author | Lukas Larsson <[email protected]> | 2017-04-06 17:13:23 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2017-04-20 10:09:15 +0200 |
commit | bb18d3305363ed9ef9eaead6fa2d796f56b1749c (patch) | |
tree | 70f5f8c806fe29e9724c56c3402941043378ae34 /erts | |
parent | 72e0725c30960541e1209a45f6a9e56fecc3be95 (diff) | |
download | otp-bb18d3305363ed9ef9eaead6fa2d796f56b1749c.tar.gz otp-bb18d3305363ed9ef9eaead6fa2d796f56b1749c.tar.bz2 otp-bb18d3305363ed9ef9eaead6fa2d796f56b1749c.zip |
erts: Fix erlexec to handle mismatch in sysconf and proc fs
This behaviour has been seen when using docker together with --cpuset-cpus.
Diffstat (limited to 'erts')
-rw-r--r-- | erts/lib_src/common/erl_misc_utils.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/erts/lib_src/common/erl_misc_utils.c b/erts/lib_src/common/erl_misc_utils.c index 8186463b9c..2ffb23bf54 100644 --- a/erts/lib_src/common/erl_misc_utils.c +++ b/erts/lib_src/common/erl_misc_utils.c @@ -842,7 +842,7 @@ read_topology(erts_cpu_info_t *cpuinfo) cpuinfo->topology[ix].logical = -1; } - ix = -1; + ix = 0; if (realpath(ERTS_SYS_NODE_PATH, npath)) { ndir = opendir(npath); @@ -886,6 +886,7 @@ read_topology(erts_cpu_info_t *cpuinfo) cdir = NULL; break; } + if (sscanf(cde->d_name, "cpu%d", &cpu_id) == 1) { char buf[50]; /* Much more than enough for an integer */ int processor_id, core_id; @@ -906,23 +907,33 @@ read_topology(erts_cpu_info_t *cpuinfo) if (sscanf(buf, "%d", &core_id) != 1) continue; + /* + * The number of CPUs that proc fs presents is greater + * then the number of CPUs configured in sysconf. + * This has been known to happen in docker. When this + * happens we refuse to give a CPU topology. + */ + if (ix >= cpuinfo->configured) + goto error; + /* * We now know node id, processor id, and * core id of the logical processor with * the cpu id 'cpu_id'. */ - ix++; cpuinfo->topology[ix].node = node_id; cpuinfo->topology[ix].processor = processor_id; cpuinfo->topology[ix].processor_node = -1; /* Fixed later */ cpuinfo->topology[ix].core = core_id; cpuinfo->topology[ix].thread = 0; /* we'll numerate later */ cpuinfo->topology[ix].logical = cpu_id; + ix++; + } } } while (got_nodes); - res = ix+1; + res = ix; if (!res || res < cpuinfo->online) res = 0; |