1 // SPDX-License-Identifier: GPL-2.0
3 * Intel Speed Select -- Enumerate and control features
4 * Copyright (c) 2019 Intel Corporation.
7 #include <linux/isst_if.h>
11 struct process_cmd_struct {
14 void (*process_fn)(int arg);
18 static const char *version_str = "v1.14";
20 static const int supported_api_ver = 1;
21 static struct isst_if_platform_info isst_platform_info;
22 static char *progname;
23 static int debug_flag;
27 static int cpu_stepping;
29 #define MAX_CPUS_IN_ONE_REQ 256
30 static short max_target_cpus;
31 static unsigned short target_cpus[MAX_CPUS_IN_ONE_REQ];
33 static int topo_max_cpus;
34 static size_t present_cpumask_size;
35 static cpu_set_t *present_cpumask;
36 static size_t target_cpumask_size;
37 static cpu_set_t *target_cpumask;
38 static int tdp_level = 0xFF;
39 static int fact_bucket = 0xFF;
40 static int fact_avx = 0xFF;
41 static unsigned long long fact_trl;
42 static int out_format_json;
44 static int force_online_offline;
46 static int fact_enable_fail;
49 static int current_clos = -1;
50 static int clos_epp = -1;
51 static int clos_prop_prio = -1;
52 static int clos_min = -1;
53 static int clos_max = -1;
54 static int clos_desired = -1;
55 static int clos_priority_type;
58 unsigned short core_id;
59 unsigned short pkg_id;
60 unsigned short die_id;
61 unsigned short punit_id;
62 unsigned short punit_cpu;
63 unsigned short punit_cpu_core;
64 unsigned short initialized;
66 struct _cpu_map *cpu_map;
75 FILE *get_output_file(void)
80 int is_debug_enabled(void)
85 void debug_printf(const char *format, ...)
89 va_start(args, format);
92 vprintf(format, args);
98 int is_clx_n_platform(void)
100 if (cpu_model == 0x55)
101 if (cpu_stepping == 0x6 || cpu_stepping == 0x7)
106 int is_skx_based_platform(void)
108 if (cpu_model == 0x55)
114 int is_spr_platform(void)
116 if (cpu_model == 0x8F || cpu_model == 0xCF)
122 int is_icx_platform(void)
124 if (cpu_model == 0x6A || cpu_model == 0x6C)
130 static int update_cpu_model(void)
132 unsigned int ebx, ecx, edx;
133 unsigned int fms, family;
135 __cpuid(1, fms, ebx, ecx, edx);
136 family = (fms >> 8) & 0xf;
137 cpu_model = (fms >> 4) & 0xf;
138 if (family == 6 || family == 0xf)
139 cpu_model += ((fms >> 16) & 0xf) << 4;
141 cpu_stepping = fms & 0xf;
142 /* only three CascadeLake-N models are supported */
143 if (is_clx_n_platform()) {
149 fp = fopen("/proc/cpuinfo", "r");
151 err(-1, "cannot open /proc/cpuinfo\n");
153 while (getline(&line, &n, fp) > 0) {
154 if (strstr(line, "model name")) {
155 if (strstr(line, "6252N") ||
156 strstr(line, "6230N") ||
157 strstr(line, "5218N"))
169 int api_version(void)
171 return isst_platform_info.api_version;
174 /* Open a file, and exit on failure */
175 static FILE *fopen_or_exit(const char *path, const char *mode)
177 FILE *filep = fopen(path, mode);
180 err(1, "%s: open failed", path);
185 /* Parse a file containing a single int */
186 static int parse_int_file(int fatal, const char *fmt, ...)
194 vsnprintf(path, sizeof(path), fmt, args);
197 filep = fopen_or_exit(path, "r");
199 filep = fopen(path, "r");
203 if (fscanf(filep, "%d", &value) != 1)
204 err(1, "%s: failed to parse number from file", path);
210 int cpufreq_sysfs_present(void)
214 dir = opendir("/sys/devices/system/cpu/cpu0/cpufreq");
223 int out_format_is_json(void)
225 return out_format_json;
228 static int get_stored_topology_info(int cpu, int *core_id, int *pkg_id, int *die_id)
230 const char *pathname = "/var/run/isst_cpu_topology.dat";
231 struct cpu_topology cpu_top;
235 fp = fopen(pathname, "rb");
239 ret = fseek(fp, cpu * sizeof(cpu_top), SEEK_SET);
243 ret = fread(&cpu_top, sizeof(cpu_top), 1, fp);
249 *pkg_id = cpu_top.pkg_id;
250 *core_id = cpu_top.core_id;
251 *die_id = cpu_top.die_id;
260 static void store_cpu_topology(void)
262 const char *pathname = "/var/run/isst_cpu_topology.dat";
266 fp = fopen(pathname, "rb");
268 /* Mapping already exists */
273 fp = fopen(pathname, "wb");
275 fprintf(stderr, "Can't create file:%s\n", pathname);
279 fprintf(stderr, "Caching topology information\n");
281 for (i = 0; i < topo_max_cpus; ++i) {
282 struct cpu_topology cpu_top;
284 cpu_top.core_id = parse_int_file(0,
285 "/sys/devices/system/cpu/cpu%d/topology/core_id", i);
286 if (cpu_top.core_id < 0)
287 cpu_top.core_id = -1;
289 cpu_top.pkg_id = parse_int_file(0,
290 "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", i);
291 if (cpu_top.pkg_id < 0)
294 cpu_top.die_id = parse_int_file(0,
295 "/sys/devices/system/cpu/cpu%d/topology/die_id", i);
296 if (cpu_top.die_id < 0)
301 if (fwrite(&cpu_top, sizeof(cpu_top), 1, fp) != 1) {
302 fprintf(stderr, "Can't write to:%s\n", pathname);
310 static int get_physical_package_id(int cpu)
317 if (cpu_map && cpu_map[cpu].initialized)
318 return cpu_map[cpu].pkg_id;
320 ret = parse_int_file(0,
321 "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",
324 int core_id, pkg_id, die_id;
326 ret = get_stored_topology_info(cpu, &core_id, &pkg_id, &die_id);
334 static int get_physical_core_id(int cpu)
341 if (cpu_map && cpu_map[cpu].initialized)
342 return cpu_map[cpu].core_id;
344 ret = parse_int_file(0,
345 "/sys/devices/system/cpu/cpu%d/topology/core_id",
348 int core_id, pkg_id, die_id;
350 ret = get_stored_topology_info(cpu, &core_id, &pkg_id, &die_id);
358 static int get_physical_die_id(int cpu)
365 if (cpu_map && cpu_map[cpu].initialized)
366 return cpu_map[cpu].die_id;
368 ret = parse_int_file(0,
369 "/sys/devices/system/cpu/cpu%d/topology/die_id",
372 int core_id, pkg_id, die_id;
374 ret = get_stored_topology_info(cpu, &core_id, &pkg_id, &die_id);
389 static int get_physical_punit_id(int cpu)
394 if (cpu_map && cpu_map[cpu].initialized)
395 return cpu_map[cpu].punit_id;
400 void set_isst_id(struct isst_id *id, int cpu)
404 id->pkg = get_physical_package_id(cpu);
405 if (id->pkg >= MAX_PACKAGE_COUNT)
408 id->die = get_physical_die_id(cpu);
409 if (id->die >= MAX_DIE_PER_PACKAGE)
412 id->punit = get_physical_punit_id(cpu);
413 if (id->punit >= MAX_PUNIT_PER_DIE)
417 int is_cpu_in_power_domain(int cpu, struct isst_id *id)
421 set_isst_id(&tid, cpu);
423 if (id->pkg == tid.pkg && id->die == tid.die && id->punit == tid.punit)
429 int get_cpufreq_base_freq(int cpu)
431 return parse_int_file(0, "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency", cpu);
434 int get_topo_max_cpus(void)
436 return topo_max_cpus;
439 static unsigned int is_cpu_online(int cpu)
443 unsigned char online;
445 snprintf(buffer, sizeof(buffer),
446 "/sys/devices/system/cpu/cpu%d/online", cpu);
448 fd = open(buffer, O_RDONLY);
452 ret = read(fd, &online, sizeof(online));
466 void set_cpu_online_offline(int cpu, int state)
471 snprintf(buffer, sizeof(buffer),
472 "/sys/devices/system/cpu/cpu%d/online", cpu);
474 fd = open(buffer, O_WRONLY);
477 fprintf(stderr, "This system is not configured for CPU 0 online/offline\n");
478 fprintf(stderr, "Ignoring online request for CPU 0 as this is already online\n");
481 err(-1, "%s open failed", buffer);
485 ret = write(fd, "1\n", 2);
487 ret = write(fd, "0\n", 2);
490 perror("Online/Offline: Operation failed\n");
495 static void force_all_cpus_online(void)
499 fprintf(stderr, "Forcing all CPUs online\n");
501 for (i = 0; i < topo_max_cpus; ++i)
502 set_cpu_online_offline(i, 1);
504 unlink("/var/run/isst_cpu_topology.dat");
507 void for_each_online_power_domain_in_set(void (*callback)(struct isst_id *, void *, void *,
509 void *arg1, void *arg2, void *arg3,
513 int cpus[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE][MAX_PUNIT_PER_DIE];
514 int valid_mask[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE] = {0};
517 memset(cpus, -1, sizeof(cpus));
519 for (i = 0; i < topo_max_cpus; ++i) {
522 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
525 online = parse_int_file(
526 i != 0, "/sys/devices/system/cpu/cpu%d/online", i);
528 online = 1; /* online entry for CPU 0 needs some special configs */
535 if (id.pkg < 0 || id.die < 0 || id.punit < 0)
538 valid_mask[id.pkg][id.die] = 1;
540 if (cpus[id.pkg][id.die][id.punit] == -1)
541 cpus[id.pkg][id.die][id.punit] = i;
544 for (i = 0; i < MAX_PACKAGE_COUNT; i++) {
545 for (j = 0; j < MAX_DIE_PER_PACKAGE; j++) {
548 * How to check a non-cpu die for a package/die with all cpu offlined?
550 if (!valid_mask[i][j])
552 for (k = 0; k < MAX_PUNIT_PER_DIE; k++) {
553 id.cpu = cpus[i][j][k];
557 if (isst_is_punit_valid(&id))
558 callback(&id, arg1, arg2, arg3, arg4);
564 static void for_each_online_target_cpu_in_set(
565 void (*callback)(struct isst_id *, void *, void *, void *, void *), void *arg1,
566 void *arg2, void *arg3, void *arg4)
571 for (i = 0; i < topo_max_cpus; ++i) {
574 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
577 online = parse_int_file(
578 1, "/sys/devices/system/cpu/cpu%d/online", i);
581 1; /* online entry for CPU 0 needs some special configs */
584 if (online && callback) {
585 callback(&id, arg1, arg2, arg3, arg4);
591 fprintf(stderr, "No valid CPU in the list\n");
594 #define BITMASK_SIZE 32
595 static void set_max_cpu_num(void)
602 for (i = 0; i < 256; ++i) {
605 snprintf(path, sizeof(path),
606 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", i);
607 filep = fopen(path, "r");
613 fprintf(stderr, "Can't get max cpu number\n");
617 while (fscanf(filep, "%lx,", &dummy) == 1)
618 topo_max_cpus += BITMASK_SIZE;
621 debug_printf("max cpus %d\n", topo_max_cpus);
624 size_t alloc_cpu_set(cpu_set_t **cpu_set)
629 _cpu_set = CPU_ALLOC((topo_max_cpus + 1));
630 if (_cpu_set == NULL)
632 size = CPU_ALLOC_SIZE((topo_max_cpus + 1));
633 CPU_ZERO_S(size, _cpu_set);
639 void free_cpu_set(cpu_set_t *cpu_set)
644 static int cpu_cnt[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE][MAX_PUNIT_PER_DIE];
646 int get_max_punit_core_id(struct isst_id *id)
651 for (i = 0; i < topo_max_cpus; ++i)
653 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
656 if (is_cpu_in_power_domain(i, id) &&
657 cpu_map[i].punit_cpu_core > max_id)
658 max_id = cpu_map[i].punit_cpu_core;
664 int get_cpu_count(struct isst_id *id)
666 if (id->pkg < 0 || id->die < 0 || id->punit < 0)
669 return cpu_cnt[id->pkg][id->die][id->punit];
672 static void update_punit_cpu_info(__u32 physical_cpu, struct _cpu_map *cpu_map)
674 if (api_version() > 1) {
677 * [15:11] PM_DOMAIN_ID
678 * [10:3] MODULE_ID (aka IDI_AGENT_ID)
679 * [2:0] LP_ID (We don't care about these bits we only
680 * care die and core id
683 * [1:0] core ID within module
688 cpu_map->punit_id = (physical_cpu >> 11) & 0x1f;
689 cpu_map->punit_cpu_core = (physical_cpu >> 3) & 0xff;
690 cpu_map->punit_cpu = physical_cpu & 0x7ff;
697 * Bit 0 – thread ID
698 * Bit 8:1 – core ID
699 * Bit 13:9 – punit ID
701 cpu_map->punit_cpu = physical_cpu & 0x1ff;
702 cpu_map->punit_cpu_core = (cpu_map->punit_cpu >> 1); // shift to get core id
703 punit_id = (physical_cpu >> 9) & 0x1f;
705 if (punit_id >= MAX_PUNIT_PER_DIE)
708 cpu_map->punit_id = punit_id;
712 static void create_cpu_map(void)
714 const char *pathname = "/dev/isst_interface";
718 struct isst_if_cpu_maps map;
720 /* Use calloc to make sure the memory is initialized to Zero */
721 cpu_map = calloc(topo_max_cpus, sizeof(*cpu_map));
725 fd = open(pathname, O_RDWR);
726 if (fd < 0 && !is_clx_n_platform())
727 err(-1, "%s open failed", pathname);
729 size = alloc_cpu_set(&present_cpumask);
730 present_cpumask_size = size;
732 for (i = 0; i < topo_max_cpus; ++i) {
734 int pkg_id, die_id, core_id, punit_id;
736 /* check if CPU is online */
737 snprintf(buffer, sizeof(buffer),
738 "/sys/devices/system/cpu/cpu%d", i);
739 dir = opendir(buffer);
744 CPU_SET_S(i, size, present_cpumask);
746 pkg_id = get_physical_package_id(i);
747 die_id = get_physical_die_id(i);
748 core_id = get_physical_core_id(i);
750 if (pkg_id < 0 || die_id < 0 || core_id < 0)
753 cpu_map[i].pkg_id = pkg_id;
754 cpu_map[i].die_id = die_id;
755 cpu_map[i].core_id = core_id;
762 map.cpu_map[0].logical_cpu = i;
763 debug_printf(" map logical_cpu:%d\n",
764 map.cpu_map[0].logical_cpu);
765 if (ioctl(fd, ISST_IF_GET_PHY_ID, &map) == -1) {
766 perror("ISST_IF_GET_PHY_ID");
767 fprintf(outf, "Error: map logical_cpu:%d\n",
768 map.cpu_map[0].logical_cpu);
770 update_punit_cpu_info(map.cpu_map[0].physical_cpu, &cpu_map[i]);
773 cpu_map[i].initialized = 1;
775 cpu_cnt[pkg_id][die_id][punit_id]++;
778 "map logical_cpu:%d core: %d die:%d pkg:%d punit:%d punit_cpu:%d punit_core:%d\n",
779 i, cpu_map[i].core_id, cpu_map[i].die_id,
780 cpu_map[i].pkg_id, cpu_map[i].punit_id,
781 cpu_map[i].punit_cpu, cpu_map[i].punit_cpu_core);
786 size = alloc_cpu_set(&target_cpumask);
787 target_cpumask_size = size;
788 for (i = 0; i < max_target_cpus; ++i) {
789 if (!CPU_ISSET_S(target_cpus[i], present_cpumask_size,
793 CPU_SET_S(target_cpus[i], size, target_cpumask);
797 void set_cpu_mask_from_punit_coremask(struct isst_id *id, unsigned long long core_mask,
798 size_t core_cpumask_size,
799 cpu_set_t *core_cpumask, int *cpu_cnt)
805 for (i = 0; i < 64; ++i) {
806 if (core_mask & BIT_ULL(i)) {
809 for (j = 0; j < topo_max_cpus; ++j) {
810 if (!CPU_ISSET_S(j, present_cpumask_size, present_cpumask))
813 if (is_cpu_in_power_domain(j, id) &&
814 cpu_map[j].punit_cpu_core == i) {
815 CPU_SET_S(j, core_cpumask_size,
826 int find_phy_core_num(int logical_cpu)
828 if (logical_cpu < topo_max_cpus)
829 return cpu_map[logical_cpu].punit_cpu_core;
836 static int isst_fill_platform_info(void)
838 const char *pathname = "/dev/isst_interface";
841 if (is_clx_n_platform()) {
842 isst_platform_info.api_version = 1;
843 goto set_platform_ops;
846 fd = open(pathname, O_RDWR);
848 err(-1, "%s open failed", pathname);
850 if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &isst_platform_info) == -1) {
851 perror("ISST_IF_GET_PLATFORM_INFO");
858 if (isst_platform_info.api_version > supported_api_ver) {
859 printf("Incompatible API versions; Upgrade of tool is required\n");
864 if (isst_set_platform_ops(isst_platform_info.api_version)) {
865 fprintf(stderr, "Failed to set platform callbacks\n");
871 void get_isst_status(struct isst_id *id, void *arg1, void *arg2, void *arg3, void *arg4)
873 struct isst_pkg_ctdp pkg_dev;
874 struct isst_id *tid = (struct isst_id *)arg2;
875 int *mask = (int *)arg3;
876 int *max_level = (int *)arg4;
879 /* Only check the first cpu power domain */
880 if (id->cpu < 0 || tid->cpu >= 0)
883 ret = isst_get_ctdp_levels(id, &pkg_dev);
893 if (*max_level < pkg_dev.levels)
894 *max_level = pkg_dev.levels;
896 for (j = 0; j <= pkg_dev.levels; ++j) {
897 struct isst_pkg_ctdp_level_info ctdp_level;
899 ret = isst_get_ctdp_control(id, j, &ctdp_level);
903 if (ctdp_level.fact_support)
906 if (ctdp_level.pbf_support)
913 tid->punit = id->punit;
916 static void isst_print_extended_platform_info(void)
918 int cp_state, cp_cap;
920 int mask = 0, max_level = 0;
923 for_each_online_power_domain_in_set(get_isst_status, NULL, &id, &mask, &max_level);
926 fprintf(outf, "Intel(R) SST-PP (feature perf-profile) is supported\n");
928 fprintf(outf, "Intel(R) SST-PP (feature perf-profile) is not supported\n");
929 fprintf(outf, "Only performance level 0 (base level) is present\n");
933 fprintf(outf, "TDP level change control is locked\n");
935 fprintf(outf, "TDP level change control is unlocked, max level: %d\n", max_level);
938 fprintf(outf, "Intel(R) SST-TF (feature turbo-freq) is supported\n");
940 fprintf(outf, "Intel(R) SST-TF (feature turbo-freq) is not supported\n");
943 fprintf(outf, "Intel(R) SST-BF (feature base-freq) is supported\n");
945 fprintf(outf, "Intel(R) SST-BF (feature base-freq) is not supported\n");
947 if (isst_read_pm_config(&id, &cp_state, &cp_cap)) {
948 fprintf(outf, "Intel(R) SST-CP (feature core-power) status is unknown\n");
953 fprintf(outf, "Intel(R) SST-CP (feature core-power) is supported\n");
955 fprintf(outf, "Intel(R) SST-CP (feature core-power) is not supported\n");
958 static void isst_print_platform_information(void)
960 if (is_clx_n_platform()) {
961 fprintf(stderr, "\nThis option in not supported on this platform\n");
965 /* Early initialization to create working cpu_map */
969 fprintf(outf, "Platform: API version : %d\n",
970 isst_platform_info.api_version);
971 fprintf(outf, "Platform: Driver version : %d\n",
972 isst_platform_info.driver_version);
973 fprintf(outf, "Platform: mbox supported : %d\n",
974 isst_platform_info.mbox_supported);
975 fprintf(outf, "Platform: mmio supported : %d\n",
976 isst_platform_info.mmio_supported);
977 isst_print_extended_platform_info();
982 static char *local_str0, *local_str1;
983 static void exec_on_get_ctdp_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
986 int (*fn_ptr)(struct isst_id *id, void *arg);
990 ret = fn_ptr(id, arg2);
992 isst_display_error_info_message(1, "get_tdp_* failed", 0, 0);
994 isst_ctdp_display_core_info(id, outf, arg3,
995 *(unsigned int *)arg4,
996 local_str0, local_str1);
999 #define _get_tdp_level(desc, suffix, object, help, str0, str1) \
1000 static void get_tdp_##object(int arg) \
1002 struct isst_pkg_ctdp ctdp; \
1006 "Print %s [No command arguments are required]\n", \
1010 local_str0 = str0; \
1011 local_str1 = str1; \
1012 isst_ctdp_display_information_start(outf); \
1013 if (max_target_cpus) \
1014 for_each_online_target_cpu_in_set( \
1015 exec_on_get_ctdp_cpu, isst_get_ctdp_##suffix, \
1016 &ctdp, desc, &ctdp.object); \
1018 for_each_online_power_domain_in_set(exec_on_get_ctdp_cpu, \
1019 isst_get_ctdp_##suffix, \
1022 isst_ctdp_display_information_end(outf); \
1025 _get_tdp_level("get-config-levels", levels, levels, "Max TDP level", NULL, NULL);
1026 _get_tdp_level("get-config-version", levels, version, "TDP version", NULL, NULL);
1027 _get_tdp_level("get-config-enabled", levels, enabled, "perf-profile enable status", "disabled", "enabled");
1028 _get_tdp_level("get-config-current_level", levels, current_level,
1029 "Current TDP Level", NULL, NULL);
1030 _get_tdp_level("get-lock-status", levels, locked, "TDP lock status", "unlocked", "locked");
1032 struct isst_pkg_ctdp clx_n_pkg_dev;
1034 static int clx_n_get_base_ratio(void)
1037 char *begin, *end, *line = NULL;
1042 fp = fopen("/proc/cpuinfo", "r");
1044 err(-1, "cannot open /proc/cpuinfo\n");
1046 while (getline(&line, &n, fp) > 0) {
1047 if (strstr(line, "model name")) {
1048 /* this is true for CascadeLake-N */
1049 begin = strstr(line, "@ ") + 2;
1050 end = strstr(line, "GHz");
1051 strncpy(number, begin, end - begin);
1052 value = atof(number) * 10;
1059 return (int)(value);
1062 static int clx_n_config(struct isst_id *id)
1065 unsigned long cpu_bf;
1066 struct isst_pkg_ctdp_level_info *ctdp_level;
1067 struct isst_pbf_info *pbf_info;
1069 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1070 pbf_info = &ctdp_level->pbf_info;
1071 ctdp_level->core_cpumask_size =
1072 alloc_cpu_set(&ctdp_level->core_cpumask);
1074 /* find the frequency base ratio */
1075 ctdp_level->tdp_ratio = clx_n_get_base_ratio();
1076 if (ctdp_level->tdp_ratio == 0) {
1077 debug_printf("CLX: cn base ratio is zero\n");
1082 /* find the high and low priority frequencies */
1083 pbf_info->p1_high = 0;
1084 pbf_info->p1_low = ~0;
1086 for (i = 0; i < topo_max_cpus; i++) {
1087 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
1090 if (!is_cpu_in_power_domain(i, id))
1093 CPU_SET_S(i, ctdp_level->core_cpumask_size,
1094 ctdp_level->core_cpumask);
1096 cpu_bf = parse_int_file(1,
1097 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
1099 if (cpu_bf > pbf_info->p1_high)
1100 pbf_info->p1_high = cpu_bf;
1101 if (cpu_bf < pbf_info->p1_low)
1102 pbf_info->p1_low = cpu_bf;
1105 if (pbf_info->p1_high == ~0UL) {
1106 debug_printf("CLX: maximum base frequency not set\n");
1111 if (pbf_info->p1_low == 0) {
1112 debug_printf("CLX: minimum base frequency not set\n");
1117 /* convert frequencies back to ratios */
1118 pbf_info->p1_high = pbf_info->p1_high / 100000;
1119 pbf_info->p1_low = pbf_info->p1_low / 100000;
1121 /* create high priority cpu mask */
1122 pbf_info->core_cpumask_size = alloc_cpu_set(&pbf_info->core_cpumask);
1123 for (i = 0; i < topo_max_cpus; i++) {
1124 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
1127 if (!is_cpu_in_power_domain(i, id))
1130 cpu_bf = parse_int_file(1,
1131 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
1133 cpu_bf = cpu_bf / 100000;
1134 if (cpu_bf == pbf_info->p1_high)
1135 CPU_SET_S(i, pbf_info->core_cpumask_size,
1136 pbf_info->core_cpumask);
1139 /* extra ctdp & pbf struct parameters */
1140 ctdp_level->processed = 1;
1141 ctdp_level->pbf_support = 1; /* PBF is always supported and enabled */
1142 ctdp_level->pbf_enabled = 1;
1143 ctdp_level->fact_support = 0; /* FACT is never supported */
1144 ctdp_level->fact_enabled = 0;
1149 free_cpu_set(ctdp_level->core_cpumask);
1153 static void dump_clx_n_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
1154 void *arg3, void *arg4)
1158 if (tdp_level != 0xff && tdp_level != 0) {
1159 isst_display_error_info_message(1, "Invalid level", 1, tdp_level);
1163 ret = clx_n_config(id);
1165 debug_printf("clx_n_config failed");
1167 struct isst_pkg_ctdp_level_info *ctdp_level;
1168 struct isst_pbf_info *pbf_info;
1170 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1171 pbf_info = &ctdp_level->pbf_info;
1172 clx_n_pkg_dev.processed = 1;
1173 isst_ctdp_display_information(id, outf, tdp_level, &clx_n_pkg_dev);
1174 free_cpu_set(ctdp_level->core_cpumask);
1175 free_cpu_set(pbf_info->core_cpumask);
1179 static void dump_isst_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
1180 void *arg3, void *arg4)
1182 struct isst_pkg_ctdp pkg_dev;
1185 memset(&pkg_dev, 0, sizeof(pkg_dev));
1186 ret = isst_get_process_ctdp(id, tdp_level, &pkg_dev);
1188 isst_display_error_info_message(1, "Failed to get perf-profile info on cpu", 1, id->cpu);
1189 isst_ctdp_display_information_end(outf);
1192 isst_ctdp_display_information(id, outf, tdp_level, &pkg_dev);
1193 isst_get_process_ctdp_complete(id, &pkg_dev);
1197 static void dump_isst_config(int arg)
1203 "Print Intel(R) Speed Select Technology Performance profile configuration\n");
1205 "including base frequency and turbo frequency configurations\n");
1206 fprintf(stderr, "Optional: -l|--level : Specify tdp level\n");
1208 "\tIf no arguments, dump information for all TDP levels\n");
1212 if (!is_clx_n_platform())
1213 fn = dump_isst_config_for_cpu;
1215 fn = dump_clx_n_config_for_cpu;
1217 isst_ctdp_display_information_start(outf);
1219 if (max_target_cpus)
1220 for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
1222 for_each_online_power_domain_in_set(fn, NULL, NULL, NULL, NULL);
1224 isst_ctdp_display_information_end(outf);
1227 static void adjust_scaling_max_from_base_freq(int cpu);
1229 static void set_tdp_level_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
1234 ret = isst_set_tdp_level(id, tdp_level);
1236 isst_display_error_info_message(1, "Set TDP level failed", 0, 0);
1237 isst_ctdp_display_information_end(outf);
1240 isst_display_result(id, outf, "perf-profile", "set_tdp_level",
1242 if (force_online_offline) {
1243 struct isst_pkg_ctdp_level_info ctdp_level;
1245 /* Wait for updated base frequencies */
1248 /* Adjusting uncore freq */
1249 isst_adjust_uncore_freq(id, tdp_level, &ctdp_level);
1251 fprintf(stderr, "Option is set to online/offline\n");
1252 ctdp_level.core_cpumask_size =
1253 alloc_cpu_set(&ctdp_level.core_cpumask);
1254 ret = isst_get_coremask_info(id, tdp_level, &ctdp_level);
1256 isst_display_error_info_message(1, "Can't get coremask, online/offline option is ignored", 0, 0);
1259 if (ctdp_level.cpu_count) {
1260 int i, max_cpus = get_topo_max_cpus();
1261 for (i = 0; i < max_cpus; ++i) {
1262 if (!is_cpu_in_power_domain(i, id))
1264 if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
1265 fprintf(stderr, "online cpu %d\n", i);
1266 set_cpu_online_offline(i, 1);
1267 adjust_scaling_max_from_base_freq(i);
1269 fprintf(stderr, "offline cpu %d\n", i);
1270 set_cpu_online_offline(i, 0);
1278 static void set_tdp_level(int arg)
1281 fprintf(stderr, "Set Config TDP level\n");
1283 "\t Arguments: -l|--level : Specify tdp level\n");
1285 "\t Optional Arguments: -o | online : online/offline for the tdp level\n");
1287 "\t online/offline operation has limitations, refer to Linux hotplug documentation\n");
1291 if (tdp_level == 0xff) {
1292 isst_display_error_info_message(1, "Invalid command: specify tdp_level", 0, 0);
1295 isst_ctdp_display_information_start(outf);
1296 if (max_target_cpus)
1297 for_each_online_target_cpu_in_set(set_tdp_level_for_cpu, NULL,
1300 for_each_online_power_domain_in_set(set_tdp_level_for_cpu, NULL,
1302 isst_ctdp_display_information_end(outf);
1305 static void clx_n_dump_pbf_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
1306 void *arg3, void *arg4)
1310 ret = clx_n_config(id);
1312 isst_display_error_info_message(1, "clx_n_config failed", 0, 0);
1314 struct isst_pkg_ctdp_level_info *ctdp_level;
1315 struct isst_pbf_info *pbf_info;
1317 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1318 pbf_info = &ctdp_level->pbf_info;
1319 isst_pbf_display_information(id, outf, tdp_level, pbf_info);
1320 free_cpu_set(ctdp_level->core_cpumask);
1321 free_cpu_set(pbf_info->core_cpumask);
1325 static void dump_pbf_config_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
1328 struct isst_pbf_info pbf_info;
1331 ret = isst_get_pbf_info(id, tdp_level, &pbf_info);
1333 isst_display_error_info_message(1, "Failed to get base-freq info at this level", 1, tdp_level);
1334 isst_ctdp_display_information_end(outf);
1337 isst_pbf_display_information(id, outf, tdp_level, &pbf_info);
1338 free_cpu_set(pbf_info.core_cpumask);
1342 static void dump_pbf_config(int arg)
1348 "Print Intel(R) Speed Select Technology base frequency configuration for a TDP level\n");
1350 "\tArguments: -l|--level : Specify tdp level\n");
1354 if (tdp_level == 0xff) {
1355 isst_display_error_info_message(1, "Invalid command: specify tdp_level", 0, 0);
1359 if (!is_clx_n_platform())
1360 fn = dump_pbf_config_for_cpu;
1362 fn = clx_n_dump_pbf_config_for_cpu;
1364 isst_ctdp_display_information_start(outf);
1366 if (max_target_cpus)
1367 for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
1369 for_each_online_power_domain_in_set(fn, NULL, NULL, NULL, NULL);
1371 isst_ctdp_display_information_end(outf);
1374 static int set_clos_param(struct isst_id *id, int clos, int epp, int wt, int min, int max)
1376 struct isst_clos_config clos_config;
1379 ret = isst_pm_get_clos(id, clos, &clos_config);
1381 isst_display_error_info_message(1, "isst_pm_get_clos failed", 0, 0);
1384 clos_config.clos_min = min;
1385 clos_config.clos_max = max;
1386 clos_config.epp = epp;
1387 clos_config.clos_prop_prio = wt;
1388 ret = isst_set_clos(id, clos, &clos_config);
1390 isst_display_error_info_message(1, "isst_set_clos failed", 0, 0);
1397 static int set_cpufreq_scaling_min_max(int cpu, int max, int freq)
1399 char buffer[128], freq_str[16];
1403 snprintf(buffer, sizeof(buffer),
1404 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
1406 snprintf(buffer, sizeof(buffer),
1407 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
1409 fd = open(buffer, O_WRONLY);
1413 snprintf(freq_str, sizeof(freq_str), "%d", freq);
1414 len = strlen(freq_str);
1415 ret = write(fd, freq_str, len);
1425 static int no_turbo(void)
1427 return parse_int_file(0, "/sys/devices/system/cpu/intel_pstate/no_turbo");
1430 static void adjust_scaling_max_from_base_freq(int cpu)
1432 int base_freq, scaling_max_freq;
1434 scaling_max_freq = parse_int_file(0, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
1435 base_freq = get_cpufreq_base_freq(cpu);
1436 if (scaling_max_freq < base_freq || no_turbo())
1437 set_cpufreq_scaling_min_max(cpu, 1, base_freq);
1440 static void adjust_scaling_min_from_base_freq(int cpu)
1442 int base_freq, scaling_min_freq;
1444 scaling_min_freq = parse_int_file(0, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
1445 base_freq = get_cpufreq_base_freq(cpu);
1446 if (scaling_min_freq < base_freq)
1447 set_cpufreq_scaling_min_max(cpu, 0, base_freq);
1450 static int set_clx_pbf_cpufreq_scaling_min_max(struct isst_id *id)
1452 struct isst_pkg_ctdp_level_info *ctdp_level;
1453 struct isst_pbf_info *pbf_info;
1454 int i, freq, freq_high, freq_low;
1457 ret = clx_n_config(id);
1459 debug_printf("cpufreq_scaling_min_max failed for CLX");
1463 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1464 pbf_info = &ctdp_level->pbf_info;
1465 freq_high = pbf_info->p1_high * 100000;
1466 freq_low = pbf_info->p1_low * 100000;
1468 for (i = 0; i < get_topo_max_cpus(); ++i) {
1469 if (!is_cpu_in_power_domain(i, id))
1472 if (CPU_ISSET_S(i, pbf_info->core_cpumask_size,
1473 pbf_info->core_cpumask))
1478 set_cpufreq_scaling_min_max(i, 1, freq);
1479 set_cpufreq_scaling_min_max(i, 0, freq);
1485 static int set_cpufreq_scaling_min_max_from_cpuinfo(int cpu, int cpuinfo_max, int scaling_max)
1487 char buffer[128], min_freq[16];
1490 if (!CPU_ISSET_S(cpu, present_cpumask_size, present_cpumask))
1494 snprintf(buffer, sizeof(buffer),
1495 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu);
1497 snprintf(buffer, sizeof(buffer),
1498 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", cpu);
1500 fd = open(buffer, O_RDONLY);
1504 len = read(fd, min_freq, sizeof(min_freq));
1511 snprintf(buffer, sizeof(buffer),
1512 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
1514 snprintf(buffer, sizeof(buffer),
1515 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
1517 fd = open(buffer, O_WRONLY);
1521 min_freq[15] = '\0';
1522 len = strlen(min_freq);
1523 ret = write(fd, min_freq, len);
1533 static void set_scaling_min_to_cpuinfo_max(struct isst_id *id)
1537 for (i = 0; i < get_topo_max_cpus(); ++i) {
1538 if (!is_cpu_in_power_domain(i, id))
1541 if (is_cpu_online(i) != 1)
1544 adjust_scaling_max_from_base_freq(i);
1545 set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 0);
1546 adjust_scaling_min_from_base_freq(i);
1550 static void set_scaling_min_to_cpuinfo_min(struct isst_id *id)
1554 for (i = 0; i < get_topo_max_cpus(); ++i) {
1555 if (!is_cpu_in_power_domain(i, id))
1558 if (is_cpu_online(i) != 1)
1561 adjust_scaling_max_from_base_freq(i);
1562 set_cpufreq_scaling_min_max_from_cpuinfo(i, 0, 0);
1566 static void set_scaling_max_to_cpuinfo_max(struct isst_id *id)
1570 for (i = 0; i < get_topo_max_cpus(); ++i) {
1571 if (!is_cpu_in_power_domain(i, id))
1574 set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 1);
1578 static int set_core_priority_and_min(struct isst_id *id, int mask_size,
1579 cpu_set_t *cpu_mask, int min_high,
1584 if (!CPU_COUNT_S(mask_size, cpu_mask))
1587 ret = set_clos_param(id, 0, 0, 0, min_high, 0xff);
1591 ret = set_clos_param(id, 1, 15, 15, min_low, 0xff);
1595 ret = set_clos_param(id, 2, 15, 15, min_low, 0xff);
1599 ret = set_clos_param(id, 3, 15, 15, min_low, 0xff);
1603 for (i = 0; i < get_topo_max_cpus(); ++i) {
1607 if (!is_cpu_in_power_domain(i, id))
1610 if (CPU_ISSET_S(i, mask_size, cpu_mask))
1615 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
1616 set_isst_id(&tid, i);
1617 ret = isst_clos_associate(&tid, clos);
1619 isst_display_error_info_message(1, "isst_clos_associate failed", 0, 0);
1627 static int set_pbf_core_power(struct isst_id *id)
1629 struct isst_pbf_info pbf_info;
1630 struct isst_pkg_ctdp pkg_dev;
1633 ret = isst_get_ctdp_levels(id, &pkg_dev);
1635 debug_printf("isst_get_ctdp_levels failed");
1638 debug_printf("Current_level: %d\n", pkg_dev.current_level);
1640 ret = isst_get_pbf_info(id, pkg_dev.current_level, &pbf_info);
1642 debug_printf("isst_get_pbf_info failed");
1645 debug_printf("p1_high: %d p1_low: %d\n", pbf_info.p1_high,
1648 ret = set_core_priority_and_min(id, pbf_info.core_cpumask_size,
1649 pbf_info.core_cpumask,
1650 pbf_info.p1_high, pbf_info.p1_low);
1652 debug_printf("set_core_priority_and_min failed");
1656 ret = isst_pm_qos_config(id, 1, 1);
1658 debug_printf("isst_pm_qos_config failed");
1665 static void set_pbf_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
1668 struct isst_pkg_ctdp_level_info ctdp_level;
1669 struct isst_pkg_ctdp pkg_dev;
1671 int status = *(int *)arg4;
1673 if (is_clx_n_platform()) {
1676 set_clx_pbf_cpufreq_scaling_min_max(id);
1679 set_scaling_max_to_cpuinfo_max(id);
1680 set_scaling_min_to_cpuinfo_min(id);
1685 ret = isst_get_ctdp_levels(id, &pkg_dev);
1687 isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
1691 ret = isst_get_ctdp_control(id, pkg_dev.current_level, &ctdp_level);
1693 isst_display_error_info_message(1, "Failed to get current level", 0, 0);
1697 if (!ctdp_level.pbf_support) {
1698 isst_display_error_info_message(1, "base-freq feature is not present at this level", 1, pkg_dev.current_level);
1703 if (auto_mode && status) {
1704 ret = set_pbf_core_power(id);
1709 ret = isst_set_pbf_fact_status(id, 1, status);
1711 debug_printf("isst_set_pbf_fact_status failed");
1713 isst_pm_qos_config(id, 0, 0);
1717 set_scaling_min_to_cpuinfo_max(id);
1719 set_scaling_min_to_cpuinfo_min(id);
1723 if (auto_mode && !status)
1724 isst_pm_qos_config(id, 0, 1);
1728 isst_display_result(id, outf, "base-freq", "enable",
1731 isst_display_result(id, outf, "base-freq", "disable",
1735 static void set_pbf_enable(int arg)
1742 "Enable Intel Speed Select Technology base frequency feature\n");
1743 if (is_clx_n_platform()) {
1745 "\tOn this platform this command doesn't enable feature in the hardware.\n");
1747 "\tIt updates the cpufreq scaling_min_freq to match cpufreq base_frequency.\n");
1752 "\tOptional Arguments: -a|--auto : Use priority of cores to set core-power associations\n");
1755 if (is_clx_n_platform()) {
1757 "\tOn this platform this command doesn't disable feature in the hardware.\n");
1759 "\tIt updates the cpufreq scaling_min_freq to match cpuinfo_min_freq\n");
1763 "Disable Intel Speed Select Technology base frequency feature\n");
1765 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1770 isst_ctdp_display_information_start(outf);
1771 if (max_target_cpus)
1772 for_each_online_target_cpu_in_set(set_pbf_for_cpu, NULL, NULL,
1775 for_each_online_power_domain_in_set(set_pbf_for_cpu, NULL, NULL,
1777 isst_ctdp_display_information_end(outf);
1780 static void dump_fact_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
1781 void *arg3, void *arg4)
1783 struct isst_fact_info fact_info;
1786 ret = isst_get_fact_info(id, tdp_level, fact_bucket, &fact_info);
1788 isst_display_error_info_message(1, "Failed to get turbo-freq info at this level", 1, tdp_level);
1789 isst_ctdp_display_information_end(outf);
1792 isst_fact_display_information(id, outf, tdp_level, fact_bucket,
1793 fact_avx, &fact_info);
1797 static void dump_fact_config(int arg)
1801 "Print complete Intel Speed Select Technology turbo frequency configuration for a TDP level. Other arguments are optional.\n");
1803 "\tArguments: -l|--level : Specify tdp level\n");
1805 "\tArguments: -b|--bucket : Bucket index to dump\n");
1807 "\tArguments: -r|--trl-type : Specify trl type: sse|avx2|avx512\n");
1811 if (tdp_level == 0xff) {
1812 isst_display_error_info_message(1, "Invalid command: specify tdp_level\n", 0, 0);
1816 isst_ctdp_display_information_start(outf);
1817 if (max_target_cpus)
1818 for_each_online_target_cpu_in_set(dump_fact_config_for_cpu,
1819 NULL, NULL, NULL, NULL);
1821 for_each_online_power_domain_in_set(dump_fact_config_for_cpu, NULL,
1823 isst_ctdp_display_information_end(outf);
1826 static void set_fact_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
1829 struct isst_pkg_ctdp_level_info ctdp_level;
1830 struct isst_pkg_ctdp pkg_dev;
1832 int status = *(int *)arg4;
1834 if (status && no_turbo()) {
1835 isst_display_error_info_message(1, "Turbo mode is disabled", 0, 0);
1840 ret = isst_get_ctdp_levels(id, &pkg_dev);
1842 isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
1846 ret = isst_get_ctdp_control(id, pkg_dev.current_level, &ctdp_level);
1848 isst_display_error_info_message(1, "Failed to get current level", 0, 0);
1852 if (!ctdp_level.fact_support) {
1853 isst_display_error_info_message(1, "turbo-freq feature is not present at this level", 1, pkg_dev.current_level);
1859 ret = isst_pm_qos_config(id, 1, 1);
1864 ret = isst_set_pbf_fact_status(id, 0, status);
1866 debug_printf("isst_set_pbf_fact_status failed");
1868 isst_pm_qos_config(id, 0, 0);
1875 struct isst_pkg_ctdp pkg_dev;
1877 ret = isst_get_ctdp_levels(id, &pkg_dev);
1879 ret = isst_set_trl(id, fact_trl);
1880 if (ret && auto_mode)
1881 isst_pm_qos_config(id, 0, 0);
1884 isst_pm_qos_config(id, 0, 0);
1889 isst_display_result(id, outf, "turbo-freq", "enable", ret);
1891 fact_enable_fail = ret;
1893 /* Since we modified TRL during Fact enable, restore it */
1894 isst_set_trl_from_current_tdp(id, fact_trl);
1895 isst_display_result(id, outf, "turbo-freq", "disable", ret);
1899 static void set_fact_enable(int arg)
1901 int i, ret, enable = arg;
1907 "Enable Intel Speed Select Technology Turbo frequency feature\n");
1909 "Optional: -t|--trl : Specify turbo ratio limit\n");
1911 "\tOptional Arguments: -a|--auto : Designate specified target CPUs with");
1913 "-C|--cpu option as as high priority using core-power feature\n");
1916 "Disable Intel Speed Select Technology turbo frequency feature\n");
1918 "Optional: -t|--trl : Specify turbo ratio limit\n");
1920 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1925 isst_ctdp_display_information_start(outf);
1926 if (max_target_cpus)
1927 for_each_online_target_cpu_in_set(set_fact_for_cpu, NULL, NULL,
1930 for_each_online_power_domain_in_set(set_fact_for_cpu, NULL, NULL,
1932 isst_ctdp_display_information_end(outf);
1934 if (!fact_enable_fail && enable && auto_mode) {
1936 * When we adjust CLOS param, we have to set for siblings also.
1937 * So for the each user specified CPU, also add the sibling
1938 * in the present_cpu_mask.
1940 for (i = 0; i < get_topo_max_cpus(); ++i) {
1941 char buffer[128], sibling_list[128], *cpu_str;
1944 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
1947 snprintf(buffer, sizeof(buffer),
1948 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i);
1950 fd = open(buffer, O_RDONLY);
1954 len = read(fd, sibling_list, sizeof(sibling_list));
1960 sibling_list[127] = '\0';
1961 cpu_str = strtok(sibling_list, ",");
1962 while (cpu_str != NULL) {
1965 sscanf(cpu_str, "%d", &cpu);
1966 CPU_SET_S(cpu, target_cpumask_size, target_cpumask);
1967 cpu_str = strtok(NULL, ",");
1971 for (i = 0; i < get_topo_max_cpus(); ++i) {
1974 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
1977 if (is_cpu_online(i) != 1)
1980 set_isst_id(&id, i);
1981 ret = set_clos_param(&id, 0, 0, 0, 0, 0xff);
1985 ret = set_clos_param(&id, 1, 15, 15, 0, 0xff);
1989 ret = set_clos_param(&id, 2, 15, 15, 0, 0xff);
1993 ret = set_clos_param(&id, 3, 15, 15, 0, 0xff);
1997 if (CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
2002 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
2003 ret = isst_clos_associate(&id, clos);
2007 set_isst_id(&id, -1);
2008 isst_display_result(&id, outf, "turbo-freq --auto", "enable", 0);
2014 isst_display_result(&id, outf, "turbo-freq --auto", "enable", ret);
2018 static void enable_clos_qos_config(struct isst_id *id, void *arg1, void *arg2, void *arg3,
2022 int status = *(int *)arg4;
2024 if (is_skx_based_platform())
2025 clos_priority_type = 1;
2027 ret = isst_pm_qos_config(id, status, clos_priority_type);
2029 isst_display_error_info_message(1, "isst_pm_qos_config failed", 0, 0);
2032 isst_display_result(id, outf, "core-power", "enable",
2035 isst_display_result(id, outf, "core-power", "disable",
2039 static void set_clos_enable(int arg)
2046 "Enable core-power for a package/die\n");
2047 if (!is_skx_based_platform()) {
2049 "\tClos Enable: Specify priority type with [--priority|-p]\n");
2050 fprintf(stderr, "\t\t 0: Proportional, 1: Ordered\n");
2054 "Disable core-power: [No command arguments are required]\n");
2059 if (enable && cpufreq_sysfs_present()) {
2061 "cpufreq subsystem and core-power enable will interfere with each other!\n");
2064 isst_ctdp_display_information_start(outf);
2065 if (max_target_cpus)
2066 for_each_online_target_cpu_in_set(enable_clos_qos_config, NULL,
2067 NULL, NULL, &enable);
2069 for_each_online_power_domain_in_set(enable_clos_qos_config, NULL,
2070 NULL, NULL, &enable);
2071 isst_ctdp_display_information_end(outf);
2074 static void dump_clos_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
2075 void *arg3, void *arg4)
2077 struct isst_clos_config clos_config;
2080 ret = isst_pm_get_clos(id, current_clos, &clos_config);
2082 isst_display_error_info_message(1, "isst_pm_get_clos failed", 0, 0);
2084 isst_clos_display_information(id, outf, current_clos,
2088 static void dump_clos_config(int arg)
2092 "Print Intel Speed Select Technology core power configuration\n");
2094 "\tArguments: [-c | --clos]: Specify clos id\n");
2097 if (current_clos < 0 || current_clos > 3) {
2098 isst_display_error_info_message(1, "Invalid clos id\n", 0, 0);
2099 isst_ctdp_display_information_end(outf);
2103 isst_ctdp_display_information_start(outf);
2104 if (max_target_cpus)
2105 for_each_online_target_cpu_in_set(dump_clos_config_for_cpu,
2106 NULL, NULL, NULL, NULL);
2108 for_each_online_power_domain_in_set(dump_clos_config_for_cpu, NULL,
2110 isst_ctdp_display_information_end(outf);
2113 static void get_clos_info_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
2116 int enable, ret, prio_type;
2118 ret = isst_clos_get_clos_information(id, &enable, &prio_type);
2120 isst_display_error_info_message(1, "isst_clos_get_info failed", 0, 0);
2122 int cp_state, cp_cap;
2124 isst_read_pm_config(id, &cp_state, &cp_cap);
2125 isst_clos_display_clos_information(id, outf, enable, prio_type,
2130 static void dump_clos_info(int arg)
2134 "Print Intel Speed Select Technology core power information\n");
2135 fprintf(stderr, "\t Optionally specify targeted cpu id with [--cpu|-c]\n");
2139 isst_ctdp_display_information_start(outf);
2140 if (max_target_cpus)
2141 for_each_online_target_cpu_in_set(get_clos_info_for_cpu, NULL,
2144 for_each_online_power_domain_in_set(get_clos_info_for_cpu, NULL,
2146 isst_ctdp_display_information_end(outf);
2150 static void set_clos_config_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
2153 struct isst_clos_config clos_config;
2156 clos_config.epp = clos_epp;
2157 clos_config.clos_prop_prio = clos_prop_prio;
2158 clos_config.clos_min = clos_min;
2159 clos_config.clos_max = clos_max;
2160 clos_config.clos_desired = clos_desired;
2161 ret = isst_set_clos(id, current_clos, &clos_config);
2163 isst_display_error_info_message(1, "isst_set_clos failed", 0, 0);
2165 isst_display_result(id, outf, "core-power", "config", ret);
2168 static void set_clos_config(int arg)
2172 "Set core-power configuration for one of the four clos ids\n");
2174 "\tSpecify targeted clos id with [--clos|-c]\n");
2175 if (!is_skx_based_platform()) {
2176 fprintf(stderr, "\tSpecify clos EPP with [--epp|-e]\n");
2178 "\tSpecify clos Proportional Priority [--weight|-w]\n");
2180 fprintf(stderr, "\tSpecify clos min in MHz with [--min|-n]\n");
2181 fprintf(stderr, "\tSpecify clos max in MHz with [--max|-m]\n");
2185 if (current_clos < 0 || current_clos > 3) {
2186 isst_display_error_info_message(1, "Invalid clos id\n", 0, 0);
2189 if (!is_skx_based_platform() && (clos_epp < 0 || clos_epp > 0x0F)) {
2190 fprintf(stderr, "clos epp is not specified or invalid, default: 0\n");
2193 if (!is_skx_based_platform() && (clos_prop_prio < 0 || clos_prop_prio > 0x0F)) {
2195 "clos frequency weight is not specified or invalid, default: 0\n");
2199 fprintf(stderr, "clos min is not specified, default: 0\n");
2203 fprintf(stderr, "clos max is not specified, default: Max frequency (ratio 0xff)\n");
2207 fprintf(stderr, "clos desired is not supported on this platform\n");
2208 clos_desired = 0x00;
2211 isst_ctdp_display_information_start(outf);
2212 if (max_target_cpus)
2213 for_each_online_target_cpu_in_set(set_clos_config_for_cpu, NULL,
2216 for_each_online_power_domain_in_set(set_clos_config_for_cpu, NULL,
2218 isst_ctdp_display_information_end(outf);
2221 static void set_clos_assoc_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
2226 ret = isst_clos_associate(id, current_clos);
2228 debug_printf("isst_clos_associate failed");
2230 isst_display_result(id, outf, "core-power", "assoc", ret);
2233 static void set_clos_assoc(int arg)
2236 fprintf(stderr, "Associate a clos id to a CPU\n");
2238 "\tSpecify targeted clos id with [--clos|-c]\n");
2240 "\tFor example to associate clos 1 to CPU 0: issue\n");
2242 "\tintel-speed-select --cpu 0 core-power assoc --clos 1\n");
2246 if (current_clos < 0 || current_clos > 3) {
2247 isst_display_error_info_message(1, "Invalid clos id\n", 0, 0);
2250 if (max_target_cpus)
2251 for_each_online_target_cpu_in_set(set_clos_assoc_for_cpu, NULL,
2254 isst_display_error_info_message(1, "Invalid target cpu. Specify with [-c|--cpu]", 0, 0);
2258 static void get_clos_assoc_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
2263 ret = isst_clos_get_assoc_status(id, &clos);
2265 isst_display_error_info_message(1, "isst_clos_get_assoc_status failed", 0, 0);
2267 isst_clos_display_assoc_information(id, outf, clos);
2270 static void get_clos_assoc(int arg)
2273 fprintf(stderr, "Get associate clos id to a CPU\n");
2274 fprintf(stderr, "\tSpecify targeted cpu id with [--cpu|-c]\n");
2278 if (!max_target_cpus) {
2279 isst_display_error_info_message(1, "Invalid target cpu. Specify with [-c|--cpu]", 0, 0);
2283 isst_ctdp_display_information_start(outf);
2284 for_each_online_target_cpu_in_set(get_clos_assoc_for_cpu, NULL,
2286 isst_ctdp_display_information_end(outf);
2289 static void set_turbo_mode_for_cpu(struct isst_id *id, int status)
2294 base_freq = get_cpufreq_base_freq(id->cpu);
2295 set_cpufreq_scaling_min_max(id->cpu, 1, base_freq);
2297 set_scaling_max_to_cpuinfo_max(id);
2301 isst_display_result(id, outf, "turbo-mode", "enable", 0);
2303 isst_display_result(id, outf, "turbo-mode", "disable", 0);
2307 static void set_turbo_mode(int arg)
2309 int i, enable = arg;
2314 fprintf(stderr, "Set turbo mode enable\n");
2316 fprintf(stderr, "Set turbo mode disable\n");
2320 isst_ctdp_display_information_start(outf);
2322 for (i = 0; i < topo_max_cpus; ++i) {
2326 online = parse_int_file(
2327 1, "/sys/devices/system/cpu/cpu%d/online", i);
2330 1; /* online entry for CPU 0 needs some special configs */
2333 set_isst_id(&id, i);
2334 set_turbo_mode_for_cpu(&id, enable);
2338 isst_ctdp_display_information_end(outf);
2341 static void get_set_trl(struct isst_id *id, void *arg1, void *arg2, void *arg3,
2344 unsigned long long trl;
2345 int set = *(int *)arg4;
2348 if (set && !fact_trl) {
2349 isst_display_error_info_message(1, "Invalid TRL. Specify with [-t|--trl]", 0, 0);
2354 ret = isst_set_trl(id, fact_trl);
2355 isst_display_result(id, outf, "turbo-mode", "set-trl", ret);
2359 ret = isst_get_trl(id, &trl);
2361 isst_display_result(id, outf, "turbo-mode", "get-trl", ret);
2363 isst_trl_display_information(id, outf, trl);
2366 static void process_trl(int arg)
2370 fprintf(stderr, "Set TRL (turbo ratio limits)\n");
2371 fprintf(stderr, "\t t|--trl: Specify turbo ratio limit for setting TRL\n");
2373 fprintf(stderr, "Get TRL (turbo ratio limits)\n");
2378 isst_ctdp_display_information_start(outf);
2379 if (max_target_cpus)
2380 for_each_online_target_cpu_in_set(get_set_trl, NULL,
2383 for_each_online_power_domain_in_set(get_set_trl, NULL,
2385 isst_ctdp_display_information_end(outf);
2388 static struct process_cmd_struct clx_n_cmds[] = {
2389 { "perf-profile", "info", dump_isst_config, 0 },
2390 { "base-freq", "info", dump_pbf_config, 0 },
2391 { "base-freq", "enable", set_pbf_enable, 1 },
2392 { "base-freq", "disable", set_pbf_enable, 0 },
2393 { NULL, NULL, NULL, 0 }
2396 static struct process_cmd_struct isst_cmds[] = {
2397 { "perf-profile", "get-lock-status", get_tdp_locked, 0 },
2398 { "perf-profile", "get-config-levels", get_tdp_levels, 0 },
2399 { "perf-profile", "get-config-version", get_tdp_version, 0 },
2400 { "perf-profile", "get-config-enabled", get_tdp_enabled, 0 },
2401 { "perf-profile", "get-config-current-level", get_tdp_current_level,
2403 { "perf-profile", "set-config-level", set_tdp_level, 0 },
2404 { "perf-profile", "info", dump_isst_config, 0 },
2405 { "base-freq", "info", dump_pbf_config, 0 },
2406 { "base-freq", "enable", set_pbf_enable, 1 },
2407 { "base-freq", "disable", set_pbf_enable, 0 },
2408 { "turbo-freq", "info", dump_fact_config, 0 },
2409 { "turbo-freq", "enable", set_fact_enable, 1 },
2410 { "turbo-freq", "disable", set_fact_enable, 0 },
2411 { "core-power", "info", dump_clos_info, 0 },
2412 { "core-power", "enable", set_clos_enable, 1 },
2413 { "core-power", "disable", set_clos_enable, 0 },
2414 { "core-power", "config", set_clos_config, 0 },
2415 { "core-power", "get-config", dump_clos_config, 0 },
2416 { "core-power", "assoc", set_clos_assoc, 0 },
2417 { "core-power", "get-assoc", get_clos_assoc, 0 },
2418 { "turbo-mode", "enable", set_turbo_mode, 0 },
2419 { "turbo-mode", "disable", set_turbo_mode, 1 },
2420 { "turbo-mode", "get-trl", process_trl, 0 },
2421 { "turbo-mode", "set-trl", process_trl, 1 },
2422 { NULL, NULL, NULL }
2426 * parse cpuset with following syntax
2427 * 1,2,4..6,8-10 and set bits in cpu_subset
2429 void parse_cpu_command(char *optarg)
2431 unsigned int start, end;
2436 while (next && *next) {
2437 if (*next == '-') /* no negative cpu numbers */
2440 start = strtoul(next, &next, 10);
2442 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
2443 target_cpus[max_target_cpus++] = start;
2454 next += 1; /* start range */
2455 } else if (*next == '.') {
2458 next += 1; /* start range */
2463 end = strtoul(next, &next, 10);
2467 while (++start <= end) {
2468 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
2469 target_cpus[max_target_cpus++] = start;
2474 else if (*next != '\0')
2482 for (i = 0; i < max_target_cpus; ++i)
2483 printf("cpu [%d] in arg\n", target_cpus[i]);
2489 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg);
2493 static void parse_cmd_args(int argc, int start, char **argv)
2498 static struct option long_options[] = {
2499 { "bucket", required_argument, 0, 'b' },
2500 { "level", required_argument, 0, 'l' },
2501 { "online", required_argument, 0, 'o' },
2502 { "trl-type", required_argument, 0, 'r' },
2503 { "trl", required_argument, 0, 't' },
2504 { "help", no_argument, 0, 'h' },
2505 { "clos", required_argument, 0, 'c' },
2506 { "desired", required_argument, 0, 'd' },
2507 { "epp", required_argument, 0, 'e' },
2508 { "min", required_argument, 0, 'n' },
2509 { "max", required_argument, 0, 'm' },
2510 { "priority", required_argument, 0, 'p' },
2511 { "weight", required_argument, 0, 'w' },
2512 { "auto", no_argument, 0, 'a' },
2516 option_index = start;
2519 while ((opt = getopt_long(argc, argv, "b:l:t:c:d:e:n:m:p:w:r:hoa",
2520 long_options, &option_index)) != -1) {
2526 fact_bucket = atoi(optarg);
2532 tdp_level = atoi(optarg);
2535 force_online_offline = 1;
2538 sscanf(optarg, "0x%llx", &fact_trl);
2541 if (!strncmp(optarg, "sse", 3)) {
2543 } else if (!strncmp(optarg, "avx2", 4)) {
2545 } else if (!strncmp(optarg, "avx512", 6)) {
2548 fprintf(outf, "Invalid sse,avx options\n");
2554 current_clos = atoi(optarg);
2557 clos_desired = atoi(optarg);
2558 clos_desired /= isst_get_disp_freq_multiplier();
2561 clos_epp = atoi(optarg);
2562 if (is_skx_based_platform()) {
2563 isst_display_error_info_message(1, "epp can't be specified on this platform", 0, 0);
2568 clos_min = atoi(optarg);
2569 clos_min /= isst_get_disp_freq_multiplier();
2572 clos_max = atoi(optarg);
2573 clos_max /= isst_get_disp_freq_multiplier();
2576 clos_priority_type = atoi(optarg);
2577 if (is_skx_based_platform() && !clos_priority_type) {
2578 isst_display_error_info_message(1, "Invalid clos priority type: proportional for this platform", 0, 0);
2583 clos_prop_prio = atoi(optarg);
2584 if (is_skx_based_platform()) {
2585 isst_display_error_info_message(1, "weight can't be specified on this platform", 0, 0);
2590 printf("Unknown option: ignore\n");
2595 printf("Garbage at the end of command: ignore\n");
2598 static void isst_help(void)
2600 printf("perf-profile:\tAn architectural mechanism that allows multiple optimized \n\
2601 performance profiles per system via static and/or dynamic\n\
2602 adjustment of core count, workload, Tjmax, and\n\
2604 printf("\nCommands : For feature=perf-profile\n");
2607 if (!is_clx_n_platform()) {
2608 printf("\tget-lock-status\n");
2609 printf("\tget-config-levels\n");
2610 printf("\tget-config-version\n");
2611 printf("\tget-config-enabled\n");
2612 printf("\tget-config-current-level\n");
2613 printf("\tset-config-level\n");
2617 static void pbf_help(void)
2619 printf("base-freq:\tEnables users to increase guaranteed base frequency\n\
2620 on certain cores (high priority cores) in exchange for lower\n\
2621 base frequency on remaining cores (low priority cores).\n");
2622 printf("\tcommand : info\n");
2623 printf("\tcommand : enable\n");
2624 printf("\tcommand : disable\n");
2627 static void fact_help(void)
2629 printf("turbo-freq:\tEnables the ability to set different turbo ratio\n\
2630 limits to cores based on priority.\n");
2631 printf("\nCommand: For feature=turbo-freq\n");
2632 printf("\tcommand : info\n");
2633 printf("\tcommand : enable\n");
2634 printf("\tcommand : disable\n");
2637 static void turbo_mode_help(void)
2639 printf("turbo-mode:\tEnables users to enable/disable turbo mode by adjusting frequency settings. Also allows to get and set turbo ratio limits (TRL).\n");
2640 printf("\tcommand : enable\n");
2641 printf("\tcommand : disable\n");
2642 printf("\tcommand : get-trl\n");
2643 printf("\tcommand : set-trl\n");
2647 static void core_power_help(void)
2649 printf("core-power:\tInterface that allows user to define per core/tile\n\
2651 printf("\nCommands : For feature=core-power\n");
2653 printf("\tenable\n");
2654 printf("\tdisable\n");
2655 printf("\tconfig\n");
2656 printf("\tget-config\n");
2657 printf("\tassoc\n");
2658 printf("\tget-assoc\n");
2661 struct process_cmd_help_struct {
2663 void (*process_fn)(void);
2666 static struct process_cmd_help_struct isst_help_cmds[] = {
2667 { "perf-profile", isst_help },
2668 { "base-freq", pbf_help },
2669 { "turbo-freq", fact_help },
2670 { "core-power", core_power_help },
2671 { "turbo-mode", turbo_mode_help },
2675 static struct process_cmd_help_struct clx_n_help_cmds[] = {
2676 { "perf-profile", isst_help },
2677 { "base-freq", pbf_help },
2681 void process_command(int argc, char **argv,
2682 struct process_cmd_help_struct *help_cmds,
2683 struct process_cmd_struct *cmds)
2685 int i = 0, matched = 0;
2686 char *feature = argv[optind];
2687 char *cmd = argv[optind + 1];
2689 if (!feature || !cmd)
2692 debug_printf("feature name [%s] command [%s]\n", feature, cmd);
2693 if (!strcmp(cmd, "-h") || !strcmp(cmd, "--help")) {
2694 while (help_cmds[i].feature) {
2695 if (!strcmp(help_cmds[i].feature, feature)) {
2696 help_cmds[i].process_fn();
2704 while (cmds[i].feature) {
2705 if (!strcmp(cmds[i].feature, feature) &&
2706 !strcmp(cmds[i].command, cmd)) {
2707 parse_cmd_args(argc, optind + 1, argv);
2708 cmds[i].process_fn(cmds[i].arg);
2716 fprintf(stderr, "Invalid command\n");
2719 static void usage(void)
2721 if (is_clx_n_platform()) {
2722 fprintf(stderr, "\nThere is limited support of Intel Speed Select features on this platform.\n");
2723 fprintf(stderr, "Everything is pre-configured using BIOS options, this tool can't enable any feature in the hardware.\n\n");
2726 printf("\nUsage:\n");
2727 printf("intel-speed-select [OPTIONS] FEATURE COMMAND COMMAND_ARGUMENTS\n");
2728 printf("\nUse this tool to enumerate and control the Intel Speed Select Technology features:\n");
2729 if (is_clx_n_platform())
2730 printf("\nFEATURE : [perf-profile|base-freq]\n");
2732 printf("\nFEATURE : [perf-profile|base-freq|turbo-freq|core-power|turbo-mode]\n");
2733 printf("\nFor help on each feature, use -h|--help\n");
2734 printf("\tFor example: intel-speed-select perf-profile -h\n");
2736 printf("\nFor additional help on each command for a feature, use --h|--help\n");
2737 printf("\tFor example: intel-speed-select perf-profile get-lock-status -h\n");
2738 printf("\t\t This will print help for the command \"get-lock-status\" for the feature \"perf-profile\"\n");
2740 printf("\nOPTIONS\n");
2741 printf("\t[-c|--cpu] : logical cpu number\n");
2742 printf("\t\tDefault: Die scoped for all dies in the system with multiple dies/package\n");
2743 printf("\t\t\t Or Package scoped for all Packages when each package contains one die\n");
2744 printf("\t[-d|--debug] : Debug mode\n");
2745 printf("\t[-f|--format] : output format [json|text]. Default: text\n");
2746 printf("\t[-h|--help] : Print help\n");
2747 printf("\t[-i|--info] : Print platform information\n");
2748 printf("\t[-a|--all-cpus-online] : Force online every CPU in the system\n");
2749 printf("\t[-o|--out] : Output file\n");
2750 printf("\t\t\tDefault : stderr\n");
2751 printf("\t[-p|--pause] : Delay between two mail box commands in milliseconds\n");
2752 printf("\t[-r|--retry] : Retry count for mail box commands on failure, default 3\n");
2753 printf("\t[-v|--version] : Print version\n");
2754 printf("\t[-b|--oob : Start a daemon to process HFI events for perf profile change from Out of Band agent.\n");
2755 printf("\t[-n|--no-daemon : Don't run as daemon. By default --oob will turn on daemon mode\n");
2756 printf("\t[-w|--delay : Delay for reading config level state change in OOB poll mode.\n");
2757 printf("\nResult format\n");
2758 printf("\tResult display uses a common format for each command:\n");
2759 printf("\tResults are formatted in text/JSON with\n");
2760 printf("\t\tPackage, Die, CPU, and command specific results.\n");
2762 printf("\nExamples\n");
2763 printf("\tTo get platform information:\n");
2764 printf("\t\tintel-speed-select --info\n");
2765 printf("\tTo get full perf-profile information dump:\n");
2766 printf("\t\tintel-speed-select perf-profile info\n");
2767 printf("\tTo get full base-freq information dump:\n");
2768 printf("\t\tintel-speed-select base-freq info -l 0\n");
2769 if (!is_clx_n_platform()) {
2770 printf("\tTo get full turbo-freq information dump:\n");
2771 printf("\t\tintel-speed-select turbo-freq info -l 0\n");
2776 static void print_version(void)
2778 fprintf(outf, "Version %s\n", version_str);
2782 static void cmdline(int argc, char **argv)
2784 const char *pathname = "/dev/isst_interface";
2787 int opt, force_cpus_online = 0;
2788 int option_index = 0;
2791 int poll_interval = -1;
2793 int mbox_delay = 0, mbox_retries = 3;
2795 static struct option long_options[] = {
2796 { "all-cpus-online", no_argument, 0, 'a' },
2797 { "cpu", required_argument, 0, 'c' },
2798 { "debug", no_argument, 0, 'd' },
2799 { "format", required_argument, 0, 'f' },
2800 { "help", no_argument, 0, 'h' },
2801 { "info", no_argument, 0, 'i' },
2802 { "pause", required_argument, 0, 'p' },
2803 { "out", required_argument, 0, 'o' },
2804 { "retry", required_argument, 0, 'r' },
2805 { "version", no_argument, 0, 'v' },
2806 { "oob", no_argument, 0, 'b' },
2807 { "no-daemon", no_argument, 0, 'n' },
2808 { "poll-interval", required_argument, 0, 'w' },
2812 if (geteuid() != 0) {
2813 fprintf(stderr, "Must run as root\n");
2817 ret = update_cpu_model();
2819 err(-1, "Invalid CPU model (%d)\n", cpu_model);
2820 printf("Intel(R) Speed Select Technology\n");
2821 printf("Executing on CPU model:%d[0x%x]\n", cpu_model, cpu_model);
2823 if (!is_clx_n_platform()) {
2824 fp = fopen(pathname, "rb");
2826 fprintf(stderr, "Intel speed select drivers are not loaded on this system.\n");
2827 fprintf(stderr, "Verify that kernel config includes CONFIG_INTEL_SPEED_SELECT_INTERFACE.\n");
2828 fprintf(stderr, "If the config is included then this is not a supported platform.\n");
2834 ret = isst_fill_platform_info();
2839 while ((opt = getopt_long_only(argc, argv, "+c:df:hio:vabw:n", long_options,
2840 &option_index)) != -1) {
2843 force_cpus_online = 1;
2846 parse_cpu_command(optarg);
2850 printf("Debug Mode ON\n");
2853 if (!strncmp(optarg, "json", 4))
2854 out_format_json = 1;
2860 isst_print_platform_information();
2865 outf = fopen_or_exit(optarg, "w");
2868 ret = strtol(optarg, &ptr, 10);
2870 fprintf(stderr, "Invalid pause interval, ignore\n");
2875 ret = strtol(optarg, &ptr, 10);
2877 fprintf(stderr, "Invalid retry count, ignore\n");
2891 ret = strtol(optarg, &ptr, 10);
2893 fprintf(stderr, "Invalid poll interval count\n");
2896 poll_interval = ret;
2903 if (optind > (argc - 2) && !oob_mode) {
2908 isst_update_platform_param(ISST_PARAM_MBOX_DELAY, mbox_delay);
2909 isst_update_platform_param(ISST_PARAM_MBOX_RETRIES, mbox_retries);
2912 if (force_cpus_online)
2913 force_all_cpus_online();
2914 store_cpu_topology();
2919 fprintf(stderr, "OOB mode is enabled in debug mode\n");
2921 ret = isst_daemon(debug_flag, poll_interval, no_daemon);
2923 fprintf(stderr, "OOB mode enable failed\n");
2927 if (!is_clx_n_platform()) {
2928 process_command(argc, argv, isst_help_cmds, isst_cmds);
2930 process_command(argc, argv, clx_n_help_cmds, clx_n_cmds);
2933 free_cpu_set(present_cpumask);
2934 free_cpu_set(target_cpumask);
2937 int main(int argc, char **argv)
2940 cmdline(argc, argv);