2019-02-19 17:58:13 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <sys/param.h>
|
2019-06-05 06:50:41 +08:00
|
|
|
#include <sys/utsname.h>
|
2019-02-19 17:58:14 +08:00
|
|
|
#include <inttypes.h>
|
2019-07-04 22:21:24 +08:00
|
|
|
#include <stdlib.h>
|
2019-08-22 21:48:31 +08:00
|
|
|
#include <string.h>
|
2019-02-19 17:58:15 +08:00
|
|
|
#include <api/fs/fs.h>
|
2019-07-04 22:32:27 +08:00
|
|
|
#include <linux/zalloc.h>
|
2019-07-21 19:24:30 +08:00
|
|
|
#include <perf/cpumap.h>
|
2019-02-19 17:58:13 +08:00
|
|
|
|
|
|
|
#include "cputopo.h"
|
|
|
|
#include "cpumap.h"
|
2019-08-22 21:48:31 +08:00
|
|
|
#include "debug.h"
|
2019-02-19 17:58:14 +08:00
|
|
|
#include "env.h"
|
2023-05-27 15:21:54 +08:00
|
|
|
#include "pmu.h"
|
2023-05-27 15:22:03 +08:00
|
|
|
#include "pmus.h"
|
2019-02-19 17:58:13 +08:00
|
|
|
|
2021-11-11 08:21:03 +08:00
|
|
|
#define PACKAGE_CPUS_FMT \
|
|
|
|
"%s/devices/system/cpu/cpu%d/topology/package_cpus_list"
|
|
|
|
#define PACKAGE_CPUS_FMT_OLD \
|
2019-02-19 17:58:15 +08:00
|
|
|
"%s/devices/system/cpu/cpu%d/topology/core_siblings_list"
|
2021-11-11 08:21:04 +08:00
|
|
|
#define DIE_CPUS_FMT \
|
2019-06-05 06:50:41 +08:00
|
|
|
"%s/devices/system/cpu/cpu%d/topology/die_cpus_list"
|
2021-11-11 08:21:05 +08:00
|
|
|
#define CORE_CPUS_FMT \
|
2019-06-05 06:50:44 +08:00
|
|
|
"%s/devices/system/cpu/cpu%d/topology/core_cpus_list"
|
2021-11-11 08:21:05 +08:00
|
|
|
#define CORE_CPUS_FMT_OLD \
|
|
|
|
"%s/devices/system/cpu/cpu%d/topology/thread_siblings_list"
|
2019-02-19 17:58:15 +08:00
|
|
|
#define NODE_ONLINE_FMT \
|
|
|
|
"%s/devices/system/node/online"
|
|
|
|
#define NODE_MEMINFO_FMT \
|
|
|
|
"%s/devices/system/node/node%d/meminfo"
|
|
|
|
#define NODE_CPULIST_FMT \
|
|
|
|
"%s/devices/system/node/node%d/cpulist"
|
2019-02-19 17:58:13 +08:00
|
|
|
|
|
|
|
static int build_cpu_topology(struct cpu_topology *tp, int cpu)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char filename[MAXPATHLEN];
|
|
|
|
char *buf = NULL, *p;
|
|
|
|
size_t len = 0;
|
|
|
|
ssize_t sret;
|
|
|
|
u32 i = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
2021-11-11 08:21:03 +08:00
|
|
|
scnprintf(filename, MAXPATHLEN, PACKAGE_CPUS_FMT,
|
2019-02-19 17:58:15 +08:00
|
|
|
sysfs__mountpoint(), cpu);
|
2021-11-11 08:21:03 +08:00
|
|
|
if (access(filename, F_OK) == -1) {
|
|
|
|
scnprintf(filename, MAXPATHLEN, PACKAGE_CPUS_FMT_OLD,
|
|
|
|
sysfs__mountpoint(), cpu);
|
|
|
|
}
|
2019-02-19 17:58:13 +08:00
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (!fp)
|
2019-06-05 06:50:41 +08:00
|
|
|
goto try_dies;
|
2019-02-19 17:58:13 +08:00
|
|
|
|
|
|
|
sret = getline(&buf, &len, fp);
|
|
|
|
fclose(fp);
|
|
|
|
if (sret <= 0)
|
2019-06-05 06:50:41 +08:00
|
|
|
goto try_dies;
|
2019-02-19 17:58:13 +08:00
|
|
|
|
|
|
|
p = strchr(buf, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
2021-11-11 08:21:03 +08:00
|
|
|
for (i = 0; i < tp->package_cpus_lists; i++) {
|
|
|
|
if (!strcmp(buf, tp->package_cpus_list[i]))
|
2019-02-19 17:58:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-11-11 08:21:03 +08:00
|
|
|
if (i == tp->package_cpus_lists) {
|
|
|
|
tp->package_cpus_list[i] = buf;
|
|
|
|
tp->package_cpus_lists++;
|
2019-02-19 17:58:13 +08:00
|
|
|
buf = NULL;
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
2019-06-05 06:50:41 +08:00
|
|
|
try_dies:
|
2021-11-11 08:21:04 +08:00
|
|
|
if (!tp->die_cpus_list)
|
2019-06-05 06:50:41 +08:00
|
|
|
goto try_threads;
|
|
|
|
|
2021-11-11 08:21:04 +08:00
|
|
|
scnprintf(filename, MAXPATHLEN, DIE_CPUS_FMT,
|
2019-06-05 06:50:41 +08:00
|
|
|
sysfs__mountpoint(), cpu);
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (!fp)
|
|
|
|
goto try_threads;
|
|
|
|
|
|
|
|
sret = getline(&buf, &len, fp);
|
|
|
|
fclose(fp);
|
|
|
|
if (sret <= 0)
|
|
|
|
goto try_threads;
|
|
|
|
|
|
|
|
p = strchr(buf, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
2021-11-11 08:21:04 +08:00
|
|
|
for (i = 0; i < tp->die_cpus_lists; i++) {
|
|
|
|
if (!strcmp(buf, tp->die_cpus_list[i]))
|
2019-06-05 06:50:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-11-11 08:21:04 +08:00
|
|
|
if (i == tp->die_cpus_lists) {
|
|
|
|
tp->die_cpus_list[i] = buf;
|
|
|
|
tp->die_cpus_lists++;
|
2019-06-05 06:50:41 +08:00
|
|
|
buf = NULL;
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
2019-02-19 17:58:13 +08:00
|
|
|
try_threads:
|
2021-11-11 08:21:05 +08:00
|
|
|
scnprintf(filename, MAXPATHLEN, CORE_CPUS_FMT,
|
2019-02-19 17:58:15 +08:00
|
|
|
sysfs__mountpoint(), cpu);
|
2019-06-05 06:50:44 +08:00
|
|
|
if (access(filename, F_OK) == -1) {
|
2021-11-11 08:21:05 +08:00
|
|
|
scnprintf(filename, MAXPATHLEN, CORE_CPUS_FMT_OLD,
|
2019-06-05 06:50:44 +08:00
|
|
|
sysfs__mountpoint(), cpu);
|
|
|
|
}
|
2019-02-19 17:58:13 +08:00
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (!fp)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (getline(&buf, &len, fp) <= 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
p = strchr(buf, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
2021-11-11 08:21:05 +08:00
|
|
|
for (i = 0; i < tp->core_cpus_lists; i++) {
|
|
|
|
if (!strcmp(buf, tp->core_cpus_list[i]))
|
2019-02-19 17:58:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-11-11 08:21:05 +08:00
|
|
|
if (i == tp->core_cpus_lists) {
|
|
|
|
tp->core_cpus_list[i] = buf;
|
|
|
|
tp->core_cpus_lists++;
|
2019-02-19 17:58:13 +08:00
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
done:
|
|
|
|
if (fp)
|
|
|
|
fclose(fp);
|
|
|
|
free(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_topology__delete(struct cpu_topology *tp)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
if (!tp)
|
|
|
|
return;
|
|
|
|
|
2021-11-11 08:21:03 +08:00
|
|
|
for (i = 0 ; i < tp->package_cpus_lists; i++)
|
|
|
|
zfree(&tp->package_cpus_list[i]);
|
2019-02-19 17:58:13 +08:00
|
|
|
|
2021-11-11 08:21:04 +08:00
|
|
|
for (i = 0 ; i < tp->die_cpus_lists; i++)
|
|
|
|
zfree(&tp->die_cpus_list[i]);
|
2019-06-05 06:50:41 +08:00
|
|
|
|
2021-11-11 08:21:05 +08:00
|
|
|
for (i = 0 ; i < tp->core_cpus_lists; i++)
|
|
|
|
zfree(&tp->core_cpus_list[i]);
|
2019-02-19 17:58:13 +08:00
|
|
|
|
|
|
|
free(tp);
|
|
|
|
}
|
|
|
|
|
2022-09-01 01:49:22 +08:00
|
|
|
bool cpu_topology__smt_on(const struct cpu_topology *topology)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < topology->core_cpus_lists; i++) {
|
|
|
|
const char *cpu_list = topology->core_cpus_list[i];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is a need to separate siblings in a core then SMT is
|
|
|
|
* enabled.
|
|
|
|
*/
|
|
|
|
if (strchr(cpu_list, ',') || strchr(cpu_list, '-'))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-01 01:49:23 +08:00
|
|
|
bool cpu_topology__core_wide(const struct cpu_topology *topology,
|
|
|
|
const char *user_requested_cpu_list)
|
|
|
|
{
|
|
|
|
struct perf_cpu_map *user_requested_cpus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If user_requested_cpu_list is empty then all CPUs are recorded and so
|
|
|
|
* core_wide is true.
|
|
|
|
*/
|
|
|
|
if (!user_requested_cpu_list)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
user_requested_cpus = perf_cpu_map__new(user_requested_cpu_list);
|
|
|
|
/* Check that every user requested CPU is the complete set of SMT threads on a core. */
|
|
|
|
for (u32 i = 0; i < topology->core_cpus_lists; i++) {
|
|
|
|
const char *core_cpu_list = topology->core_cpus_list[i];
|
|
|
|
struct perf_cpu_map *core_cpus = perf_cpu_map__new(core_cpu_list);
|
|
|
|
struct perf_cpu cpu;
|
|
|
|
int idx;
|
|
|
|
bool has_first, first = true;
|
|
|
|
|
|
|
|
perf_cpu_map__for_each_cpu(cpu, idx, core_cpus) {
|
|
|
|
if (first) {
|
|
|
|
has_first = perf_cpu_map__has(user_requested_cpus, cpu);
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If the first core CPU is user requested then
|
|
|
|
* all subsequent CPUs in the core must be user
|
|
|
|
* requested too. If the first CPU isn't user
|
|
|
|
* requested then none of the others must be
|
|
|
|
* too.
|
|
|
|
*/
|
|
|
|
if (perf_cpu_map__has(user_requested_cpus, cpu) != has_first) {
|
|
|
|
perf_cpu_map__put(core_cpus);
|
|
|
|
perf_cpu_map__put(user_requested_cpus);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
perf_cpu_map__put(core_cpus);
|
|
|
|
}
|
|
|
|
perf_cpu_map__put(user_requested_cpus);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-05 06:50:41 +08:00
|
|
|
static bool has_die_topology(void)
|
|
|
|
{
|
|
|
|
char filename[MAXPATHLEN];
|
|
|
|
struct utsname uts;
|
|
|
|
|
|
|
|
if (uname(&uts) < 0)
|
|
|
|
return false;
|
|
|
|
|
2021-11-24 17:03:43 +08:00
|
|
|
if (strncmp(uts.machine, "x86_64", 6) &&
|
|
|
|
strncmp(uts.machine, "s390x", 5))
|
2019-06-05 06:50:41 +08:00
|
|
|
return false;
|
|
|
|
|
2021-11-11 08:21:04 +08:00
|
|
|
scnprintf(filename, MAXPATHLEN, DIE_CPUS_FMT,
|
2019-06-05 06:50:41 +08:00
|
|
|
sysfs__mountpoint(), 0);
|
|
|
|
if (access(filename, F_OK) == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-02-19 17:28:04 +08:00
|
|
|
const struct cpu_topology *online_topology(void)
|
|
|
|
{
|
|
|
|
static const struct cpu_topology *topology;
|
|
|
|
|
|
|
|
if (!topology) {
|
|
|
|
topology = cpu_topology__new();
|
|
|
|
if (!topology) {
|
|
|
|
pr_err("Error creating CPU topology");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return topology;
|
|
|
|
}
|
|
|
|
|
2019-02-19 17:58:13 +08:00
|
|
|
struct cpu_topology *cpu_topology__new(void)
|
|
|
|
{
|
|
|
|
struct cpu_topology *tp = NULL;
|
|
|
|
void *addr;
|
2019-06-05 06:50:41 +08:00
|
|
|
u32 nr, i, nr_addr;
|
2019-02-19 17:58:13 +08:00
|
|
|
size_t sz;
|
|
|
|
long ncpus;
|
|
|
|
int ret = -1;
|
2019-07-21 19:23:49 +08:00
|
|
|
struct perf_cpu_map *map;
|
2019-06-05 06:50:41 +08:00
|
|
|
bool has_die = has_die_topology();
|
2019-02-19 17:58:13 +08:00
|
|
|
|
2022-01-05 14:13:51 +08:00
|
|
|
ncpus = cpu__max_present_cpu().cpu;
|
2019-02-19 17:58:13 +08:00
|
|
|
|
|
|
|
/* build online CPU map */
|
2019-07-21 19:24:30 +08:00
|
|
|
map = perf_cpu_map__new(NULL);
|
2019-02-19 17:58:13 +08:00
|
|
|
if (map == NULL) {
|
|
|
|
pr_debug("failed to get system cpumap\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nr = (u32)(ncpus & UINT_MAX);
|
|
|
|
|
|
|
|
sz = nr * sizeof(char *);
|
2019-06-05 06:50:41 +08:00
|
|
|
if (has_die)
|
|
|
|
nr_addr = 3;
|
|
|
|
else
|
|
|
|
nr_addr = 2;
|
|
|
|
addr = calloc(1, sizeof(*tp) + nr_addr * sz);
|
2019-02-19 17:58:13 +08:00
|
|
|
if (!addr)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
tp = addr;
|
|
|
|
addr += sizeof(*tp);
|
2021-11-11 08:21:03 +08:00
|
|
|
tp->package_cpus_list = addr;
|
2019-02-19 17:58:13 +08:00
|
|
|
addr += sz;
|
2019-06-05 06:50:41 +08:00
|
|
|
if (has_die) {
|
2021-11-11 08:21:04 +08:00
|
|
|
tp->die_cpus_list = addr;
|
2019-06-05 06:50:41 +08:00
|
|
|
addr += sz;
|
|
|
|
}
|
2021-11-11 08:21:05 +08:00
|
|
|
tp->core_cpus_list = addr;
|
2019-02-19 17:58:13 +08:00
|
|
|
|
|
|
|
for (i = 0; i < nr; i++) {
|
2022-01-05 14:13:51 +08:00
|
|
|
if (!perf_cpu_map__has(map, (struct perf_cpu){ .cpu = i }))
|
2019-02-19 17:58:13 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = build_cpu_topology(tp, i);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_free:
|
2019-07-21 19:24:17 +08:00
|
|
|
perf_cpu_map__put(map);
|
2019-02-19 17:58:13 +08:00
|
|
|
if (ret) {
|
|
|
|
cpu_topology__delete(tp);
|
|
|
|
tp = NULL;
|
|
|
|
}
|
|
|
|
return tp;
|
|
|
|
}
|
2019-02-19 17:58:14 +08:00
|
|
|
|
|
|
|
static int load_numa_node(struct numa_topology_node *node, int nr)
|
|
|
|
{
|
|
|
|
char str[MAXPATHLEN];
|
|
|
|
char field[32];
|
|
|
|
char *buf = NULL, *p;
|
|
|
|
size_t len = 0;
|
|
|
|
int ret = -1;
|
|
|
|
FILE *fp;
|
|
|
|
u64 mem;
|
|
|
|
|
|
|
|
node->node = (u32) nr;
|
|
|
|
|
2019-02-19 17:58:15 +08:00
|
|
|
scnprintf(str, MAXPATHLEN, NODE_MEMINFO_FMT,
|
|
|
|
sysfs__mountpoint(), nr);
|
2019-02-19 17:58:14 +08:00
|
|
|
fp = fopen(str, "r");
|
|
|
|
if (!fp)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (getline(&buf, &len, fp) > 0) {
|
|
|
|
/* skip over invalid lines */
|
|
|
|
if (!strchr(buf, ':'))
|
|
|
|
continue;
|
|
|
|
if (sscanf(buf, "%*s %*d %31s %"PRIu64, field, &mem) != 2)
|
|
|
|
goto err;
|
|
|
|
if (!strcmp(field, "MemTotal:"))
|
|
|
|
node->mem_total = mem;
|
|
|
|
if (!strcmp(field, "MemFree:"))
|
|
|
|
node->mem_free = mem;
|
|
|
|
if (node->mem_total && node->mem_free)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
fp = NULL;
|
|
|
|
|
2019-02-19 17:58:15 +08:00
|
|
|
scnprintf(str, MAXPATHLEN, NODE_CPULIST_FMT,
|
|
|
|
sysfs__mountpoint(), nr);
|
2019-02-19 17:58:14 +08:00
|
|
|
|
|
|
|
fp = fopen(str, "r");
|
|
|
|
if (!fp)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (getline(&buf, &len, fp) <= 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
p = strchr(buf, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
node->cpus = buf;
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
free(buf);
|
|
|
|
if (fp)
|
|
|
|
fclose(fp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct numa_topology *numa_topology__new(void)
|
|
|
|
{
|
2019-07-21 19:23:49 +08:00
|
|
|
struct perf_cpu_map *node_map = NULL;
|
2019-02-19 17:58:14 +08:00
|
|
|
struct numa_topology *tp = NULL;
|
2019-02-19 17:58:15 +08:00
|
|
|
char path[MAXPATHLEN];
|
2019-02-19 17:58:14 +08:00
|
|
|
char *buf = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
u32 nr, i;
|
|
|
|
FILE *fp;
|
|
|
|
char *c;
|
|
|
|
|
2019-02-19 17:58:15 +08:00
|
|
|
scnprintf(path, MAXPATHLEN, NODE_ONLINE_FMT,
|
|
|
|
sysfs__mountpoint());
|
|
|
|
|
|
|
|
fp = fopen(path, "r");
|
2019-02-19 17:58:14 +08:00
|
|
|
if (!fp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (getline(&buf, &len, fp) <= 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
c = strchr(buf, '\n');
|
|
|
|
if (c)
|
|
|
|
*c = '\0';
|
|
|
|
|
2019-07-21 19:24:30 +08:00
|
|
|
node_map = perf_cpu_map__new(buf);
|
2019-02-19 17:58:14 +08:00
|
|
|
if (!node_map)
|
|
|
|
goto out;
|
|
|
|
|
2022-01-22 12:58:10 +08:00
|
|
|
nr = (u32) perf_cpu_map__nr(node_map);
|
2019-02-19 17:58:14 +08:00
|
|
|
|
|
|
|
tp = zalloc(sizeof(*tp) + sizeof(tp->nodes[0])*nr);
|
|
|
|
if (!tp)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
tp->nr = nr;
|
|
|
|
|
|
|
|
for (i = 0; i < nr; i++) {
|
2022-01-22 12:58:10 +08:00
|
|
|
if (load_numa_node(&tp->nodes[i], perf_cpu_map__cpu(node_map, i).cpu)) {
|
2019-02-19 17:58:14 +08:00
|
|
|
numa_topology__delete(tp);
|
|
|
|
tp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(buf);
|
|
|
|
fclose(fp);
|
2019-07-21 19:24:17 +08:00
|
|
|
perf_cpu_map__put(node_map);
|
2019-02-19 17:58:14 +08:00
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void numa_topology__delete(struct numa_topology *tp)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < tp->nr; i++)
|
2019-07-04 23:06:20 +08:00
|
|
|
zfree(&tp->nodes[i].cpus);
|
2019-02-19 17:58:14 +08:00
|
|
|
|
|
|
|
free(tp);
|
|
|
|
}
|
2021-05-14 20:29:47 +08:00
|
|
|
|
|
|
|
static int load_hybrid_node(struct hybrid_topology_node *node,
|
|
|
|
struct perf_pmu *pmu)
|
|
|
|
{
|
|
|
|
char *buf = NULL, *p;
|
|
|
|
FILE *fp;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
node->pmu_name = strdup(pmu->name);
|
|
|
|
if (!node->pmu_name)
|
|
|
|
return -1;
|
|
|
|
|
2023-01-20 22:36:55 +08:00
|
|
|
fp = perf_pmu__open_file(pmu, "cpus");
|
2021-05-14 20:29:47 +08:00
|
|
|
if (!fp)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (getline(&buf, &len, fp) <= 0) {
|
|
|
|
fclose(fp);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = strchr(buf, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
node->cpus = buf;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
zfree(&node->pmu_name);
|
|
|
|
free(buf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hybrid_topology *hybrid_topology__new(void)
|
|
|
|
{
|
2023-05-27 15:21:54 +08:00
|
|
|
struct perf_pmu *pmu = NULL;
|
2021-05-14 20:29:47 +08:00
|
|
|
struct hybrid_topology *tp = NULL;
|
2023-05-27 15:21:54 +08:00
|
|
|
u32 nr = 0, i = 0;
|
2021-05-14 20:29:47 +08:00
|
|
|
|
2023-05-27 15:22:03 +08:00
|
|
|
if (!perf_pmus__has_hybrid())
|
2023-05-27 15:21:54 +08:00
|
|
|
return NULL;
|
|
|
|
|
2023-05-27 15:22:05 +08:00
|
|
|
while ((pmu = perf_pmus__scan_core(pmu)) != NULL)
|
|
|
|
nr++;
|
|
|
|
|
2021-05-14 20:29:47 +08:00
|
|
|
if (nr == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tp = zalloc(sizeof(*tp) + sizeof(tp->nodes[0]) * nr);
|
|
|
|
if (!tp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tp->nr = nr;
|
2023-05-27 15:22:05 +08:00
|
|
|
while ((pmu = perf_pmus__scan_core(pmu)) != NULL) {
|
2021-05-14 20:29:47 +08:00
|
|
|
if (load_hybrid_node(&tp->nodes[i], pmu)) {
|
|
|
|
hybrid_topology__delete(tp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hybrid_topology__delete(struct hybrid_topology *tp)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < tp->nr; i++) {
|
|
|
|
zfree(&tp->nodes[i].pmu_name);
|
|
|
|
zfree(&tp->nodes[i].cpus);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(tp);
|
|
|
|
}
|