aboutsummaryrefslogtreecommitdiffstats
path: root/tools/power/x86/intel-speed-select
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tools/power/x86/intel-speed-select/Build2
-rw-r--r--tools/power/x86/intel-speed-select/Makefile14
-rw-r--r--tools/power/x86/intel-speed-select/hfi-events.c312
-rw-r--r--tools/power/x86/intel-speed-select/isst-config.c567
-rw-r--r--tools/power/x86/intel-speed-select/isst-core.c313
-rw-r--r--tools/power/x86/intel-speed-select/isst-daemon.c242
-rw-r--r--tools/power/x86/intel-speed-select/isst-display.c76
-rw-r--r--tools/power/x86/intel-speed-select/isst.h97
8 files changed, 1098 insertions, 525 deletions
diff --git a/tools/power/x86/intel-speed-select/Build b/tools/power/x86/intel-speed-select/Build
index b61456d75190..81e36bd578b1 100644
--- a/tools/power/x86/intel-speed-select/Build
+++ b/tools/power/x86/intel-speed-select/Build
@@ -1 +1 @@
-intel-speed-select-y += isst-config.o isst-core.o isst-display.o
+intel-speed-select-y += isst-config.o isst-core.o isst-display.o isst-daemon.o hfi-events.o
diff --git a/tools/power/x86/intel-speed-select/Makefile b/tools/power/x86/intel-speed-select/Makefile
index 12c6939dca2a..7221f2f55e8b 100644
--- a/tools/power/x86/intel-speed-select/Makefile
+++ b/tools/power/x86/intel-speed-select/Makefile
@@ -13,8 +13,8 @@ endif
# Do not use make's built-in rules
# (this improves performance and avoids hard-to-debug behaviour);
MAKEFLAGS += -r
-
-override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
+override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include -I/usr/include/libnl3
+override LDFLAGS += -lnl-genl-3 -lnl-3
ALL_TARGETS := intel-speed-select
ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
@@ -31,19 +31,23 @@ $(OUTPUT)include/linux/isst_if.h: ../../../../include/uapi/linux/isst_if.h
mkdir -p $(OUTPUT)include/linux 2>&1 || true
ln -sf $(CURDIR)/../../../../include/uapi/linux/isst_if.h $@
-prepare: $(OUTPUT)include/linux/isst_if.h
+$(OUTPUT)include/linux/thermal.h: ../../../../include/uapi/linux/thermal.h
+ mkdir -p $(OUTPUT)include/linux 2>&1 || true
+ ln -sf $(CURDIR)/../../../../include/uapi/linux/thermal.h $@
+
+prepare: $(OUTPUT)include/linux/isst_if.h $(OUTPUT)include/linux/thermal.h
ISST_IN := $(OUTPUT)intel-speed-select-in.o
$(ISST_IN): prepare FORCE
$(Q)$(MAKE) $(build)=intel-speed-select
$(OUTPUT)intel-speed-select: $(ISST_IN)
- $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
+ $(QUIET_LINK)$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
clean:
rm -f $(ALL_PROGRAMS)
rm -rf $(OUTPUT)include/linux/isst_if.h
- find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
+ find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
install: $(ALL_PROGRAMS)
install -d -m 755 $(DESTDIR)$(bindir); \
diff --git a/tools/power/x86/intel-speed-select/hfi-events.c b/tools/power/x86/intel-speed-select/hfi-events.c
new file mode 100644
index 000000000000..be96e90cc2a1
--- /dev/null
+++ b/tools/power/x86/intel-speed-select/hfi-events.c
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Speed Select -- Read HFI events for OOB
+ * Copyright (c) 2022 Intel Corporation.
+ */
+
+/*
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+
+ * WPA Supplicant - driver interaction with Linux nl80211/cfg80211
+ * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of
+ * BSD license.
+ *
+ * Requires
+ * libnl-genl-3-dev
+ *
+ * For Fedora/CenOS
+ * dnf install libnl3-devel
+ * For Ubuntu
+ * apt install libnl-3-dev libnl-genl-3-dev
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <getopt.h>
+#include <signal.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+
+#include <linux/thermal.h>
+#include "isst.h"
+
+struct hfi_event_data {
+ struct nl_sock *nl_handle;
+ struct nl_cb *nl_cb;
+};
+
+struct hfi_event_data drv;
+
+static int ack_handler(struct nl_msg *msg, void *arg)
+{
+ int *err = arg;
+ *err = 0;
+ return NL_STOP;
+}
+
+static int finish_handler(struct nl_msg *msg, void *arg)
+{
+ int *ret = arg;
+ *ret = 0;
+ return NL_SKIP;
+}
+
+static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
+ void *arg)
+{
+ int *ret = arg;
+ *ret = err->error;
+ return NL_SKIP;
+}
+
+static int seq_check_handler(struct nl_msg *msg, void *arg)
+{
+ return NL_OK;
+}
+
+static int send_and_recv_msgs(struct hfi_event_data *drv,
+ struct nl_msg *msg,
+ int (*valid_handler)(struct nl_msg *, void *),
+ void *valid_data)
+{
+ struct nl_cb *cb;
+ int err = -ENOMEM;
+
+ cb = nl_cb_clone(drv->nl_cb);
+ if (!cb)
+ goto out;
+
+ err = nl_send_auto_complete(drv->nl_handle, msg);
+ if (err < 0)
+ goto out;
+
+ err = 1;
+
+ nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
+ nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
+ nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
+
+ if (valid_handler)
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
+ valid_handler, valid_data);
+
+ while (err > 0)
+ nl_recvmsgs(drv->nl_handle, cb);
+ out:
+ nl_cb_put(cb);
+ nlmsg_free(msg);
+ return err;
+}
+
+struct family_data {
+ const char *group;
+ int id;
+};
+
+static int family_handler(struct nl_msg *msg, void *arg)
+{
+ struct family_data *res = arg;
+ struct nlattr *tb[CTRL_ATTR_MAX + 1];
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ struct nlattr *mcgrp;
+ int i;
+
+ nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL);
+ if (!tb[CTRL_ATTR_MCAST_GROUPS])
+ return NL_SKIP;
+
+ nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
+ struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
+ nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
+ nla_len(mcgrp), NULL);
+ if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
+ !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
+ strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
+ res->group,
+ nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
+ continue;
+ res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
+ break;
+ }
+
+ return 0;
+}
+
+static int nl_get_multicast_id(struct hfi_event_data *drv,
+ const char *family, const char *group)
+{
+ struct nl_msg *msg;
+ int ret = -1;
+ struct family_data res = { group, -ENOENT };
+
+ msg = nlmsg_alloc();
+ if (!msg)
+ return -ENOMEM;
+ genlmsg_put(msg, 0, 0, genl_ctrl_resolve(drv->nl_handle, "nlctrl"),
+ 0, 0, CTRL_CMD_GETFAMILY, 0);
+ NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family);
+
+ ret = send_and_recv_msgs(drv, msg, family_handler, &res);
+ msg = NULL;
+ if (ret == 0)
+ ret = res.id;
+
+nla_put_failure:
+ nlmsg_free(msg);
+ return ret;
+}
+
+struct perf_cap {
+ int cpu;
+ int perf;
+ int eff;
+};
+
+static void process_hfi_event(struct perf_cap *perf_cap)
+{
+ struct isst_id id;
+
+ set_isst_id(&id, perf_cap->cpu);
+ process_level_change(&id);
+}
+
+static int handle_event(struct nl_msg *n, void *arg)
+{
+ struct nlmsghdr *nlh = nlmsg_hdr(n);
+ struct genlmsghdr *genlhdr = genlmsg_hdr(nlh);
+ struct nlattr *attrs[THERMAL_GENL_ATTR_MAX + 1];
+ int ret;
+ struct perf_cap perf_cap = {0};
+
+ ret = genlmsg_parse(nlh, 0, attrs, THERMAL_GENL_ATTR_MAX, NULL);
+
+ debug_printf("Received event %d parse_rer:%d\n", genlhdr->cmd, ret);
+ if (genlhdr->cmd == THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE) {
+ struct nlattr *cap;
+ int j, index = 0;
+
+ debug_printf("THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE\n");
+ nla_for_each_nested(cap, attrs[THERMAL_GENL_ATTR_CPU_CAPABILITY], j) {
+ switch (index) {
+ case 0:
+ perf_cap.cpu = nla_get_u32(cap);
+ break;
+ case 1:
+ perf_cap.perf = nla_get_u32(cap);
+ break;
+ case 2:
+ perf_cap.eff = nla_get_u32(cap);
+ break;
+ default:
+ break;
+ }
+ ++index;
+ if (index == 3) {
+ index = 0;
+ process_hfi_event(&perf_cap);
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int _hfi_exit;
+
+static int check_hf_suport(void)
+{
+ unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
+
+ __cpuid(6, eax, ebx, ecx, edx);
+ if (eax & BIT(19))
+ return 1;
+
+ return 0;
+}
+
+int hfi_main(void)
+{
+ struct nl_sock *sock;
+ struct nl_cb *cb;
+ int err = 0;
+ int mcast_id;
+ int no_block = 0;
+
+ if (!check_hf_suport()) {
+ fprintf(stderr, "CPU Doesn't support HFI\n");
+ return -1;
+ }
+
+ sock = nl_socket_alloc();
+ if (!sock) {
+ fprintf(stderr, "nl_socket_alloc failed\n");
+ return -1;
+ }
+
+ if (genl_connect(sock)) {
+ fprintf(stderr, "genl_connect(sk_event) failed\n");
+ goto free_sock;
+ }
+
+ drv.nl_handle = sock;
+ drv.nl_cb = cb = nl_cb_alloc(NL_CB_DEFAULT);
+ if (drv.nl_cb == NULL) {
+ printf("Failed to allocate netlink callbacks");
+ goto free_sock;
+ }
+
+ mcast_id = nl_get_multicast_id(&drv, THERMAL_GENL_FAMILY_NAME,
+ THERMAL_GENL_EVENT_GROUP_NAME);
+ if (mcast_id < 0) {
+ fprintf(stderr, "nl_get_multicast_id failed\n");
+ goto free_sock;
+ }
+
+ if (nl_socket_add_membership(sock, mcast_id)) {
+ fprintf(stderr, "nl_socket_add_membership failed");
+ goto free_sock;
+ }
+
+ nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, seq_check_handler, 0);
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, handle_event, NULL);
+
+ if (no_block)
+ nl_socket_set_nonblocking(sock);
+
+ debug_printf("hfi is initialized\n");
+
+ while (!_hfi_exit && !err) {
+ err = nl_recvmsgs(sock, cb);
+ debug_printf("nl_recv_message err:%d\n", err);
+ }
+
+ return 0;
+
+ /* Netlink library doesn't have calls to dealloc cb or disconnect */
+free_sock:
+ nl_socket_free(sock);
+
+ return -1;
+}
+
+void hfi_exit(void)
+{
+ _hfi_exit = 1;
+}
diff --git a/tools/power/x86/intel-speed-select/isst-config.c b/tools/power/x86/intel-speed-select/isst-config.c
index bf9fd3549a1d..a160bad291eb 100644
--- a/tools/power/x86/intel-speed-select/isst-config.c
+++ b/tools/power/x86/intel-speed-select/isst-config.c
@@ -15,7 +15,8 @@ struct process_cmd_struct {
int arg;
};
-static const char *version_str = "v1.10";
+static const char *version_str = "v1.13";
+
static const int supported_api_ver = 1;
static struct isst_if_platform_info isst_platform_info;
static char *progname;
@@ -62,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;
@@ -297,10 +299,16 @@ static void store_cpu_topology(void)
fclose(fp);
}
-int get_physical_package_id(int cpu)
+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);
@@ -315,10 +323,16 @@ int get_physical_package_id(int cpu)
return ret;
}
-int get_physical_core_id(int cpu)
+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);
@@ -333,10 +347,16 @@ int get_physical_core_id(int cpu)
return ret;
}
-int get_physical_die_id(int cpu)
+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);
@@ -358,6 +378,31 @@ int get_physical_die_id(int cpu)
return ret;
}
+void set_isst_id(struct isst_id *id, int cpu)
+{
+ id->cpu = cpu;
+
+ id->pkg = get_physical_package_id(cpu);
+ if (id < 0 || id->pkg >= MAX_PACKAGE_COUNT)
+ id->pkg = -1;
+
+ id->die = get_physical_die_id(cpu);
+ if (id < 0 || id->die >= MAX_DIE_PER_PACKAGE)
+ id->die = -1;
+}
+
+int is_cpu_in_power_domain(int cpu, struct isst_id *id)
+{
+ struct isst_id tid;
+
+ set_isst_id(&tid, cpu);
+
+ if (id->pkg == tid.pkg && id->die == tid.die)
+ return 1;
+
+ return 0;
+}
+
int get_cpufreq_base_freq(int cpu)
{
return parse_int_file(0, "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency", cpu);
@@ -368,7 +413,7 @@ int get_topo_max_cpus(void)
return topo_max_cpus;
}
-static void set_cpu_online_offline(int cpu, int state)
+void set_cpu_online_offline(int cpu, int state)
{
char buffer[128];
int fd, ret;
@@ -409,15 +454,14 @@ static void force_all_cpus_online(void)
unlink("/var/run/isst_cpu_topology.dat");
}
-#define MAX_PACKAGE_COUNT 8
-#define MAX_DIE_PER_PACKAGE 2
-static void for_each_online_package_in_set(void (*callback)(int, void *, void *,
- void *, void *),
- void *arg1, void *arg2, void *arg3,
- void *arg4)
+void for_each_online_package_in_set(void (*callback)(struct isst_id *, void *, void *,
+ void *, void *),
+ void *arg1, void *arg2, void *arg3,
+ void *arg4)
{
int max_packages[MAX_PACKAGE_COUNT * MAX_PACKAGE_COUNT];
int pkg_index = 0, i;
+ struct isst_id id;
memset(max_packages, 0xff, sizeof(max_packages));
for (i = 0; i < topo_max_cpus; ++i) {
@@ -451,18 +495,20 @@ static void for_each_online_package_in_set(void (*callback)(int, void *, void *,
}
}
+ set_isst_id(&id, i);
if (!skip && online && callback) {
- callback(i, arg1, arg2, arg3, arg4);
+ callback(&id, arg1, arg2, arg3, arg4);
max_packages[pkg_index++] = pkg_id;
}
}
}
static void for_each_online_target_cpu_in_set(
- void (*callback)(int, void *, void *, void *, void *), void *arg1,
+ void (*callback)(struct isst_id *, void *, void *, void *, void *), void *arg1,
void *arg2, void *arg3, void *arg4)
{
int i, found = 0;
+ struct isst_id id;
for (i = 0; i < topo_max_cpus; ++i) {
int online;
@@ -476,8 +522,9 @@ static void for_each_online_target_cpu_in_set(
online =
1; /* online entry for CPU 0 needs some special configs */
+ set_isst_id(&id, i);
if (online && callback) {
- callback(i, arg1, arg2, arg3, arg4);
+ callback(&id, arg1, arg2, arg3, arg4);
found = 1;
}
}
@@ -537,47 +584,8 @@ void free_cpu_set(cpu_set_t *cpu_set)
}
static int cpu_cnt[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
-static long long core_mask[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
-static void set_cpu_present_cpu_mask(void)
-{
- size_t size;
- DIR *dir;
- int i;
-
- size = alloc_cpu_set(&present_cpumask);
- present_cpumask_size = size;
- for (i = 0; i < topo_max_cpus; ++i) {
- char buffer[256];
- snprintf(buffer, sizeof(buffer),
- "/sys/devices/system/cpu/cpu%d", i);
- dir = opendir(buffer);
- if (dir) {
- int pkg_id, die_id;
-
- CPU_SET_S(i, size, present_cpumask);
- die_id = get_physical_die_id(i);
- if (die_id < 0)
- die_id = 0;
-
- pkg_id = get_physical_package_id(i);
- if (pkg_id < 0) {
- fprintf(stderr, "Failed to get package id, CPU %d may be offline\n", i);
- continue;
- }
- if (pkg_id < MAX_PACKAGE_COUNT &&
- die_id < MAX_DIE_PER_PACKAGE) {
- int core_id = get_physical_core_id(i);
-
- cpu_cnt[pkg_id][die_id]++;
- core_mask[pkg_id][die_id] |= (1ULL << core_id);
- }
- }
- closedir(dir);
- }
-}
-
-int get_max_punit_core_id(int pkg_id, int die_id)
+int get_max_punit_core_id(struct isst_id *id)
{
int max_id = 0;
int i;
@@ -587,60 +595,74 @@ int get_max_punit_core_id(int pkg_id, int die_id)
if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
continue;
- if (cpu_map[i].pkg_id == pkg_id &&
- cpu_map[i].die_id == die_id &&
- cpu_map[i].punit_cpu_core > max_id)
+ if (is_cpu_in_power_domain(i, id) &&
+ cpu_map[i].punit_cpu_core > max_id)
max_id = cpu_map[i].punit_cpu_core;
}
return max_id;
}
-int get_cpu_count(int pkg_id, int die_id)
+int get_cpu_count(struct isst_id *id)
{
- if (pkg_id < MAX_PACKAGE_COUNT && die_id < MAX_DIE_PER_PACKAGE)
- return cpu_cnt[pkg_id][die_id];
+ if (id->pkg < 0 || id->die < 0)
+ return 0;
- return 0;
-}
-
-static void set_cpu_target_cpu_mask(void)
-{
- size_t size;
- int i;
-
- size = alloc_cpu_set(&target_cpumask);
- target_cpumask_size = size;
- for (i = 0; i < max_target_cpus; ++i) {
- if (!CPU_ISSET_S(target_cpus[i], present_cpumask_size,
- present_cpumask))
- continue;
-
- CPU_SET_S(target_cpus[i], size, target_cpumask);
- }
+ return cpu_cnt[id->pkg][id->die];
}
static void create_cpu_map(void)
{
const char *pathname = "/dev/isst_interface";
+ size_t size;
+ DIR *dir;
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);
+ size = alloc_cpu_set(&present_cpumask);
+ present_cpumask_size = size;
+
for (i = 0; i < topo_max_cpus; ++i) {
- if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
+ char buffer[256];
+ int pkg_id, die_id, core_id;
+
+ /* check if CPU is online */
+ snprintf(buffer, sizeof(buffer),
+ "/sys/devices/system/cpu/cpu%d", i);
+ dir = opendir(buffer);
+ if (!dir)
continue;
+ closedir(dir);
+ CPU_SET_S(i, size, present_cpumask);
+
+ pkg_id = get_physical_package_id(i);
+ die_id = get_physical_die_id(i);
+ core_id = get_physical_core_id(i);
+
+ if (pkg_id < 0 || die_id < 0 || core_id < 0)
+ continue;
+
+ cpu_map[i].pkg_id = pkg_id;
+ cpu_map[i].die_id = die_id;
+ cpu_map[i].core_id = core_id;
+ cpu_map[i].initialized = 1;
+
+ cpu_cnt[pkg_id][die_id]++;
+
+ 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) {
@@ -649,9 +671,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
@@ -662,35 +681,27 @@ static void create_cpu_map(void)
cpu_map[i].pkg_id, cpu_map[i].punit_cpu,
cpu_map[i].punit_cpu_core);
}
-
- if (fd)
+ if (fd >= 0)
close(fd);
-}
-int find_logical_cpu(int pkg_id, int die_id, int punit_core_id)
-{
- int i;
+ size = alloc_cpu_set(&target_cpumask);
+ target_cpumask_size = size;
+ for (i = 0; i < max_target_cpus; ++i) {
+ if (!CPU_ISSET_S(target_cpus[i], present_cpumask_size,
+ present_cpumask))
+ continue;
- for (i = 0; i < topo_max_cpus; ++i) {
- if (cpu_map[i].pkg_id == pkg_id &&
- cpu_map[i].die_id == die_id &&
- cpu_map[i].punit_cpu_core == punit_core_id)
- return i;
+ CPU_SET_S(target_cpus[i], size, target_cpumask);
}
-
- return -EINVAL;
}
-void set_cpu_mask_from_punit_coremask(int cpu, unsigned long long core_mask,
+void set_cpu_mask_from_punit_coremask(struct isst_id *id, unsigned long long core_mask,
size_t core_cpumask_size,
cpu_set_t *core_cpumask, int *cpu_cnt)
{
int i, cnt = 0;
- int die_id, pkg_id;
*cpu_cnt = 0;
- die_id = get_physical_die_id(cpu);
- pkg_id = get_physical_package_id(cpu);
for (i = 0; i < 64; ++i) {
if (core_mask & BIT_ULL(i)) {
@@ -700,8 +711,7 @@ void set_cpu_mask_from_punit_coremask(int cpu, unsigned long long core_mask,
if (!CPU_ISSET_S(j, present_cpumask_size, present_cpumask))
continue;
- if (cpu_map[j].pkg_id == pkg_id &&
- cpu_map[j].die_id == die_id &&
+ if (is_cpu_in_power_domain(j, id) &&
cpu_map[j].punit_cpu_core == i) {
CPU_SET_S(j, core_cpumask_size,
core_cpumask);
@@ -932,6 +942,7 @@ static void isst_print_extended_platform_info(void)
struct isst_pkg_ctdp pkg_dev;
int ret, i, j;
FILE *filep;
+ struct isst_id id;
for (i = 0; i < 256; ++i) {
char path[256];
@@ -948,7 +959,8 @@ static void isst_print_extended_platform_info(void)
fclose(filep);
- ret = isst_get_ctdp_levels(i, &pkg_dev);
+ set_isst_id(&id, i);
+ ret = isst_get_ctdp_levels(&id, &pkg_dev);
if (ret)
return;
@@ -965,7 +977,7 @@ static void isst_print_extended_platform_info(void)
fprintf(outf, "TDP level change control is unlocked, max level: %d \n", pkg_dev.levels);
for (j = 0; j <= pkg_dev.levels; ++j) {
- ret = isst_get_ctdp_control(i, j, &ctdp_level);
+ ret = isst_get_ctdp_control(&id, j, &ctdp_level);
if (ret)
continue;
@@ -986,7 +998,7 @@ static void isst_print_extended_platform_info(void)
else
fprintf(outf, "Intel(R) SST-BF (feature base-freq) is not supported\n");
- ret = isst_read_pm_config(i, &cp_state, &cp_cap);
+ ret = isst_read_pm_config(&id, &cp_state, &cp_cap);
if (ret) {
fprintf(outf, "Intel(R) SST-CP (feature core-power) status is unknown\n");
return;
@@ -1008,6 +1020,10 @@ static void isst_print_platform_information(void)
exit(0);
}
+ /* Early initialization to create working cpu_map */
+ set_max_cpu_num();
+ create_cpu_map();
+
fd = open(pathname, O_RDWR);
if (fd < 0)
err(-1, "%s open failed", pathname);
@@ -1032,18 +1048,18 @@ static void isst_print_platform_information(void)
}
static char *local_str0, *local_str1;
-static void exec_on_get_ctdp_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void exec_on_get_ctdp_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
- int (*fn_ptr)(int cpu, void *arg);
+ int (*fn_ptr)(struct isst_id *id, void *arg);
int ret;
fn_ptr = arg1;
- ret = fn_ptr(cpu, arg2);
+ ret = fn_ptr(id, arg2);
if (ret)
isst_display_error_info_message(1, "get_tdp_* failed", 0, 0);
else
- isst_ctdp_display_core_info(cpu, outf, arg3,
+ isst_ctdp_display_core_info(id, outf, arg3,
*(unsigned int *)arg4,
local_str0, local_str1);
}
@@ -1111,9 +1127,9 @@ static int clx_n_get_base_ratio(void)
return (int)(value);
}
-static int clx_n_config(int cpu)
+static int clx_n_config(struct isst_id *id)
{
- int i, ret, pkg_id, die_id;
+ int i, ret;
unsigned long cpu_bf;
struct isst_pkg_ctdp_level_info *ctdp_level;
struct isst_pbf_info *pbf_info;
@@ -1135,15 +1151,11 @@ static int clx_n_config(int cpu)
pbf_info->p1_high = 0;
pbf_info->p1_low = ~0;
- pkg_id = get_physical_package_id(cpu);
- die_id = get_physical_die_id(cpu);
-
for (i = 0; i < topo_max_cpus; i++) {
if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
continue;
- if (pkg_id != get_physical_package_id(i) ||
- die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
CPU_SET_S(i, ctdp_level->core_cpumask_size,
@@ -1180,8 +1192,7 @@ static int clx_n_config(int cpu)
if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
continue;
- if (pkg_id != get_physical_package_id(i) ||
- die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
cpu_bf = parse_int_file(1,
@@ -1207,7 +1218,7 @@ error_ret:
return ret;
}
-static void dump_clx_n_config_for_cpu(int cpu, void *arg1, void *arg2,
+static void dump_clx_n_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
void *arg3, void *arg4)
{
int ret;
@@ -1217,7 +1228,7 @@ static void dump_clx_n_config_for_cpu(int cpu, void *arg1, void *arg2,
exit(0);
}
- ret = clx_n_config(cpu);
+ ret = clx_n_config(id);
if (ret) {
debug_printf("clx_n_config failed");
} else {
@@ -1227,27 +1238,27 @@ static void dump_clx_n_config_for_cpu(int cpu, void *arg1, void *arg2,
ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
pbf_info = &ctdp_level->pbf_info;
clx_n_pkg_dev.processed = 1;
- isst_ctdp_display_information(cpu, outf, tdp_level, &clx_n_pkg_dev);
+ isst_ctdp_display_information(id, outf, tdp_level, &clx_n_pkg_dev);
free_cpu_set(ctdp_level->core_cpumask);
free_cpu_set(pbf_info->core_cpumask);
}
}
-static void dump_isst_config_for_cpu(int cpu, void *arg1, void *arg2,
+static void dump_isst_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
void *arg3, void *arg4)
{
struct isst_pkg_ctdp pkg_dev;
int ret;
memset(&pkg_dev, 0, sizeof(pkg_dev));
- ret = isst_get_process_ctdp(cpu, tdp_level, &pkg_dev);
+ ret = isst_get_process_ctdp(id, tdp_level, &pkg_dev);
if (ret) {
- isst_display_error_info_message(1, "Failed to get perf-profile info on cpu", 1, cpu);
+ isst_display_error_info_message(1, "Failed to get perf-profile info on cpu", 1, id->cpu);
isst_ctdp_display_information_end(outf);
exit(1);
} else {
- isst_ctdp_display_information(cpu, outf, tdp_level, &pkg_dev);
- isst_get_process_ctdp_complete(cpu, &pkg_dev);
+ isst_ctdp_display_information(id, outf, tdp_level, &pkg_dev);
+ isst_get_process_ctdp_complete(id, &pkg_dev);
}
}
@@ -1283,23 +1294,21 @@ static void dump_isst_config(int arg)
static void adjust_scaling_max_from_base_freq(int cpu);
-static void set_tdp_level_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void set_tdp_level_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
int ret;
- ret = isst_set_tdp_level(cpu, tdp_level);
+ ret = isst_set_tdp_level(id, tdp_level);
if (ret) {
isst_display_error_info_message(1, "Set TDP level failed", 0, 0);
isst_ctdp_display_information_end(outf);
exit(1);
} else {
- isst_display_result(cpu, outf, "perf-profile", "set_tdp_level",
+ isst_display_result(id, outf, "perf-profile", "set_tdp_level",
ret);
if (force_online_offline) {
struct isst_pkg_ctdp_level_info ctdp_level;
- int pkg_id = get_physical_package_id(cpu);
- int die_id = get_physical_die_id(cpu);
/* Wait for updated base frequencies */
usleep(2000);
@@ -1307,7 +1316,7 @@ static void set_tdp_level_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
fprintf(stderr, "Option is set to online/offline\n");
ctdp_level.core_cpumask_size =
alloc_cpu_set(&ctdp_level.core_cpumask);
- ret = isst_get_coremask_info(cpu, tdp_level, &ctdp_level);
+ ret = isst_get_coremask_info(id, tdp_level, &ctdp_level);
if (ret) {
isst_display_error_info_message(1, "Can't get coremask, online/offline option is ignored", 0, 0);
return;
@@ -1315,7 +1324,7 @@ static void set_tdp_level_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
if (ctdp_level.cpu_count) {
int i, max_cpus = get_topo_max_cpus();
for (i = 0; i < max_cpus; ++i) {
- if (pkg_id != get_physical_package_id(i) || die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
fprintf(stderr, "online cpu %d\n", i);
@@ -1358,12 +1367,12 @@ static void set_tdp_level(int arg)
isst_ctdp_display_information_end(outf);
}
-static void clx_n_dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2,
+static void clx_n_dump_pbf_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
void *arg3, void *arg4)
{
int ret;
- ret = clx_n_config(cpu);
+ ret = clx_n_config(id);
if (ret) {
isst_display_error_info_message(1, "clx_n_config failed", 0, 0);
} else {
@@ -1372,25 +1381,25 @@ static void clx_n_dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2,
ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
pbf_info = &ctdp_level->pbf_info;
- isst_pbf_display_information(cpu, outf, tdp_level, pbf_info);
+ isst_pbf_display_information(id, outf, tdp_level, pbf_info);
free_cpu_set(ctdp_level->core_cpumask);
free_cpu_set(pbf_info->core_cpumask);
}
}
-static void dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void dump_pbf_config_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
struct isst_pbf_info pbf_info;
int ret;
- ret = isst_get_pbf_info(cpu, tdp_level, &pbf_info);
+ ret = isst_get_pbf_info(id, tdp_level, &pbf_info);
if (ret) {
isst_display_error_info_message(1, "Failed to get base-freq info at this level", 1, tdp_level);
isst_ctdp_display_information_end(outf);
exit(1);
} else {
- isst_pbf_display_information(cpu, outf, tdp_level, &pbf_info);
+ isst_pbf_display_information(id, outf, tdp_level, &pbf_info);
isst_get_pbf_info_complete(&pbf_info);
}
}
@@ -1427,12 +1436,12 @@ static void dump_pbf_config(int arg)
isst_ctdp_display_information_end(outf);
}
-static int set_clos_param(int cpu, int clos, int epp, int wt, int min, int max)
+static int set_clos_param(struct isst_id *id, int clos, int epp, int wt, int min, int max)
{
struct isst_clos_config clos_config;
int ret;
- ret = isst_pm_get_clos(cpu, clos, &clos_config);
+ ret = isst_pm_get_clos(id, clos, &clos_config);
if (ret) {
isst_display_error_info_message(1, "isst_pm_get_clos failed", 0, 0);
return ret;
@@ -1441,7 +1450,7 @@ static int set_clos_param(int cpu, int clos, int epp, int wt, int min, int max)
clos_config.clos_max = max;
clos_config.epp = epp;
clos_config.clos_prop_prio = wt;
- ret = isst_set_clos(cpu, clos, &clos_config);
+ ret = isst_set_clos(id, clos, &clos_config);
if (ret) {
isst_display_error_info_message(1, "isst_set_clos failed", 0, 0);
return ret;
@@ -1503,14 +1512,14 @@ static void adjust_scaling_min_from_base_freq(int cpu)
set_cpufreq_scaling_min_max(cpu, 0, base_freq);
}
-static int set_clx_pbf_cpufreq_scaling_min_max(int cpu)
+static int set_clx_pbf_cpufreq_scaling_min_max(struct isst_id *id)
{
struct isst_pkg_ctdp_level_info *ctdp_level;
struct isst_pbf_info *pbf_info;
- int i, pkg_id, die_id, freq, freq_high, freq_low;
+ int i, freq, freq_high, freq_low;
int ret;
- ret = clx_n_config(cpu);
+ ret = clx_n_config(id);
if (ret) {
debug_printf("cpufreq_scaling_min_max failed for CLX");
return ret;
@@ -1521,11 +1530,8 @@ static int set_clx_pbf_cpufreq_scaling_min_max(int cpu)
freq_high = pbf_info->p1_high * 100000;
freq_low = pbf_info->p1_low * 100000;
- pkg_id = get_physical_package_id(cpu);
- die_id = get_physical_die_id(cpu);
for (i = 0; i < get_topo_max_cpus(); ++i) {
- if (pkg_id != get_physical_package_id(i) ||
- die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
if (CPU_ISSET_S(i, pbf_info->core_cpumask_size,
@@ -1588,84 +1594,75 @@ static int set_cpufreq_scaling_min_max_from_cpuinfo(int cpu, int cpuinfo_max, in
return 0;
}
-static void set_scaling_min_to_cpuinfo_max(int cpu)
+static void set_scaling_min_to_cpuinfo_max(struct isst_id *id)
{
- int i, pkg_id, die_id;
+ int i;
- pkg_id = get_physical_package_id(cpu);
- die_id = get_physical_die_id(cpu);
for (i = 0; i < get_topo_max_cpus(); ++i) {
- if (pkg_id != get_physical_package_id(i) ||
- die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
+ adjust_scaling_max_from_base_freq(i);
set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 0);
adjust_scaling_min_from_base_freq(i);
}
}
-static void set_scaling_min_to_cpuinfo_min(int cpu)
+static void set_scaling_min_to_cpuinfo_min(struct isst_id *id)
{
- int i, pkg_id, die_id;
+ int i;
- pkg_id = get_physical_package_id(cpu);
- die_id = get_physical_die_id(cpu);
for (i = 0; i < get_topo_max_cpus(); ++i) {
- if (pkg_id != get_physical_package_id(i) ||
- die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
+ adjust_scaling_max_from_base_freq(i);
set_cpufreq_scaling_min_max_from_cpuinfo(i, 0, 0);
}
}
-static void set_scaling_max_to_cpuinfo_max(int cpu)
+static void set_scaling_max_to_cpuinfo_max(struct isst_id *id)
{
- int i, pkg_id, die_id;
+ int i;
- pkg_id = get_physical_package_id(cpu);
- die_id = get_physical_die_id(cpu);
for (i = 0; i < get_topo_max_cpus(); ++i) {
- if (pkg_id != get_physical_package_id(i) ||
- die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 1);
}
}
-static int set_core_priority_and_min(int cpu, int mask_size,
+static int set_core_priority_and_min(struct isst_id *id, int mask_size,
cpu_set_t *cpu_mask, int min_high,
int min_low)
{
- int pkg_id, die_id, ret, i;
+ int ret, i;
if (!CPU_COUNT_S(mask_size, cpu_mask))
return -1;
- ret = set_clos_param(cpu, 0, 0, 0, min_high, 0xff);
+ ret = set_clos_param(id, 0, 0, 0, min_high, 0xff);
if (ret)
return ret;
- ret = set_clos_param(cpu, 1, 15, 15, min_low, 0xff);
+ ret = set_clos_param(id, 1, 15, 15, min_low, 0xff);
if (ret)
return ret;
- ret = set_clos_param(cpu, 2, 15, 15, min_low, 0xff);
+ ret = set_clos_param(id, 2, 15, 15, min_low, 0xff);
if (ret)
return ret;
- ret = set_clos_param(cpu, 3, 15, 15, min_low, 0xff);
+ ret = set_clos_param(id, 3, 15, 15, min_low, 0xff);
if (ret)
return ret;
- pkg_id = get_physical_package_id(cpu);
- die_id = get_physical_die_id(cpu);
for (i = 0; i < get_topo_max_cpus(); ++i) {
int clos;
+ struct isst_id tid;
- if (pkg_id != get_physical_package_id(i) ||
- die_id != get_physical_die_id(i))
+ if (!is_cpu_in_power_domain(i, id))
continue;
if (CPU_ISSET_S(i, mask_size, cpu_mask))
@@ -1674,7 +1671,8 @@ static int set_core_priority_and_min(int cpu, int mask_size,
clos = 3;
debug_printf("Associate cpu: %d clos: %d\n", i, clos);
- ret = isst_clos_associate(i, clos);
+ set_isst_id(&tid, i);
+ ret = isst_clos_associate(&tid, clos);
if (ret) {
isst_display_error_info_message(1, "isst_clos_associate failed", 0, 0);
return ret;
@@ -1684,20 +1682,20 @@ static int set_core_priority_and_min(int cpu, int mask_size,
return 0;
}
-static int set_pbf_core_power(int cpu)
+static int set_pbf_core_power(struct isst_id *id)
{
struct isst_pbf_info pbf_info;
struct isst_pkg_ctdp pkg_dev;
int ret;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
debug_printf("isst_get_ctdp_levels failed");
return ret;
}
debug_printf("Current_level: %d\n", pkg_dev.current_level);
- ret = isst_get_pbf_info(cpu, pkg_dev.current_level, &pbf_info);
+ ret = isst_get_pbf_info(id, pkg_dev.current_level, &pbf_info);
if (ret) {
debug_printf("isst_get_pbf_info failed");
return ret;
@@ -1705,7 +1703,7 @@ static int set_pbf_core_power(int cpu)
debug_printf("p1_high: %d p1_low: %d\n", pbf_info.p1_high,
pbf_info.p1_low);
- ret = set_core_priority_and_min(cpu, pbf_info.core_cpumask_size,
+ ret = set_core_priority_and_min(id, pbf_info.core_cpumask_size,
pbf_info.core_cpumask,
pbf_info.p1_high, pbf_info.p1_low);
if (ret) {
@@ -1713,7 +1711,7 @@ static int set_pbf_core_power(int cpu)
return ret;
}
- ret = isst_pm_qos_config(cpu, 1, 1);
+ ret = isst_pm_qos_config(id, 1, 1);
if (ret) {
debug_printf("isst_pm_qos_config failed");
return ret;
@@ -1722,7 +1720,7 @@ static int set_pbf_core_power(int cpu)
return 0;
}
-static void set_pbf_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void set_pbf_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
struct isst_pkg_ctdp_level_info ctdp_level;
@@ -1733,22 +1731,22 @@ static void set_pbf_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
if (is_clx_n_platform()) {
ret = 0;
if (status) {
- set_clx_pbf_cpufreq_scaling_min_max(cpu);
+ set_clx_pbf_cpufreq_scaling_min_max(id);
} else {
- set_scaling_max_to_cpuinfo_max(cpu);
- set_scaling_min_to_cpuinfo_min(cpu);
+ set_scaling_max_to_cpuinfo_max(id);
+ set_scaling_min_to_cpuinfo_min(id);
}
goto disp_result;
}
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
goto disp_result;
}
- ret = isst_get_ctdp_control(cpu, pkg_dev.current_level, &ctdp_level);
+ ret = isst_get_ctdp_control(id, pkg_dev.current_level, &ctdp_level);
if (ret) {
isst_display_error_info_message(1, "Failed to get current level", 0, 0);
goto disp_result;
@@ -1761,34 +1759,34 @@ static void set_pbf_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
}
if (auto_mode && status) {
- ret = set_pbf_core_power(cpu);
+ ret = set_pbf_core_power(id);
if (ret)
goto disp_result;
}
- ret = isst_set_pbf_fact_status(cpu, 1, status);
+ ret = isst_set_pbf_fact_status(id, 1, status);
if (ret) {
debug_printf("isst_set_pbf_fact_status failed");
if (auto_mode)
- isst_pm_qos_config(cpu, 0, 0);
+ isst_pm_qos_config(id, 0, 0);
} else {
if (auto_mode) {
if (status)
- set_scaling_min_to_cpuinfo_max(cpu);
+ set_scaling_min_to_cpuinfo_max(id);
else
- set_scaling_min_to_cpuinfo_min(cpu);
+ set_scaling_min_to_cpuinfo_min(id);
}
}
if (auto_mode && !status)
- isst_pm_qos_config(cpu, 0, 1);
+ isst_pm_qos_config(id, 0, 1);
disp_result:
if (status)
- isst_display_result(cpu, outf, "base-freq", "enable",
+ isst_display_result(id, outf, "base-freq", "enable",
ret);
else
- isst_display_result(cpu, outf, "base-freq", "disable",
+ isst_display_result(id, outf, "base-freq", "disable",
ret);
}
@@ -1837,19 +1835,19 @@ static void set_pbf_enable(int arg)
isst_ctdp_display_information_end(outf);
}
-static void dump_fact_config_for_cpu(int cpu, void *arg1, void *arg2,
+static void dump_fact_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
void *arg3, void *arg4)
{
struct isst_fact_info fact_info;
int ret;
- ret = isst_get_fact_info(cpu, tdp_level, fact_bucket, &fact_info);
+ ret = isst_get_fact_info(id, tdp_level, fact_bucket, &fact_info);
if (ret) {
isst_display_error_info_message(1, "Failed to get turbo-freq info at this level", 1, tdp_level);
isst_ctdp_display_information_end(outf);
exit(1);
} else {
- isst_fact_display_information(cpu, outf, tdp_level, fact_bucket,
+ isst_fact_display_information(id, outf, tdp_level, fact_bucket,
fact_avx, &fact_info);
}
}
@@ -1883,7 +1881,7 @@ static void dump_fact_config(int arg)
isst_ctdp_display_information_end(outf);
}
-static void set_fact_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void set_fact_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
struct isst_pkg_ctdp_level_info ctdp_level;
@@ -1891,13 +1889,19 @@ static void set_fact_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
int ret;
int status = *(int *)arg4;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ if (status && no_turbo()) {
+ isst_display_error_info_message(1, "Turbo mode is disabled", 0, 0);
+ ret = -1;
+ goto disp_results;
+ }
+
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
goto disp_results;
}
- ret = isst_get_ctdp_control(cpu, pkg_dev.current_level, &ctdp_level);
+ ret = isst_get_ctdp_control(id, pkg_dev.current_level, &ctdp_level);
if (ret) {
isst_display_error_info_message(1, "Failed to get current level", 0, 0);
goto disp_results;
@@ -1910,16 +1914,16 @@ static void set_fact_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
}
if (status) {
- ret = isst_pm_qos_config(cpu, 1, 1);
+ ret = isst_pm_qos_config(id, 1, 1);
if (ret)
goto disp_results;
}
- ret = isst_set_pbf_fact_status(cpu, 0, status);
+ ret = isst_set_pbf_fact_status(id, 0, status);
if (ret) {
debug_printf("isst_set_pbf_fact_status failed");
if (auto_mode)
- isst_pm_qos_config(cpu, 0, 0);
+ isst_pm_qos_config(id, 0, 0);
goto disp_results;
}
@@ -1928,31 +1932,32 @@ static void set_fact_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
if (status) {
struct isst_pkg_ctdp pkg_dev;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (!ret)
- ret = isst_set_trl(cpu, fact_trl);
+ ret = isst_set_trl(id, fact_trl);
if (ret && auto_mode)
- isst_pm_qos_config(cpu, 0, 0);
+ isst_pm_qos_config(id, 0, 0);
} else {
if (auto_mode)
- isst_pm_qos_config(cpu, 0, 0);
+ isst_pm_qos_config(id, 0, 0);
}
disp_results:
if (status) {
- isst_display_result(cpu, outf, "turbo-freq", "enable", ret);
+ isst_display_result(id, outf, "turbo-freq", "enable", ret);
if (ret)
fact_enable_fail = ret;
} else {
/* Since we modified TRL during Fact enable, restore it */
- isst_set_trl_from_current_tdp(cpu, fact_trl);
- isst_display_result(cpu, outf, "turbo-freq", "disable", ret);
+ isst_set_trl_from_current_tdp(id, fact_trl);
+ isst_display_result(id, outf, "turbo-freq", "disable", ret);
}
}
static void set_fact_enable(int arg)
{
int i, ret, enable = arg;
+ struct isst_id id;
if (cmd_help) {
if (enable) {
@@ -2026,19 +2031,20 @@ static void set_fact_enable(int arg)
if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
continue;
- ret = set_clos_param(i, 0, 0, 0, 0, 0xff);
+ set_isst_id(&id, i);
+ ret = set_clos_param(&id, 0, 0, 0, 0, 0xff);
if (ret)
goto error_disp;
- ret = set_clos_param(i, 1, 15, 15, 0, 0xff);
+ ret = set_clos_param(&id, 1, 15, 15, 0, 0xff);
if (ret)
goto error_disp;
- ret = set_clos_param(i, 2, 15, 15, 0, 0xff);
+ ret = set_clos_param(&id, 2, 15, 15, 0, 0xff);
if (ret)
goto error_disp;
- ret = set_clos_param(i, 3, 15, 15, 0, 0xff);
+ ret = set_clos_param(&id, 3, 15, 15, 0, 0xff);
if (ret)
goto error_disp;
@@ -2048,21 +2054,22 @@ static void set_fact_enable(int arg)
clos = 3;
debug_printf("Associate cpu: %d clos: %d\n", i, clos);
- ret = isst_clos_associate(i, clos);
+ ret = isst_clos_associate(&id, clos);
if (ret)
goto error_disp;
}
- isst_display_result(-1, outf, "turbo-freq --auto", "enable", 0);
+ set_isst_id(&id, -1);
+ isst_display_result(&id, outf, "turbo-freq --auto", "enable", 0);
}
return;
error_disp:
- isst_display_result(i, outf, "turbo-freq --auto", "enable", ret);
+ isst_display_result(&id, outf, "turbo-freq --auto", "enable", ret);
}
-static void enable_clos_qos_config(int cpu, void *arg1, void *arg2, void *arg3,
+static void enable_clos_qos_config(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
int ret;
@@ -2071,15 +2078,15 @@ static void enable_clos_qos_config(int cpu, void *arg1, void *arg2, void *arg3,
if (is_skx_based_platform())
clos_priority_type = 1;
- ret = isst_pm_qos_config(cpu, status, clos_priority_type);
+ ret = isst_pm_qos_config(id, status, clos_priority_type);
if (ret)
isst_display_error_info_message(1, "isst_pm_qos_config failed", 0, 0);
if (status)
- isst_display_result(cpu, outf, "core-power", "enable",
+ isst_display_result(id, outf, "core-power", "enable",
ret);
else
- isst_display_result(cpu, outf, "core-power", "disable",
+ isst_display_result(id, outf, "core-power", "disable",
ret);
}
@@ -2118,17 +2125,17 @@ static void set_clos_enable(int arg)
isst_ctdp_display_information_end(outf);
}
-static void dump_clos_config_for_cpu(int cpu, void *arg1, void *arg2,
+static void dump_clos_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
void *arg3, void *arg4)
{
struct isst_clos_config clos_config;
int ret;
- ret = isst_pm_get_clos(cpu, current_clos, &clos_config);
+ ret = isst_pm_get_clos(id, current_clos, &clos_config);
if (ret)
isst_display_error_info_message(1, "isst_pm_get_clos failed", 0, 0);
else
- isst_clos_display_information(cpu, outf, current_clos,
+ isst_clos_display_information(id, outf, current_clos,
&clos_config);
}
@@ -2157,19 +2164,19 @@ static void dump_clos_config(int arg)
isst_ctdp_display_information_end(outf);
}
-static void get_clos_info_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void get_clos_info_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
int enable, ret, prio_type;
- ret = isst_clos_get_clos_information(cpu, &enable, &prio_type);
+ ret = isst_clos_get_clos_information(id, &enable, &prio_type);
if (ret)
isst_display_error_info_message(1, "isst_clos_get_info failed", 0, 0);
else {
int cp_state, cp_cap;
- isst_read_pm_config(cpu, &cp_state, &cp_cap);
- isst_clos_display_clos_information(cpu, outf, enable, prio_type,
+ isst_read_pm_config(id, &cp_state, &cp_cap);
+ isst_clos_display_clos_information(id, outf, enable, prio_type,
cp_state, cp_cap);
}
}
@@ -2194,25 +2201,22 @@ static void dump_clos_info(int arg)
}
-static void set_clos_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void set_clos_config_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
struct isst_clos_config clos_config;
int ret;
- clos_config.pkg_id = get_physical_package_id(cpu);
- clos_config.die_id = get_physical_die_id(cpu);
-
clos_config.epp = clos_epp;
clos_config.clos_prop_prio = clos_prop_prio;
clos_config.clos_min = clos_min;
clos_config.clos_max = clos_max;
clos_config.clos_desired = clos_desired;
- ret = isst_set_clos(cpu, current_clos, &clos_config);
+ ret = isst_set_clos(id, current_clos, &clos_config);
if (ret)
isst_display_error_info_message(1, "isst_set_clos failed", 0, 0);
else
- isst_display_result(cpu, outf, "core-power", "config", ret);
+ isst_display_result(id, outf, "core-power", "config", ret);
}
static void set_clos_config(int arg)
@@ -2268,16 +2272,16 @@ static void set_clos_config(int arg)
isst_ctdp_display_information_end(outf);
}
-static void set_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void set_clos_assoc_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
int ret;
- ret = isst_clos_associate(cpu, current_clos);
+ ret = isst_clos_associate(id, current_clos);
if (ret)
debug_printf("isst_clos_associate failed");
else
- isst_display_result(cpu, outf, "core-power", "assoc", ret);
+ isst_display_result(id, outf, "core-power", "assoc", ret);
}
static void set_clos_assoc(int arg)
@@ -2305,16 +2309,16 @@ static void set_clos_assoc(int arg)
}
}
-static void get_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
+static void get_clos_assoc_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
int clos, ret;
- ret = isst_clos_get_assoc_status(cpu, &clos);
+ ret = isst_clos_get_assoc_status(id, &clos);
if (ret)
isst_display_error_info_message(1, "isst_clos_get_assoc_status failed", 0, 0);
else
- isst_clos_display_assoc_information(cpu, outf, clos);
+ isst_clos_display_assoc_information(id, outf, clos);
}
static void get_clos_assoc(int arg)
@@ -2336,27 +2340,28 @@ static void get_clos_assoc(int arg)
isst_ctdp_display_information_end(outf);
}
-static void set_turbo_mode_for_cpu(int cpu, int status)
+static void set_turbo_mode_for_cpu(struct isst_id *id, int status)
{
int base_freq;
if (status) {
- base_freq = get_cpufreq_base_freq(cpu);
- set_cpufreq_scaling_min_max(cpu, 1, base_freq);
+ base_freq = get_cpufreq_base_freq(id->cpu);
+ set_cpufreq_scaling_min_max(id->cpu, 1, base_freq);
} else {
- set_scaling_max_to_cpuinfo_max(cpu);
+ set_scaling_max_to_cpuinfo_max(id);
}
if (status) {
- isst_display_result(cpu, outf, "turbo-mode", "enable", 0);
+ isst_display_result(id, outf, "turbo-mode", "enable", 0);
} else {
- isst_display_result(cpu, outf, "turbo-mode", "disable", 0);
+ isst_display_result(id, outf, "turbo-mode", "disable", 0);
}
}
static void set_turbo_mode(int arg)
{
int i, enable = arg;
+ struct isst_id id;
if (cmd_help) {
if (enable)
@@ -2378,14 +2383,16 @@ static void set_turbo_mode(int arg)
online =
1; /* online entry for CPU 0 needs some special configs */
- if (online)
- set_turbo_mode_for_cpu(i, enable);
+ if (online) {
+ set_isst_id(&id, i);
+ set_turbo_mode_for_cpu(&id, enable);
+ }
}
isst_ctdp_display_information_end(outf);
}
-static void get_set_trl(int cpu, void *arg1, void *arg2, void *arg3,
+static void get_set_trl(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
unsigned long long trl;
@@ -2398,16 +2405,16 @@ static void get_set_trl(int cpu, void *arg1, void *arg2, void *arg3,
}
if (set) {
- ret = isst_set_trl(cpu, fact_trl);
- isst_display_result(cpu, outf, "turbo-mode", "set-trl", ret);
+ ret = isst_set_trl(id, fact_trl);
+ isst_display_result(id, outf, "turbo-mode", "set-trl", ret);
return;
}
- ret = isst_get_trl(cpu, &trl);
+ ret = isst_get_trl(id, &trl);
if (ret)
- isst_display_result(cpu, outf, "turbo-mode", "get-trl", ret);
+ isst_display_result(id, outf, "turbo-mode", "get-trl", ret);
else
- isst_trl_display_information(cpu, outf, trl);
+ isst_trl_display_information(id, outf, trl);
}
static void process_trl(int arg)
@@ -2747,9 +2754,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) &&
@@ -2801,7 +2805,9 @@ static void usage(void)
printf("\t[-p|--pause] : Delay between two mail box commands in milliseconds\n");
printf("\t[-r|--retry] : Retry count for mail box commands on failure, default 3\n");
printf("\t[-v|--version] : Print version\n");
-
+ printf("\t[-b|--oob : Start a daemon to process HFI events for perf profile change from Out of Band agent.\n");
+ printf("\t[-n|--no-daemon : Don't run as daemon. By default --oob will turn on daemon mode\n");
+ printf("\t[-w|--delay : Delay for reading config level state change in OOB poll mode.\n");
printf("\nResult format\n");
printf("\tResult display uses a common format for each command:\n");
printf("\tResults are formatted in text/JSON with\n");
@@ -2835,6 +2841,9 @@ static void cmdline(int argc, char **argv)
int opt, force_cpus_online = 0;
int option_index = 0;
int ret;
+ int oob_mode = 0;
+ int poll_interval = -1;
+ int no_daemon = 0;
static struct option long_options[] = {
{ "all-cpus-online", no_argument, 0, 'a' },
@@ -2847,6 +2856,9 @@ static void cmdline(int argc, char **argv)
{ "out", required_argument, 0, 'o' },
{ "retry", required_argument, 0, 'r' },
{ "version", no_argument, 0, 'v' },
+ { "oob", no_argument, 0, 'b' },
+ { "no-daemon", no_argument, 0, 'n' },
+ { "poll-interval", required_argument, 0, 'w' },
{ 0, 0, 0, 0 }
};
@@ -2873,7 +2885,7 @@ static void cmdline(int argc, char **argv)
}
progname = argv[0];
- while ((opt = getopt_long_only(argc, argv, "+c:df:hio:va", long_options,
+ while ((opt = getopt_long_only(argc, argv, "+c:df:hio:vabw:n", long_options,
&option_index)) != -1) {
switch (opt) {
case 'a':
@@ -2918,12 +2930,26 @@ static void cmdline(int argc, char **argv)
case 'v':
print_version();
break;
+ case 'b':
+ oob_mode = 1;
+ break;
+ case 'n':
+ no_daemon = 1;
+ break;
+ case 'w':
+ ret = strtol(optarg, &ptr, 10);
+ if (!ret) {
+ fprintf(stderr, "Invalid poll interval count\n");
+ exit(0);
+ }
+ poll_interval = ret;
+ break;
default:
usage();
}
}
- if (optind > (argc - 2)) {
+ if (optind > (argc - 2) && !oob_mode) {
usage();
exit(0);
}
@@ -2931,8 +2957,17 @@ static void cmdline(int argc, char **argv)
if (force_cpus_online)
force_all_cpus_online();
store_cpu_topology();
- set_cpu_present_cpu_mask();
- set_cpu_target_cpu_mask();
+ create_cpu_map();
+
+ if (oob_mode) {
+ if (debug_flag)
+ fprintf(stderr, "OOB mode is enabled in debug mode\n");
+
+ ret = isst_daemon(debug_flag, poll_interval, no_daemon);
+ if (ret)
+ fprintf(stderr, "OOB mode enable failed\n");
+ goto out;
+ }
if (!is_clx_n_platform()) {
ret = isst_fill_platform_info();
diff --git a/tools/power/x86/intel-speed-select/isst-core.c b/tools/power/x86/intel-speed-select/isst-core.c
index 4431c8a0d40a..f701b45c832c 100644
--- a/tools/power/x86/intel-speed-select/isst-core.c
+++ b/tools/power/x86/intel-speed-select/isst-core.c
@@ -6,7 +6,7 @@
#include "isst.h"
-int isst_write_pm_config(int cpu, int cp_state)
+int isst_write_pm_config(struct isst_id *id, int cp_state)
{
unsigned int req, resp;
int ret;
@@ -16,27 +16,27 @@ int isst_write_pm_config(int cpu, int cp_state)
else
req = 0;
- ret = isst_send_mbox_command(cpu, WRITE_PM_CONFIG, PM_FEATURE, 0, req,
+ ret = isst_send_mbox_command(id->cpu, WRITE_PM_CONFIG, PM_FEATURE, 0, req,
&resp);
if (ret)
return ret;
- debug_printf("cpu:%d WRITE_PM_CONFIG resp:%x\n", cpu, resp);
+ debug_printf("cpu:%d WRITE_PM_CONFIG resp:%x\n", id->cpu, resp);
return 0;
}
-int isst_read_pm_config(int cpu, int *cp_state, int *cp_cap)
+int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, READ_PM_CONFIG, PM_FEATURE, 0, 0,
+ ret = isst_send_mbox_command(id->cpu, READ_PM_CONFIG, PM_FEATURE, 0, 0,
&resp);
if (ret)
return ret;
- debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", cpu, resp);
+ debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", id->cpu, resp);
*cp_state = resp & BIT(16);
*cp_cap = resp & BIT(0) ? 1 : 0;
@@ -44,12 +44,12 @@ int isst_read_pm_config(int cpu, int *cp_state, int *cp_cap)
return 0;
}
-int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev)
+int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_LEVELS_INFO, 0, 0, &resp);
if (ret) {
pkg_dev->levels = 0;
@@ -60,7 +60,7 @@ int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev)
return 0;
}
- debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", cpu, resp);
+ debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", id->cpu, resp);
pkg_dev->version = resp & 0xff;
pkg_dev->levels = (resp >> 8) & 0xff;
@@ -71,14 +71,14 @@ int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev)
return 0;
}
-int isst_get_ctdp_control(int cpu, int config_index,
+int isst_get_ctdp_control(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
int cp_state, cp_cap;
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_TDP_CONTROL, 0,
config_index, &resp);
if (ret)
@@ -89,30 +89,30 @@ int isst_get_ctdp_control(int cpu, int config_index,
ctdp_level->fact_enabled = !!(resp & BIT(16));
ctdp_level->pbf_enabled = !!(resp & BIT(17));
- ret = isst_read_pm_config(cpu, &cp_state, &cp_cap);
+ ret = isst_read_pm_config(id, &cp_state, &cp_cap);
if (ret) {
- debug_printf("cpu:%d pm_config is not supported \n", cpu);
+ debug_printf("cpu:%d pm_config is not supported\n", id->cpu);
} else {
- debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d \n", cpu, cp_state, cp_cap);
+ debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d\n", id->cpu, cp_state, cp_cap);
ctdp_level->sst_cp_support = cp_cap;
ctdp_level->sst_cp_enabled = cp_state;
}
debug_printf(
"cpu:%d CONFIG_TDP_GET_TDP_CONTROL resp:%x fact_support:%d pbf_support: %d fact_enabled:%d pbf_enabled:%d\n",
- cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support,
+ id->cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support,
ctdp_level->fact_enabled, ctdp_level->pbf_enabled);
return 0;
}
-int isst_get_tdp_info(int cpu, int config_index,
+int isst_get_tdp_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO,
0, config_index, &resp);
if (ret) {
isst_display_error_info_message(1, "Invalid level, Can't get TDP information at level", 1, config_index);
@@ -124,18 +124,18 @@ int isst_get_tdp_info(int cpu, int config_index,
debug_printf(
"cpu:%d ctdp:%d CONFIG_TDP_GET_TDP_INFO resp:%x tdp_ratio:%d pkg_tdp:%d\n",
- cpu, config_index, resp, ctdp_level->tdp_ratio,
+ id->cpu, config_index, resp, ctdp_level->tdp_ratio,
ctdp_level->pkg_tdp);
return 0;
}
-int isst_get_pwr_info(int cpu, int config_index,
+int isst_get_pwr_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO,
0, config_index, &resp);
if (ret)
return ret;
@@ -145,18 +145,18 @@ int isst_get_pwr_info(int cpu, int config_index,
debug_printf(
"cpu:%d ctdp:%d CONFIG_TDP_GET_PWR_INFO resp:%x pkg_max_power:%d pkg_min_power:%d\n",
- cpu, config_index, resp, ctdp_level->pkg_max_power,
+ id->cpu, config_index, resp, ctdp_level->pkg_max_power,
ctdp_level->pkg_min_power);
return 0;
}
-void isst_get_uncore_p0_p1_info(int cpu, int config_index,
+void isst_get_uncore_p0_p1_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_UNCORE_P0_P1_INFO, 0,
config_index, &resp);
if (ret) {
@@ -169,16 +169,16 @@ void isst_get_uncore_p0_p1_info(int cpu, int config_index,
ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
debug_printf(
"cpu:%d ctdp:%d CONFIG_TDP_GET_UNCORE_P0_P1_INFO resp:%x uncore p0:%d uncore p1:%d\n",
- cpu, config_index, resp, ctdp_level->uncore_p0,
+ id->cpu, config_index, resp, ctdp_level->uncore_p0,
ctdp_level->uncore_p1);
}
-void isst_get_p1_info(int cpu, int config_index,
+void isst_get_p1_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0,
config_index, &resp);
if (ret) {
ctdp_level->sse_p1 = 0;
@@ -192,17 +192,17 @@ void isst_get_p1_info(int cpu, int config_index,
ctdp_level->avx512_p1 = (resp & GENMASK(23, 16)) >> 16;
debug_printf(
"cpu:%d ctdp:%d CONFIG_TDP_GET_P1_INFO resp:%x sse_p1:%d avx2_p1:%d avx512_p1:%d\n",
- cpu, config_index, resp, ctdp_level->sse_p1,
+ id->cpu, config_index, resp, ctdp_level->sse_p1,
ctdp_level->avx2_p1, ctdp_level->avx512_p1);
}
-void isst_get_uncore_mem_freq(int cpu, int config_index,
+void isst_get_uncore_mem_freq(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ,
0, config_index, &resp);
if (ret) {
ctdp_level->mem_freq = 0;
@@ -226,16 +226,16 @@ void isst_get_uncore_mem_freq(int cpu, int config_index,
}
debug_printf(
"cpu:%d ctdp:%d CONFIG_TDP_GET_MEM_FREQ resp:%x uncore mem_freq:%d\n",
- cpu, config_index, resp, ctdp_level->mem_freq);
+ id->cpu, config_index, resp, ctdp_level->mem_freq);
}
-int isst_get_tjmax_info(int cpu, int config_index,
+int isst_get_tjmax_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO,
0, config_index, &resp);
if (ret)
return ret;
@@ -244,12 +244,12 @@ int isst_get_tjmax_info(int cpu, int config_index,
debug_printf(
"cpu:%d ctdp:%d CONFIG_TDP_GET_TJMAX_INFO resp:%x t_proc_hot:%d\n",
- cpu, config_index, resp, ctdp_level->t_proc_hot);
+ id->cpu, config_index, resp, ctdp_level->t_proc_hot);
return 0;
}
-int isst_get_coremask_info(int cpu, int config_index,
+int isst_get_coremask_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
unsigned int resp;
@@ -260,7 +260,7 @@ int isst_get_coremask_info(int cpu, int config_index,
unsigned long long mask;
int cpu_count = 0;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_CORE_MASK, 0,
(i << 8) | config_index, &resp);
if (ret)
@@ -268,27 +268,27 @@ int isst_get_coremask_info(int cpu, int config_index,
debug_printf(
"cpu:%d ctdp:%d mask:%d CONFIG_TDP_GET_CORE_MASK resp:%x\n",
- cpu, config_index, i, resp);
+ id->cpu, config_index, i, resp);
mask = (unsigned long long)resp << (32 * i);
- set_cpu_mask_from_punit_coremask(cpu, mask,
+ set_cpu_mask_from_punit_coremask(id, mask,
ctdp_level->core_cpumask_size,
ctdp_level->core_cpumask,
&cpu_count);
ctdp_level->cpu_count += cpu_count;
- debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", cpu,
+ debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", id->cpu,
config_index, i, ctdp_level->cpu_count);
}
return 0;
}
-int isst_get_get_trl_from_msr(int cpu, int *trl)
+int isst_get_get_trl_from_msr(struct isst_id *id, int *trl)
{
unsigned long long msr_trl;
int ret;
- ret = isst_send_msr_command(cpu, 0x1AD, 0, &msr_trl);
+ ret = isst_send_msr_command(id->cpu, 0x1AD, 0, &msr_trl);
if (ret)
return ret;
@@ -304,13 +304,13 @@ int isst_get_get_trl_from_msr(int cpu, int *trl)
return 0;
}
-int isst_get_get_trl(int cpu, int level, int avx_level, int *trl)
+int isst_get_get_trl(struct isst_id *id, int level, int avx_level, int *trl)
{
unsigned int req, resp;
int ret;
req = level | (avx_level << 16);
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
&resp);
if (ret)
@@ -318,7 +318,7 @@ int isst_get_get_trl(int cpu, int level, int avx_level, int *trl)
debug_printf(
"cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\n",
- cpu, req, resp);
+ id->cpu, req, resp);
trl[0] = resp & GENMASK(7, 0);
trl[1] = (resp & GENMASK(15, 8)) >> 8;
@@ -326,13 +326,13 @@ int isst_get_get_trl(int cpu, int level, int avx_level, int *trl)
trl[3] = (resp & GENMASK(31, 24)) >> 24;
req = level | BIT(8) | (avx_level << 16);
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
&resp);
if (ret)
return ret;
- debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", cpu,
+ debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", id->cpu,
req, resp);
trl[4] = resp & GENMASK(7, 0);
@@ -343,61 +343,37 @@ int isst_get_get_trl(int cpu, int level, int avx_level, int *trl)
return 0;
}
-int isst_get_trl_bucket_info(int cpu, unsigned long long *buckets_info)
+int isst_get_trl_bucket_info(struct isst_id *id, unsigned long long *buckets_info)
{
int ret;
- debug_printf("cpu:%d bucket info via MSR\n", cpu);
+ debug_printf("cpu:%d bucket info via MSR\n", id->cpu);
*buckets_info = 0;
- ret = isst_send_msr_command(cpu, 0x1ae, 0, buckets_info);
+ ret = isst_send_msr_command(id->cpu, 0x1ae, 0, buckets_info);
if (ret)
return ret;
- debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", cpu,
+ debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", id->cpu,
*buckets_info);
return 0;
}
-int isst_set_tdp_level_msr(int cpu, int tdp_level)
-{
- unsigned long long level = tdp_level;
- int ret;
-
- debug_printf("cpu: tdp_level via MSR %d\n", cpu, tdp_level);
-
- if (isst_get_config_tdp_lock_status(cpu)) {
- isst_display_error_info_message(1, "tdp_locked", 0, 0);
- return -1;
- }
-
- if (tdp_level > 2)
- return -1; /* invalid value */
-
- ret = isst_send_msr_command(cpu, 0x64b, 1, &level);
- if (ret)
- return ret;
-
- debug_printf("cpu: tdp_level via MSR successful %d\n", cpu, tdp_level);
-
- return 0;
-}
-
-int isst_set_tdp_level(int cpu, int tdp_level)
+int isst_set_tdp_level(struct isst_id *id, int tdp_level)
{
unsigned int resp;
int ret;
- if (isst_get_config_tdp_lock_status(cpu)) {
+ if (isst_get_config_tdp_lock_status(id)) {
isst_display_error_info_message(1, "TDP is locked", 0, 0);
return -1;
}
- ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0,
tdp_level, &resp);
if (ret) {
isst_display_error_info_message(1, "Set TDP level failed for level", 1, tdp_level);
@@ -407,14 +383,14 @@ int isst_set_tdp_level(int cpu, int tdp_level)
return 0;
}
-int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info)
+int isst_get_pbf_info(struct isst_id *id, int level, struct isst_pbf_info *pbf_info)
{
struct isst_pkg_ctdp_level_info ctdp_level;
struct isst_pkg_ctdp pkg_dev;
int i, ret, max_punit_core, max_mask_index;
unsigned int req, resp;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
return ret;
@@ -425,7 +401,7 @@ int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info)
return -1;
}
- ret = isst_get_ctdp_control(cpu, level, &ctdp_level);
+ ret = isst_get_ctdp_control(id, level, &ctdp_level);
if (ret)
return ret;
@@ -436,14 +412,14 @@ int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info)
pbf_info->core_cpumask_size = alloc_cpu_set(&pbf_info->core_cpumask);
- max_punit_core = get_max_punit_core_id(get_physical_package_id(cpu), get_physical_die_id(cpu));
+ max_punit_core = get_max_punit_core_id(id);
max_mask_index = max_punit_core > 32 ? 2 : 1;
for (i = 0; i < max_mask_index; ++i) {
unsigned long long mask;
int count;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_PBF_GET_CORE_MASK_INFO,
0, (i << 8) | level, &resp);
if (ret)
@@ -451,23 +427,23 @@ int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info)
debug_printf(
"cpu:%d CONFIG_TDP_PBF_GET_CORE_MASK_INFO resp:%x\n",
- cpu, resp);
+ id->cpu, resp);
mask = (unsigned long long)resp << (32 * i);
- set_cpu_mask_from_punit_coremask(cpu, mask,
+ set_cpu_mask_from_punit_coremask(id, mask,
pbf_info->core_cpumask_size,
pbf_info->core_cpumask,
&count);
}
req = level;
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO, 0, req,
&resp);
if (ret)
return ret;
- debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", cpu,
+ debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", id->cpu,
resp);
pbf_info->p1_low = resp & 0xff;
@@ -475,21 +451,21 @@ int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info)
req = level;
ret = isst_send_mbox_command(
- cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp);
+ id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp);
if (ret)
return ret;
- debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", cpu, resp);
+ debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", id->cpu, resp);
pbf_info->tdp = resp & 0xffff;
req = level;
ret = isst_send_mbox_command(
- cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp);
+ id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp);
if (ret)
return ret;
- debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", cpu,
+ debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", id->cpu,
resp);
pbf_info->t_control = (resp >> 8) & 0xff;
pbf_info->t_prochot = resp & 0xff;
@@ -502,7 +478,7 @@ void isst_get_pbf_info_complete(struct isst_pbf_info *pbf_info)
free_cpu_set(pbf_info->core_cpumask);
}
-int isst_set_pbf_fact_status(int cpu, int pbf, int enable)
+int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable)
{
struct isst_pkg_ctdp pkg_dev;
struct isst_pkg_ctdp_level_info ctdp_level;
@@ -510,13 +486,13 @@ int isst_set_pbf_fact_status(int cpu, int pbf, int enable)
unsigned int req = 0, resp;
int ret;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret)
- debug_printf("cpu:%d No support for dynamic ISST\n", cpu);
+ debug_printf("cpu:%d No support for dynamic ISST\n", id->cpu);
current_level = pkg_dev.current_level;
- ret = isst_get_ctdp_control(cpu, current_level, &ctdp_level);
+ ret = isst_get_ctdp_control(id, current_level, &ctdp_level);
if (ret)
return ret;
@@ -542,18 +518,18 @@ int isst_set_pbf_fact_status(int cpu, int pbf, int enable)
req &= ~BIT(16);
}
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_SET_TDP_CONTROL, 0, req, &resp);
if (ret)
return ret;
debug_printf("cpu:%d CONFIG_TDP_SET_TDP_CONTROL pbf/fact:%d req:%x\n",
- cpu, pbf, req);
+ id->cpu, pbf, req);
return 0;
}
-int isst_get_fact_bucket_info(int cpu, int level,
+int isst_get_fact_bucket_info(struct isst_id *id, int level,
struct isst_fact_bucket_info *bucket_info)
{
unsigned int resp;
@@ -563,7 +539,7 @@ int isst_get_fact_bucket_info(int cpu, int level,
int j;
ret = isst_send_mbox_command(
- cpu, CONFIG_TDP,
+ id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES, 0,
(i << 8) | level, &resp);
if (ret)
@@ -571,7 +547,7 @@ int isst_get_fact_bucket_info(int cpu, int level,
debug_printf(
"cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES index:%d level:%d resp:%x\n",
- cpu, i, level, resp);
+ id->cpu, i, level, resp);
for (j = 0; j < 4; ++j) {
bucket_info[j + (i * 4)].high_priority_cores_count =
@@ -584,7 +560,7 @@ int isst_get_fact_bucket_info(int cpu, int level,
int j;
ret = isst_send_mbox_command(
- cpu, CONFIG_TDP,
+ id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS, 0,
(k << 16) | (i << 8) | level, &resp);
if (ret)
@@ -592,7 +568,7 @@ int isst_get_fact_bucket_info(int cpu, int level,
debug_printf(
"cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS index:%d level:%d avx:%d resp:%x\n",
- cpu, i, level, k, resp);
+ id->cpu, i, level, k, resp);
for (j = 0; j < 4; ++j) {
switch (k) {
@@ -618,14 +594,14 @@ int isst_get_fact_bucket_info(int cpu, int level,
return 0;
}
-int isst_get_fact_info(int cpu, int level, int fact_bucket, struct isst_fact_info *fact_info)
+int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info)
{
struct isst_pkg_ctdp_level_info ctdp_level;
struct isst_pkg_ctdp pkg_dev;
unsigned int resp;
int j, ret, print;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
return ret;
@@ -636,7 +612,7 @@ int isst_get_fact_info(int cpu, int level, int fact_bucket, struct isst_fact_inf
return -1;
}
- ret = isst_get_ctdp_control(cpu, level, &ctdp_level);
+ ret = isst_get_ctdp_control(id, level, &ctdp_level);
if (ret)
return ret;
@@ -645,20 +621,20 @@ int isst_get_fact_info(int cpu, int level, int fact_bucket, struct isst_fact_inf
return -1;
}
- ret = isst_send_mbox_command(cpu, CONFIG_TDP,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO, 0,
level, &resp);
if (ret)
return ret;
debug_printf("cpu:%d CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO resp:%x\n",
- cpu, resp);
+ id->cpu, resp);
fact_info->lp_clipping_ratio_license_sse = resp & 0xff;
fact_info->lp_clipping_ratio_license_avx2 = (resp >> 8) & 0xff;
fact_info->lp_clipping_ratio_license_avx512 = (resp >> 16) & 0xff;
- ret = isst_get_fact_bucket_info(cpu, level, fact_info->bucket_info);
+ ret = isst_get_fact_bucket_info(id, level, fact_info->bucket_info);
if (ret)
return ret;
@@ -680,32 +656,32 @@ int isst_get_fact_info(int cpu, int level, int fact_bucket, struct isst_fact_inf
return 0;
}
-int isst_get_trl(int cpu, unsigned long long *trl)
+int isst_get_trl(struct isst_id *id, unsigned long long *trl)
{
int ret;
- ret = isst_send_msr_command(cpu, 0x1AD, 0, trl);
+ ret = isst_send_msr_command(id->cpu, 0x1AD, 0, trl);
if (ret)
return ret;
return 0;
}
-int isst_set_trl(int cpu, unsigned long long trl)
+int isst_set_trl(struct isst_id *id, unsigned long long trl)
{
int ret;
if (!trl)
trl = 0xFFFFFFFFFFFFFFFFULL;
- ret = isst_send_msr_command(cpu, 0x1AD, 1, &trl);
+ ret = isst_send_msr_command(id->cpu, 0x1AD, 1, &trl);
if (ret)
return ret;
return 0;
}
-int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl)
+int isst_set_trl_from_current_tdp(struct isst_id *id, unsigned long long trl)
{
unsigned long long msr_trl;
int ret;
@@ -717,11 +693,11 @@ int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl)
int trl[8];
int i;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret)
return ret;
- ret = isst_get_get_trl(cpu, pkg_dev.current_level, 0, trl);
+ ret = isst_get_get_trl(id, pkg_dev.current_level, 0, trl);
if (ret)
return ret;
@@ -732,7 +708,7 @@ int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl)
msr_trl |= (_trl << (i * 8));
}
}
- ret = isst_send_msr_command(cpu, 0x1AD, 1, &msr_trl);
+ ret = isst_send_msr_command(id->cpu, 0x1AD, 1, &msr_trl);
if (ret)
return ret;
@@ -740,12 +716,12 @@ int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl)
}
/* Return 1 if locked */
-int isst_get_config_tdp_lock_status(int cpu)
+int isst_get_config_tdp_lock_status(struct isst_id *id)
{
unsigned long long tdp_control = 0;
int ret;
- ret = isst_send_msr_command(cpu, 0x64b, 0, &tdp_control);
+ ret = isst_send_msr_command(id->cpu, 0x64b, 0, &tdp_control);
if (ret)
return ret;
@@ -754,7 +730,7 @@ int isst_get_config_tdp_lock_status(int cpu)
return ret;
}
-void isst_get_process_ctdp_complete(int cpu, struct isst_pkg_ctdp *pkg_dev)
+void isst_get_process_ctdp_complete(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
{
int i;
@@ -771,19 +747,19 @@ void isst_get_process_ctdp_complete(int cpu, struct isst_pkg_ctdp *pkg_dev)
}
}
-int isst_get_process_ctdp(int cpu, int tdp_level, struct isst_pkg_ctdp *pkg_dev)
+int isst_get_process_ctdp(struct isst_id *id, int tdp_level, struct isst_pkg_ctdp *pkg_dev)
{
int i, ret, valid = 0;
if (pkg_dev->processed)
return 0;
- ret = isst_get_ctdp_levels(cpu, pkg_dev);
+ ret = isst_get_ctdp_levels(id, pkg_dev);
if (ret)
return ret;
debug_printf("cpu: %d ctdp enable:%d current level: %d levels:%d\n",
- cpu, pkg_dev->enabled, pkg_dev->current_level,
+ id->cpu, pkg_dev->enabled, pkg_dev->current_level,
pkg_dev->levels);
if (tdp_level != 0xff && tdp_level > pkg_dev->levels) {
@@ -800,16 +776,16 @@ int isst_get_process_ctdp(int cpu, int tdp_level, struct isst_pkg_ctdp *pkg_dev)
if (tdp_level != 0xff && i != tdp_level)
continue;
- debug_printf("cpu:%d Get Information for TDP level:%d\n", cpu,
+ debug_printf("cpu:%d Get Information for TDP level:%d\n", id->cpu,
i);
ctdp_level = &pkg_dev->ctdp_level[i];
ctdp_level->level = i;
- ctdp_level->control_cpu = cpu;
- ctdp_level->pkg_id = get_physical_package_id(cpu);
- ctdp_level->die_id = get_physical_die_id(cpu);
+ ctdp_level->control_cpu = id->cpu;
+ ctdp_level->pkg_id = id->pkg;
+ ctdp_level->die_id = id->die;
- ret = isst_get_ctdp_control(cpu, i, ctdp_level);
+ ret = isst_get_ctdp_control(id, i, ctdp_level);
if (ret)
continue;
@@ -818,13 +794,13 @@ int isst_get_process_ctdp(int cpu, int tdp_level, struct isst_pkg_ctdp *pkg_dev)
ctdp_level->processed = 1;
if (ctdp_level->pbf_support) {
- ret = isst_get_pbf_info(cpu, i, &ctdp_level->pbf_info);
+ ret = isst_get_pbf_info(id, i, &ctdp_level->pbf_info);
if (!ret)
ctdp_level->pbf_found = 1;
}
if (ctdp_level->fact_support) {
- ret = isst_get_fact_info(cpu, i, 0xff,
+ ret = isst_get_fact_info(id, i, 0xff,
&ctdp_level->fact_info);
if (ret)
return ret;
@@ -833,76 +809,76 @@ int isst_get_process_ctdp(int cpu, int tdp_level, struct isst_pkg_ctdp *pkg_dev)
if (!pkg_dev->enabled && is_skx_based_platform()) {
int freq;
- freq = get_cpufreq_base_freq(cpu);
+ freq = get_cpufreq_base_freq(id->cpu);
if (freq > 0) {
ctdp_level->sse_p1 = freq / 100000;
ctdp_level->tdp_ratio = ctdp_level->sse_p1;
}
- isst_get_get_trl_from_msr(cpu, ctdp_level->trl_sse_active_cores);
- isst_get_trl_bucket_info(cpu, &ctdp_level->buckets_info);
+ isst_get_get_trl_from_msr(id, ctdp_level->trl_sse_active_cores);
+ isst_get_trl_bucket_info(id, &ctdp_level->buckets_info);
continue;
}
- ret = isst_get_tdp_info(cpu, i, ctdp_level);
+ ret = isst_get_tdp_info(id, i, ctdp_level);
if (ret)
return ret;
- ret = isst_get_pwr_info(cpu, i, ctdp_level);
+ ret = isst_get_pwr_info(id, i, ctdp_level);
if (ret)
return ret;
- ret = isst_get_tjmax_info(cpu, i, ctdp_level);
+ ret = isst_get_tjmax_info(id, i, ctdp_level);
if (ret)
return ret;
ctdp_level->core_cpumask_size =
alloc_cpu_set(&ctdp_level->core_cpumask);
- ret = isst_get_coremask_info(cpu, i, ctdp_level);
+ ret = isst_get_coremask_info(id, i, ctdp_level);
if (ret)
return ret;
- ret = isst_get_trl_bucket_info(cpu, &ctdp_level->buckets_info);
+ ret = isst_get_trl_bucket_info(id, &ctdp_level->buckets_info);
if (ret)
return ret;
- ret = isst_get_get_trl(cpu, i, 0,
+ ret = isst_get_get_trl(id, i, 0,
ctdp_level->trl_sse_active_cores);
if (ret)
return ret;
- ret = isst_get_get_trl(cpu, i, 1,
+ ret = isst_get_get_trl(id, i, 1,
ctdp_level->trl_avx_active_cores);
if (ret)
return ret;
- ret = isst_get_get_trl(cpu, i, 2,
+ ret = isst_get_get_trl(id, i, 2,
ctdp_level->trl_avx_512_active_cores);
if (ret)
return ret;
- isst_get_uncore_p0_p1_info(cpu, i, ctdp_level);
- isst_get_p1_info(cpu, i, ctdp_level);
- isst_get_uncore_mem_freq(cpu, i, ctdp_level);
+ isst_get_uncore_p0_p1_info(id, i, ctdp_level);
+ isst_get_p1_info(id, i, ctdp_level);
+ isst_get_uncore_mem_freq(id, i, ctdp_level);
}
if (!valid)
- isst_display_error_info_message(0, "Invalid level, Can't get TDP control information at specified levels on cpu", 1, cpu);
+ isst_display_error_info_message(0, "Invalid level, Can't get TDP control information at specified levels on cpu", 1, id->cpu);
return 0;
}
-int isst_clos_get_clos_information(int cpu, int *enable, int *type)
+int isst_clos_get_clos_information(struct isst_id *id, int *enable, int *type)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
&resp);
if (ret)
return ret;
- debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", cpu, resp);
+ debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
if (resp & BIT(1))
*enable = 1;
@@ -917,7 +893,7 @@ int isst_clos_get_clos_information(int cpu, int *enable, int *type)
return 0;
}
-int isst_pm_qos_config(int cpu, int enable_clos, int priority_type)
+int isst_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type)
{
unsigned int req, resp;
int ret;
@@ -926,13 +902,13 @@ int isst_pm_qos_config(int cpu, int enable_clos, int priority_type)
struct isst_pkg_ctdp pkg_dev;
struct isst_pkg_ctdp_level_info ctdp_level;
- ret = isst_get_ctdp_levels(cpu, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
debug_printf("isst_get_ctdp_levels\n");
return ret;
}
- ret = isst_get_ctdp_control(cpu, pkg_dev.current_level,
+ ret = isst_get_ctdp_control(id, pkg_dev.current_level,
&ctdp_level);
if (ret)
return ret;
@@ -941,23 +917,23 @@ int isst_pm_qos_config(int cpu, int enable_clos, int priority_type)
isst_display_error_info_message(1, "Ignoring request, turbo-freq feature is still enabled", 0, 0);
return -EINVAL;
}
- ret = isst_write_pm_config(cpu, 0);
+ ret = isst_write_pm_config(id, 0);
if (ret)
isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
} else {
- ret = isst_write_pm_config(cpu, 1);
+ ret = isst_write_pm_config(id, 1);
if (ret)
isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
}
- ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
&resp);
if (ret) {
isst_display_error_info_message(1, "CLOS_PM_QOS_CONFIG command failed", 0, 0);
return ret;
}
- debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", cpu, resp);
+ debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
req = resp;
@@ -974,30 +950,27 @@ int isst_pm_qos_config(int cpu, int enable_clos, int priority_type)
else
req = req & ~BIT(2);
- ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG,
BIT(MBOX_CMD_WRITE_BIT), req, &resp);
if (ret)
return ret;
- debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", cpu,
+ debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", id->cpu,
priority_type, req);
return 0;
}
-int isst_pm_get_clos(int cpu, int clos, struct isst_clos_config *clos_config)
+int isst_pm_get_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
{
unsigned int resp;
int ret;
- ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_CLOS, clos, 0,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, clos, 0,
&resp);
if (ret)
return ret;
- clos_config->pkg_id = get_physical_package_id(cpu);
- clos_config->die_id = get_physical_die_id(cpu);
-
clos_config->epp = resp & 0x0f;
clos_config->clos_prop_prio = (resp >> 4) & 0x0f;
clos_config->clos_min = (resp >> 8) & 0xff;
@@ -1007,7 +980,7 @@ int isst_pm_get_clos(int cpu, int clos, struct isst_clos_config *clos_config)
return 0;
}
-int isst_set_clos(int cpu, int clos, struct isst_clos_config *clos_config)
+int isst_set_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
{
unsigned int req, resp;
unsigned int param;
@@ -1021,53 +994,53 @@ int isst_set_clos(int cpu, int clos, struct isst_clos_config *clos_config)
param = BIT(MBOX_CMD_WRITE_BIT) | clos;
- ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_CLOS, param, req,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, param, req,
&resp);
if (ret)
return ret;
- debug_printf("cpu:%d CLOS_PM_CLOS param:%x req:%x\n", cpu, param, req);
+ debug_printf("cpu:%d CLOS_PM_CLOS param:%x req:%x\n", id->cpu, param, req);
return 0;
}
-int isst_clos_get_assoc_status(int cpu, int *clos_id)
+int isst_clos_get_assoc_status(struct isst_id *id, int *clos_id)
{
unsigned int resp;
unsigned int param;
int core_id, ret;
- core_id = find_phy_core_num(cpu);
+ core_id = find_phy_core_num(id->cpu);
param = core_id;
- ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, 0,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, 0,
&resp);
if (ret)
return ret;
- debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x resp:%x\n", cpu, param,
+ debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x resp:%x\n", id->cpu, param,
resp);
*clos_id = (resp >> 16) & 0x03;
return 0;
}
-int isst_clos_associate(int cpu, int clos_id)
+int isst_clos_associate(struct isst_id *id, int clos_id)
{
unsigned int req, resp;
unsigned int param;
int core_id, ret;
req = (clos_id & 0x03) << 16;
- core_id = find_phy_core_num(cpu);
+ core_id = find_phy_core_num(id->cpu);
param = BIT(MBOX_CMD_WRITE_BIT) | core_id;
- ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param,
+ ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param,
req, &resp);
if (ret)
return ret;
- debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x req:%x\n", cpu, param,
+ debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x req:%x\n", id->cpu, param,
req);
return 0;
diff --git a/tools/power/x86/intel-speed-select/isst-daemon.c b/tools/power/x86/intel-speed-select/isst-daemon.c
new file mode 100644
index 000000000000..0699137c0901
--- /dev/null
+++ b/tools/power/x86/intel-speed-select/isst-daemon.c
@@ -0,0 +1,242 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Speed Select -- Allow speed select to daemonize
+ * Copyright (c) 2022 Intel Corporation.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <getopt.h>
+#include <signal.h>
+#include <time.h>
+
+#include "isst.h"
+
+static int per_package_levels_info[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
+static time_t per_package_levels_tm[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
+
+static void init_levels(void)
+{
+ int i, j;
+
+ for (i = 0; i < MAX_PACKAGE_COUNT; ++i)
+ for (j = 0; j < MAX_DIE_PER_PACKAGE; ++j)
+ per_package_levels_info[i][j] = -1;
+}
+
+void process_level_change(struct isst_id *id)
+{
+ struct isst_pkg_ctdp_level_info ctdp_level;
+ struct isst_pkg_ctdp pkg_dev;
+ time_t tm;
+ int ret;
+
+ if (id->pkg < 0 || id->die < 0) {
+ debug_printf("Invalid package/die info for cpu:%d\n", id->cpu);
+ return;
+ }
+
+ tm = time(NULL);
+ if (tm - per_package_levels_tm[id->pkg][id->die] < 2)
+ return;
+
+ per_package_levels_tm[id->pkg][id->die] = tm;
+
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
+ if (ret) {
+ debug_printf("Can't get tdp levels for cpu:%d\n", id->cpu);
+ return;
+ }
+
+ debug_printf("Get Config level %d pkg:%d die:%d current_level:%d\n", id->cpu,
+ id->pkg, id->die, pkg_dev.current_level);
+
+ if (pkg_dev.locked) {
+ debug_printf("config TDP s locked \n");
+ return;
+ }
+
+ if (per_package_levels_info[id->pkg][id->die] == pkg_dev.current_level)
+ return;
+
+ debug_printf("**Config level change for cpu:%d pkg:%d die:%d from %d to %d\n",
+ id->cpu, id->pkg, id->die, per_package_levels_info[id->pkg][id->die],
+ pkg_dev.current_level);
+
+ per_package_levels_info[id->pkg][id->die] = pkg_dev.current_level;
+
+ ctdp_level.core_cpumask_size =
+ alloc_cpu_set(&ctdp_level.core_cpumask);
+ ret = isst_get_coremask_info(id, pkg_dev.current_level, &ctdp_level);
+ if (ret) {
+ free_cpu_set(ctdp_level.core_cpumask);
+ debug_printf("Can't get core_mask:%d\n", id->cpu);
+ return;
+ }
+
+ if (ctdp_level.cpu_count) {
+ int i, max_cpus = get_topo_max_cpus();
+ for (i = 0; i < max_cpus; ++i) {
+ if (!is_cpu_in_power_domain(i, id))
+ continue;
+ if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
+ fprintf(stderr, "online cpu %d\n", i);
+ set_cpu_online_offline(i, 1);
+ } else {
+ fprintf(stderr, "offline cpu %d\n", i);
+ set_cpu_online_offline(i, 0);
+ }
+ }
+ }
+
+ free_cpu_set(ctdp_level.core_cpumask);
+}
+
+static void _poll_for_config_change(struct isst_id *id, void *arg1, void *arg2,
+ void *arg3, void *arg4)
+{
+ process_level_change(id);
+}
+
+static void poll_for_config_change(void)
+{
+ for_each_online_package_in_set(_poll_for_config_change, NULL, NULL,
+ NULL, NULL);
+}
+
+static int done = 0;
+static int pid_file_handle;
+
+static void signal_handler(int sig)
+{
+ switch (sig) {
+ case SIGINT:
+ case SIGTERM:
+ done = 1;
+ hfi_exit();
+ exit(0);
+ break;
+ default:
+ break;
+ }
+}
+
+static void daemonize(char *rundir, char *pidfile)
+{
+ int pid, sid, i;
+ char str[10];
+ struct sigaction sig_actions;
+ sigset_t sig_set;
+ int ret;
+
+ if (getppid() == 1)
+ return;
+
+ sigemptyset(&sig_set);
+ sigaddset(&sig_set, SIGCHLD);
+ sigaddset(&sig_set, SIGTSTP);
+ sigaddset(&sig_set, SIGTTOU);
+ sigaddset(&sig_set, SIGTTIN);
+ sigprocmask(SIG_BLOCK, &sig_set, NULL);
+
+ sig_actions.sa_handler = signal_handler;
+ sigemptyset(&sig_actions.sa_mask);
+ sig_actions.sa_flags = 0;
+
+ sigaction(SIGHUP, &sig_actions, NULL);
+ sigaction(SIGTERM, &sig_actions, NULL);
+ sigaction(SIGINT, &sig_actions, NULL);
+
+ pid = fork();
+ if (pid < 0) {
+ /* Could not fork */
+ exit(EXIT_FAILURE);
+ }
+ if (pid > 0)
+ exit(EXIT_SUCCESS);
+
+ umask(027);
+
+ sid = setsid();
+ if (sid < 0)
+ exit(EXIT_FAILURE);
+
+ /* close all descriptors */
+ for (i = getdtablesize(); i >= 0; --i)
+ close(i);
+
+ i = open("/dev/null", O_RDWR);
+ ret = dup(i);
+ if (ret == -1)
+ exit(EXIT_FAILURE);
+
+ ret = dup(i);
+ if (ret == -1)
+ exit(EXIT_FAILURE);
+
+ ret = chdir(rundir);
+ if (ret == -1)
+ exit(EXIT_FAILURE);
+
+ pid_file_handle = open(pidfile, O_RDWR | O_CREAT, 0600);
+ if (pid_file_handle == -1) {
+ /* Couldn't open lock file */
+ exit(1);
+ }
+ /* Try to lock file */
+#ifdef LOCKF_SUPPORT
+ if (lockf(pid_file_handle, F_TLOCK, 0) == -1) {
+#else
+ if (flock(pid_file_handle, LOCK_EX|LOCK_NB) < 0) {
+#endif
+ /* Couldn't get lock on lock file */
+ fprintf(stderr, "Couldn't get lock file %d\n", getpid());
+ exit(1);
+ }
+ snprintf(str, sizeof(str), "%d\n", getpid());
+ ret = write(pid_file_handle, str, strlen(str));
+ if (ret == -1)
+ exit(EXIT_FAILURE);
+
+ close(i);
+}
+
+int isst_daemon(int debug_mode, int poll_interval, int no_daemon)
+{
+ int ret;
+
+ if (!no_daemon && poll_interval < 0 && !debug_mode) {
+ fprintf(stderr, "OOB mode is enabled and will run as daemon\n");
+ daemonize((char *) "/tmp/",
+ (char *)"/tmp/hfi-events.pid");
+ } else {
+ signal(SIGINT, signal_handler);
+ }
+
+ init_levels();
+
+ if (poll_interval < 0) {
+ ret = hfi_main();
+ if (ret) {
+ fprintf(stderr, "HFI initialization failed\n");
+ }
+ fprintf(stderr, "Must specify poll-interval\n");
+ return ret;
+ }
+
+ debug_printf("Starting loop\n");
+ while (!done) {
+ sleep(poll_interval);
+ poll_for_config_change();
+ }
+
+ return 0;
+}
diff --git a/tools/power/x86/intel-speed-select/isst-display.c b/tools/power/x86/intel-speed-select/isst-display.c
index f97d8859ada7..b19f57d30f55 100644
--- a/tools/power/x86/intel-speed-select/isst-display.c
+++ b/tools/power/x86/intel-speed-select/isst-display.c
@@ -166,29 +166,27 @@ static void format_and_print(FILE *outf, int level, char *header, char *value)
last_level = level;
}
-static int print_package_info(int cpu, FILE *outf)
+static int print_package_info(struct isst_id *id, FILE *outf)
{
char header[256];
if (out_format_is_json()) {
snprintf(header, sizeof(header), "package-%d:die-%d:cpu-%d",
- get_physical_package_id(cpu), get_physical_die_id(cpu),
- cpu);
+ id->pkg, id->die, id->cpu);
format_and_print(outf, 1, header, NULL);
return 1;
}
- snprintf(header, sizeof(header), "package-%d",
- get_physical_package_id(cpu));
+ snprintf(header, sizeof(header), "package-%d", id->pkg);
format_and_print(outf, 1, header, NULL);
- snprintf(header, sizeof(header), "die-%d", get_physical_die_id(cpu));
+ snprintf(header, sizeof(header), "die-%d", id->die);
format_and_print(outf, 2, header, NULL);
- snprintf(header, sizeof(header), "cpu-%d", cpu);
+ snprintf(header, sizeof(header), "cpu-%d", id->cpu);
format_and_print(outf, 3, header, NULL);
return 3;
}
-static void _isst_pbf_display_information(int cpu, FILE *outf, int level,
+static void _isst_pbf_display_information(struct isst_id *id, FILE *outf, int level,
struct isst_pbf_info *pbf_info,
int disp_level)
{
@@ -231,7 +229,7 @@ static void _isst_pbf_display_information(int cpu, FILE *outf, int level,
format_and_print(outf, disp_level + 1, header, value);
}
-static void _isst_fact_display_information(int cpu, FILE *outf, int level,
+static void _isst_fact_display_information(struct isst_id *id, FILE *outf, int level,
int fact_bucket, int fact_avx,
struct isst_fact_info *fact_info,
int base_level)
@@ -319,7 +317,7 @@ static void _isst_fact_display_information(int cpu, FILE *outf, int level,
format_and_print(outf, base_level + 2, header, value);
}
-void isst_ctdp_display_core_info(int cpu, FILE *outf, char *prefix,
+void isst_ctdp_display_core_info(struct isst_id *id, FILE *outf, char *prefix,
unsigned int val, char *str0, char *str1)
{
char header[256];
@@ -328,17 +326,14 @@ void isst_ctdp_display_core_info(int cpu, FILE *outf, char *prefix,
if (out_format_is_json()) {
snprintf(header, sizeof(header), "package-%d:die-%d:cpu-%d",
- get_physical_package_id(cpu), get_physical_die_id(cpu),
- cpu);
+ id->pkg, id->die, id->cpu);
format_and_print(outf, level++, header, NULL);
} else {
- snprintf(header, sizeof(header), "package-%d",
- get_physical_package_id(cpu));
+ snprintf(header, sizeof(header), "package-%d", id->pkg);
format_and_print(outf, level++, header, NULL);
- snprintf(header, sizeof(header), "die-%d",
- get_physical_die_id(cpu));
+ snprintf(header, sizeof(header), "die-%d", id->die);
format_and_print(outf, level++, header, NULL);
- snprintf(header, sizeof(header), "cpu-%d", cpu);
+ snprintf(header, sizeof(header), "cpu-%d", id->cpu);
format_and_print(outf, level++, header, NULL);
}
@@ -353,7 +348,7 @@ void isst_ctdp_display_core_info(int cpu, FILE *outf, char *prefix,
format_and_print(outf, 1, NULL, NULL);
}
-void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level,
+void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level,
struct isst_pkg_ctdp *pkg_dev)
{
char header[256];
@@ -362,7 +357,7 @@ void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level,
int i;
if (pkg_dev->processed)
- level = print_package_info(cpu, outf);
+ level = print_package_info(id, outf);
for (i = 0; i <= pkg_dev->levels; ++i) {
struct isst_pkg_ctdp_level_info *ctdp_level;
@@ -377,8 +372,7 @@ void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level,
format_and_print(outf, level + 1, header, NULL);
snprintf(header, sizeof(header), "cpu-count");
- j = get_cpu_count(get_physical_die_id(cpu),
- get_physical_die_id(cpu));
+ j = get_cpu_count(id);
snprintf(value, sizeof(value), "%d", j);
format_and_print(outf, level + 2, header, value);
@@ -485,7 +479,7 @@ void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level,
if (is_clx_n_platform()) {
if (ctdp_level->pbf_support)
- _isst_pbf_display_information(cpu, outf,
+ _isst_pbf_display_information(id, outf,
tdp_level,
&ctdp_level->pbf_info,
level + 2);
@@ -557,11 +551,11 @@ void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level,
}
if (ctdp_level->pbf_support)
- _isst_pbf_display_information(cpu, outf, i,
+ _isst_pbf_display_information(id, outf, i,
&ctdp_level->pbf_info,
level + 2);
if (ctdp_level->fact_support)
- _isst_fact_display_information(cpu, outf, i, 0xff, 0xff,
+ _isst_fact_display_information(id, outf, i, 0xff, 0xff,
&ctdp_level->fact_info,
level + 2);
}
@@ -583,36 +577,36 @@ void isst_ctdp_display_information_end(FILE *outf)
start = 0;
}
-void isst_pbf_display_information(int cpu, FILE *outf, int level,
+void isst_pbf_display_information(struct isst_id *id, FILE *outf, int level,
struct isst_pbf_info *pbf_info)
{
int _level;
- _level = print_package_info(cpu, outf);
- _isst_pbf_display_information(cpu, outf, level, pbf_info, _level + 1);
+ _level = print_package_info(id, outf);
+ _isst_pbf_display_information(id, outf, level, pbf_info, _level + 1);
format_and_print(outf, 1, NULL, NULL);
}
-void isst_fact_display_information(int cpu, FILE *outf, int level,
+void isst_fact_display_information(struct isst_id *id, FILE *outf, int level,
int fact_bucket, int fact_avx,
struct isst_fact_info *fact_info)
{
int _level;
- _level = print_package_info(cpu, outf);
- _isst_fact_display_information(cpu, outf, level, fact_bucket, fact_avx,
+ _level = print_package_info(id, outf);
+ _isst_fact_display_information(id, outf, level, fact_bucket, fact_avx,
fact_info, _level + 1);
format_and_print(outf, 1, NULL, NULL);
}
-void isst_clos_display_information(int cpu, FILE *outf, int clos,
+void isst_clos_display_information(struct isst_id *id, FILE *outf, int clos,
struct isst_clos_config *clos_config)
{
char header[256];
char value[256];
int level;
- level = print_package_info(cpu, outf);
+ level = print_package_info(id, outf);
snprintf(header, sizeof(header), "core-power");
format_and_print(outf, level + 1, header, NULL);
@@ -647,7 +641,7 @@ void isst_clos_display_information(int cpu, FILE *outf, int clos,
format_and_print(outf, level, NULL, NULL);
}
-void isst_clos_display_clos_information(int cpu, FILE *outf,
+void isst_clos_display_clos_information(struct isst_id *id, FILE *outf,
int clos_enable, int type,
int state, int cap)
{
@@ -655,7 +649,7 @@ void isst_clos_display_clos_information(int cpu, FILE *outf,
char value[256];
int level;
- level = print_package_info(cpu, outf);
+ level = print_package_info(id, outf);
snprintf(header, sizeof(header), "core-power");
format_and_print(outf, level + 1, header, NULL);
@@ -691,13 +685,13 @@ void isst_clos_display_clos_information(int cpu, FILE *outf,
format_and_print(outf, level, NULL, NULL);
}
-void isst_clos_display_assoc_information(int cpu, FILE *outf, int clos)
+void isst_clos_display_assoc_information(struct isst_id *id, FILE *outf, int clos)
{
char header[256];
char value[256];
int level;
- level = print_package_info(cpu, outf);
+ level = print_package_info(id, outf);
snprintf(header, sizeof(header), "get-assoc");
format_and_print(outf, level + 1, header, NULL);
@@ -709,15 +703,15 @@ void isst_clos_display_assoc_information(int cpu, FILE *outf, int clos)
format_and_print(outf, level, NULL, NULL);
}
-void isst_display_result(int cpu, FILE *outf, char *feature, char *cmd,
+void isst_display_result(struct isst_id *id, FILE *outf, char *feature, char *cmd,
int result)
{
char header[256];
char value[256];
int level = 3;
- if (cpu >= 0)
- level = print_package_info(cpu, outf);
+ if (id->cpu >= 0)
+ level = print_package_info(id, outf);
snprintf(header, sizeof(header), "%s", feature);
format_and_print(outf, level + 1, header, NULL);
@@ -772,13 +766,13 @@ void isst_display_error_info_message(int error, char *msg, int arg_valid, int ar
format_and_print(outf, 0, NULL, NULL);
}
-void isst_trl_display_information(int cpu, FILE *outf, unsigned long long trl)
+void isst_trl_display_information(struct isst_id *id, FILE *outf, unsigned long long trl)
{
char header[256];
char value[256];
int level;
- level = print_package_info(cpu, outf);
+ level = print_package_info(id, outf);
snprintf(header, sizeof(header), "get-trl");
format_and_print(outf, level + 1, header, NULL);
diff --git a/tools/power/x86/intel-speed-select/isst.h b/tools/power/x86/intel-speed-select/isst.h
index 1aa15d5ea57c..409fcc9c8033 100644
--- a/tools/power/x86/intel-speed-select/isst.h
+++ b/tools/power/x86/intel-speed-select/isst.h
@@ -76,9 +76,17 @@
#define DISP_FREQ_MULTIPLIER 100
+#define MAX_PACKAGE_COUNT 8
+#define MAX_DIE_PER_PACKAGE 2
+
+/* Unified structure to specific a CPU or a Power Domain */
+struct isst_id {
+ int cpu;
+ int pkg;
+ int die;
+};
+
struct isst_clos_config {
- int pkg_id;
- int die_id;
unsigned char epp;
unsigned char clos_prop_prio;
unsigned char clos_min;
@@ -168,22 +176,20 @@ struct isst_pkg_ctdp {
struct isst_pkg_ctdp_level_info ctdp_level[ISST_MAX_TDP_LEVELS];
};
+extern int is_cpu_in_power_domain(int cpu, struct isst_id *id);
extern int get_topo_max_cpus(void);
-extern int get_cpu_count(int pkg_id, int die_id);
-extern int get_max_punit_core_id(int pkg_id, int die_id);
+extern int get_cpu_count(struct isst_id *id);
+extern int get_max_punit_core_id(struct isst_id *id);
/* Common interfaces */
FILE *get_output_file(void);
extern void debug_printf(const char *format, ...);
extern int out_format_is_json(void);
-extern int get_physical_package_id(int cpu);
-extern int get_physical_die_id(int cpu);
+extern void set_isst_id(struct isst_id *id, int cpu);
extern size_t alloc_cpu_set(cpu_set_t **cpu_set);
extern void free_cpu_set(cpu_set_t *cpu_set);
-extern int find_logical_cpu(int pkg_id, int die_id, int phy_cpu);
-extern int find_phy_cpu_num(int logical_cpu);
extern int find_phy_core_num(int logical_cpu);
-extern void set_cpu_mask_from_punit_coremask(int cpu,
+extern void set_cpu_mask_from_punit_coremask(struct isst_id *id,
unsigned long long core_mask,
size_t core_cpumask_size,
cpu_set_t *core_cpumask,
@@ -197,67 +203,74 @@ extern int isst_send_mbox_command(unsigned int cpu, unsigned char command,
extern int isst_send_msr_command(unsigned int cpu, unsigned int command,
int write, unsigned long long *req_resp);
-extern int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev);
-extern int isst_get_ctdp_control(int cpu, int config_index,
+extern int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev);
+extern int isst_get_ctdp_control(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level);
-extern int isst_get_coremask_info(int cpu, int config_index,
+extern int isst_get_coremask_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level);
-extern int isst_get_process_ctdp(int cpu, int tdp_level,
+extern int isst_get_process_ctdp(struct isst_id *id, int tdp_level,
struct isst_pkg_ctdp *pkg_dev);
-extern void isst_get_process_ctdp_complete(int cpu,
+extern void isst_get_process_ctdp_complete(struct isst_id *id,
struct isst_pkg_ctdp *pkg_dev);
-extern void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level,
+extern void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level,
struct isst_pkg_ctdp *pkg_dev);
-extern void isst_ctdp_display_core_info(int cpu, FILE *outf, char *prefix,
+extern void isst_ctdp_display_core_info(struct isst_id *id, FILE *outf, char *prefix,
unsigned int val, char *str0, char *str1);
extern void isst_ctdp_display_information_start(FILE *outf);
extern void isst_ctdp_display_information_end(FILE *outf);
-extern void isst_pbf_display_information(int cpu, FILE *outf, int level,
+extern void isst_pbf_display_information(struct isst_id *id, FILE *outf, int level,
struct isst_pbf_info *info);
-extern int isst_set_tdp_level(int cpu, int tdp_level);
-extern int isst_set_tdp_level_msr(int cpu, int tdp_level);
-extern int isst_set_pbf_fact_status(int cpu, int pbf, int enable);
-extern int isst_get_pbf_info(int cpu, int level,
+extern int isst_set_tdp_level(struct isst_id *id, int tdp_level);
+extern int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable);
+extern int isst_get_pbf_info(struct isst_id *id, int level,
struct isst_pbf_info *pbf_info);
extern void isst_get_pbf_info_complete(struct isst_pbf_info *pbf_info);
-extern int isst_get_fact_info(int cpu, int level, int fact_bucket,
+extern int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket,
struct isst_fact_info *fact_info);
-extern int isst_get_fact_bucket_info(int cpu, int level,
+extern int isst_get_fact_bucket_info(struct isst_id *id, int level,
struct isst_fact_bucket_info *bucket_info);
-extern void isst_fact_display_information(int cpu, FILE *outf, int level,
+extern void isst_fact_display_information(struct isst_id *id, FILE *outf, int level,
int fact_bucket, int fact_avx,
struct isst_fact_info *fact_info);
-extern int isst_set_trl(int cpu, unsigned long long trl);
-extern int isst_get_trl(int cpu, unsigned long long *trl);
-extern int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl);
-extern int isst_get_config_tdp_lock_status(int cpu);
+extern int isst_set_trl(struct isst_id *id, unsigned long long trl);
+extern int isst_get_trl(struct isst_id *id, unsigned long long *trl);
+extern int isst_set_trl_from_current_tdp(struct isst_id *id, unsigned long long trl);
+extern int isst_get_config_tdp_lock_status(struct isst_id *id);
-extern int isst_pm_qos_config(int cpu, int enable_clos, int priority_type);
-extern int isst_pm_get_clos(int cpu, int clos,
+extern int isst_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type);
+extern int isst_pm_get_clos(struct isst_id *id, int clos,
struct isst_clos_config *clos_config);
-extern int isst_set_clos(int cpu, int clos,
+extern int isst_set_clos(struct isst_id *id, int clos,
struct isst_clos_config *clos_config);
-extern int isst_clos_associate(int cpu, int clos);
-extern int isst_clos_get_assoc_status(int cpu, int *clos_id);
-extern void isst_clos_display_information(int cpu, FILE *outf, int clos,
+extern int isst_clos_associate(struct isst_id *id, int clos);
+extern int isst_clos_get_assoc_status(struct isst_id *id, int *clos_id);
+extern void isst_clos_display_information(struct isst_id *id, FILE *outf, int clos,
struct isst_clos_config *clos_config);
-extern void isst_clos_display_assoc_information(int cpu, FILE *outf, int clos);
-extern int isst_read_reg(unsigned short reg, unsigned int *val);
-extern int isst_write_reg(int reg, unsigned int val);
+extern void isst_clos_display_assoc_information(struct isst_id *id, FILE *outf, int clos);
-extern void isst_display_result(int cpu, FILE *outf, char *feature, char *cmd,
+extern void isst_display_result(struct isst_id *id, FILE *outf, char *feature, char *cmd,
int result);
-extern int isst_clos_get_clos_information(int cpu, int *enable, int *type);
-extern void isst_clos_display_clos_information(int cpu, FILE *outf,
+extern int isst_clos_get_clos_information(struct isst_id *id, int *enable, int *type);
+extern void isst_clos_display_clos_information(struct isst_id *id, FILE *outf,
int clos_enable, int type,
int state, int cap);
extern int is_clx_n_platform(void);
extern int get_cpufreq_base_freq(int cpu);
-extern int isst_read_pm_config(int cpu, int *cp_state, int *cp_cap);
+extern int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap);
extern void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg);
extern int is_skx_based_platform(void);
extern int is_spr_platform(void);
extern int is_icx_platform(void);
-extern void isst_trl_display_information(int cpu, FILE *outf, unsigned long long trl);
+extern void isst_trl_display_information(struct isst_id *id, FILE *outf, unsigned long long trl);
+
+extern void set_cpu_online_offline(int cpu, int state);
+extern void for_each_online_package_in_set(void (*callback)(struct isst_id *, void *, void *,
+ void *, void *),
+ void *arg1, void *arg2, void *arg3,
+ void *arg4);
+extern int isst_daemon(int debug_mode, int poll_interval, int no_daemon);
+extern void process_level_change(struct isst_id *id);
+extern int hfi_main(void);
+extern void hfi_exit(void);
#endif