Skip to content

Commit 40f5cfe

Browse files
praritlenb
authored andcommitted
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: Prarit Bhargava <prarit@redhat.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 70a9c6e commit 40f5cfe

File tree

1 file changed

+85
-58
lines changed

1 file changed

+85
-58
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,21 @@ struct pkg_data {
216216
#define ODD_COUNTERS thread_odd, core_odd, package_odd
217217
#define EVEN_COUNTERS thread_even, core_even, package_even
218218

219-
#define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \
220-
(thread_base + (pkg_no) * topo.cores_per_node * \
221-
topo.threads_per_core + \
222-
(core_no) * topo.threads_per_core + (thread_no))
223-
#define GET_CORE(core_base, core_no, pkg_no) \
224-
(core_base + (pkg_no) * topo.cores_per_node + (core_no))
219+
#define GET_THREAD(thread_base, thread_no, core_no, node_no, pkg_no) \
220+
((thread_base) + \
221+
((pkg_no) * \
222+
topo.nodes_per_pkg * topo.cores_per_node * topo.threads_per_core) + \
223+
((node_no) * topo.cores_per_node * topo.threads_per_core) + \
224+
((core_no) * topo.threads_per_core) + \
225+
(thread_no))
226+
227+
#define GET_CORE(core_base, core_no, node_no, pkg_no) \
228+
((core_base) + \
229+
((pkg_no) * topo.nodes_per_pkg * topo.cores_per_node) + \
230+
((node_no) * topo.cores_per_node) + \
231+
(core_no))
232+
233+
225234
#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no)
226235

227236
enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE};
@@ -297,27 +306,33 @@ int cpu_is_not_present(int cpu)
297306
int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *),
298307
struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base)
299308
{
300-
int retval, pkg_no, core_no, thread_no;
309+
int retval, pkg_no, core_no, thread_no, node_no;
301310

302311
for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
303312
for (core_no = 0; core_no < topo.cores_per_node; ++core_no) {
304-
for (thread_no = 0; thread_no <
305-
topo.threads_per_core; ++thread_no) {
306-
struct thread_data *t;
307-
struct core_data *c;
308-
struct pkg_data *p;
309-
310-
t = GET_THREAD(thread_base, thread_no, core_no, pkg_no);
311-
312-
if (cpu_is_not_present(t->cpu_id))
313-
continue;
314-
315-
c = GET_CORE(core_base, core_no, pkg_no);
316-
p = GET_PKG(pkg_base, pkg_no);
317-
318-
retval = func(t, c, p);
319-
if (retval)
320-
return retval;
313+
for (node_no = 0; node_no < topo.nodes_per_pkg;
314+
node_no++) {
315+
for (thread_no = 0; thread_no <
316+
topo.threads_per_core; ++thread_no) {
317+
struct thread_data *t;
318+
struct core_data *c;
319+
struct pkg_data *p;
320+
321+
t = GET_THREAD(thread_base, thread_no,
322+
core_no, node_no,
323+
pkg_no);
324+
325+
if (cpu_is_not_present(t->cpu_id))
326+
continue;
327+
328+
c = GET_CORE(core_base, core_no,
329+
node_no, pkg_no);
330+
p = GET_PKG(pkg_base, pkg_no);
331+
332+
retval = func(t, c, p);
333+
if (retval)
334+
return retval;
335+
}
321336
}
322337
}
323338
}
@@ -2488,32 +2503,42 @@ int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *,
24882503
struct thread_data *thread_base2, struct core_data *core_base2,
24892504
struct pkg_data *pkg_base2)
24902505
{
2491-
int retval, pkg_no, core_no, thread_no;
2506+
int retval, pkg_no, node_no, core_no, thread_no;
24922507

24932508
for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
2494-
for (core_no = 0; core_no < topo.cores_per_node; ++core_no) {
2495-
for (thread_no = 0; thread_no <
2496-
topo.threads_per_core; ++thread_no) {
2497-
struct thread_data *t, *t2;
2498-
struct core_data *c, *c2;
2499-
struct pkg_data *p, *p2;
2500-
2501-
t = GET_THREAD(thread_base, thread_no, core_no, pkg_no);
2502-
2503-
if (cpu_is_not_present(t->cpu_id))
2504-
continue;
2505-
2506-
t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no);
2507-
2508-
c = GET_CORE(core_base, core_no, pkg_no);
2509-
c2 = GET_CORE(core_base2, core_no, pkg_no);
2510-
2511-
p = GET_PKG(pkg_base, pkg_no);
2512-
p2 = GET_PKG(pkg_base2, pkg_no);
2513-
2514-
retval = func(t, c, p, t2, c2, p2);
2515-
if (retval)
2516-
return retval;
2509+
for (node_no = 0; node_no < topo.nodes_per_pkg; ++node_no) {
2510+
for (core_no = 0; core_no < topo.cores_per_node;
2511+
++core_no) {
2512+
for (thread_no = 0; thread_no <
2513+
topo.threads_per_core; ++thread_no) {
2514+
struct thread_data *t, *t2;
2515+
struct core_data *c, *c2;
2516+
struct pkg_data *p, *p2;
2517+
2518+
t = GET_THREAD(thread_base, thread_no,
2519+
core_no, node_no,
2520+
pkg_no);
2521+
2522+
if (cpu_is_not_present(t->cpu_id))
2523+
continue;
2524+
2525+
t2 = GET_THREAD(thread_base2, thread_no,
2526+
core_no, node_no,
2527+
pkg_no);
2528+
2529+
c = GET_CORE(core_base, core_no,
2530+
node_no, pkg_no);
2531+
c2 = GET_CORE(core_base2, core_no,
2532+
node_no,
2533+
pkg_no);
2534+
2535+
p = GET_PKG(pkg_base, pkg_no);
2536+
p2 = GET_PKG(pkg_base2, pkg_no);
2537+
2538+
retval = func(t, c, p, t2, c2, p2);
2539+
if (retval)
2540+
return retval;
2541+
}
25172542
}
25182543
}
25192544
}
@@ -4752,25 +4777,26 @@ void topology_probe()
47524777
}
47534778

