Commit 40f5cfe7 authored by Prarit Bhargava's avatar Prarit Bhargava Committed by Len Brown

tools/power turbostat: add node information into turbostat calculations

The previous patches have added node information to turbostat, but the
counters code does not take it into account.

Add node information from cpu_topology calculations to turbostat
counters.
Signed-off-by: default avatarPrarit Bhargava <prarit@redhat.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 70a9c6e8
...@@ -216,12 +216,21 @@ struct pkg_data { ...@@ -216,12 +216,21 @@ struct pkg_data {
#define ODD_COUNTERS thread_odd, core_odd, package_odd #define ODD_COUNTERS thread_odd, core_odd, package_odd
#define EVEN_COUNTERS thread_even, core_even, package_even #define EVEN_COUNTERS thread_even, core_even, package_even
#define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ #define GET_THREAD(thread_base, thread_no, core_no, node_no, pkg_no) \
(thread_base + (pkg_no) * topo.cores_per_node * \ ((thread_base) + \
topo.threads_per_core + \ ((pkg_no) * \
(core_no) * topo.threads_per_core + (thread_no)) topo.nodes_per_pkg * topo.cores_per_node * topo.threads_per_core) + \
#define GET_CORE(core_base, core_no, pkg_no) \ ((node_no) * topo.cores_per_node * topo.threads_per_core) + \
(core_base + (pkg_no) * topo.cores_per_node + (core_no)) ((core_no) * topo.threads_per_core) + \
(thread_no))
#define GET_CORE(core_base, core_no, node_no, pkg_no) \
((core_base) + \
((pkg_no) * topo.nodes_per_pkg * topo.cores_per_node) + \
((node_no) * topo.cores_per_node) + \
(core_no))
#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no)
enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE};
...@@ -297,22 +306,27 @@ int cpu_is_not_present(int cpu) ...@@ -297,22 +306,27 @@ int cpu_is_not_present(int cpu)
int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *),
struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base)
{ {
int retval, pkg_no, core_no, thread_no; int retval, pkg_no, core_no, thread_no, node_no;
for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
for (core_no = 0; core_no < topo.cores_per_node; ++core_no) { for (core_no = 0; core_no < topo.cores_per_node; ++core_no) {
for (node_no = 0; node_no < topo.nodes_per_pkg;
node_no++) {
for (thread_no = 0; thread_no < for (thread_no = 0; thread_no <
topo.threads_per_core; ++thread_no) { topo.threads_per_core; ++thread_no) {
struct thread_data *t; struct thread_data *t;
struct core_data *c; struct core_data *c;
struct pkg_data *p; struct pkg_data *p;
t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); t = GET_THREAD(thread_base, thread_no,
core_no, node_no,
pkg_no);
if (cpu_is_not_present(t->cpu_id)) if (cpu_is_not_present(t->cpu_id))
continue; continue;
c = GET_CORE(core_base, core_no, pkg_no); c = GET_CORE(core_base, core_no,
node_no, pkg_no);
p = GET_PKG(pkg_base, pkg_no); p = GET_PKG(pkg_base, pkg_no);
retval = func(t, c, p); retval = func(t, c, p);
...@@ -321,6 +335,7 @@ int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg ...@@ -321,6 +335,7 @@ int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg
} }
} }
} }
}
return 0; return 0;
} }
...@@ -2488,25 +2503,34 @@ int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, ...@@ -2488,25 +2503,34 @@ int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *,
struct thread_data *thread_base2, struct core_data *core_base2, struct thread_data *thread_base2, struct core_data *core_base2,
struct pkg_data *pkg_base2) struct pkg_data *pkg_base2)
{ {
int retval, pkg_no, core_no, thread_no; int retval, pkg_no, node_no, core_no, thread_no;
for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
for (core_no = 0; core_no < topo.cores_per_node; ++core_no) { for (node_no = 0; node_no < topo.nodes_per_pkg; ++node_no) {
for (core_no = 0; core_no < topo.cores_per_node;
++core_no) {
for (thread_no = 0; thread_no < for (thread_no = 0; thread_no <
topo.threads_per_core; ++thread_no) { topo.threads_per_core; ++thread_no) {
struct thread_data *t, *t2; struct thread_data *t, *t2;
struct core_data *c, *c2; struct core_data *c, *c2;
struct pkg_data *p, *p2; struct pkg_data *p, *p2;
t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); t = GET_THREAD(thread_base, thread_no,
core_no, node_no,
pkg_no);
if (cpu_is_not_present(t->cpu_id)) if (cpu_is_not_present(t->cpu_id))
continue; continue;
t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); t2 = GET_THREAD(thread_base2, thread_no,
core_no, node_no,
pkg_no);
c = GET_CORE(core_base, core_no, pkg_no); c = GET_CORE(core_base, core_no,
c2 = GET_CORE(core_base2, core_no, pkg_no); node_no, pkg_no);
c2 = GET_CORE(core_base2, core_no,
node_no,
pkg_no);
p = GET_PKG(pkg_base, pkg_no); p = GET_PKG(pkg_base, pkg_no);
p2 = GET_PKG(pkg_base2, pkg_no); p2 = GET_PKG(pkg_base2, pkg_no);
...@@ -2517,6 +2541,7 @@ int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, ...@@ -2517,6 +2541,7 @@ int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *,
} }
} }
} }
}
return 0; return 0;
} }
...@@ -4752,25 +4777,26 @@ void topology_probe() ...@@ -4752,25 +4777,26 @@ void topology_probe()
} }
void void
allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) allocate_counters(struct thread_data **t, struct core_data **c,
struct pkg_data **p)
{ {
int i; int i;
int num_cores = topo.cores_per_node * topo.nodes_per_pkg *
topo.num_packages;
int num_threads = topo.threads_per_core * num_cores;
*t = calloc(topo.threads_per_core * topo.cores_per_node * *t = calloc(num_threads, sizeof(struct thread_data));
topo.num_packages, sizeof(struct thread_data));
if (*t == NULL) if (*t == NULL)
goto error; goto error;
for (i = 0; i < topo.threads_per_core * for (i = 0; i < num_threads; i++)
topo.cores_per_node * topo.num_packages; i++)
(*t)[i].cpu_id = -1; (*t)[i].cpu_id = -1;
*c = calloc(topo.cores_per_node * topo.num_packages, *c = calloc(num_cores, sizeof(struct core_data));
sizeof(struct core_data));
if (*c == NULL) if (*c == NULL)
goto error; goto error;
for (i = 0; i < topo.cores_per_node * topo.num_packages; i++) for (i = 0; i < num_cores; i++)
(*c)[i].core_id = -1; (*c)[i].core_id = -1;
*p = calloc(topo.num_packages, sizeof(struct pkg_data)); *p = calloc(topo.num_packages, sizeof(struct pkg_data));
...@@ -4793,14 +4819,15 @@ void init_counter(struct thread_data *thread_base, struct core_data *core_base, ...@@ -4793,14 +4819,15 @@ void init_counter(struct thread_data *thread_base, struct core_data *core_base,
struct pkg_data *pkg_base, int cpu_id) struct pkg_data *pkg_base, int cpu_id)
{ {
int pkg_id = cpus[cpu_id].physical_package_id; int pkg_id = cpus[cpu_id].physical_package_id;
int node_id = cpus[cpu_id].logical_node_id;
int core_id = cpus[cpu_id].physical_core_id; int core_id = cpus[cpu_id].physical_core_id;
int thread_id = cpus[cpu_id].thread_id; int thread_id = cpus[cpu_id].thread_id;
struct thread_data *t; struct thread_data *t;
struct core_data *c; struct core_data *c;
struct pkg_data *p; struct pkg_data *p;
t = GET_THREAD(thread_base, thread_id, core_id, pkg_id); t = GET_THREAD(thread_base, thread_id, core_id, node_id, pkg_id);
c = GET_CORE(core_base, core_id, pkg_id); c = GET_CORE(core_base, core_id, node_id, pkg_id);
p = GET_PKG(pkg_base, pkg_id); p = GET_PKG(pkg_base, pkg_id);
t->cpu_id = cpu_id; t->cpu_id = cpu_id;
......
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