From bb77b3911f67b269999beccc4c6a65a1ef9bd024 Mon Sep 17 00:00:00 2001 From: Anton Gladky Date: Sat, 20 Oct 2018 23:54:48 +0200 Subject: [PATCH 1/2] Fix parsing of cpuinfo for s390 platform. s390 has another line structure for processor-field. It should be differently parsed. --- src/sysinfo.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sysinfo.cc b/src/sysinfo.cc index d4e5336fdb..d8df7da7f6 100644 --- a/src/sysinfo.cc +++ b/src/sysinfo.cc @@ -404,7 +404,11 @@ int GetNumCPUs() { if (ln.empty()) continue; size_t SplitIdx = ln.find(':'); std::string value; +#if defined(__s390__) + if (SplitIdx != std::string::npos) value = ln.substr(SplitIdx - 1, 2); +#else if (SplitIdx != std::string::npos) value = ln.substr(SplitIdx + 1); +#endif if (ln.size() >= Key.size() && ln.compare(0, Key.size(), Key) == 0) { NumCPUs++; if (!value.empty()) { From e095f4476813c307c57e478c86c04701d50a58e8 Mon Sep 17 00:00:00 2001 From: Anton Gladky Date: Sun, 21 Oct 2018 08:51:24 +0200 Subject: [PATCH 2/2] Make the calculation of cpus for s390 reliable for any CPU number --- src/sysinfo.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sysinfo.cc b/src/sysinfo.cc index d8df7da7f6..d740047eea 100644 --- a/src/sysinfo.cc +++ b/src/sysinfo.cc @@ -405,7 +405,9 @@ int GetNumCPUs() { size_t SplitIdx = ln.find(':'); std::string value; #if defined(__s390__) - if (SplitIdx != std::string::npos) value = ln.substr(SplitIdx - 1, 2); + // s390 has another format in /proc/cpuinfo + // it needs to be parsed differently + if (SplitIdx != std::string::npos) value = ln.substr(Key.size()+1,SplitIdx-Key.size()-1); #else if (SplitIdx != std::string::npos) value = ln.substr(SplitIdx + 1); #endif