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)(void);
17 static const char *version_str = "v1.0";
18 static const int supported_api_ver = 1;
19 static struct isst_if_platform_info isst_platform_info;
20 static char *progname;
21 static int debug_flag;
26 #define MAX_CPUS_IN_ONE_REQ 64
27 static short max_target_cpus;
28 static unsigned short target_cpus[MAX_CPUS_IN_ONE_REQ];
30 static int topo_max_cpus;
31 static size_t present_cpumask_size;
32 static cpu_set_t *present_cpumask;
33 static size_t target_cpumask_size;
34 static cpu_set_t *target_cpumask;
35 static int tdp_level = 0xFF;
36 static int fact_bucket = 0xFF;
37 static int fact_avx = 0xFF;
38 static unsigned long long fact_trl;
39 static int out_format_json;
41 static int force_online_offline;
45 static int current_clos = -1;
46 static int clos_epp = -1;
47 static int clos_prop_prio = -1;
48 static int clos_min = -1;
49 static int clos_max = -1;
50 static int clos_desired = -1;
51 static int clos_priority_type;
54 unsigned short core_id;
55 unsigned short pkg_id;
56 unsigned short die_id;
57 unsigned short punit_cpu;
58 unsigned short punit_cpu_core;
60 struct _cpu_map *cpu_map;
62 void debug_printf(const char *format, ...)
66 va_start(args, format);
69 vprintf(format, args);
74 static void update_cpu_model(void)
76 unsigned int ebx, ecx, edx;
77 unsigned int fms, family;
79 __cpuid(1, fms, ebx, ecx, edx);
80 family = (fms >> 8) & 0xf;
81 cpu_model = (fms >> 4) & 0xf;
82 if (family == 6 || family == 0xf)
83 cpu_model += ((fms >> 16) & 0xf) << 4;
86 /* Open a file, and exit on failure */
87 static FILE *fopen_or_exit(const char *path, const char *mode)
89 FILE *filep = fopen(path, mode);
92 err(1, "%s: open failed", path);
97 /* Parse a file containing a single int */
98 static int parse_int_file(int fatal, const char *fmt, ...)
106 vsnprintf(path, sizeof(path), fmt, args);
109 filep = fopen_or_exit(path, "r");
111 filep = fopen(path, "r");
115 if (fscanf(filep, "%d", &value) != 1)
116 err(1, "%s: failed to parse number from file", path);
122 int cpufreq_sysfs_present(void)
126 dir = opendir("/sys/devices/system/cpu/cpu0/cpufreq");
135 int out_format_is_json(void)
137 return out_format_json;
140 int get_physical_package_id(int cpu)
142 return parse_int_file(
143 0, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",
147 int get_physical_core_id(int cpu)
149 return parse_int_file(
150 0, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu);
153 int get_physical_die_id(int cpu)
157 ret = parse_int_file(0, "/sys/devices/system/cpu/cpu%d/topology/die_id",
165 int get_topo_max_cpus(void)
167 return topo_max_cpus;
170 static void set_cpu_online_offline(int cpu, int state)
175 snprintf(buffer, sizeof(buffer),
176 "/sys/devices/system/cpu/cpu%d/online", cpu);
178 fd = open(buffer, O_WRONLY);
180 err(-1, "%s open failed", buffer);
183 ret = write(fd, "1\n", 2);
185 ret = write(fd, "0\n", 2);
188 perror("Online/Offline: Operation failed\n");
193 #define MAX_PACKAGE_COUNT 8
194 #define MAX_DIE_PER_PACKAGE 2
195 static void for_each_online_package_in_set(void (*callback)(int, void *, void *,
197 void *arg1, void *arg2, void *arg3,
200 int max_packages[MAX_PACKAGE_COUNT * MAX_PACKAGE_COUNT];
201 int pkg_index = 0, i;
203 memset(max_packages, 0xff, sizeof(max_packages));
204 for (i = 0; i < topo_max_cpus; ++i) {
205 int j, online, pkg_id, die_id = 0, skip = 0;
207 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
210 online = parse_int_file(
211 1, "/sys/devices/system/cpu/cpu%d/online", i);
214 1; /* online entry for CPU 0 needs some special configs */
216 die_id = get_physical_die_id(i);
219 pkg_id = get_physical_package_id(i);
220 /* Create an unique id for package, die combination to store */
221 pkg_id = (MAX_PACKAGE_COUNT * pkg_id + die_id);
223 for (j = 0; j < pkg_index; ++j) {
224 if (max_packages[j] == pkg_id) {
230 if (!skip && online && callback) {
231 callback(i, arg1, arg2, arg3, arg4);
232 max_packages[pkg_index++] = pkg_id;
237 static void for_each_online_target_cpu_in_set(
238 void (*callback)(int, void *, void *, void *, void *), void *arg1,
239 void *arg2, void *arg3, void *arg4)
243 for (i = 0; i < topo_max_cpus; ++i) {
246 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
249 online = parse_int_file(
250 1, "/sys/devices/system/cpu/cpu%d/online", i);
253 1; /* online entry for CPU 0 needs some special configs */
255 if (online && callback)
256 callback(i, arg1, arg2, arg3, arg4);
260 #define BITMASK_SIZE 32
261 static void set_max_cpu_num(void)
267 filep = fopen_or_exit(
268 "/sys/devices/system/cpu/cpu0/topology/thread_siblings", "r");
269 while (fscanf(filep, "%lx,", &dummy) == 1)
270 topo_max_cpus += BITMASK_SIZE;
272 topo_max_cpus--; /* 0 based */
274 debug_printf("max cpus %d\n", topo_max_cpus);
277 size_t alloc_cpu_set(cpu_set_t **cpu_set)
282 _cpu_set = CPU_ALLOC((topo_max_cpus + 1));
283 if (_cpu_set == NULL)
285 size = CPU_ALLOC_SIZE((topo_max_cpus + 1));
286 CPU_ZERO_S(size, _cpu_set);
292 void free_cpu_set(cpu_set_t *cpu_set)
297 static int cpu_cnt[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
298 static void set_cpu_present_cpu_mask(void)
304 size = alloc_cpu_set(&present_cpumask);
305 present_cpumask_size = size;
306 for (i = 0; i < topo_max_cpus; ++i) {
309 snprintf(buffer, sizeof(buffer),
310 "/sys/devices/system/cpu/cpu%d", i);
311 dir = opendir(buffer);
315 CPU_SET_S(i, size, present_cpumask);
316 die_id = get_physical_die_id(i);
320 pkg_id = get_physical_package_id(i);
321 if (pkg_id < MAX_PACKAGE_COUNT &&
322 die_id < MAX_DIE_PER_PACKAGE)
323 cpu_cnt[pkg_id][die_id]++;
329 int get_cpu_count(int pkg_id, int die_id)
331 if (pkg_id < MAX_PACKAGE_COUNT && die_id < MAX_DIE_PER_PACKAGE)
332 return cpu_cnt[pkg_id][die_id];
337 static void set_cpu_target_cpu_mask(void)
342 size = alloc_cpu_set(&target_cpumask);
343 target_cpumask_size = size;
344 for (i = 0; i < max_target_cpus; ++i) {
345 if (!CPU_ISSET_S(target_cpus[i], present_cpumask_size,
349 CPU_SET_S(target_cpus[i], size, target_cpumask);
353 static void create_cpu_map(void)
355 const char *pathname = "/dev/isst_interface";
357 struct isst_if_cpu_maps map;
359 cpu_map = malloc(sizeof(*cpu_map) * topo_max_cpus);
363 fd = open(pathname, O_RDWR);
365 err(-1, "%s open failed", pathname);
367 for (i = 0; i < topo_max_cpus; ++i) {
368 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
372 map.cpu_map[0].logical_cpu = i;
374 debug_printf(" map logical_cpu:%d\n",
375 map.cpu_map[0].logical_cpu);
376 if (ioctl(fd, ISST_IF_GET_PHY_ID, &map) == -1) {
377 perror("ISST_IF_GET_PHY_ID");
378 fprintf(outf, "Error: map logical_cpu:%d\n",
379 map.cpu_map[0].logical_cpu);
382 cpu_map[i].core_id = get_physical_core_id(i);
383 cpu_map[i].pkg_id = get_physical_package_id(i);
384 cpu_map[i].die_id = get_physical_die_id(i);
385 cpu_map[i].punit_cpu = map.cpu_map[0].physical_cpu;
386 cpu_map[i].punit_cpu_core = (map.cpu_map[0].physical_cpu >>
387 1); // shift to get core id
390 "map logical_cpu:%d core: %d die:%d pkg:%d punit_cpu:%d punit_core:%d\n",
391 i, cpu_map[i].core_id, cpu_map[i].die_id,
392 cpu_map[i].pkg_id, cpu_map[i].punit_cpu,
393 cpu_map[i].punit_cpu_core);
400 int find_logical_cpu(int pkg_id, int die_id, int punit_core_id)
404 for (i = 0; i < topo_max_cpus; ++i) {
405 if (cpu_map[i].pkg_id == pkg_id &&
406 cpu_map[i].die_id == die_id &&
407 cpu_map[i].punit_cpu_core == punit_core_id)
414 void set_cpu_mask_from_punit_coremask(int cpu, unsigned long long core_mask,
415 size_t core_cpumask_size,
416 cpu_set_t *core_cpumask, int *cpu_cnt)
422 die_id = get_physical_die_id(cpu);
423 pkg_id = get_physical_package_id(cpu);
425 for (i = 0; i < 64; ++i) {
426 if (core_mask & BIT(i)) {
429 for (j = 0; j < topo_max_cpus; ++j) {
430 if (!CPU_ISSET_S(j, present_cpumask_size, present_cpumask))
433 if (cpu_map[j].pkg_id == pkg_id &&
434 cpu_map[j].die_id == die_id &&
435 cpu_map[j].punit_cpu_core == i) {
436 CPU_SET_S(j, core_cpumask_size,
447 int find_phy_core_num(int logical_cpu)
449 if (logical_cpu < topo_max_cpus)
450 return cpu_map[logical_cpu].punit_cpu_core;
455 static int isst_send_mmio_command(unsigned int cpu, unsigned int reg, int write,
458 struct isst_if_io_regs io_regs;
459 const char *pathname = "/dev/isst_interface";
463 debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu, reg, write);
465 fd = open(pathname, O_RDWR);
467 err(-1, "%s open failed", pathname);
469 io_regs.req_count = 1;
470 io_regs.io_reg[0].logical_cpu = cpu;
471 io_regs.io_reg[0].reg = reg;
472 cmd = ISST_IF_IO_CMD;
474 io_regs.io_reg[0].read_write = 1;
475 io_regs.io_reg[0].value = *value;
477 io_regs.io_reg[0].read_write = 0;
480 if (ioctl(fd, cmd, &io_regs) == -1) {
481 perror("ISST_IF_IO_CMD");
482 fprintf(outf, "Error: mmio_cmd cpu:%d reg:%x read_write:%x\n",
486 *value = io_regs.io_reg[0].value;
489 "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
490 cpu, reg, write, *value);
498 int isst_send_mbox_command(unsigned int cpu, unsigned char command,
499 unsigned char sub_command, unsigned int parameter,
500 unsigned int req_data, unsigned int *resp)
502 const char *pathname = "/dev/isst_interface";
504 struct isst_if_mbox_cmds mbox_cmds = { 0 };
507 "mbox_send: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
508 cpu, command, sub_command, parameter, req_data);
510 if (isst_platform_info.mmio_supported && command == CONFIG_CLOS) {
513 int clos_id, core_id, ret = 0;
515 debug_printf("CPU %d\n", cpu);
517 if (parameter & BIT(MBOX_CMD_WRITE_BIT)) {
522 switch (sub_command) {
524 core_id = parameter & 0xff;
525 ret = isst_send_mmio_command(
526 cpu, PQR_ASSOC_OFFSET + core_id * 4, write,
532 clos_id = parameter & 0x03;
533 ret = isst_send_mmio_command(
534 cpu, PM_CLOS_OFFSET + clos_id * 4, write,
539 case CLOS_PM_QOS_CONFIG:
540 ret = isst_send_mmio_command(cpu, PM_QOS_CONFIG_OFFSET,
553 mbox_cmds.cmd_count = 1;
554 mbox_cmds.mbox_cmd[0].logical_cpu = cpu;
555 mbox_cmds.mbox_cmd[0].command = command;
556 mbox_cmds.mbox_cmd[0].sub_command = sub_command;
557 mbox_cmds.mbox_cmd[0].parameter = parameter;
558 mbox_cmds.mbox_cmd[0].req_data = req_data;
560 fd = open(pathname, O_RDWR);
562 err(-1, "%s open failed", pathname);
564 if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
565 perror("ISST_IF_MBOX_COMMAND");
567 "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
568 cpu, command, sub_command, parameter, req_data);
570 *resp = mbox_cmds.mbox_cmd[0].resp_data;
572 "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
573 cpu, command, sub_command, parameter, req_data, *resp);
581 int isst_send_msr_command(unsigned int cpu, unsigned int msr, int write,
582 unsigned long long *req_resp)
584 struct isst_if_msr_cmds msr_cmds;
585 const char *pathname = "/dev/isst_interface";
588 fd = open(pathname, O_RDWR);
590 err(-1, "%s open failed", pathname);
592 msr_cmds.cmd_count = 1;
593 msr_cmds.msr_cmd[0].logical_cpu = cpu;
594 msr_cmds.msr_cmd[0].msr = msr;
595 msr_cmds.msr_cmd[0].read_write = write;
597 msr_cmds.msr_cmd[0].data = *req_resp;
599 if (ioctl(fd, ISST_IF_MSR_COMMAND, &msr_cmds) == -1) {
600 perror("ISST_IF_MSR_COMMAD");
601 fprintf(outf, "Error: msr_cmd cpu:%d msr:%x read_write:%d\n",
605 *req_resp = msr_cmds.msr_cmd[0].data;
608 "msr_cmd response: cpu:%d msr:%x rd_write:%x resp:%llx %llx\n",
609 cpu, msr, write, *req_resp, msr_cmds.msr_cmd[0].data);
617 static int isst_fill_platform_info(void)
619 const char *pathname = "/dev/isst_interface";
622 fd = open(pathname, O_RDWR);
624 err(-1, "%s open failed", pathname);
626 if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &isst_platform_info) == -1) {
627 perror("ISST_IF_GET_PLATFORM_INFO");
634 if (isst_platform_info.api_version > supported_api_ver) {
635 printf("Incompatible API versions; Upgrade of tool is required\n");
641 static void isst_print_platform_information(void)
643 struct isst_if_platform_info platform_info;
644 const char *pathname = "/dev/isst_interface";
647 fd = open(pathname, O_RDWR);
649 err(-1, "%s open failed", pathname);
651 if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &platform_info) == -1) {
652 perror("ISST_IF_GET_PLATFORM_INFO");
654 fprintf(outf, "Platform: API version : %d\n",
655 platform_info.api_version);
656 fprintf(outf, "Platform: Driver version : %d\n",
657 platform_info.driver_version);
658 fprintf(outf, "Platform: mbox supported : %d\n",
659 platform_info.mbox_supported);
660 fprintf(outf, "Platform: mmio supported : %d\n",
661 platform_info.mmio_supported);
669 static void exec_on_get_ctdp_cpu(int cpu, void *arg1, void *arg2, void *arg3,
672 int (*fn_ptr)(int cpu, void *arg);
676 ret = fn_ptr(cpu, arg2);
680 isst_ctdp_display_core_info(cpu, outf, arg3,
681 *(unsigned int *)arg4);
684 #define _get_tdp_level(desc, suffix, object, help) \
685 static void get_tdp_##object(void) \
687 struct isst_pkg_ctdp ctdp; \
691 "Print %s [No command arguments are required]\n", \
695 isst_ctdp_display_information_start(outf); \
696 if (max_target_cpus) \
697 for_each_online_target_cpu_in_set( \
698 exec_on_get_ctdp_cpu, isst_get_ctdp_##suffix, \
699 &ctdp, desc, &ctdp.object); \
701 for_each_online_package_in_set(exec_on_get_ctdp_cpu, \
702 isst_get_ctdp_##suffix, \
705 isst_ctdp_display_information_end(outf); \
708 _get_tdp_level("get-config-levels", levels, levels, "TDP levels");
709 _get_tdp_level("get-config-version", levels, version, "TDP version");
710 _get_tdp_level("get-config-enabled", levels, enabled, "TDP enable status");
711 _get_tdp_level("get-config-current_level", levels, current_level,
712 "Current TDP Level");
713 _get_tdp_level("get-lock-status", levels, locked, "TDP lock status");
715 static void dump_isst_config_for_cpu(int cpu, void *arg1, void *arg2,
716 void *arg3, void *arg4)
718 struct isst_pkg_ctdp pkg_dev;
721 memset(&pkg_dev, 0, sizeof(pkg_dev));
722 ret = isst_get_process_ctdp(cpu, tdp_level, &pkg_dev);
724 perror("isst_get_process_ctdp");
726 isst_ctdp_display_information(cpu, outf, tdp_level, &pkg_dev);
727 isst_get_process_ctdp_complete(cpu, &pkg_dev);
731 static void dump_isst_config(void)
735 "Print Intel(R) Speed Select Technology Performance profile configuration\n");
737 "including base frequency and turbo frequency configurations\n");
738 fprintf(stderr, "Optional: -l|--level : Specify tdp level\n");
740 "\tIf no arguments, dump information for all TDP levels\n");
744 isst_ctdp_display_information_start(outf);
747 for_each_online_target_cpu_in_set(dump_isst_config_for_cpu,
748 NULL, NULL, NULL, NULL);
750 for_each_online_package_in_set(dump_isst_config_for_cpu, NULL,
753 isst_ctdp_display_information_end(outf);
756 static void set_tdp_level_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
761 ret = isst_set_tdp_level(cpu, tdp_level);
763 perror("set_tdp_level_for_cpu");
765 isst_display_result(cpu, outf, "perf-profile", "set_tdp_level",
767 if (force_online_offline) {
768 struct isst_pkg_ctdp_level_info ctdp_level;
769 int pkg_id = get_physical_package_id(cpu);
770 int die_id = get_physical_die_id(cpu);
772 fprintf(stderr, "Option is set to online/offline\n");
773 ctdp_level.core_cpumask_size =
774 alloc_cpu_set(&ctdp_level.core_cpumask);
775 isst_get_coremask_info(cpu, tdp_level, &ctdp_level);
776 if (ctdp_level.cpu_count) {
777 int i, max_cpus = get_topo_max_cpus();
778 for (i = 0; i < max_cpus; ++i) {
779 if (pkg_id != get_physical_package_id(i) || die_id != get_physical_die_id(i))
781 if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
782 fprintf(stderr, "online cpu %d\n", i);
783 set_cpu_online_offline(i, 1);
785 fprintf(stderr, "offline cpu %d\n", i);
786 set_cpu_online_offline(i, 0);
794 static void set_tdp_level(void)
797 fprintf(stderr, "Set Config TDP level\n");
799 "\t Arguments: -l|--level : Specify tdp level\n");
801 "\t Optional Arguments: -o | online : online/offline for the tdp level\n");
805 if (tdp_level == 0xff) {
806 fprintf(outf, "Invalid command: specify tdp_level\n");
809 isst_ctdp_display_information_start(outf);
811 for_each_online_target_cpu_in_set(set_tdp_level_for_cpu, NULL,
814 for_each_online_package_in_set(set_tdp_level_for_cpu, NULL,
816 isst_ctdp_display_information_end(outf);
819 static void dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
822 struct isst_pbf_info pbf_info;
825 ret = isst_get_pbf_info(cpu, tdp_level, &pbf_info);
827 perror("isst_get_pbf_info");
829 isst_pbf_display_information(cpu, outf, tdp_level, &pbf_info);
830 isst_get_pbf_info_complete(&pbf_info);
834 static void dump_pbf_config(void)
838 "Print Intel(R) Speed Select Technology base frequency configuration for a TDP level\n");
840 "\tArguments: -l|--level : Specify tdp level\n");
844 if (tdp_level == 0xff) {
845 fprintf(outf, "Invalid command: specify tdp_level\n");
849 isst_ctdp_display_information_start(outf);
851 for_each_online_target_cpu_in_set(dump_pbf_config_for_cpu, NULL,
854 for_each_online_package_in_set(dump_pbf_config_for_cpu, NULL,
856 isst_ctdp_display_information_end(outf);
859 static int set_clos_param(int cpu, int clos, int epp, int wt, int min, int max)
861 struct isst_clos_config clos_config;
864 ret = isst_pm_get_clos(cpu, clos, &clos_config);
866 perror("isst_pm_get_clos");
869 clos_config.clos_min = min;
870 clos_config.clos_max = max;
871 clos_config.epp = epp;
872 clos_config.clos_prop_prio = wt;
873 ret = isst_set_clos(cpu, clos, &clos_config);
875 perror("isst_pm_set_clos");
882 static int set_cpufreq_cpuinfo_scaling_min(int cpu, int max)
884 char buffer[128], min_freq[16];
887 if (!CPU_ISSET_S(cpu, present_cpumask_size, present_cpumask))
891 snprintf(buffer, sizeof(buffer),
892 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu);
894 snprintf(buffer, sizeof(buffer),
895 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", cpu);
897 fd = open(buffer, O_RDONLY);
901 len = read(fd, min_freq, sizeof(min_freq));
907 snprintf(buffer, sizeof(buffer),
908 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
910 fd = open(buffer, O_WRONLY);
914 len = strlen(min_freq);
915 ret = write(fd, min_freq, len);
925 static void set_scaling_min_to_cpuinfo_max(int cpu)
927 int i, pkg_id, die_id;
929 pkg_id = get_physical_package_id(cpu);
930 die_id = get_physical_die_id(cpu);
931 for (i = 0; i < get_topo_max_cpus(); ++i) {
932 if (pkg_id != get_physical_package_id(i) ||
933 die_id != get_physical_die_id(i))
936 set_cpufreq_cpuinfo_scaling_min(i, 1);
940 static void set_scaling_min_to_cpuinfo_min(int cpu)
942 int i, pkg_id, die_id;
944 pkg_id = get_physical_package_id(cpu);
945 die_id = get_physical_die_id(cpu);
946 for (i = 0; i < get_topo_max_cpus(); ++i) {
947 if (pkg_id != get_physical_package_id(i) ||
948 die_id != get_physical_die_id(i))
951 set_cpufreq_cpuinfo_scaling_min(i, 0);
955 static int set_core_priority_and_min(int cpu, int mask_size,
956 cpu_set_t *cpu_mask, int min_high,
959 int pkg_id, die_id, ret, i;
961 if (!CPU_COUNT_S(mask_size, cpu_mask))
964 ret = set_clos_param(cpu, 0, 0, 0, min_high, 0xff);
968 ret = set_clos_param(cpu, 1, 15, 0, min_low, 0xff);
972 ret = set_clos_param(cpu, 2, 15, 0, min_low, 0xff);
976 ret = set_clos_param(cpu, 3, 15, 0, min_low, 0xff);
980 pkg_id = get_physical_package_id(cpu);
981 die_id = get_physical_die_id(cpu);
982 for (i = 0; i < get_topo_max_cpus(); ++i) {
985 if (pkg_id != get_physical_package_id(i) ||
986 die_id != get_physical_die_id(i))
989 if (CPU_ISSET_S(i, mask_size, cpu_mask))
994 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
995 ret = isst_clos_associate(i, clos);
997 perror("isst_clos_associate");
1005 static int set_pbf_core_power(int cpu)
1007 struct isst_pbf_info pbf_info;
1008 struct isst_pkg_ctdp pkg_dev;
1011 ret = isst_get_ctdp_levels(cpu, &pkg_dev);
1013 perror("isst_get_ctdp_levels");
1016 debug_printf("Current_level: %d\n", pkg_dev.current_level);
1018 ret = isst_get_pbf_info(cpu, pkg_dev.current_level, &pbf_info);
1020 perror("isst_get_pbf_info");
1023 debug_printf("p1_high: %d p1_low: %d\n", pbf_info.p1_high,
1026 ret = set_core_priority_and_min(cpu, pbf_info.core_cpumask_size,
1027 pbf_info.core_cpumask,
1028 pbf_info.p1_high, pbf_info.p1_low);
1030 perror("set_core_priority_and_min");
1034 ret = isst_pm_qos_config(cpu, 1, 1);
1036 perror("isst_pm_qos_config");
1043 static void set_pbf_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1047 int status = *(int *)arg4;
1051 ret = set_pbf_core_power(cpu);
1055 isst_pm_qos_config(cpu, 0, 0);
1059 ret = isst_set_pbf_fact_status(cpu, 1, status);
1061 perror("isst_set_pbf");
1063 isst_pm_qos_config(cpu, 0, 0);
1067 set_scaling_min_to_cpuinfo_max(cpu);
1069 set_scaling_min_to_cpuinfo_min(cpu);
1075 isst_display_result(cpu, outf, "base-freq", "enable",
1078 isst_display_result(cpu, outf, "base-freq", "disable",
1082 static void set_pbf_enable(void)
1088 "Enable Intel Speed Select Technology base frequency feature\n");
1090 "\tOptional Arguments: -a|--auto : Use priority of cores to set core-power associations\n");
1095 isst_ctdp_display_information_start(outf);
1096 if (max_target_cpus)
1097 for_each_online_target_cpu_in_set(set_pbf_for_cpu, NULL, NULL,
1100 for_each_online_package_in_set(set_pbf_for_cpu, NULL, NULL,
1102 isst_ctdp_display_information_end(outf);
1105 static void set_pbf_disable(void)
1111 "Disable Intel Speed Select Technology base frequency feature\n");
1113 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1117 isst_ctdp_display_information_start(outf);
1118 if (max_target_cpus)
1119 for_each_online_target_cpu_in_set(set_pbf_for_cpu, NULL, NULL,
1122 for_each_online_package_in_set(set_pbf_for_cpu, NULL, NULL,
1124 isst_ctdp_display_information_end(outf);
1127 static void dump_fact_config_for_cpu(int cpu, void *arg1, void *arg2,
1128 void *arg3, void *arg4)
1130 struct isst_fact_info fact_info;
1133 ret = isst_get_fact_info(cpu, tdp_level, &fact_info);
1135 perror("isst_get_fact_bucket_info");
1137 isst_fact_display_information(cpu, outf, tdp_level, fact_bucket,
1138 fact_avx, &fact_info);
1141 static void dump_fact_config(void)
1145 "Print complete Intel Speed Select Technology turbo frequency configuration for a TDP level. Other arguments are optional.\n");
1147 "\tArguments: -l|--level : Specify tdp level\n");
1149 "\tArguments: -b|--bucket : Bucket index to dump\n");
1151 "\tArguments: -r|--trl-type : Specify trl type: sse|avx2|avx512\n");
1155 if (tdp_level == 0xff) {
1156 fprintf(outf, "Invalid command: specify tdp_level\n");
1160 isst_ctdp_display_information_start(outf);
1161 if (max_target_cpus)
1162 for_each_online_target_cpu_in_set(dump_fact_config_for_cpu,
1163 NULL, NULL, NULL, NULL);
1165 for_each_online_package_in_set(dump_fact_config_for_cpu, NULL,
1167 isst_ctdp_display_information_end(outf);
1170 static void set_fact_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1174 int status = *(int *)arg4;
1178 ret = isst_pm_qos_config(cpu, 1, 1);
1182 isst_pm_qos_config(cpu, 0, 0);
1186 ret = isst_set_pbf_fact_status(cpu, 0, status);
1188 perror("isst_set_fact");
1190 isst_pm_qos_config(cpu, 0, 0);
1197 struct isst_pkg_ctdp pkg_dev;
1199 ret = isst_get_ctdp_levels(cpu, &pkg_dev);
1201 ret = isst_set_trl(cpu, fact_trl);
1202 if (ret && auto_mode)
1203 isst_pm_qos_config(cpu, 0, 0);
1208 isst_display_result(cpu, outf, "turbo-freq", "enable", ret);
1210 /* Since we modified TRL during Fact enable, restore it */
1211 isst_set_trl_from_current_tdp(cpu, fact_trl);
1212 isst_display_result(cpu, outf, "turbo-freq", "disable", ret);
1216 static void set_fact_enable(void)
1218 int status = 1, i, ret;
1222 "Enable Intel Speed Select Technology Turbo frequency feature\n");
1224 "Optional: -t|--trl : Specify turbo ratio limit\n");
1226 "\tOptional Arguments: -a|--auto : Designate specified target CPUs with");
1227 fprintf(stderr, "-C|--cpu option as as high priority using core-power feature\n");
1231 isst_ctdp_display_information_start(outf);
1232 if (max_target_cpus)
1233 for_each_online_target_cpu_in_set(set_fact_for_cpu, NULL, NULL,
1236 for_each_online_package_in_set(set_fact_for_cpu, NULL, NULL,
1238 isst_ctdp_display_information_end(outf);
1242 * When we adjust CLOS param, we have to set for siblings also.
1243 * So for the each user specified CPU, also add the sibling
1244 * in the present_cpu_mask.
1246 for (i = 0; i < get_topo_max_cpus(); ++i) {
1247 char buffer[128], sibling_list[128], *cpu_str;
1250 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
1253 snprintf(buffer, sizeof(buffer),
1254 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i);
1256 fd = open(buffer, O_RDONLY);
1260 len = read(fd, sibling_list, sizeof(sibling_list));
1266 cpu_str = strtok(sibling_list, ",");
1267 while (cpu_str != NULL) {
1270 sscanf(cpu_str, "%d", &cpu);
1271 CPU_SET_S(cpu, target_cpumask_size, target_cpumask);
1272 cpu_str = strtok(NULL, ",");
1276 for (i = 0; i < get_topo_max_cpus(); ++i) {
1279 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
1282 ret = set_clos_param(i, 0, 0, 0, 0, 0xff);
1286 ret = set_clos_param(i, 1, 15, 0, 0, 0xff);
1290 ret = set_clos_param(i, 2, 15, 0, 0, 0xff);
1294 ret = set_clos_param(i, 3, 15, 0, 0, 0xff);
1298 if (CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
1303 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
1304 ret = isst_clos_associate(i, clos);
1308 isst_display_result(i, outf, "turbo-freq --auto", "enable", 0);
1314 isst_display_result(i, outf, "turbo-freq --auto", "enable", ret);
1318 static void set_fact_disable(void)
1324 "Disable Intel Speed Select Technology turbo frequency feature\n");
1326 "Optional: -t|--trl : Specify turbo ratio limit\n");
1328 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1332 isst_ctdp_display_information_start(outf);
1333 if (max_target_cpus)
1334 for_each_online_target_cpu_in_set(set_fact_for_cpu, NULL, NULL,
1337 for_each_online_package_in_set(set_fact_for_cpu, NULL, NULL,
1339 isst_ctdp_display_information_end(outf);
1342 static void enable_clos_qos_config(int cpu, void *arg1, void *arg2, void *arg3,
1346 int status = *(int *)arg4;
1348 ret = isst_pm_qos_config(cpu, status, clos_priority_type);
1350 perror("isst_pm_qos_config");
1353 isst_display_result(cpu, outf, "core-power", "enable",
1356 isst_display_result(cpu, outf, "core-power", "disable",
1360 static void set_clos_enable(void)
1365 fprintf(stderr, "Enable core-power for a package/die\n");
1367 "\tClos Enable: Specify priority type with [--priority|-p]\n");
1368 fprintf(stderr, "\t\t 0: Proportional, 1: Ordered\n");
1372 if (cpufreq_sysfs_present()) {
1374 "cpufreq subsystem and core-power enable will interfere with each other!\n");
1377 isst_ctdp_display_information_start(outf);
1378 if (max_target_cpus)
1379 for_each_online_target_cpu_in_set(enable_clos_qos_config, NULL,
1380 NULL, NULL, &status);
1382 for_each_online_package_in_set(enable_clos_qos_config, NULL,
1383 NULL, NULL, &status);
1384 isst_ctdp_display_information_end(outf);
1387 static void set_clos_disable(void)
1393 "Disable core-power: [No command arguments are required]\n");
1397 isst_ctdp_display_information_start(outf);
1398 if (max_target_cpus)
1399 for_each_online_target_cpu_in_set(enable_clos_qos_config, NULL,
1400 NULL, NULL, &status);
1402 for_each_online_package_in_set(enable_clos_qos_config, NULL,
1403 NULL, NULL, &status);
1404 isst_ctdp_display_information_end(outf);
1407 static void dump_clos_config_for_cpu(int cpu, void *arg1, void *arg2,
1408 void *arg3, void *arg4)
1410 struct isst_clos_config clos_config;
1413 ret = isst_pm_get_clos(cpu, current_clos, &clos_config);
1415 perror("isst_pm_get_clos");
1417 isst_clos_display_information(cpu, outf, current_clos,
1421 static void dump_clos_config(void)
1425 "Print Intel Speed Select Technology core power configuration\n");
1427 "\tArguments: [-c | --clos]: Specify clos id\n");
1430 if (current_clos < 0 || current_clos > 3) {
1431 fprintf(stderr, "Invalid clos id\n");
1435 isst_ctdp_display_information_start(outf);
1436 if (max_target_cpus)
1437 for_each_online_target_cpu_in_set(dump_clos_config_for_cpu,
1438 NULL, NULL, NULL, NULL);
1440 for_each_online_package_in_set(dump_clos_config_for_cpu, NULL,
1442 isst_ctdp_display_information_end(outf);
1445 static void get_clos_info_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1448 int enable, ret, prio_type;
1450 ret = isst_clos_get_clos_information(cpu, &enable, &prio_type);
1452 perror("isst_clos_get_info");
1454 isst_clos_display_clos_information(cpu, outf, enable, prio_type);
1457 static void dump_clos_info(void)
1461 "Print Intel Speed Select Technology core power information\n");
1462 fprintf(stderr, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1466 if (!max_target_cpus) {
1468 "Invalid target cpu. Specify with [-c|--cpu]\n");
1472 isst_ctdp_display_information_start(outf);
1473 for_each_online_target_cpu_in_set(get_clos_info_for_cpu, NULL,
1475 isst_ctdp_display_information_end(outf);
1479 static void set_clos_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1482 struct isst_clos_config clos_config;
1485 clos_config.pkg_id = get_physical_package_id(cpu);
1486 clos_config.die_id = get_physical_die_id(cpu);
1488 clos_config.epp = clos_epp;
1489 clos_config.clos_prop_prio = clos_prop_prio;
1490 clos_config.clos_min = clos_min;
1491 clos_config.clos_max = clos_max;
1492 clos_config.clos_desired = clos_desired;
1493 ret = isst_set_clos(cpu, current_clos, &clos_config);
1495 perror("isst_set_clos");
1497 isst_display_result(cpu, outf, "core-power", "config", ret);
1500 static void set_clos_config(void)
1504 "Set core-power configuration for one of the four clos ids\n");
1506 "\tSpecify targeted clos id with [--clos|-c]\n");
1507 fprintf(stderr, "\tSpecify clos EPP with [--epp|-e]\n");
1509 "\tSpecify clos Proportional Priority [--weight|-w]\n");
1510 fprintf(stderr, "\tSpecify clos min with [--min|-n]\n");
1511 fprintf(stderr, "\tSpecify clos max with [--max|-m]\n");
1512 fprintf(stderr, "\tSpecify clos desired with [--desired|-d]\n");
1516 if (current_clos < 0 || current_clos > 3) {
1517 fprintf(stderr, "Invalid clos id\n");
1520 if (clos_epp < 0 || clos_epp > 0x0F) {
1521 fprintf(stderr, "clos epp is not specified, default: 0\n");
1524 if (clos_prop_prio < 0 || clos_prop_prio > 0x0F) {
1526 "clos frequency weight is not specified, default: 0\n");
1530 fprintf(stderr, "clos min is not specified, default: 0\n");
1534 fprintf(stderr, "clos max is not specified, default: 0xff\n");
1537 if (clos_desired < 0) {
1538 fprintf(stderr, "clos desired is not specified, default: 0\n");
1539 clos_desired = 0x00;
1542 isst_ctdp_display_information_start(outf);
1543 if (max_target_cpus)
1544 for_each_online_target_cpu_in_set(set_clos_config_for_cpu, NULL,
1547 for_each_online_package_in_set(set_clos_config_for_cpu, NULL,
1549 isst_ctdp_display_information_end(outf);
1552 static void set_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1557 ret = isst_clos_associate(cpu, current_clos);
1559 perror("isst_clos_associate");
1561 isst_display_result(cpu, outf, "core-power", "assoc", ret);
1564 static void set_clos_assoc(void)
1567 fprintf(stderr, "Associate a clos id to a CPU\n");
1569 "\tSpecify targeted clos id with [--clos|-c]\n");
1573 if (current_clos < 0 || current_clos > 3) {
1574 fprintf(stderr, "Invalid clos id\n");
1577 if (max_target_cpus)
1578 for_each_online_target_cpu_in_set(set_clos_assoc_for_cpu, NULL,
1582 "Invalid target cpu. Specify with [-c|--cpu]\n");
1586 static void get_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1591 ret = isst_clos_get_assoc_status(cpu, &clos);
1593 perror("isst_clos_get_assoc_status");
1595 isst_clos_display_assoc_information(cpu, outf, clos);
1598 static void get_clos_assoc(void)
1601 fprintf(stderr, "Get associate clos id to a CPU\n");
1602 fprintf(stderr, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1606 if (!max_target_cpus) {
1608 "Invalid target cpu. Specify with [-c|--cpu]\n");
1612 isst_ctdp_display_information_start(outf);
1613 for_each_online_target_cpu_in_set(get_clos_assoc_for_cpu, NULL,
1615 isst_ctdp_display_information_end(outf);
1618 static struct process_cmd_struct isst_cmds[] = {
1619 { "perf-profile", "get-lock-status", get_tdp_locked },
1620 { "perf-profile", "get-config-levels", get_tdp_levels },
1621 { "perf-profile", "get-config-version", get_tdp_version },
1622 { "perf-profile", "get-config-enabled", get_tdp_enabled },
1623 { "perf-profile", "get-config-current-level", get_tdp_current_level },
1624 { "perf-profile", "set-config-level", set_tdp_level },
1625 { "perf-profile", "info", dump_isst_config },
1626 { "base-freq", "info", dump_pbf_config },
1627 { "base-freq", "enable", set_pbf_enable },
1628 { "base-freq", "disable", set_pbf_disable },
1629 { "turbo-freq", "info", dump_fact_config },
1630 { "turbo-freq", "enable", set_fact_enable },
1631 { "turbo-freq", "disable", set_fact_disable },
1632 { "core-power", "info", dump_clos_info },
1633 { "core-power", "enable", set_clos_enable },
1634 { "core-power", "disable", set_clos_disable },
1635 { "core-power", "config", set_clos_config },
1636 { "core-power", "get-config", dump_clos_config },
1637 { "core-power", "assoc", set_clos_assoc },
1638 { "core-power", "get-assoc", get_clos_assoc },
1639 { NULL, NULL, NULL }
1643 * parse cpuset with following syntax
1644 * 1,2,4..6,8-10 and set bits in cpu_subset
1646 void parse_cpu_command(char *optarg)
1648 unsigned int start, end;
1653 while (next && *next) {
1654 if (*next == '-') /* no negative cpu numbers */
1657 start = strtoul(next, &next, 10);
1659 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
1660 target_cpus[max_target_cpus++] = start;
1671 next += 1; /* start range */
1672 } else if (*next == '.') {
1675 next += 1; /* start range */
1680 end = strtoul(next, &next, 10);
1684 while (++start <= end) {
1685 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
1686 target_cpus[max_target_cpus++] = start;
1691 else if (*next != '\0')
1699 for (i = 0; i < max_target_cpus; ++i)
1700 printf("cpu [%d] in arg\n", target_cpus[i]);
1706 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg);
1710 static void parse_cmd_args(int argc, int start, char **argv)
1715 static struct option long_options[] = {
1716 { "bucket", required_argument, 0, 'b' },
1717 { "level", required_argument, 0, 'l' },
1718 { "online", required_argument, 0, 'o' },
1719 { "trl-type", required_argument, 0, 'r' },
1720 { "trl", required_argument, 0, 't' },
1721 { "help", no_argument, 0, 'h' },
1722 { "clos", required_argument, 0, 'c' },
1723 { "desired", required_argument, 0, 'd' },
1724 { "epp", required_argument, 0, 'e' },
1725 { "min", required_argument, 0, 'n' },
1726 { "max", required_argument, 0, 'm' },
1727 { "priority", required_argument, 0, 'p' },
1728 { "weight", required_argument, 0, 'w' },
1729 { "auto", no_argument, 0, 'a' },
1733 option_index = start;
1736 while ((opt = getopt_long(argc, argv, "b:l:t:c:d:e:n:m:p:w:hoa",
1737 long_options, &option_index)) != -1) {
1743 fact_bucket = atoi(optarg);
1749 tdp_level = atoi(optarg);
1752 force_online_offline = 1;
1755 sscanf(optarg, "0x%llx", &fact_trl);
1758 if (!strncmp(optarg, "sse", 3)) {
1760 } else if (!strncmp(optarg, "avx2", 4)) {
1762 } else if (!strncmp(optarg, "avx512", 4)) {
1765 fprintf(outf, "Invalid sse,avx options\n");
1771 current_clos = atoi(optarg);
1774 clos_desired = atoi(optarg);
1777 clos_epp = atoi(optarg);
1780 clos_min = atoi(optarg);
1783 clos_max = atoi(optarg);
1786 clos_priority_type = atoi(optarg);
1789 clos_prop_prio = atoi(optarg);
1792 printf("no match\n");
1797 static void isst_help(void)
1799 printf("perf-profile:\tAn architectural mechanism that allows multiple optimized \n\
1800 performance profiles per system via static and/or dynamic\n\
1801 adjustment of core count, workload, Tjmax, and\n\
1803 printf("\nCommands : For feature=perf-profile\n");
1805 printf("\tget-lock-status\n");
1806 printf("\tget-config-levels\n");
1807 printf("\tget-config-version\n");
1808 printf("\tget-config-enabled\n");
1809 printf("\tget-config-current-level\n");
1810 printf("\tset-config-level\n");
1813 static void pbf_help(void)
1815 printf("base-freq:\tEnables users to increase guaranteed base frequency\n\
1816 on certain cores (high priority cores) in exchange for lower\n\
1817 base frequency on remaining cores (low priority cores).\n");
1818 printf("\tcommand : info\n");
1819 printf("\tcommand : enable\n");
1820 printf("\tcommand : disable\n");
1823 static void fact_help(void)
1825 printf("turbo-freq:\tEnables the ability to set different turbo ratio\n\
1826 limits to cores based on priority.\n");
1827 printf("\nCommand: For feature=turbo-freq\n");
1828 printf("\tcommand : info\n");
1829 printf("\tcommand : enable\n");
1830 printf("\tcommand : disable\n");
1833 static void core_power_help(void)
1835 printf("core-power:\tInterface that allows user to define per core/tile\n\
1837 printf("\nCommands : For feature=core-power\n");
1839 printf("\tenable\n");
1840 printf("\tdisable\n");
1841 printf("\tconfig\n");
1842 printf("\tget-config\n");
1843 printf("\tassoc\n");
1844 printf("\tget-assoc\n");
1847 struct process_cmd_help_struct {
1849 void (*process_fn)(void);
1852 static struct process_cmd_help_struct isst_help_cmds[] = {
1853 { "perf-profile", isst_help },
1854 { "base-freq", pbf_help },
1855 { "turbo-freq", fact_help },
1856 { "core-power", core_power_help },
1860 void process_command(int argc, char **argv)
1862 int i = 0, matched = 0;
1863 char *feature = argv[optind];
1864 char *cmd = argv[optind + 1];
1866 if (!feature || !cmd)
1869 debug_printf("feature name [%s] command [%s]\n", feature, cmd);
1870 if (!strcmp(cmd, "-h") || !strcmp(cmd, "--help")) {
1871 while (isst_help_cmds[i].feature) {
1872 if (!strcmp(isst_help_cmds[i].feature, feature)) {
1873 isst_help_cmds[i].process_fn();
1883 while (isst_cmds[i].feature) {
1884 if (!strcmp(isst_cmds[i].feature, feature) &&
1885 !strcmp(isst_cmds[i].command, cmd)) {
1886 parse_cmd_args(argc, optind + 1, argv);
1887 isst_cmds[i].process_fn();
1895 fprintf(stderr, "Invalid command\n");
1898 static void usage(void)
1900 printf("Intel(R) Speed Select Technology\n");
1901 printf("\nUsage:\n");
1902 printf("intel-speed-select [OPTIONS] FEATURE COMMAND COMMAND_ARGUMENTS\n");
1903 printf("\nUse this tool to enumerate and control the Intel Speed Select Technology features,\n");
1904 printf("\nFEATURE : [perf-profile|base-freq|turbo-freq|core-power]\n");
1905 printf("\nFor help on each feature, use -h|--help\n");
1906 printf("\tFor example: intel-speed-select perf-profile -h\n");
1908 printf("\nFor additional help on each command for a feature, use --h|--help\n");
1909 printf("\tFor example: intel-speed-select perf-profile get-lock-status -h\n");
1910 printf("\t\t This will print help for the command \"get-lock-status\" for the feature \"perf-profile\"\n");
1912 printf("\nOPTIONS\n");
1913 printf("\t[-c|--cpu] : logical cpu number\n");
1914 printf("\t\tDefault: Die scoped for all dies in the system with multiple dies/package\n");
1915 printf("\t\t\t Or Package scoped for all Packages when each package contains one die\n");
1916 printf("\t[-d|--debug] : Debug mode\n");
1917 printf("\t[-h|--help] : Print help\n");
1918 printf("\t[-i|--info] : Print platform information\n");
1919 printf("\t[-o|--out] : Output file\n");
1920 printf("\t\t\tDefault : stderr\n");
1921 printf("\t[-f|--format] : output format [json|text]. Default: text\n");
1922 printf("\t[-v|--version] : Print version\n");
1924 printf("\nResult format\n");
1925 printf("\tResult display uses a common format for each command:\n");
1926 printf("\tResults are formatted in text/JSON with\n");
1927 printf("\t\tPackage, Die, CPU, and command specific results.\n");
1931 static void print_version(void)
1933 fprintf(outf, "Version %s\n", version_str);
1934 fprintf(outf, "Build date %s time %s\n", __DATE__, __TIME__);
1938 static void cmdline(int argc, char **argv)
1941 int option_index = 0;
1944 static struct option long_options[] = {
1945 { "cpu", required_argument, 0, 'c' },
1946 { "debug", no_argument, 0, 'd' },
1947 { "format", required_argument, 0, 'f' },
1948 { "help", no_argument, 0, 'h' },
1949 { "info", no_argument, 0, 'i' },
1950 { "out", required_argument, 0, 'o' },
1951 { "version", no_argument, 0, 'v' },
1956 while ((opt = getopt_long_only(argc, argv, "+c:df:hio:v", long_options,
1957 &option_index)) != -1) {
1960 parse_cpu_command(optarg);
1964 printf("Debug Mode ON\n");
1967 if (!strncmp(optarg, "json", 4))
1968 out_format_json = 1;
1974 isst_print_platform_information();
1979 outf = fopen_or_exit(optarg, "w");
1989 if (geteuid() != 0) {
1990 fprintf(stderr, "Must run as root\n");
1994 if (optind > (argc - 2)) {
1995 fprintf(stderr, "Feature name and|or command not specified\n");
1999 printf("Intel(R) Speed Select Technology\n");
2000 printf("Executing on CPU model:%d[0x%x]\n", cpu_model, cpu_model);
2002 set_cpu_present_cpu_mask();
2003 set_cpu_target_cpu_mask();
2004 ret = isst_fill_platform_info();
2008 process_command(argc, argv);
2010 free_cpu_set(present_cpumask);
2011 free_cpu_set(target_cpumask);
2014 int main(int argc, char **argv)
2017 cmdline(argc, argv);