summaryrefslogtreecommitdiffstats
path: root/tools/power
diff options
context:
space:
mode:
authorNathan Ciobanu <nathan.d.ciobanu@linux.intel.com>2018-06-08 15:15:12 -0700
committerLen Brown <len.brown@intel.com>2018-06-20 13:55:04 -0400
commit42dd45209201edb222de5f9eadc1c8f93700ef28 (patch)
tree6932027a3b20fd4ff1bfabe3656397b0abe7d0dc /tools/power
parent4c2122d42116ebaa1665ad0fbef2c558fdc0e3c6 (diff)
downloadlinux-42dd45209201edb222de5f9eadc1c8f93700ef28.tar.bz2
tools/power turbostat: fix segfault on 'no node' machines
Running turbostat on machines that don't expose nodes in sysfs (no /sys/bus/node) causes a segfault or a -nan value diesplayed in the log. This is caused by physical_node_id being reported as -1 and logical_node_id being calculated as a negative number resulting in the new GET_THREAD/GET_CORE returning an incorrect address. Signed-off-by: Nathan Ciobanu <nathan.d.ciobanu@linux.intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/x86/turbostat/turbostat.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 3bc2c9d94739..97cc00a9c763 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2492,6 +2492,12 @@ void set_node_data(void)
if (pni[pkg].count > topo.nodes_per_pkg)
topo.nodes_per_pkg = pni[0].count;
+ /* Fake 1 node per pkg for machines that don't
+ * expose nodes and thus avoid -nan results
+ */
+ if (topo.nodes_per_pkg == 0)
+ topo.nodes_per_pkg = 1;
+
for (cpu = 0; cpu < topo.num_cpus; cpu++) {
pkg = cpus[cpu].physical_package_id;
node = cpus[cpu].physical_node_id;
@@ -4904,6 +4910,13 @@ void init_counter(struct thread_data *thread_base, struct core_data *core_base,
struct core_data *c;
struct pkg_data *p;
+
+ /* Workaround for systems where physical_node_id==-1
+ * and logical_node_id==(-1 - topo.num_cpus)
+ */
+ if (node_id < 0)
+ node_id = 0;
+
t = GET_THREAD(thread_base, thread_id, core_id, node_id, pkg_id);
c = GET_CORE(core_base, core_id, node_id, pkg_id);
p = GET_PKG(pkg_base, pkg_id);