aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Weil <sw@weilnetz.de>2012-07-12 22:37:47 +0200
committerChris E Ferron <chris.e.ferron@linux.intel.com>2012-07-17 14:45:25 -0700
commit068433139ae930ec03c5f602b629e0921c484d3b (patch)
treed36ea76f7db6cd580cceafccf969024fd83987da
parent3d6764e47916953b62c02a312f79355e3ae66a8d (diff)
Fix handling of /proc/cpuinfo for non x86 architectures
Not all architectures include lines with "vendor_id\t" or "processor\t". ARM Linux without SMP support includes neither of these two entries. With SMP support, there are "processor\t" entries for each CPU. Set vendor to an empty string initially, so there is a default value. Assume CPU id 0 when no number was set while encountering the first "bogomips\t" line. If there are more such lines without a correct number, only the first CPU is handled. This should not be needed for ARM, but makes the code more robust because it avoids calling handle_one_cpu twice with number == 0. Signed-off-by: Stefan Weil <sw@weilnetz.de>
-rw-r--r--src/cpu/cpu.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
index 92512a6..941bcff 100644
--- a/src/cpu/cpu.cpp
+++ b/src/cpu/cpu.cpp
@@ -232,6 +232,8 @@ void enumerate_cpus(void)
if (!file)
return;
+ /* Not all /proc/cpuinfo include "vendor_id\t". */
+ vendor[0] = '\0';
while (file) {
@@ -271,8 +273,15 @@ void enumerate_cpus(void)
}
}
if (strncasecmp(line, "bogomips\t", 9) == 0) {
- handle_one_cpu(number, vendor, family, model);
- set_max_cpu(number);
+ if (number == -1) {
+ /* Not all /proc/cpuinfo include "processor\t". */
+ number = 0;
+ }
+ if (number >= 0) {
+ handle_one_cpu(number, vendor, family, model);
+ set_max_cpu(number);
+ number = -2;
+ }
}
}