Skip to content

Commit

Permalink
Fix runtime crash when parsing /proc/cpuinfo fails (#1900)
Browse files Browse the repository at this point in the history
The testcase fails on sparc64, because the parsing of /proc/cpuinfo
fails and thus currently returns "0" CPUs which finally leads
to division-by-zero faults in the tests.

Fix the issue by returning at least "1" CPU which allows the
tests to run. A error message will be printed in any case.

Long-term the code should be fixed to parse the cpuinfo output
on sparch which looks like this:
...
type            : sun4v
ncpus probed    : 48
ncpus active    : 48
  • Loading branch information
hdeller authored Jan 9, 2025
1 parent 077db43 commit 39be87d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sysinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,12 @@ int GetNumCPUsImpl() {
}

int GetNumCPUs() {
const int num_cpus = GetNumCPUsImpl();
int num_cpus = GetNumCPUsImpl();
if (num_cpus < 1) {
std::cerr << "Unable to extract number of CPUs. If your platform uses "
"/proc/cpuinfo, custom support may need to be added.\n";
/* There is at least one CPU which we run on. */
num_cpus = 1;
}
return num_cpus;
}
Expand Down

0 comments on commit 39be87d

Please sign in to comment.