Commit 01a67adf authored by Mika Westerberg's avatar Mika Westerberg Committed by Len Brown

tools/power turbostat: Allocate correct amount of fd and irq entries

The tool uses topo.max_cpu_num to determine number of entries needed for
fd_percpu[] and irqs_per_cpu[]. For example on a system with 4 CPUs
topo.max_cpu_num is 3 so we get too small array for holding per-CPU items.

Fix this to use right number of entries, which is topo.max_cpu_num + 1.
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 3d109de2
...@@ -1618,7 +1618,7 @@ void free_fd_percpu(void) ...@@ -1618,7 +1618,7 @@ void free_fd_percpu(void)
{ {
int i; int i;
for (i = 0; i < topo.max_cpu_num; ++i) { for (i = 0; i < topo.max_cpu_num + 1; ++i) {
if (fd_percpu[i] != 0) if (fd_percpu[i] != 0)
close(fd_percpu[i]); close(fd_percpu[i]);
} }
...@@ -3584,7 +3584,7 @@ void allocate_output_buffer() ...@@ -3584,7 +3584,7 @@ void allocate_output_buffer()
} }
void allocate_fd_percpu(void) void allocate_fd_percpu(void)
{ {
fd_percpu = calloc(topo.max_cpu_num, sizeof(int)); fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int));
if (fd_percpu == NULL) if (fd_percpu == NULL)
err(-1, "calloc fd_percpu"); err(-1, "calloc fd_percpu");
} }
...@@ -3594,9 +3594,9 @@ void allocate_irq_buffers(void) ...@@ -3594,9 +3594,9 @@ void allocate_irq_buffers(void)
if (irq_column_2_cpu == NULL) if (irq_column_2_cpu == NULL)
err(-1, "calloc %d", topo.num_cpus); err(-1, "calloc %d", topo.num_cpus);
irqs_per_cpu = calloc(topo.max_cpu_num, sizeof(int)); irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int));
if (irqs_per_cpu == NULL) if (irqs_per_cpu == NULL)
err(-1, "calloc %d", topo.max_cpu_num); err(-1, "calloc %d", topo.max_cpu_num + 1);
} }
void setup_all_buffers(void) void setup_all_buffers(void)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment