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.0";
19 static const int supported_api_ver = 1;
20 static struct isst_if_platform_info isst_platform_info;
21 static char *progname;
22 static int debug_flag;
26 static int cpu_stepping;
28 #define MAX_CPUS_IN_ONE_REQ 64
29 static short max_target_cpus;
30 static unsigned short target_cpus[MAX_CPUS_IN_ONE_REQ];
32 static int topo_max_cpus;
33 static size_t present_cpumask_size;
34 static cpu_set_t *present_cpumask;
35 static size_t target_cpumask_size;
36 static cpu_set_t *target_cpumask;
37 static int tdp_level = 0xFF;
38 static int fact_bucket = 0xFF;
39 static int fact_avx = 0xFF;
40 static unsigned long long fact_trl;
41 static int out_format_json;
43 static int force_online_offline;
47 static int current_clos = -1;
48 static int clos_epp = -1;
49 static int clos_prop_prio = -1;
50 static int clos_min = -1;
51 static int clos_max = -1;
52 static int clos_desired = -1;
53 static int clos_priority_type;
56 unsigned short core_id;
57 unsigned short pkg_id;
58 unsigned short die_id;
59 unsigned short punit_cpu;
60 unsigned short punit_cpu_core;
62 struct _cpu_map *cpu_map;
64 void debug_printf(const char *format, ...)
68 va_start(args, format);
71 vprintf(format, args);
77 int is_clx_n_platform(void)
79 if (cpu_model == 0x55)
80 if (cpu_stepping == 0x6 || cpu_stepping == 0x7)
85 static int update_cpu_model(void)
87 unsigned int ebx, ecx, edx;
88 unsigned int fms, family;
90 __cpuid(1, fms, ebx, ecx, edx);
91 family = (fms >> 8) & 0xf;
92 cpu_model = (fms >> 4) & 0xf;
93 if (family == 6 || family == 0xf)
94 cpu_model += ((fms >> 16) & 0xf) << 4;
96 cpu_stepping = fms & 0xf;
97 /* only three CascadeLake-N models are supported */
98 if (is_clx_n_platform()) {
104 fp = fopen("/proc/cpuinfo", "r");
106 err(-1, "cannot open /proc/cpuinfo\n");
108 while (getline(&line, &n, fp) > 0) {
109 if (strstr(line, "model name")) {
110 if (strstr(line, "6252N") ||
111 strstr(line, "6230N") ||
112 strstr(line, "5218N"))
124 /* Open a file, and exit on failure */
125 static FILE *fopen_or_exit(const char *path, const char *mode)
127 FILE *filep = fopen(path, mode);
130 err(1, "%s: open failed", path);
135 /* Parse a file containing a single int */
136 static int parse_int_file(int fatal, const char *fmt, ...)
144 vsnprintf(path, sizeof(path), fmt, args);
147 filep = fopen_or_exit(path, "r");
149 filep = fopen(path, "r");
153 if (fscanf(filep, "%d", &value) != 1)
154 err(1, "%s: failed to parse number from file", path);
160 int cpufreq_sysfs_present(void)
164 dir = opendir("/sys/devices/system/cpu/cpu0/cpufreq");
173 int out_format_is_json(void)
175 return out_format_json;
178 int get_physical_package_id(int cpu)
180 return parse_int_file(
181 0, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",
185 int get_physical_core_id(int cpu)
187 return parse_int_file(
188 0, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu);
191 int get_physical_die_id(int cpu)
195 ret = parse_int_file(0, "/sys/devices/system/cpu/cpu%d/topology/die_id",
203 int get_topo_max_cpus(void)
205 return topo_max_cpus;
208 static void set_cpu_online_offline(int cpu, int state)
213 snprintf(buffer, sizeof(buffer),
214 "/sys/devices/system/cpu/cpu%d/online", cpu);
216 fd = open(buffer, O_WRONLY);
218 err(-1, "%s open failed", buffer);
221 ret = write(fd, "1\n", 2);
223 ret = write(fd, "0\n", 2);
226 perror("Online/Offline: Operation failed\n");
231 #define MAX_PACKAGE_COUNT 8
232 #define MAX_DIE_PER_PACKAGE 2
233 static void for_each_online_package_in_set(void (*callback)(int, void *, void *,
235 void *arg1, void *arg2, void *arg3,
238 int max_packages[MAX_PACKAGE_COUNT * MAX_PACKAGE_COUNT];
239 int pkg_index = 0, i;
241 memset(max_packages, 0xff, sizeof(max_packages));
242 for (i = 0; i < topo_max_cpus; ++i) {
243 int j, online, pkg_id, die_id = 0, skip = 0;
245 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
248 online = parse_int_file(
249 1, "/sys/devices/system/cpu/cpu%d/online", i);
252 1; /* online entry for CPU 0 needs some special configs */
254 die_id = get_physical_die_id(i);
257 pkg_id = get_physical_package_id(i);
258 /* Create an unique id for package, die combination to store */
259 pkg_id = (MAX_PACKAGE_COUNT * pkg_id + die_id);
261 for (j = 0; j < pkg_index; ++j) {
262 if (max_packages[j] == pkg_id) {
268 if (!skip && online && callback) {
269 callback(i, arg1, arg2, arg3, arg4);
270 max_packages[pkg_index++] = pkg_id;
275 static void for_each_online_target_cpu_in_set(
276 void (*callback)(int, void *, void *, void *, void *), void *arg1,
277 void *arg2, void *arg3, void *arg4)
281 for (i = 0; i < topo_max_cpus; ++i) {
284 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
287 online = parse_int_file(
288 1, "/sys/devices/system/cpu/cpu%d/online", i);
291 1; /* online entry for CPU 0 needs some special configs */
293 if (online && callback)
294 callback(i, arg1, arg2, arg3, arg4);
298 #define BITMASK_SIZE 32
299 static void set_max_cpu_num(void)
305 filep = fopen_or_exit(
306 "/sys/devices/system/cpu/cpu0/topology/thread_siblings", "r");
307 while (fscanf(filep, "%lx,", &dummy) == 1)
308 topo_max_cpus += BITMASK_SIZE;
310 topo_max_cpus--; /* 0 based */
312 debug_printf("max cpus %d\n", topo_max_cpus);
315 size_t alloc_cpu_set(cpu_set_t **cpu_set)
320 _cpu_set = CPU_ALLOC((topo_max_cpus + 1));
321 if (_cpu_set == NULL)
323 size = CPU_ALLOC_SIZE((topo_max_cpus + 1));
324 CPU_ZERO_S(size, _cpu_set);
330 void free_cpu_set(cpu_set_t *cpu_set)
335 static int cpu_cnt[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
336 static void set_cpu_present_cpu_mask(void)
342 size = alloc_cpu_set(&present_cpumask);
343 present_cpumask_size = size;
344 for (i = 0; i < topo_max_cpus; ++i) {
347 snprintf(buffer, sizeof(buffer),
348 "/sys/devices/system/cpu/cpu%d", i);
349 dir = opendir(buffer);
353 CPU_SET_S(i, size, present_cpumask);
354 die_id = get_physical_die_id(i);
358 pkg_id = get_physical_package_id(i);
359 if (pkg_id < MAX_PACKAGE_COUNT &&
360 die_id < MAX_DIE_PER_PACKAGE)
361 cpu_cnt[pkg_id][die_id]++;
367 int get_cpu_count(int pkg_id, int die_id)
369 if (pkg_id < MAX_PACKAGE_COUNT && die_id < MAX_DIE_PER_PACKAGE)
370 return cpu_cnt[pkg_id][die_id];
375 static void set_cpu_target_cpu_mask(void)
380 size = alloc_cpu_set(&target_cpumask);
381 target_cpumask_size = size;
382 for (i = 0; i < max_target_cpus; ++i) {
383 if (!CPU_ISSET_S(target_cpus[i], present_cpumask_size,
387 CPU_SET_S(target_cpus[i], size, target_cpumask);
391 static void create_cpu_map(void)
393 const char *pathname = "/dev/isst_interface";
395 struct isst_if_cpu_maps map;
397 cpu_map = malloc(sizeof(*cpu_map) * topo_max_cpus);
401 fd = open(pathname, O_RDWR);
403 err(-1, "%s open failed", pathname);
405 for (i = 0; i < topo_max_cpus; ++i) {
406 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
410 map.cpu_map[0].logical_cpu = i;
412 debug_printf(" map logical_cpu:%d\n",
413 map.cpu_map[0].logical_cpu);
414 if (ioctl(fd, ISST_IF_GET_PHY_ID, &map) == -1) {
415 perror("ISST_IF_GET_PHY_ID");
416 fprintf(outf, "Error: map logical_cpu:%d\n",
417 map.cpu_map[0].logical_cpu);
420 cpu_map[i].core_id = get_physical_core_id(i);
421 cpu_map[i].pkg_id = get_physical_package_id(i);
422 cpu_map[i].die_id = get_physical_die_id(i);
423 cpu_map[i].punit_cpu = map.cpu_map[0].physical_cpu;
424 cpu_map[i].punit_cpu_core = (map.cpu_map[0].physical_cpu >>
425 1); // shift to get core id
428 "map logical_cpu:%d core: %d die:%d pkg:%d punit_cpu:%d punit_core:%d\n",
429 i, cpu_map[i].core_id, cpu_map[i].die_id,
430 cpu_map[i].pkg_id, cpu_map[i].punit_cpu,
431 cpu_map[i].punit_cpu_core);
438 int find_logical_cpu(int pkg_id, int die_id, int punit_core_id)
442 for (i = 0; i < topo_max_cpus; ++i) {
443 if (cpu_map[i].pkg_id == pkg_id &&
444 cpu_map[i].die_id == die_id &&
445 cpu_map[i].punit_cpu_core == punit_core_id)
452 void set_cpu_mask_from_punit_coremask(int cpu, unsigned long long core_mask,
453 size_t core_cpumask_size,
454 cpu_set_t *core_cpumask, int *cpu_cnt)
460 die_id = get_physical_die_id(cpu);
461 pkg_id = get_physical_package_id(cpu);
463 for (i = 0; i < 64; ++i) {
464 if (core_mask & BIT(i)) {
467 for (j = 0; j < topo_max_cpus; ++j) {
468 if (!CPU_ISSET_S(j, present_cpumask_size, present_cpumask))
471 if (cpu_map[j].pkg_id == pkg_id &&
472 cpu_map[j].die_id == die_id &&
473 cpu_map[j].punit_cpu_core == i) {
474 CPU_SET_S(j, core_cpumask_size,
485 int find_phy_core_num(int logical_cpu)
487 if (logical_cpu < topo_max_cpus)
488 return cpu_map[logical_cpu].punit_cpu_core;
493 static int isst_send_mmio_command(unsigned int cpu, unsigned int reg, int write,
496 struct isst_if_io_regs io_regs;
497 const char *pathname = "/dev/isst_interface";
501 debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu, reg, write);
503 fd = open(pathname, O_RDWR);
505 err(-1, "%s open failed", pathname);
507 io_regs.req_count = 1;
508 io_regs.io_reg[0].logical_cpu = cpu;
509 io_regs.io_reg[0].reg = reg;
510 cmd = ISST_IF_IO_CMD;
512 io_regs.io_reg[0].read_write = 1;
513 io_regs.io_reg[0].value = *value;
515 io_regs.io_reg[0].read_write = 0;
518 if (ioctl(fd, cmd, &io_regs) == -1) {
519 perror("ISST_IF_IO_CMD");
520 fprintf(outf, "Error: mmio_cmd cpu:%d reg:%x read_write:%x\n",
524 *value = io_regs.io_reg[0].value;
527 "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
528 cpu, reg, write, *value);
536 int isst_send_mbox_command(unsigned int cpu, unsigned char command,
537 unsigned char sub_command, unsigned int parameter,
538 unsigned int req_data, unsigned int *resp)
540 const char *pathname = "/dev/isst_interface";
542 struct isst_if_mbox_cmds mbox_cmds = { 0 };
545 "mbox_send: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
546 cpu, command, sub_command, parameter, req_data);
548 if (isst_platform_info.mmio_supported && command == CONFIG_CLOS) {
551 int clos_id, core_id, ret = 0;
553 debug_printf("CPU %d\n", cpu);
555 if (parameter & BIT(MBOX_CMD_WRITE_BIT)) {
560 switch (sub_command) {
562 core_id = parameter & 0xff;
563 ret = isst_send_mmio_command(
564 cpu, PQR_ASSOC_OFFSET + core_id * 4, write,
570 clos_id = parameter & 0x03;
571 ret = isst_send_mmio_command(
572 cpu, PM_CLOS_OFFSET + clos_id * 4, write,
585 mbox_cmds.cmd_count = 1;
586 mbox_cmds.mbox_cmd[0].logical_cpu = cpu;
587 mbox_cmds.mbox_cmd[0].command = command;
588 mbox_cmds.mbox_cmd[0].sub_command = sub_command;
589 mbox_cmds.mbox_cmd[0].parameter = parameter;
590 mbox_cmds.mbox_cmd[0].req_data = req_data;
592 fd = open(pathname, O_RDWR);
594 err(-1, "%s open failed", pathname);
596 if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
597 perror("ISST_IF_MBOX_COMMAND");
599 "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
600 cpu, command, sub_command, parameter, req_data);
602 *resp = mbox_cmds.mbox_cmd[0].resp_data;
604 "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
605 cpu, command, sub_command, parameter, req_data, *resp);
613 int isst_send_msr_command(unsigned int cpu, unsigned int msr, int write,
614 unsigned long long *req_resp)
616 struct isst_if_msr_cmds msr_cmds;
617 const char *pathname = "/dev/isst_interface";
620 fd = open(pathname, O_RDWR);
622 err(-1, "%s open failed", pathname);
624 msr_cmds.cmd_count = 1;
625 msr_cmds.msr_cmd[0].logical_cpu = cpu;
626 msr_cmds.msr_cmd[0].msr = msr;
627 msr_cmds.msr_cmd[0].read_write = write;
629 msr_cmds.msr_cmd[0].data = *req_resp;
631 if (ioctl(fd, ISST_IF_MSR_COMMAND, &msr_cmds) == -1) {
632 perror("ISST_IF_MSR_COMMAD");
633 fprintf(outf, "Error: msr_cmd cpu:%d msr:%x read_write:%d\n",
637 *req_resp = msr_cmds.msr_cmd[0].data;
640 "msr_cmd response: cpu:%d msr:%x rd_write:%x resp:%llx %llx\n",
641 cpu, msr, write, *req_resp, msr_cmds.msr_cmd[0].data);
649 static int isst_fill_platform_info(void)
651 const char *pathname = "/dev/isst_interface";
654 fd = open(pathname, O_RDWR);
656 err(-1, "%s open failed", pathname);
658 if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &isst_platform_info) == -1) {
659 perror("ISST_IF_GET_PLATFORM_INFO");
666 if (isst_platform_info.api_version > supported_api_ver) {
667 printf("Incompatible API versions; Upgrade of tool is required\n");
673 static void isst_print_platform_information(void)
675 struct isst_if_platform_info platform_info;
676 const char *pathname = "/dev/isst_interface";
679 fd = open(pathname, O_RDWR);
681 err(-1, "%s open failed", pathname);
683 if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &platform_info) == -1) {
684 perror("ISST_IF_GET_PLATFORM_INFO");
686 fprintf(outf, "Platform: API version : %d\n",
687 platform_info.api_version);
688 fprintf(outf, "Platform: Driver version : %d\n",
689 platform_info.driver_version);
690 fprintf(outf, "Platform: mbox supported : %d\n",
691 platform_info.mbox_supported);
692 fprintf(outf, "Platform: mmio supported : %d\n",
693 platform_info.mmio_supported);
701 static void exec_on_get_ctdp_cpu(int cpu, void *arg1, void *arg2, void *arg3,
704 int (*fn_ptr)(int cpu, void *arg);
708 ret = fn_ptr(cpu, arg2);
712 isst_ctdp_display_core_info(cpu, outf, arg3,
713 *(unsigned int *)arg4);
716 #define _get_tdp_level(desc, suffix, object, help) \
717 static void get_tdp_##object(int arg) \
719 struct isst_pkg_ctdp ctdp; \
723 "Print %s [No command arguments are required]\n", \
727 isst_ctdp_display_information_start(outf); \
728 if (max_target_cpus) \
729 for_each_online_target_cpu_in_set( \
730 exec_on_get_ctdp_cpu, isst_get_ctdp_##suffix, \
731 &ctdp, desc, &ctdp.object); \
733 for_each_online_package_in_set(exec_on_get_ctdp_cpu, \
734 isst_get_ctdp_##suffix, \
737 isst_ctdp_display_information_end(outf); \
740 _get_tdp_level("get-config-levels", levels, levels, "TDP levels");
741 _get_tdp_level("get-config-version", levels, version, "TDP version");
742 _get_tdp_level("get-config-enabled", levels, enabled, "TDP enable status");
743 _get_tdp_level("get-config-current_level", levels, current_level,
744 "Current TDP Level");
745 _get_tdp_level("get-lock-status", levels, locked, "TDP lock status");
747 struct isst_pkg_ctdp clx_n_pkg_dev;
749 static int clx_n_get_base_ratio(void)
752 char *begin, *end, *line = NULL;
757 fp = fopen("/proc/cpuinfo", "r");
759 err(-1, "cannot open /proc/cpuinfo\n");
761 while (getline(&line, &n, fp) > 0) {
762 if (strstr(line, "model name")) {
763 /* this is true for CascadeLake-N */
764 begin = strstr(line, "@ ") + 2;
765 end = strstr(line, "GHz");
766 strncpy(number, begin, end - begin);
767 value = atof(number) * 10;
777 static int clx_n_config(int cpu)
779 int i, ret, pkg_id, die_id;
780 unsigned long cpu_bf;
781 struct isst_pkg_ctdp_level_info *ctdp_level;
782 struct isst_pbf_info *pbf_info;
784 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
785 pbf_info = &ctdp_level->pbf_info;
786 ctdp_level->core_cpumask_size =
787 alloc_cpu_set(&ctdp_level->core_cpumask);
789 /* find the frequency base ratio */
790 ctdp_level->tdp_ratio = clx_n_get_base_ratio();
791 if (ctdp_level->tdp_ratio == 0) {
792 debug_printf("CLX: cn base ratio is zero\n");
797 /* find the high and low priority frequencies */
798 pbf_info->p1_high = 0;
799 pbf_info->p1_low = ~0;
801 pkg_id = get_physical_package_id(cpu);
802 die_id = get_physical_die_id(cpu);
804 for (i = 0; i < topo_max_cpus; i++) {
805 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
808 if (pkg_id != get_physical_package_id(i) ||
809 die_id != get_physical_die_id(i))
812 CPU_SET_S(i, ctdp_level->core_cpumask_size,
813 ctdp_level->core_cpumask);
815 cpu_bf = parse_int_file(1,
816 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
818 if (cpu_bf > pbf_info->p1_high)
819 pbf_info->p1_high = cpu_bf;
820 if (cpu_bf < pbf_info->p1_low)
821 pbf_info->p1_low = cpu_bf;
824 if (pbf_info->p1_high == ~0UL) {
825 debug_printf("CLX: maximum base frequency not set\n");
830 if (pbf_info->p1_low == 0) {
831 debug_printf("CLX: minimum base frequency not set\n");
836 /* convert frequencies back to ratios */
837 pbf_info->p1_high = pbf_info->p1_high / 100000;
838 pbf_info->p1_low = pbf_info->p1_low / 100000;
840 /* create high priority cpu mask */
841 pbf_info->core_cpumask_size = alloc_cpu_set(&pbf_info->core_cpumask);
842 for (i = 0; i < topo_max_cpus; i++) {
843 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
846 if (pkg_id != get_physical_package_id(i) ||
847 die_id != get_physical_die_id(i))
850 cpu_bf = parse_int_file(1,
851 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
853 cpu_bf = cpu_bf / 100000;
854 if (cpu_bf == pbf_info->p1_high)
855 CPU_SET_S(i, pbf_info->core_cpumask_size,
856 pbf_info->core_cpumask);
859 /* extra ctdp & pbf struct parameters */
860 ctdp_level->processed = 1;
861 ctdp_level->pbf_support = 1; /* PBF is always supported and enabled */
862 ctdp_level->pbf_enabled = 1;
863 ctdp_level->fact_support = 0; /* FACT is never supported */
864 ctdp_level->fact_enabled = 0;
869 free_cpu_set(ctdp_level->core_cpumask);
873 static void dump_clx_n_config_for_cpu(int cpu, void *arg1, void *arg2,
874 void *arg3, void *arg4)
878 ret = clx_n_config(cpu);
880 perror("isst_get_process_ctdp");
882 struct isst_pkg_ctdp_level_info *ctdp_level;
883 struct isst_pbf_info *pbf_info;
885 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
886 pbf_info = &ctdp_level->pbf_info;
887 isst_ctdp_display_information(cpu, outf, tdp_level, &clx_n_pkg_dev);
888 free_cpu_set(ctdp_level->core_cpumask);
889 free_cpu_set(pbf_info->core_cpumask);
893 static void dump_isst_config_for_cpu(int cpu, void *arg1, void *arg2,
894 void *arg3, void *arg4)
896 struct isst_pkg_ctdp pkg_dev;
899 memset(&pkg_dev, 0, sizeof(pkg_dev));
900 ret = isst_get_process_ctdp(cpu, tdp_level, &pkg_dev);
902 perror("isst_get_process_ctdp");
904 isst_ctdp_display_information(cpu, outf, tdp_level, &pkg_dev);
905 isst_get_process_ctdp_complete(cpu, &pkg_dev);
909 static void dump_isst_config(int arg)
915 "Print Intel(R) Speed Select Technology Performance profile configuration\n");
917 "including base frequency and turbo frequency configurations\n");
918 fprintf(stderr, "Optional: -l|--level : Specify tdp level\n");
920 "\tIf no arguments, dump information for all TDP levels\n");
924 if (!is_clx_n_platform())
925 fn = dump_isst_config_for_cpu;
927 fn = dump_clx_n_config_for_cpu;
929 isst_ctdp_display_information_start(outf);
932 for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
934 for_each_online_package_in_set(fn, NULL, NULL, NULL, NULL);
936 isst_ctdp_display_information_end(outf);
939 static void set_tdp_level_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
944 ret = isst_set_tdp_level(cpu, tdp_level);
946 perror("set_tdp_level_for_cpu");
948 isst_display_result(cpu, outf, "perf-profile", "set_tdp_level",
950 if (force_online_offline) {
951 struct isst_pkg_ctdp_level_info ctdp_level;
952 int pkg_id = get_physical_package_id(cpu);
953 int die_id = get_physical_die_id(cpu);
955 fprintf(stderr, "Option is set to online/offline\n");
956 ctdp_level.core_cpumask_size =
957 alloc_cpu_set(&ctdp_level.core_cpumask);
958 isst_get_coremask_info(cpu, tdp_level, &ctdp_level);
959 if (ctdp_level.cpu_count) {
960 int i, max_cpus = get_topo_max_cpus();
961 for (i = 0; i < max_cpus; ++i) {
962 if (pkg_id != get_physical_package_id(i) || die_id != get_physical_die_id(i))
964 if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
965 fprintf(stderr, "online cpu %d\n", i);
966 set_cpu_online_offline(i, 1);
968 fprintf(stderr, "offline cpu %d\n", i);
969 set_cpu_online_offline(i, 0);
977 static void set_tdp_level(int arg)
980 fprintf(stderr, "Set Config TDP level\n");
982 "\t Arguments: -l|--level : Specify tdp level\n");
984 "\t Optional Arguments: -o | online : online/offline for the tdp level\n");
988 if (tdp_level == 0xff) {
989 fprintf(outf, "Invalid command: specify tdp_level\n");
992 isst_ctdp_display_information_start(outf);
994 for_each_online_target_cpu_in_set(set_tdp_level_for_cpu, NULL,
997 for_each_online_package_in_set(set_tdp_level_for_cpu, NULL,
999 isst_ctdp_display_information_end(outf);
1002 static void clx_n_dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2,
1003 void *arg3, void *arg4)
1007 ret = clx_n_config(cpu);
1009 perror("isst_get_process_ctdp");
1011 struct isst_pkg_ctdp_level_info *ctdp_level;
1012 struct isst_pbf_info *pbf_info;
1014 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1015 pbf_info = &ctdp_level->pbf_info;
1016 isst_pbf_display_information(cpu, outf, tdp_level, pbf_info);
1017 free_cpu_set(ctdp_level->core_cpumask);
1018 free_cpu_set(pbf_info->core_cpumask);
1022 static void dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1025 struct isst_pbf_info pbf_info;
1028 ret = isst_get_pbf_info(cpu, tdp_level, &pbf_info);
1030 perror("isst_get_pbf_info");
1032 isst_pbf_display_information(cpu, outf, tdp_level, &pbf_info);
1033 isst_get_pbf_info_complete(&pbf_info);
1037 static void dump_pbf_config(int arg)
1043 "Print Intel(R) Speed Select Technology base frequency configuration for a TDP level\n");
1045 "\tArguments: -l|--level : Specify tdp level\n");
1049 if (tdp_level == 0xff) {
1050 fprintf(outf, "Invalid command: specify tdp_level\n");
1054 if (!is_clx_n_platform())
1055 fn = dump_pbf_config_for_cpu;
1057 fn = clx_n_dump_pbf_config_for_cpu;
1059 isst_ctdp_display_information_start(outf);
1061 if (max_target_cpus)
1062 for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
1064 for_each_online_package_in_set(fn, NULL, NULL, NULL, NULL);
1066 isst_ctdp_display_information_end(outf);
1069 static int set_clos_param(int cpu, int clos, int epp, int wt, int min, int max)
1071 struct isst_clos_config clos_config;
1074 ret = isst_pm_get_clos(cpu, clos, &clos_config);
1076 perror("isst_pm_get_clos");
1079 clos_config.clos_min = min;
1080 clos_config.clos_max = max;
1081 clos_config.epp = epp;
1082 clos_config.clos_prop_prio = wt;
1083 ret = isst_set_clos(cpu, clos, &clos_config);
1085 perror("isst_pm_set_clos");
1092 static int set_cpufreq_scaling_min_max(int cpu, int max, int freq)
1094 char buffer[128], freq_str[16];
1098 snprintf(buffer, sizeof(buffer),
1099 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
1101 snprintf(buffer, sizeof(buffer),
1102 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
1104 fd = open(buffer, O_WRONLY);
1108 snprintf(freq_str, sizeof(freq_str), "%d", freq);
1109 len = strlen(freq_str);
1110 ret = write(fd, freq_str, len);
1120 static int set_clx_pbf_cpufreq_scaling_min_max(int cpu)
1122 struct isst_pkg_ctdp_level_info *ctdp_level;
1123 struct isst_pbf_info *pbf_info;
1124 int i, pkg_id, die_id, freq, freq_high, freq_low;
1127 ret = clx_n_config(cpu);
1129 perror("set_clx_pbf_cpufreq_scaling_min_max");
1133 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1134 pbf_info = &ctdp_level->pbf_info;
1135 freq_high = pbf_info->p1_high * 100000;
1136 freq_low = pbf_info->p1_low * 100000;
1138 pkg_id = get_physical_package_id(cpu);
1139 die_id = get_physical_die_id(cpu);
1140 for (i = 0; i < get_topo_max_cpus(); ++i) {
1141 if (pkg_id != get_physical_package_id(i) ||
1142 die_id != get_physical_die_id(i))
1145 if (CPU_ISSET_S(i, pbf_info->core_cpumask_size,
1146 pbf_info->core_cpumask))
1151 set_cpufreq_scaling_min_max(i, 1, freq);
1152 set_cpufreq_scaling_min_max(i, 0, freq);
1158 static int set_cpufreq_scaling_min_max_from_cpuinfo(int cpu, int cpuinfo_max, int scaling_max)
1160 char buffer[128], min_freq[16];
1163 if (!CPU_ISSET_S(cpu, present_cpumask_size, present_cpumask))
1167 snprintf(buffer, sizeof(buffer),
1168 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu);
1170 snprintf(buffer, sizeof(buffer),
1171 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", cpu);
1173 fd = open(buffer, O_RDONLY);
1177 len = read(fd, min_freq, sizeof(min_freq));
1184 snprintf(buffer, sizeof(buffer),
1185 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
1187 snprintf(buffer, sizeof(buffer),
1188 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
1190 fd = open(buffer, O_WRONLY);
1194 len = strlen(min_freq);
1195 ret = write(fd, min_freq, len);
1205 static void set_scaling_min_to_cpuinfo_max(int cpu)
1207 int i, pkg_id, die_id;
1209 pkg_id = get_physical_package_id(cpu);
1210 die_id = get_physical_die_id(cpu);
1211 for (i = 0; i < get_topo_max_cpus(); ++i) {
1212 if (pkg_id != get_physical_package_id(i) ||
1213 die_id != get_physical_die_id(i))
1216 set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 0);
1220 static void set_scaling_min_to_cpuinfo_min(int cpu)
1222 int i, pkg_id, die_id;
1224 pkg_id = get_physical_package_id(cpu);
1225 die_id = get_physical_die_id(cpu);
1226 for (i = 0; i < get_topo_max_cpus(); ++i) {
1227 if (pkg_id != get_physical_package_id(i) ||
1228 die_id != get_physical_die_id(i))
1231 set_cpufreq_scaling_min_max_from_cpuinfo(i, 0, 0);
1235 static void set_scaling_max_to_cpuinfo_max(int cpu)
1237 int i, pkg_id, die_id;
1239 pkg_id = get_physical_package_id(cpu);
1240 die_id = get_physical_die_id(cpu);
1241 for (i = 0; i < get_topo_max_cpus(); ++i) {
1242 if (pkg_id != get_physical_package_id(i) ||
1243 die_id != get_physical_die_id(i))
1246 set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 1);
1250 static int set_core_priority_and_min(int cpu, int mask_size,
1251 cpu_set_t *cpu_mask, int min_high,
1254 int pkg_id, die_id, ret, i;
1256 if (!CPU_COUNT_S(mask_size, cpu_mask))
1259 ret = set_clos_param(cpu, 0, 0, 0, min_high, 0xff);
1263 ret = set_clos_param(cpu, 1, 15, 0, min_low, 0xff);
1267 ret = set_clos_param(cpu, 2, 15, 0, min_low, 0xff);
1271 ret = set_clos_param(cpu, 3, 15, 0, min_low, 0xff);
1275 pkg_id = get_physical_package_id(cpu);
1276 die_id = get_physical_die_id(cpu);
1277 for (i = 0; i < get_topo_max_cpus(); ++i) {
1280 if (pkg_id != get_physical_package_id(i) ||
1281 die_id != get_physical_die_id(i))
1284 if (CPU_ISSET_S(i, mask_size, cpu_mask))
1289 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
1290 ret = isst_clos_associate(i, clos);
1292 perror("isst_clos_associate");
1300 static int set_pbf_core_power(int cpu)
1302 struct isst_pbf_info pbf_info;
1303 struct isst_pkg_ctdp pkg_dev;
1306 ret = isst_get_ctdp_levels(cpu, &pkg_dev);
1308 perror("isst_get_ctdp_levels");
1311 debug_printf("Current_level: %d\n", pkg_dev.current_level);
1313 ret = isst_get_pbf_info(cpu, pkg_dev.current_level, &pbf_info);
1315 perror("isst_get_pbf_info");
1318 debug_printf("p1_high: %d p1_low: %d\n", pbf_info.p1_high,
1321 ret = set_core_priority_and_min(cpu, pbf_info.core_cpumask_size,
1322 pbf_info.core_cpumask,
1323 pbf_info.p1_high, pbf_info.p1_low);
1325 perror("set_core_priority_and_min");
1329 ret = isst_pm_qos_config(cpu, 1, 1);
1331 perror("isst_pm_qos_config");
1338 static void set_pbf_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1342 int status = *(int *)arg4;
1344 if (is_clx_n_platform()) {
1348 set_clx_pbf_cpufreq_scaling_min_max(cpu);
1353 set_scaling_max_to_cpuinfo_max(cpu);
1354 set_scaling_min_to_cpuinfo_min(cpu);
1362 ret = set_pbf_core_power(cpu);
1366 isst_pm_qos_config(cpu, 0, 0);
1370 ret = isst_set_pbf_fact_status(cpu, 1, status);
1372 perror("isst_set_pbf");
1374 isst_pm_qos_config(cpu, 0, 0);
1378 set_scaling_min_to_cpuinfo_max(cpu);
1380 set_scaling_min_to_cpuinfo_min(cpu);
1386 isst_display_result(cpu, outf, "base-freq", "enable",
1389 isst_display_result(cpu, outf, "base-freq", "disable",
1393 static void set_pbf_enable(int arg)
1400 "Enable Intel Speed Select Technology base frequency feature\n");
1402 "\tOptional Arguments: -a|--auto : Use priority of cores to set core-power associations\n");
1406 "Disable Intel Speed Select Technology base frequency feature\n");
1408 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1413 isst_ctdp_display_information_start(outf);
1414 if (max_target_cpus)
1415 for_each_online_target_cpu_in_set(set_pbf_for_cpu, NULL, NULL,
1418 for_each_online_package_in_set(set_pbf_for_cpu, NULL, NULL,
1420 isst_ctdp_display_information_end(outf);
1423 static void dump_fact_config_for_cpu(int cpu, void *arg1, void *arg2,
1424 void *arg3, void *arg4)
1426 struct isst_fact_info fact_info;
1429 ret = isst_get_fact_info(cpu, tdp_level, &fact_info);
1431 perror("isst_get_fact_bucket_info");
1433 isst_fact_display_information(cpu, outf, tdp_level, fact_bucket,
1434 fact_avx, &fact_info);
1437 static void dump_fact_config(int arg)
1441 "Print complete Intel Speed Select Technology turbo frequency configuration for a TDP level. Other arguments are optional.\n");
1443 "\tArguments: -l|--level : Specify tdp level\n");
1445 "\tArguments: -b|--bucket : Bucket index to dump\n");
1447 "\tArguments: -r|--trl-type : Specify trl type: sse|avx2|avx512\n");
1451 if (tdp_level == 0xff) {
1452 fprintf(outf, "Invalid command: specify tdp_level\n");
1456 isst_ctdp_display_information_start(outf);
1457 if (max_target_cpus)
1458 for_each_online_target_cpu_in_set(dump_fact_config_for_cpu,
1459 NULL, NULL, NULL, NULL);
1461 for_each_online_package_in_set(dump_fact_config_for_cpu, NULL,
1463 isst_ctdp_display_information_end(outf);
1466 static void set_fact_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1470 int status = *(int *)arg4;
1474 ret = isst_pm_qos_config(cpu, 1, 1);
1478 isst_pm_qos_config(cpu, 0, 0);
1482 ret = isst_set_pbf_fact_status(cpu, 0, status);
1484 perror("isst_set_fact");
1486 isst_pm_qos_config(cpu, 0, 0);
1493 struct isst_pkg_ctdp pkg_dev;
1495 ret = isst_get_ctdp_levels(cpu, &pkg_dev);
1497 ret = isst_set_trl(cpu, fact_trl);
1498 if (ret && auto_mode)
1499 isst_pm_qos_config(cpu, 0, 0);
1504 isst_display_result(cpu, outf, "turbo-freq", "enable", ret);
1506 /* Since we modified TRL during Fact enable, restore it */
1507 isst_set_trl_from_current_tdp(cpu, fact_trl);
1508 isst_display_result(cpu, outf, "turbo-freq", "disable", ret);
1512 static void set_fact_enable(int arg)
1514 int i, ret, enable = arg;
1519 "Enable Intel Speed Select Technology Turbo frequency feature\n");
1521 "Optional: -t|--trl : Specify turbo ratio limit\n");
1523 "\tOptional Arguments: -a|--auto : Designate specified target CPUs with");
1525 "-C|--cpu option as as high priority using core-power feature\n");
1528 "Disable Intel Speed Select Technology turbo frequency feature\n");
1530 "Optional: -t|--trl : Specify turbo ratio limit\n");
1532 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1537 isst_ctdp_display_information_start(outf);
1538 if (max_target_cpus)
1539 for_each_online_target_cpu_in_set(set_fact_for_cpu, NULL, NULL,
1542 for_each_online_package_in_set(set_fact_for_cpu, NULL, NULL,
1544 isst_ctdp_display_information_end(outf);
1546 if (enable && auto_mode) {
1548 * When we adjust CLOS param, we have to set for siblings also.
1549 * So for the each user specified CPU, also add the sibling
1550 * in the present_cpu_mask.
1552 for (i = 0; i < get_topo_max_cpus(); ++i) {
1553 char buffer[128], sibling_list[128], *cpu_str;
1556 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
1559 snprintf(buffer, sizeof(buffer),
1560 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i);
1562 fd = open(buffer, O_RDONLY);
1566 len = read(fd, sibling_list, sizeof(sibling_list));
1572 cpu_str = strtok(sibling_list, ",");
1573 while (cpu_str != NULL) {
1576 sscanf(cpu_str, "%d", &cpu);
1577 CPU_SET_S(cpu, target_cpumask_size, target_cpumask);
1578 cpu_str = strtok(NULL, ",");
1582 for (i = 0; i < get_topo_max_cpus(); ++i) {
1585 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
1588 ret = set_clos_param(i, 0, 0, 0, 0, 0xff);
1592 ret = set_clos_param(i, 1, 15, 0, 0, 0xff);
1596 ret = set_clos_param(i, 2, 15, 0, 0, 0xff);
1600 ret = set_clos_param(i, 3, 15, 0, 0, 0xff);
1604 if (CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
1609 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
1610 ret = isst_clos_associate(i, clos);
1614 isst_display_result(i, outf, "turbo-freq --auto", "enable", 0);
1620 isst_display_result(i, outf, "turbo-freq --auto", "enable", ret);
1624 static void enable_clos_qos_config(int cpu, void *arg1, void *arg2, void *arg3,
1628 int status = *(int *)arg4;
1630 ret = isst_pm_qos_config(cpu, status, clos_priority_type);
1632 perror("isst_pm_qos_config");
1635 isst_display_result(cpu, outf, "core-power", "enable",
1638 isst_display_result(cpu, outf, "core-power", "disable",
1642 static void set_clos_enable(int arg)
1649 "Enable core-power for a package/die\n");
1651 "\tClos Enable: Specify priority type with [--priority|-p]\n");
1652 fprintf(stderr, "\t\t 0: Proportional, 1: Ordered\n");
1655 "Disable core-power: [No command arguments are required]\n");
1660 if (enable && cpufreq_sysfs_present()) {
1662 "cpufreq subsystem and core-power enable will interfere with each other!\n");
1665 isst_ctdp_display_information_start(outf);
1666 if (max_target_cpus)
1667 for_each_online_target_cpu_in_set(enable_clos_qos_config, NULL,
1668 NULL, NULL, &enable);
1670 for_each_online_package_in_set(enable_clos_qos_config, NULL,
1671 NULL, NULL, &enable);
1672 isst_ctdp_display_information_end(outf);
1675 static void dump_clos_config_for_cpu(int cpu, void *arg1, void *arg2,
1676 void *arg3, void *arg4)
1678 struct isst_clos_config clos_config;
1681 ret = isst_pm_get_clos(cpu, current_clos, &clos_config);
1683 perror("isst_pm_get_clos");
1685 isst_clos_display_information(cpu, outf, current_clos,
1689 static void dump_clos_config(int arg)
1693 "Print Intel Speed Select Technology core power configuration\n");
1695 "\tArguments: [-c | --clos]: Specify clos id\n");
1698 if (current_clos < 0 || current_clos > 3) {
1699 fprintf(stderr, "Invalid clos id\n");
1703 isst_ctdp_display_information_start(outf);
1704 if (max_target_cpus)
1705 for_each_online_target_cpu_in_set(dump_clos_config_for_cpu,
1706 NULL, NULL, NULL, NULL);
1708 for_each_online_package_in_set(dump_clos_config_for_cpu, NULL,
1710 isst_ctdp_display_information_end(outf);
1713 static void get_clos_info_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1716 int enable, ret, prio_type;
1718 ret = isst_clos_get_clos_information(cpu, &enable, &prio_type);
1720 perror("isst_clos_get_info");
1722 isst_clos_display_clos_information(cpu, outf, enable, prio_type);
1725 static void dump_clos_info(int arg)
1729 "Print Intel Speed Select Technology core power information\n");
1730 fprintf(stderr, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1734 if (!max_target_cpus) {
1736 "Invalid target cpu. Specify with [-c|--cpu]\n");
1740 isst_ctdp_display_information_start(outf);
1741 for_each_online_target_cpu_in_set(get_clos_info_for_cpu, NULL,
1743 isst_ctdp_display_information_end(outf);
1747 static void set_clos_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1750 struct isst_clos_config clos_config;
1753 clos_config.pkg_id = get_physical_package_id(cpu);
1754 clos_config.die_id = get_physical_die_id(cpu);
1756 clos_config.epp = clos_epp;
1757 clos_config.clos_prop_prio = clos_prop_prio;
1758 clos_config.clos_min = clos_min;
1759 clos_config.clos_max = clos_max;
1760 clos_config.clos_desired = clos_desired;
1761 ret = isst_set_clos(cpu, current_clos, &clos_config);
1763 perror("isst_set_clos");
1765 isst_display_result(cpu, outf, "core-power", "config", ret);
1768 static void set_clos_config(int arg)
1772 "Set core-power configuration for one of the four clos ids\n");
1774 "\tSpecify targeted clos id with [--clos|-c]\n");
1775 fprintf(stderr, "\tSpecify clos EPP with [--epp|-e]\n");
1777 "\tSpecify clos Proportional Priority [--weight|-w]\n");
1778 fprintf(stderr, "\tSpecify clos min in MHz with [--min|-n]\n");
1779 fprintf(stderr, "\tSpecify clos max in MHz with [--max|-m]\n");
1780 fprintf(stderr, "\tSpecify clos desired in MHz with [--desired|-d]\n");
1784 if (current_clos < 0 || current_clos > 3) {
1785 fprintf(stderr, "Invalid clos id\n");
1788 if (clos_epp < 0 || clos_epp > 0x0F) {
1789 fprintf(stderr, "clos epp is not specified, default: 0\n");
1792 if (clos_prop_prio < 0 || clos_prop_prio > 0x0F) {
1794 "clos frequency weight is not specified, default: 0\n");
1798 fprintf(stderr, "clos min is not specified, default: 0\n");
1802 fprintf(stderr, "clos max is not specified, default: 25500 MHz\n");
1805 if (clos_desired < 0) {
1806 fprintf(stderr, "clos desired is not specified, default: 0\n");
1807 clos_desired = 0x00;
1810 isst_ctdp_display_information_start(outf);
1811 if (max_target_cpus)
1812 for_each_online_target_cpu_in_set(set_clos_config_for_cpu, NULL,
1815 for_each_online_package_in_set(set_clos_config_for_cpu, NULL,
1817 isst_ctdp_display_information_end(outf);
1820 static void set_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1825 ret = isst_clos_associate(cpu, current_clos);
1827 perror("isst_clos_associate");
1829 isst_display_result(cpu, outf, "core-power", "assoc", ret);
1832 static void set_clos_assoc(int arg)
1835 fprintf(stderr, "Associate a clos id to a CPU\n");
1837 "\tSpecify targeted clos id with [--clos|-c]\n");
1841 if (current_clos < 0 || current_clos > 3) {
1842 fprintf(stderr, "Invalid clos id\n");
1845 if (max_target_cpus)
1846 for_each_online_target_cpu_in_set(set_clos_assoc_for_cpu, NULL,
1850 "Invalid target cpu. Specify with [-c|--cpu]\n");
1854 static void get_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1859 ret = isst_clos_get_assoc_status(cpu, &clos);
1861 perror("isst_clos_get_assoc_status");
1863 isst_clos_display_assoc_information(cpu, outf, clos);
1866 static void get_clos_assoc(int arg)
1869 fprintf(stderr, "Get associate clos id to a CPU\n");
1870 fprintf(stderr, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1874 if (!max_target_cpus) {
1876 "Invalid target cpu. Specify with [-c|--cpu]\n");
1880 isst_ctdp_display_information_start(outf);
1881 for_each_online_target_cpu_in_set(get_clos_assoc_for_cpu, NULL,
1883 isst_ctdp_display_information_end(outf);
1886 static struct process_cmd_struct clx_n_cmds[] = {
1887 { "perf-profile", "info", dump_isst_config, 0 },
1888 { "base-freq", "info", dump_pbf_config, 0 },
1889 { "base-freq", "enable", set_pbf_enable, 1 },
1890 { "base-freq", "disable", set_pbf_enable, 0 },
1891 { NULL, NULL, NULL, 0 }
1894 static struct process_cmd_struct isst_cmds[] = {
1895 { "perf-profile", "get-lock-status", get_tdp_locked, 0 },
1896 { "perf-profile", "get-config-levels", get_tdp_levels, 0 },
1897 { "perf-profile", "get-config-version", get_tdp_version, 0 },
1898 { "perf-profile", "get-config-enabled", get_tdp_enabled, 0 },
1899 { "perf-profile", "get-config-current-level", get_tdp_current_level,
1901 { "perf-profile", "set-config-level", set_tdp_level, 0 },
1902 { "perf-profile", "info", dump_isst_config, 0 },
1903 { "base-freq", "info", dump_pbf_config, 0 },
1904 { "base-freq", "enable", set_pbf_enable, 1 },
1905 { "base-freq", "disable", set_pbf_enable, 0 },
1906 { "turbo-freq", "info", dump_fact_config, 0 },
1907 { "turbo-freq", "enable", set_fact_enable, 1 },
1908 { "turbo-freq", "disable", set_fact_enable, 0 },
1909 { "core-power", "info", dump_clos_info, 0 },
1910 { "core-power", "enable", set_clos_enable, 1 },
1911 { "core-power", "disable", set_clos_enable, 0 },
1912 { "core-power", "config", set_clos_config, 0 },
1913 { "core-power", "get-config", dump_clos_config, 0 },
1914 { "core-power", "assoc", set_clos_assoc, 0 },
1915 { "core-power", "get-assoc", get_clos_assoc, 0 },
1916 { NULL, NULL, NULL }
1920 * parse cpuset with following syntax
1921 * 1,2,4..6,8-10 and set bits in cpu_subset
1923 void parse_cpu_command(char *optarg)
1925 unsigned int start, end;
1930 while (next && *next) {
1931 if (*next == '-') /* no negative cpu numbers */
1934 start = strtoul(next, &next, 10);
1936 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
1937 target_cpus[max_target_cpus++] = start;
1948 next += 1; /* start range */
1949 } else if (*next == '.') {
1952 next += 1; /* start range */
1957 end = strtoul(next, &next, 10);
1961 while (++start <= end) {
1962 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
1963 target_cpus[max_target_cpus++] = start;
1968 else if (*next != '\0')
1976 for (i = 0; i < max_target_cpus; ++i)
1977 printf("cpu [%d] in arg\n", target_cpus[i]);
1983 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg);
1987 static void parse_cmd_args(int argc, int start, char **argv)
1992 static struct option long_options[] = {
1993 { "bucket", required_argument, 0, 'b' },
1994 { "level", required_argument, 0, 'l' },
1995 { "online", required_argument, 0, 'o' },
1996 { "trl-type", required_argument, 0, 'r' },
1997 { "trl", required_argument, 0, 't' },
1998 { "help", no_argument, 0, 'h' },
1999 { "clos", required_argument, 0, 'c' },
2000 { "desired", required_argument, 0, 'd' },
2001 { "epp", required_argument, 0, 'e' },
2002 { "min", required_argument, 0, 'n' },
2003 { "max", required_argument, 0, 'm' },
2004 { "priority", required_argument, 0, 'p' },
2005 { "weight", required_argument, 0, 'w' },
2006 { "auto", no_argument, 0, 'a' },
2010 option_index = start;
2013 while ((opt = getopt_long(argc, argv, "b:l:t:c:d:e:n:m:p:w:hoa",
2014 long_options, &option_index)) != -1) {
2020 fact_bucket = atoi(optarg);
2026 tdp_level = atoi(optarg);
2029 force_online_offline = 1;
2032 sscanf(optarg, "0x%llx", &fact_trl);
2035 if (!strncmp(optarg, "sse", 3)) {
2037 } else if (!strncmp(optarg, "avx2", 4)) {
2039 } else if (!strncmp(optarg, "avx512", 4)) {
2042 fprintf(outf, "Invalid sse,avx options\n");
2048 current_clos = atoi(optarg);
2051 clos_desired = atoi(optarg);
2052 clos_desired /= DISP_FREQ_MULTIPLIER;
2055 clos_epp = atoi(optarg);
2058 clos_min = atoi(optarg);
2059 clos_min /= DISP_FREQ_MULTIPLIER;
2062 clos_max = atoi(optarg);
2063 clos_max /= DISP_FREQ_MULTIPLIER;
2066 clos_priority_type = atoi(optarg);
2069 clos_prop_prio = atoi(optarg);
2072 printf("no match\n");
2077 static void isst_help(void)
2079 printf("perf-profile:\tAn architectural mechanism that allows multiple optimized \n\
2080 performance profiles per system via static and/or dynamic\n\
2081 adjustment of core count, workload, Tjmax, and\n\
2083 printf("\nCommands : For feature=perf-profile\n");
2086 if (!is_clx_n_platform()) {
2087 printf("\tget-lock-status\n");
2088 printf("\tget-config-levels\n");
2089 printf("\tget-config-version\n");
2090 printf("\tget-config-enabled\n");
2091 printf("\tget-config-current-level\n");
2092 printf("\tset-config-level\n");
2096 static void pbf_help(void)
2098 printf("base-freq:\tEnables users to increase guaranteed base frequency\n\
2099 on certain cores (high priority cores) in exchange for lower\n\
2100 base frequency on remaining cores (low priority cores).\n");
2101 printf("\tcommand : info\n");
2102 printf("\tcommand : enable\n");
2103 printf("\tcommand : disable\n");
2106 static void fact_help(void)
2108 printf("turbo-freq:\tEnables the ability to set different turbo ratio\n\
2109 limits to cores based on priority.\n");
2110 printf("\nCommand: For feature=turbo-freq\n");
2111 printf("\tcommand : info\n");
2112 printf("\tcommand : enable\n");
2113 printf("\tcommand : disable\n");
2116 static void core_power_help(void)
2118 printf("core-power:\tInterface that allows user to define per core/tile\n\
2120 printf("\nCommands : For feature=core-power\n");
2122 printf("\tenable\n");
2123 printf("\tdisable\n");
2124 printf("\tconfig\n");
2125 printf("\tget-config\n");
2126 printf("\tassoc\n");
2127 printf("\tget-assoc\n");
2130 struct process_cmd_help_struct {
2132 void (*process_fn)(void);
2135 static struct process_cmd_help_struct isst_help_cmds[] = {
2136 { "perf-profile", isst_help },
2137 { "base-freq", pbf_help },
2138 { "turbo-freq", fact_help },
2139 { "core-power", core_power_help },
2143 static struct process_cmd_help_struct clx_n_help_cmds[] = {
2144 { "perf-profile", isst_help },
2145 { "base-freq", pbf_help },
2149 void process_command(int argc, char **argv,
2150 struct process_cmd_help_struct *help_cmds,
2151 struct process_cmd_struct *cmds)
2153 int i = 0, matched = 0;
2154 char *feature = argv[optind];
2155 char *cmd = argv[optind + 1];
2157 if (!feature || !cmd)
2160 debug_printf("feature name [%s] command [%s]\n", feature, cmd);
2161 if (!strcmp(cmd, "-h") || !strcmp(cmd, "--help")) {
2162 while (help_cmds[i].feature) {
2163 if (!strcmp(help_cmds[i].feature, feature)) {
2164 help_cmds[i].process_fn();
2171 if (!is_clx_n_platform())
2175 while (cmds[i].feature) {
2176 if (!strcmp(cmds[i].feature, feature) &&
2177 !strcmp(cmds[i].command, cmd)) {
2178 parse_cmd_args(argc, optind + 1, argv);
2179 cmds[i].process_fn(cmds[i].arg);
2187 fprintf(stderr, "Invalid command\n");
2190 static void usage(void)
2192 printf("Intel(R) Speed Select Technology\n");
2193 printf("\nUsage:\n");
2194 printf("intel-speed-select [OPTIONS] FEATURE COMMAND COMMAND_ARGUMENTS\n");
2195 printf("\nUse this tool to enumerate and control the Intel Speed Select Technology features,\n");
2196 printf("\nFEATURE : [perf-profile|base-freq|turbo-freq|core-power]\n");
2197 printf("\nFor help on each feature, use -h|--help\n");
2198 printf("\tFor example: intel-speed-select perf-profile -h\n");
2200 printf("\nFor additional help on each command for a feature, use --h|--help\n");
2201 printf("\tFor example: intel-speed-select perf-profile get-lock-status -h\n");
2202 printf("\t\t This will print help for the command \"get-lock-status\" for the feature \"perf-profile\"\n");
2204 printf("\nOPTIONS\n");
2205 printf("\t[-c|--cpu] : logical cpu number\n");
2206 printf("\t\tDefault: Die scoped for all dies in the system with multiple dies/package\n");
2207 printf("\t\t\t Or Package scoped for all Packages when each package contains one die\n");
2208 printf("\t[-d|--debug] : Debug mode\n");
2209 printf("\t[-h|--help] : Print help\n");
2210 printf("\t[-i|--info] : Print platform information\n");
2211 printf("\t[-o|--out] : Output file\n");
2212 printf("\t\t\tDefault : stderr\n");
2213 printf("\t[-f|--format] : output format [json|text]. Default: text\n");
2214 printf("\t[-v|--version] : Print version\n");
2216 printf("\nResult format\n");
2217 printf("\tResult display uses a common format for each command:\n");
2218 printf("\tResults are formatted in text/JSON with\n");
2219 printf("\t\tPackage, Die, CPU, and command specific results.\n");
2223 static void print_version(void)
2225 fprintf(outf, "Version %s\n", version_str);
2226 fprintf(outf, "Build date %s time %s\n", __DATE__, __TIME__);
2230 static void cmdline(int argc, char **argv)
2233 int option_index = 0;
2236 static struct option long_options[] = {
2237 { "cpu", required_argument, 0, 'c' },
2238 { "debug", no_argument, 0, 'd' },
2239 { "format", required_argument, 0, 'f' },
2240 { "help", no_argument, 0, 'h' },
2241 { "info", no_argument, 0, 'i' },
2242 { "out", required_argument, 0, 'o' },
2243 { "version", no_argument, 0, 'v' },
2248 while ((opt = getopt_long_only(argc, argv, "+c:df:hio:v", long_options,
2249 &option_index)) != -1) {
2252 parse_cpu_command(optarg);
2256 printf("Debug Mode ON\n");
2259 if (!strncmp(optarg, "json", 4))
2260 out_format_json = 1;
2266 isst_print_platform_information();
2271 outf = fopen_or_exit(optarg, "w");
2281 if (geteuid() != 0) {
2282 fprintf(stderr, "Must run as root\n");
2286 if (optind > (argc - 2)) {
2287 fprintf(stderr, "Feature name and|or command not specified\n");
2290 ret = update_cpu_model();
2292 err(-1, "Invalid CPU model (%d)\n", cpu_model);
2293 printf("Intel(R) Speed Select Technology\n");
2294 printf("Executing on CPU model:%d[0x%x]\n", cpu_model, cpu_model);
2296 set_cpu_present_cpu_mask();
2297 set_cpu_target_cpu_mask();
2299 if (!is_clx_n_platform()) {
2300 ret = isst_fill_platform_info();
2303 process_command(argc, argv, isst_help_cmds, isst_cmds);
2305 process_command(argc, argv, clx_n_help_cmds, clx_n_cmds);
2308 free_cpu_set(present_cpumask);
2309 free_cpu_set(target_cpumask);
2312 int main(int argc, char **argv)
2315 cmdline(argc, argv);