From cfa50268cf216c9977a0baa2cec7a6adc82c19e9 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sun, 11 Jun 2017 14:02:51 +0200 Subject: [PATCH] NUMA topology on Linux: fix if numa-node is not in /sys/devices --- src/numa/linux/topology.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/numa/linux/topology.cpp b/src/numa/linux/topology.cpp index 939c6596..99efc6ed 100644 --- a/src/numa/linux/topology.cpp +++ b/src/numa/linux/topology.cpp @@ -149,6 +149,7 @@ std::vector< node > topology() { boost::str( boost::format("/sys/devices/system/cpu/cpu%d/") % cpu_id) }; BOOST_ASSERT( fs::exists( cpu_path) ); + bool match = false; // 2. to witch NUMA node the CPU belongs to directory_iterator e; for ( directory_iterator i{ cpu_path, "^node([0-9]+)$" }; @@ -159,18 +160,29 @@ std::vector< node > topology() { // assigned to only one NUMA node break; } + if ( ! match) { + // no '/sys/devices/system/cpu/cpu<>/node<>' + // create NUMA node with id `0` + map[0].id = 0; + map[0].logical_cpus.insert( cpu_id); + } } for ( auto entry : map) { // NUMA-node distance fs::path distance_path{ boost::str( boost::format("/sys/devices/system/node/node%d/distance") % entry.second.id) }; - BOOST_ASSERT( fs::exists( distance_path) ); - fs::ifstream fs_distance{ distance_path }; - std::string content; - std::getline( fs_distance, content); - entry.second.distance = distance_from_line( content); - topo.push_back( entry.second); + if ( fs::exists( distance_path) ) { + fs::ifstream fs_distance{ distance_path }; + std::string content; + std::getline( fs_distance, content); + entry.second.distance = distance_from_line( content); + topo.push_back( entry.second); + } else { + // fake NUMA distance + entry.second.distance.push_back( 10); + topo.push_back( entry.second); + } } return topo; }