aboutsummaryrefslogtreecommitdiff
path: root/tools/power
diff options
context:
space:
mode:
authorZhang Rui2022-08-20 23:58:26 +0800
committerSrinivas Pandruvada2022-09-15 11:16:06 -0700
commitca56725d78c5241f65cc565e5a865f45d943dc04 (patch)
treed967cfaf2eb5d45fb7787e2b31d37f990362a6a3 /tools/power
parenta05b925ace3ea977fdadb32c969c22ef51029ee7 (diff)
tools/power/x86/intel-speed-select: Utilize cpu_map to get physical id
cpu_map already has the cpu package id, die id information. Thus there is no need to re-evaluating sysfs attributes or stored data file to get the package id and die id of a given CPU each time. In order to unitlize this, cpu_map needs to be created unconditionally. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/x86/intel-speed-select/isst-config.c47
1 files changed, 36 insertions, 11 deletions
diff --git a/tools/power/x86/intel-speed-select/isst-config.c b/tools/power/x86/intel-speed-select/isst-config.c
index 946ed38c4f59..361061617ab3 100644
--- a/tools/power/x86/intel-speed-select/isst-config.c
+++ b/tools/power/x86/intel-speed-select/isst-config.c
@@ -63,6 +63,7 @@ struct _cpu_map {
unsigned short die_id;
unsigned short punit_cpu;
unsigned short punit_cpu_core;
+ unsigned short initialized;
};
struct _cpu_map *cpu_map;
@@ -302,6 +303,12 @@ static int get_physical_package_id(int cpu)
{
int ret;
+ if (cpu < 0)
+ return -1;
+
+ if (cpu_map && cpu_map[cpu].initialized)
+ return cpu_map[cpu].pkg_id;
+
ret = parse_int_file(0,
"/sys/devices/system/cpu/cpu%d/topology/physical_package_id",
cpu);
@@ -320,6 +327,12 @@ static int get_physical_core_id(int cpu)
{
int ret;
+ if (cpu < 0)
+ return -1;
+
+ if (cpu_map && cpu_map[cpu].initialized)
+ return cpu_map[cpu].core_id;
+
ret = parse_int_file(0,
"/sys/devices/system/cpu/cpu%d/topology/core_id",
cpu);
@@ -338,6 +351,12 @@ static int get_physical_die_id(int cpu)
{
int ret;
+ if (cpu < 0)
+ return -1;
+
+ if (cpu_map && cpu_map[cpu].initialized)
+ return cpu_map[cpu].die_id;
+
ret = parse_int_file(0,
"/sys/devices/system/cpu/cpu%d/topology/die_id",
cpu);
@@ -648,21 +667,28 @@ static void create_cpu_map(void)
int i, fd = 0;
struct isst_if_cpu_maps map;
- cpu_map = malloc(sizeof(*cpu_map) * topo_max_cpus);
+ /* Use calloc to make sure the memory is initialized to Zero */
+ cpu_map = calloc(topo_max_cpus, sizeof(*cpu_map));
if (!cpu_map)
err(3, "cpumap");
fd = open(pathname, O_RDWR);
- if (fd < 0)
+ if (fd < 0 && !is_clx_n_platform())
err(-1, "%s open failed", pathname);
for (i = 0; i < topo_max_cpus; ++i) {
if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
continue;
+ cpu_map[i].core_id = get_physical_core_id(i);
+ cpu_map[i].pkg_id = get_physical_package_id(i);
+ cpu_map[i].die_id = get_physical_die_id(i);
+ cpu_map[i].initialized = 1;
+
+ if (fd < 0)
+ continue;
map.cmd_count = 1;
map.cpu_map[0].logical_cpu = i;
-
debug_printf(" map logical_cpu:%d\n",
map.cpu_map[0].logical_cpu);
if (ioctl(fd, ISST_IF_GET_PHY_ID, &map) == -1) {
@@ -671,9 +697,6 @@ static void create_cpu_map(void)
map.cpu_map[0].logical_cpu);
continue;
}
- cpu_map[i].core_id = get_physical_core_id(i);
- cpu_map[i].pkg_id = get_physical_package_id(i);
- cpu_map[i].die_id = get_physical_die_id(i);
cpu_map[i].punit_cpu = map.cpu_map[0].physical_cpu;
cpu_map[i].punit_cpu_core = (map.cpu_map[0].physical_cpu >>
1); // shift to get core id
@@ -685,7 +708,7 @@ static void create_cpu_map(void)
cpu_map[i].punit_cpu_core);
}
- if (fd)
+ if (fd >= 0)
close(fd);
}
@@ -1014,6 +1037,11 @@ static void isst_print_platform_information(void)
exit(0);
}
+ /* Early initialization to create working cpu_map */
+ set_max_cpu_num();
+ set_cpu_present_cpu_mask();
+ create_cpu_map();
+
fd = open(pathname, O_RDWR);
if (fd < 0)
err(-1, "%s open failed", pathname);
@@ -2744,9 +2772,6 @@ void process_command(int argc, char **argv,
}
}
- if (!is_clx_n_platform())
- create_cpu_map();
-
i = 0;
while (cmds[i].feature) {
if (!strcmp(cmds[i].feature, feature) &&
@@ -2952,9 +2977,9 @@ static void cmdline(int argc, char **argv)
store_cpu_topology();
set_cpu_present_cpu_mask();
set_cpu_target_cpu_mask();
+ create_cpu_map();
if (oob_mode) {
- create_cpu_map();
if (debug_flag)
fprintf(stderr, "OOB mode is enabled in debug mode\n");