Skip to content

Commit

Permalink
linux: check that we may scan sysfs directories before assuming it wi…
Browse files Browse the repository at this point in the history
…ll work

Android 7 /sys/bus/{cpu,node}/devices/ is --x, we won't be able to scan it.
We must use /sys/devices/system/{cpu,node} instead.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Mar 31, 2019
1 parent 99ab501 commit 2e1ff8d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions hwloc/topology-linux.c
Expand Up @@ -4890,20 +4890,24 @@ hwloc_look_linuxfs(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
int err;

/* look for sysfs cpu path containing at least one of core_siblings and thread_siblings */
if (!hwloc_access("/sys/bus/cpu/devices/cpu0/topology/thread_siblings", R_OK, data->root_fd)
|| !hwloc_access("/sys/bus/cpu/devices/cpu0/topology/core_siblings", R_OK, data->root_fd))
if (!hwloc_access("/sys/bus/cpu/devices", R_OK|X_OK, data->root_fd)
&& (!hwloc_access("/sys/bus/cpu/devices/cpu0/topology/thread_siblings", R_OK, data->root_fd)
|| !hwloc_access("/sys/bus/cpu/devices/cpu0/topology/core_siblings", R_OK, data->root_fd)))
sysfs_cpu_path = "/sys/bus/cpu/devices";
else if (!hwloc_access("/sys/devices/system/cpu/cpu0/topology/core_siblings", R_OK, data->root_fd)
|| !hwloc_access("/sys/devices/system/cpu/cpu0/topology/thread_siblings", R_OK, data->root_fd))
else if (!hwloc_access("/sys/devices/system/cpu", R_OK|X_OK, data->root_fd)
&& (!hwloc_access("/sys/devices/system/cpu/cpu0/topology/core_siblings", R_OK, data->root_fd)
|| !hwloc_access("/sys/devices/system/cpu/cpu0/topology/thread_siblings", R_OK, data->root_fd)))
sysfs_cpu_path = "/sys/devices/system/cpu";
else
sysfs_cpu_path = NULL;
hwloc_debug("Found sysfs cpu files under %s\n", sysfs_cpu_path);

/* look for sysfs node path */
if (!hwloc_access("/sys/bus/node/devices/node0/cpumap", R_OK, data->root_fd))
if (!hwloc_access("/sys/bus/node/devices", R_OK|X_OK, data->root_fd)
&& !hwloc_access("/sys/bus/node/devices/node0/cpumap", R_OK, data->root_fd))
sysfs_node_path = "/sys/bus/node/devices";
else if (!hwloc_access("/sys/devices/system/node/node0/cpumap", R_OK, data->root_fd))
else if (!hwloc_access("/sys/devices/system/node", R_OK|X_OK, data->root_fd)
&& !hwloc_access("/sys/devices/system/node/node0/cpumap", R_OK, data->root_fd))
sysfs_node_path = "/sys/devices/system/node";
else
sysfs_node_path = NULL;
Expand Down

0 comments on commit 2e1ff8d

Please sign in to comment.