summaryrefslogtreecommitdiffstats
path: root/tools/power/x86
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-07 13:14:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-07 13:14:23 +0000
commitdcfb98cf8931dc6bce38eff8e1c82972e1adf484 (patch)
tree5395e7ca0effa58c164a86740b6470cbb47fe05e /tools/power/x86
parentAdding upstream version 6.9.8. (diff)
downloadlinux-dcfb98cf8931dc6bce38eff8e1c82972e1adf484.tar.xz
linux-dcfb98cf8931dc6bce38eff8e1c82972e1adf484.zip
Adding upstream version 6.9.9.upstream/6.9.9
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/power/x86')
-rw-r--r--tools/power/x86/turbostat/turbostat.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 8071a3ef2a..5d80d193e5 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -1022,6 +1022,7 @@ struct rapl_counter_info_t {
/* struct rapl_counter_info_t for each RAPL domain */
struct rapl_counter_info_t *rapl_counter_info_perdomain;
+unsigned int rapl_counter_info_perdomain_size;
#define RAPL_COUNTER_FLAG_USE_MSR_SUM (1u << 1)
@@ -1415,6 +1416,9 @@ struct topo_params {
int allowed_cpus;
int allowed_cores;
int max_cpu_num;
+ int max_core_id;
+ int max_package_id;
+ int max_die_id;
int max_node_num;
int nodes_per_pkg;
int cores_per_node;
@@ -3368,15 +3372,18 @@ void write_rapl_counter(struct rapl_counter *rc, struct rapl_counter_info_t *rci
rc->scale = rci->scale[idx];
}
-int get_rapl_counters(int cpu, int domain, struct core_data *c, struct pkg_data *p)
+int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct pkg_data *p)
{
unsigned long long perf_data[NUM_RAPL_COUNTERS + 1];
- struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[domain];
+ struct rapl_counter_info_t *rci;
if (debug)
fprintf(stderr, "%s: cpu%d domain%d\n", __func__, cpu, domain);
assert(rapl_counter_info_perdomain);
+ assert(domain < rapl_counter_info_perdomain_size);
+
+ rci = &rapl_counter_info_perdomain[domain];
/*
* If we have any perf counters to read, read them all now, in bulk
@@ -4180,7 +4187,7 @@ void free_fd_rapl_percpu(void)
if (!rapl_counter_info_perdomain)
return;
- const int num_domains = platform->has_per_core_rapl ? topo.num_cores : topo.num_packages;
+ const int num_domains = rapl_counter_info_perdomain_size;
for (int domain_id = 0; domain_id < num_domains; ++domain_id) {
if (rapl_counter_info_perdomain[domain_id].fd_perf != -1)
@@ -4188,6 +4195,8 @@ void free_fd_rapl_percpu(void)
}
free(rapl_counter_info_perdomain);
+ rapl_counter_info_perdomain = NULL;
+ rapl_counter_info_perdomain_size = 0;
}
void free_all_buffers(void)
@@ -6478,17 +6487,18 @@ void linux_perf_init(void)
void rapl_perf_init(void)
{
- const int num_domains = platform->has_per_core_rapl ? topo.num_cores : topo.num_packages;
+ const unsigned int num_domains = (platform->has_per_core_rapl ? topo.max_core_id : topo.max_package_id) + 1;
bool *domain_visited = calloc(num_domains, sizeof(bool));
rapl_counter_info_perdomain = calloc(num_domains, sizeof(*rapl_counter_info_perdomain));
if (rapl_counter_info_perdomain == NULL)
err(-1, "calloc rapl_counter_info_percpu");
+ rapl_counter_info_perdomain_size = num_domains;
/*
* Initialize rapl_counter_info_percpu
*/
- for (int domain_id = 0; domain_id < num_domains; ++domain_id) {
+ for (unsigned int domain_id = 0; domain_id < num_domains; ++domain_id) {
struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[domain_id];
rci->fd_perf = -1;
@@ -6508,7 +6518,7 @@ void rapl_perf_init(void)
bool has_counter = 0;
double scale;
enum rapl_unit unit;
- int next_domain;
+ unsigned int next_domain;
memset(domain_visited, 0, num_domains * sizeof(*domain_visited));
@@ -6521,6 +6531,8 @@ void rapl_perf_init(void)
next_domain =
platform->has_per_core_rapl ? cpus[cpu].physical_core_id : cpus[cpu].physical_package_id;
+ assert(next_domain < num_domains);
+
if (domain_visited[next_domain])
continue;
@@ -6967,7 +6979,6 @@ void topology_probe(bool startup)
int i;
int max_core_id = 0;
int max_package_id = 0;
- int max_die_id = 0;
int max_siblings = 0;
/* Initialize num_cpus, max_cpu_num */
@@ -7084,8 +7095,8 @@ void topology_probe(bool startup)
/* get die information */
cpus[i].die_id = get_die_id(i);
- if (cpus[i].die_id > max_die_id)
- max_die_id = cpus[i].die_id;
+ if (cpus[i].die_id > topo.max_die_id)
+ topo.max_die_id = cpus[i].die_id;
/* get numa node information */
cpus[i].physical_node_id = get_physical_node_id(&cpus[i]);
@@ -7104,6 +7115,8 @@ void topology_probe(bool startup)
if (cpus[i].thread_id == 0)
topo.num_cores++;
}
+ topo.max_core_id = max_core_id;
+ topo.max_package_id = max_package_id;
topo.cores_per_node = max_core_id + 1;
if (debug > 1)
@@ -7111,9 +7124,9 @@ void topology_probe(bool startup)
if (!summary_only && topo.cores_per_node > 1)
BIC_PRESENT(BIC_Core);
- topo.num_die = max_die_id + 1;
+ topo.num_die = topo.max_die_id + 1;
if (debug > 1)
- fprintf(outf, "max_die_id %d, sizing for %d die\n", max_die_id, topo.num_die);
+ fprintf(outf, "max_die_id %d, sizing for %d die\n", topo.max_die_id, topo.num_die);
if (!summary_only && topo.num_die > 1)
BIC_PRESENT(BIC_Die);