47544779
void
4755-
allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p)
4780+
allocate_counters(struct thread_data **t, struct core_data **c,
4781+
struct pkg_data **p)
47564782
{
47574783
int i;
4784+
int num_cores = topo.cores_per_node * topo.nodes_per_pkg *
4785+
topo.num_packages;
4786+
int num_threads = topo.threads_per_core * num_cores;
47584787

4759-
*t = calloc(topo.threads_per_core * topo.cores_per_node *
4760-
topo.num_packages, sizeof(struct thread_data));
4788+
*t = calloc(num_threads, sizeof(struct thread_data));
47614789
if (*t == NULL)
47624790
goto error;
47634791

4764-
for (i = 0; i < topo.threads_per_core *
4765-
topo.cores_per_node * topo.num_packages; i++)
4792+
for (i = 0; i < num_threads; i++)
47664793
(*t)[i].cpu_id = -1;
47674794

4768-
*c = calloc(topo.cores_per_node * topo.num_packages,
4769-
sizeof(struct core_data));
4795+
*c = calloc(num_cores, sizeof(struct core_data));
47704796
if (*c == NULL)
47714797
goto error;
47724798

4773-
for (i = 0; i < topo.cores_per_node * topo.num_packages; i++)
4799+
for (i = 0; i < num_cores; i++)
47744800
(*c)[i].core_id = -1;
47754801

47764802
*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,
47934819
struct pkg_data *pkg_base, int cpu_id)
47944820
{
47954821
int pkg_id = cpus[cpu_id].physical_package_id;
4822+
int node_id = cpus[cpu_id].logical_node_id;
47964823
int core_id = cpus[cpu_id].physical_core_id;
47974824
int thread_id = cpus[cpu_id].thread_id;
47984825
struct thread_data *t;
47994826
struct core_data *c;
48004827
struct pkg_data *p;
48014828

4802-
t = GET_THREAD(thread_base, thread_id, core_id, pkg_id);
4803-
c = GET_CORE(core_base, core_id, pkg_id);
4829+
t = GET_THREAD(thread_base, thread_id, core_id, node_id, pkg_id);
4830+
c = GET_CORE(core_base, core_id, node_id, pkg_id);
48044831
p = GET_PKG(pkg_base, pkg_id);
48054832

48064833
t->cpu_id = cpu_id;

0 commit comments

Comments
 (0)