treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / power / x86 / intel-speed-select / isst-config.c
blob2b2b8167c65be14594b7838d9bbc3b9c6780d3c7
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Intel Speed Select -- Enumerate and control features
4 * Copyright (c) 2019 Intel Corporation.
5 */
7 #include <linux/isst_if.h>
9 #include "isst.h"
11 struct process_cmd_struct {
12 char *feature;
13 char *command;
14 void (*process_fn)(int arg);
15 int arg;
18 static const char *version_str = "v1.2";
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;
23 static FILE *outf;
25 static int cpu_model;
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;
42 static int cmd_help;
43 static int force_online_offline;
44 static int auto_mode;
46 /* clos related */
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;
55 struct _cpu_map {
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, ...)
66 va_list args;
68 va_start(args, format);
70 if (debug_flag)
71 vprintf(format, args);
73 va_end(args);
77 int is_clx_n_platform(void)
79 if (cpu_model == 0x55)
80 if (cpu_stepping == 0x6 || cpu_stepping == 0x7)
81 return 1;
82 return 0;
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()) {
99 FILE *fp;
100 size_t n = 0;
101 char *line = NULL;
102 int ret = 1;
104 fp = fopen("/proc/cpuinfo", "r");
105 if (!fp)
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"))
113 ret = 0;
114 break;
117 free(line);
118 fclose(fp);
119 return ret;
121 return 0;
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);
129 if (!filep)
130 err(1, "%s: open failed", path);
132 return filep;
135 /* Parse a file containing a single int */
136 static int parse_int_file(int fatal, const char *fmt, ...)
138 va_list args;
139 char path[PATH_MAX];
140 FILE *filep;
141 int value;
143 va_start(args, fmt);
144 vsnprintf(path, sizeof(path), fmt, args);
145 va_end(args);
146 if (fatal) {
147 filep = fopen_or_exit(path, "r");
148 } else {
149 filep = fopen(path, "r");
150 if (!filep)
151 return -1;
153 if (fscanf(filep, "%d", &value) != 1)
154 err(1, "%s: failed to parse number from file", path);
155 fclose(filep);
157 return value;
160 int cpufreq_sysfs_present(void)
162 DIR *dir;
164 dir = opendir("/sys/devices/system/cpu/cpu0/cpufreq");
165 if (dir) {
166 closedir(dir);
167 return 1;
170 return 0;
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",
182 cpu);
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)
193 int ret;
195 ret = parse_int_file(0, "/sys/devices/system/cpu/cpu%d/topology/die_id",
196 cpu);
197 if (ret < 0)
198 ret = 0;
200 return ret;
203 int get_cpufreq_base_freq(int cpu)
205 return parse_int_file(0, "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency", cpu);
208 int get_topo_max_cpus(void)
210 return topo_max_cpus;
213 static void set_cpu_online_offline(int cpu, int state)
215 char buffer[128];
216 int fd, ret;
218 snprintf(buffer, sizeof(buffer),
219 "/sys/devices/system/cpu/cpu%d/online", cpu);
221 fd = open(buffer, O_WRONLY);
222 if (fd < 0)
223 err(-1, "%s open failed", buffer);
225 if (state)
226 ret = write(fd, "1\n", 2);
227 else
228 ret = write(fd, "0\n", 2);
230 if (ret == -1)
231 perror("Online/Offline: Operation failed\n");
233 close(fd);
236 #define MAX_PACKAGE_COUNT 8
237 #define MAX_DIE_PER_PACKAGE 2
238 static void for_each_online_package_in_set(void (*callback)(int, void *, void *,
239 void *, void *),
240 void *arg1, void *arg2, void *arg3,
241 void *arg4)
243 int max_packages[MAX_PACKAGE_COUNT * MAX_PACKAGE_COUNT];
244 int pkg_index = 0, i;
246 memset(max_packages, 0xff, sizeof(max_packages));
247 for (i = 0; i < topo_max_cpus; ++i) {
248 int j, online, pkg_id, die_id = 0, skip = 0;
250 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
251 continue;
252 if (i)
253 online = parse_int_file(
254 1, "/sys/devices/system/cpu/cpu%d/online", i);
255 else
256 online =
257 1; /* online entry for CPU 0 needs some special configs */
259 die_id = get_physical_die_id(i);
260 if (die_id < 0)
261 die_id = 0;
262 pkg_id = get_physical_package_id(i);
263 /* Create an unique id for package, die combination to store */
264 pkg_id = (MAX_PACKAGE_COUNT * pkg_id + die_id);
266 for (j = 0; j < pkg_index; ++j) {
267 if (max_packages[j] == pkg_id) {
268 skip = 1;
269 break;
273 if (!skip && online && callback) {
274 callback(i, arg1, arg2, arg3, arg4);
275 max_packages[pkg_index++] = pkg_id;
280 static void for_each_online_target_cpu_in_set(
281 void (*callback)(int, void *, void *, void *, void *), void *arg1,
282 void *arg2, void *arg3, void *arg4)
284 int i;
286 for (i = 0; i < topo_max_cpus; ++i) {
287 int online;
289 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
290 continue;
291 if (i)
292 online = parse_int_file(
293 1, "/sys/devices/system/cpu/cpu%d/online", i);
294 else
295 online =
296 1; /* online entry for CPU 0 needs some special configs */
298 if (online && callback)
299 callback(i, arg1, arg2, arg3, arg4);
303 #define BITMASK_SIZE 32
304 static void set_max_cpu_num(void)
306 FILE *filep;
307 unsigned long dummy;
309 topo_max_cpus = 0;
310 filep = fopen_or_exit(
311 "/sys/devices/system/cpu/cpu0/topology/thread_siblings", "r");
312 while (fscanf(filep, "%lx,", &dummy) == 1)
313 topo_max_cpus += BITMASK_SIZE;
314 fclose(filep);
315 topo_max_cpus--; /* 0 based */
317 debug_printf("max cpus %d\n", topo_max_cpus);
320 size_t alloc_cpu_set(cpu_set_t **cpu_set)
322 cpu_set_t *_cpu_set;
323 size_t size;
325 _cpu_set = CPU_ALLOC((topo_max_cpus + 1));
326 if (_cpu_set == NULL)
327 err(3, "CPU_ALLOC");
328 size = CPU_ALLOC_SIZE((topo_max_cpus + 1));
329 CPU_ZERO_S(size, _cpu_set);
331 *cpu_set = _cpu_set;
332 return size;
335 void free_cpu_set(cpu_set_t *cpu_set)
337 CPU_FREE(cpu_set);
340 static int cpu_cnt[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
341 static long long core_mask[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
342 static void set_cpu_present_cpu_mask(void)
344 size_t size;
345 DIR *dir;
346 int i;
348 size = alloc_cpu_set(&present_cpumask);
349 present_cpumask_size = size;
350 for (i = 0; i < topo_max_cpus; ++i) {
351 char buffer[256];
353 snprintf(buffer, sizeof(buffer),
354 "/sys/devices/system/cpu/cpu%d", i);
355 dir = opendir(buffer);
356 if (dir) {
357 int pkg_id, die_id;
359 CPU_SET_S(i, size, present_cpumask);
360 die_id = get_physical_die_id(i);
361 if (die_id < 0)
362 die_id = 0;
364 pkg_id = get_physical_package_id(i);
365 if (pkg_id < MAX_PACKAGE_COUNT &&
366 die_id < MAX_DIE_PER_PACKAGE) {
367 int core_id = get_physical_core_id(i);
369 cpu_cnt[pkg_id][die_id]++;
370 core_mask[pkg_id][die_id] |= (1ULL << core_id);
373 closedir(dir);
377 int get_core_count(int pkg_id, int die_id)
379 int cnt = 0;
381 if (pkg_id < MAX_PACKAGE_COUNT && die_id < MAX_DIE_PER_PACKAGE) {
382 int i;
384 for (i = 0; i < sizeof(long long) * 8; ++i) {
385 if (core_mask[pkg_id][die_id] & (1ULL << i))
386 cnt++;
390 return cnt;
393 int get_cpu_count(int pkg_id, int die_id)
395 if (pkg_id < MAX_PACKAGE_COUNT && die_id < MAX_DIE_PER_PACKAGE)
396 return cpu_cnt[pkg_id][die_id];
398 return 0;
401 static void set_cpu_target_cpu_mask(void)
403 size_t size;
404 int i;
406 size = alloc_cpu_set(&target_cpumask);
407 target_cpumask_size = size;
408 for (i = 0; i < max_target_cpus; ++i) {
409 if (!CPU_ISSET_S(target_cpus[i], present_cpumask_size,
410 present_cpumask))
411 continue;
413 CPU_SET_S(target_cpus[i], size, target_cpumask);
417 static void create_cpu_map(void)
419 const char *pathname = "/dev/isst_interface";
420 int i, fd = 0;
421 struct isst_if_cpu_maps map;
423 cpu_map = malloc(sizeof(*cpu_map) * topo_max_cpus);
424 if (!cpu_map)
425 err(3, "cpumap");
427 fd = open(pathname, O_RDWR);
428 if (fd < 0)
429 err(-1, "%s open failed", pathname);
431 for (i = 0; i < topo_max_cpus; ++i) {
432 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
433 continue;
435 map.cmd_count = 1;
436 map.cpu_map[0].logical_cpu = i;
438 debug_printf(" map logical_cpu:%d\n",
439 map.cpu_map[0].logical_cpu);
440 if (ioctl(fd, ISST_IF_GET_PHY_ID, &map) == -1) {
441 perror("ISST_IF_GET_PHY_ID");
442 fprintf(outf, "Error: map logical_cpu:%d\n",
443 map.cpu_map[0].logical_cpu);
444 continue;
446 cpu_map[i].core_id = get_physical_core_id(i);
447 cpu_map[i].pkg_id = get_physical_package_id(i);
448 cpu_map[i].die_id = get_physical_die_id(i);
449 cpu_map[i].punit_cpu = map.cpu_map[0].physical_cpu;
450 cpu_map[i].punit_cpu_core = (map.cpu_map[0].physical_cpu >>
451 1); // shift to get core id
453 debug_printf(
454 "map logical_cpu:%d core: %d die:%d pkg:%d punit_cpu:%d punit_core:%d\n",
455 i, cpu_map[i].core_id, cpu_map[i].die_id,
456 cpu_map[i].pkg_id, cpu_map[i].punit_cpu,
457 cpu_map[i].punit_cpu_core);
460 if (fd)
461 close(fd);
464 int find_logical_cpu(int pkg_id, int die_id, int punit_core_id)
466 int i;
468 for (i = 0; i < topo_max_cpus; ++i) {
469 if (cpu_map[i].pkg_id == pkg_id &&
470 cpu_map[i].die_id == die_id &&
471 cpu_map[i].punit_cpu_core == punit_core_id)
472 return i;
475 return -EINVAL;
478 void set_cpu_mask_from_punit_coremask(int cpu, unsigned long long core_mask,
479 size_t core_cpumask_size,
480 cpu_set_t *core_cpumask, int *cpu_cnt)
482 int i, cnt = 0;
483 int die_id, pkg_id;
485 *cpu_cnt = 0;
486 die_id = get_physical_die_id(cpu);
487 pkg_id = get_physical_package_id(cpu);
489 for (i = 0; i < 64; ++i) {
490 if (core_mask & BIT(i)) {
491 int j;
493 for (j = 0; j < topo_max_cpus; ++j) {
494 if (!CPU_ISSET_S(j, present_cpumask_size, present_cpumask))
495 continue;
497 if (cpu_map[j].pkg_id == pkg_id &&
498 cpu_map[j].die_id == die_id &&
499 cpu_map[j].punit_cpu_core == i) {
500 CPU_SET_S(j, core_cpumask_size,
501 core_cpumask);
502 ++cnt;
508 *cpu_cnt = cnt;
511 int find_phy_core_num(int logical_cpu)
513 if (logical_cpu < topo_max_cpus)
514 return cpu_map[logical_cpu].punit_cpu_core;
516 return -EINVAL;
519 static int isst_send_mmio_command(unsigned int cpu, unsigned int reg, int write,
520 unsigned int *value)
522 struct isst_if_io_regs io_regs;
523 const char *pathname = "/dev/isst_interface";
524 int cmd;
525 int fd;
527 debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu, reg, write);
529 fd = open(pathname, O_RDWR);
530 if (fd < 0)
531 err(-1, "%s open failed", pathname);
533 io_regs.req_count = 1;
534 io_regs.io_reg[0].logical_cpu = cpu;
535 io_regs.io_reg[0].reg = reg;
536 cmd = ISST_IF_IO_CMD;
537 if (write) {
538 io_regs.io_reg[0].read_write = 1;
539 io_regs.io_reg[0].value = *value;
540 } else {
541 io_regs.io_reg[0].read_write = 0;
544 if (ioctl(fd, cmd, &io_regs) == -1) {
545 perror("ISST_IF_IO_CMD");
546 fprintf(outf, "Error: mmio_cmd cpu:%d reg:%x read_write:%x\n",
547 cpu, reg, write);
548 } else {
549 if (!write)
550 *value = io_regs.io_reg[0].value;
552 debug_printf(
553 "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
554 cpu, reg, write, *value);
557 close(fd);
559 return 0;
562 int isst_send_mbox_command(unsigned int cpu, unsigned char command,
563 unsigned char sub_command, unsigned int parameter,
564 unsigned int req_data, unsigned int *resp)
566 const char *pathname = "/dev/isst_interface";
567 int fd;
568 struct isst_if_mbox_cmds mbox_cmds = { 0 };
570 debug_printf(
571 "mbox_send: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
572 cpu, command, sub_command, parameter, req_data);
574 if (isst_platform_info.mmio_supported && command == CONFIG_CLOS) {
575 unsigned int value;
576 int write = 0;
577 int clos_id, core_id, ret = 0;
579 debug_printf("CPU %d\n", cpu);
581 if (parameter & BIT(MBOX_CMD_WRITE_BIT)) {
582 value = req_data;
583 write = 1;
586 switch (sub_command) {
587 case CLOS_PQR_ASSOC:
588 core_id = parameter & 0xff;
589 ret = isst_send_mmio_command(
590 cpu, PQR_ASSOC_OFFSET + core_id * 4, write,
591 &value);
592 if (!ret && !write)
593 *resp = value;
594 break;
595 case CLOS_PM_CLOS:
596 clos_id = parameter & 0x03;
597 ret = isst_send_mmio_command(
598 cpu, PM_CLOS_OFFSET + clos_id * 4, write,
599 &value);
600 if (!ret && !write)
601 *resp = value;
602 break;
603 case CLOS_STATUS:
604 break;
605 default:
606 break;
608 return ret;
611 mbox_cmds.cmd_count = 1;
612 mbox_cmds.mbox_cmd[0].logical_cpu = cpu;
613 mbox_cmds.mbox_cmd[0].command = command;
614 mbox_cmds.mbox_cmd[0].sub_command = sub_command;
615 mbox_cmds.mbox_cmd[0].parameter = parameter;
616 mbox_cmds.mbox_cmd[0].req_data = req_data;
618 fd = open(pathname, O_RDWR);
619 if (fd < 0)
620 err(-1, "%s open failed", pathname);
622 if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
623 perror("ISST_IF_MBOX_COMMAND");
624 fprintf(outf,
625 "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
626 cpu, command, sub_command, parameter, req_data);
627 return -1;
628 } else {
629 *resp = mbox_cmds.mbox_cmd[0].resp_data;
630 debug_printf(
631 "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
632 cpu, command, sub_command, parameter, req_data, *resp);
635 close(fd);
637 return 0;
640 int isst_send_msr_command(unsigned int cpu, unsigned int msr, int write,
641 unsigned long long *req_resp)
643 struct isst_if_msr_cmds msr_cmds;
644 const char *pathname = "/dev/isst_interface";
645 int fd;
647 fd = open(pathname, O_RDWR);
648 if (fd < 0)
649 err(-1, "%s open failed", pathname);
651 msr_cmds.cmd_count = 1;
652 msr_cmds.msr_cmd[0].logical_cpu = cpu;
653 msr_cmds.msr_cmd[0].msr = msr;
654 msr_cmds.msr_cmd[0].read_write = write;
655 if (write)
656 msr_cmds.msr_cmd[0].data = *req_resp;
658 if (ioctl(fd, ISST_IF_MSR_COMMAND, &msr_cmds) == -1) {
659 perror("ISST_IF_MSR_COMMAD");
660 fprintf(outf, "Error: msr_cmd cpu:%d msr:%x read_write:%d\n",
661 cpu, msr, write);
662 } else {
663 if (!write)
664 *req_resp = msr_cmds.msr_cmd[0].data;
666 debug_printf(
667 "msr_cmd response: cpu:%d msr:%x rd_write:%x resp:%llx %llx\n",
668 cpu, msr, write, *req_resp, msr_cmds.msr_cmd[0].data);
671 close(fd);
673 return 0;
676 static int isst_fill_platform_info(void)
678 const char *pathname = "/dev/isst_interface";
679 int fd;
681 fd = open(pathname, O_RDWR);
682 if (fd < 0)
683 err(-1, "%s open failed", pathname);
685 if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &isst_platform_info) == -1) {
686 perror("ISST_IF_GET_PLATFORM_INFO");
687 close(fd);
688 return -1;
691 close(fd);
693 if (isst_platform_info.api_version > supported_api_ver) {
694 printf("Incompatible API versions; Upgrade of tool is required\n");
695 return -1;
697 return 0;
700 static void isst_print_platform_information(void)
702 struct isst_if_platform_info platform_info;
703 const char *pathname = "/dev/isst_interface";
704 int fd;
706 fd = open(pathname, O_RDWR);
707 if (fd < 0)
708 err(-1, "%s open failed", pathname);
710 if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &platform_info) == -1) {
711 perror("ISST_IF_GET_PLATFORM_INFO");
712 } else {
713 fprintf(outf, "Platform: API version : %d\n",
714 platform_info.api_version);
715 fprintf(outf, "Platform: Driver version : %d\n",
716 platform_info.driver_version);
717 fprintf(outf, "Platform: mbox supported : %d\n",
718 platform_info.mbox_supported);
719 fprintf(outf, "Platform: mmio supported : %d\n",
720 platform_info.mmio_supported);
723 close(fd);
725 exit(0);
728 static void exec_on_get_ctdp_cpu(int cpu, void *arg1, void *arg2, void *arg3,
729 void *arg4)
731 int (*fn_ptr)(int cpu, void *arg);
732 int ret;
734 fn_ptr = arg1;
735 ret = fn_ptr(cpu, arg2);
736 if (ret)
737 perror("get_tdp_*");
738 else
739 isst_ctdp_display_core_info(cpu, outf, arg3,
740 *(unsigned int *)arg4);
743 #define _get_tdp_level(desc, suffix, object, help) \
744 static void get_tdp_##object(int arg) \
746 struct isst_pkg_ctdp ctdp; \
748 if (cmd_help) { \
749 fprintf(stderr, \
750 "Print %s [No command arguments are required]\n", \
751 help); \
752 exit(0); \
754 isst_ctdp_display_information_start(outf); \
755 if (max_target_cpus) \
756 for_each_online_target_cpu_in_set( \
757 exec_on_get_ctdp_cpu, isst_get_ctdp_##suffix, \
758 &ctdp, desc, &ctdp.object); \
759 else \
760 for_each_online_package_in_set(exec_on_get_ctdp_cpu, \
761 isst_get_ctdp_##suffix, \
762 &ctdp, desc, \
763 &ctdp.object); \
764 isst_ctdp_display_information_end(outf); \
767 _get_tdp_level("get-config-levels", levels, levels, "TDP levels");
768 _get_tdp_level("get-config-version", levels, version, "TDP version");
769 _get_tdp_level("get-config-enabled", levels, enabled, "TDP enable status");
770 _get_tdp_level("get-config-current_level", levels, current_level,
771 "Current TDP Level");
772 _get_tdp_level("get-lock-status", levels, locked, "TDP lock status");
774 struct isst_pkg_ctdp clx_n_pkg_dev;
776 static int clx_n_get_base_ratio(void)
778 FILE *fp;
779 char *begin, *end, *line = NULL;
780 char number[5];
781 float value = 0;
782 size_t n = 0;
784 fp = fopen("/proc/cpuinfo", "r");
785 if (!fp)
786 err(-1, "cannot open /proc/cpuinfo\n");
788 while (getline(&line, &n, fp) > 0) {
789 if (strstr(line, "model name")) {
790 /* this is true for CascadeLake-N */
791 begin = strstr(line, "@ ") + 2;
792 end = strstr(line, "GHz");
793 strncpy(number, begin, end - begin);
794 value = atof(number) * 10;
795 break;
798 free(line);
799 fclose(fp);
801 return (int)(value);
804 static int clx_n_config(int cpu)
806 int i, ret, pkg_id, die_id;
807 unsigned long cpu_bf;
808 struct isst_pkg_ctdp_level_info *ctdp_level;
809 struct isst_pbf_info *pbf_info;
811 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
812 pbf_info = &ctdp_level->pbf_info;
813 ctdp_level->core_cpumask_size =
814 alloc_cpu_set(&ctdp_level->core_cpumask);
816 /* find the frequency base ratio */
817 ctdp_level->tdp_ratio = clx_n_get_base_ratio();
818 if (ctdp_level->tdp_ratio == 0) {
819 debug_printf("CLX: cn base ratio is zero\n");
820 ret = -1;
821 goto error_ret;
824 /* find the high and low priority frequencies */
825 pbf_info->p1_high = 0;
826 pbf_info->p1_low = ~0;
828 pkg_id = get_physical_package_id(cpu);
829 die_id = get_physical_die_id(cpu);
831 for (i = 0; i < topo_max_cpus; i++) {
832 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
833 continue;
835 if (pkg_id != get_physical_package_id(i) ||
836 die_id != get_physical_die_id(i))
837 continue;
839 CPU_SET_S(i, ctdp_level->core_cpumask_size,
840 ctdp_level->core_cpumask);
842 cpu_bf = parse_int_file(1,
843 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
845 if (cpu_bf > pbf_info->p1_high)
846 pbf_info->p1_high = cpu_bf;
847 if (cpu_bf < pbf_info->p1_low)
848 pbf_info->p1_low = cpu_bf;
851 if (pbf_info->p1_high == ~0UL) {
852 debug_printf("CLX: maximum base frequency not set\n");
853 ret = -1;
854 goto error_ret;
857 if (pbf_info->p1_low == 0) {
858 debug_printf("CLX: minimum base frequency not set\n");
859 ret = -1;
860 goto error_ret;
863 /* convert frequencies back to ratios */
864 pbf_info->p1_high = pbf_info->p1_high / 100000;
865 pbf_info->p1_low = pbf_info->p1_low / 100000;
867 /* create high priority cpu mask */
868 pbf_info->core_cpumask_size = alloc_cpu_set(&pbf_info->core_cpumask);
869 for (i = 0; i < topo_max_cpus; i++) {
870 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
871 continue;
873 if (pkg_id != get_physical_package_id(i) ||
874 die_id != get_physical_die_id(i))
875 continue;
877 cpu_bf = parse_int_file(1,
878 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
880 cpu_bf = cpu_bf / 100000;
881 if (cpu_bf == pbf_info->p1_high)
882 CPU_SET_S(i, pbf_info->core_cpumask_size,
883 pbf_info->core_cpumask);
886 /* extra ctdp & pbf struct parameters */
887 ctdp_level->processed = 1;
888 ctdp_level->pbf_support = 1; /* PBF is always supported and enabled */
889 ctdp_level->pbf_enabled = 1;
890 ctdp_level->fact_support = 0; /* FACT is never supported */
891 ctdp_level->fact_enabled = 0;
893 return 0;
895 error_ret:
896 free_cpu_set(ctdp_level->core_cpumask);
897 return ret;
900 static void dump_clx_n_config_for_cpu(int cpu, void *arg1, void *arg2,
901 void *arg3, void *arg4)
903 int ret;
905 ret = clx_n_config(cpu);
906 if (ret) {
907 perror("isst_get_process_ctdp");
908 } else {
909 struct isst_pkg_ctdp_level_info *ctdp_level;
910 struct isst_pbf_info *pbf_info;
912 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
913 pbf_info = &ctdp_level->pbf_info;
914 isst_ctdp_display_information(cpu, outf, tdp_level, &clx_n_pkg_dev);
915 free_cpu_set(ctdp_level->core_cpumask);
916 free_cpu_set(pbf_info->core_cpumask);
920 static void dump_isst_config_for_cpu(int cpu, void *arg1, void *arg2,
921 void *arg3, void *arg4)
923 struct isst_pkg_ctdp pkg_dev;
924 int ret;
926 memset(&pkg_dev, 0, sizeof(pkg_dev));
927 ret = isst_get_process_ctdp(cpu, tdp_level, &pkg_dev);
928 if (ret) {
929 perror("isst_get_process_ctdp");
930 } else {
931 isst_ctdp_display_information(cpu, outf, tdp_level, &pkg_dev);
932 isst_get_process_ctdp_complete(cpu, &pkg_dev);
936 static void dump_isst_config(int arg)
938 void *fn;
940 if (cmd_help) {
941 fprintf(stderr,
942 "Print Intel(R) Speed Select Technology Performance profile configuration\n");
943 fprintf(stderr,
944 "including base frequency and turbo frequency configurations\n");
945 fprintf(stderr, "Optional: -l|--level : Specify tdp level\n");
946 fprintf(stderr,
947 "\tIf no arguments, dump information for all TDP levels\n");
948 exit(0);
951 if (!is_clx_n_platform())
952 fn = dump_isst_config_for_cpu;
953 else
954 fn = dump_clx_n_config_for_cpu;
956 isst_ctdp_display_information_start(outf);
958 if (max_target_cpus)
959 for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
960 else
961 for_each_online_package_in_set(fn, NULL, NULL, NULL, NULL);
963 isst_ctdp_display_information_end(outf);
966 static void set_tdp_level_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
967 void *arg4)
969 int ret;
971 ret = isst_set_tdp_level(cpu, tdp_level);
972 if (ret)
973 perror("set_tdp_level_for_cpu");
974 else {
975 isst_display_result(cpu, outf, "perf-profile", "set_tdp_level",
976 ret);
977 if (force_online_offline) {
978 struct isst_pkg_ctdp_level_info ctdp_level;
979 int pkg_id = get_physical_package_id(cpu);
980 int die_id = get_physical_die_id(cpu);
982 fprintf(stderr, "Option is set to online/offline\n");
983 ctdp_level.core_cpumask_size =
984 alloc_cpu_set(&ctdp_level.core_cpumask);
985 isst_get_coremask_info(cpu, tdp_level, &ctdp_level);
986 if (ctdp_level.cpu_count) {
987 int i, max_cpus = get_topo_max_cpus();
988 for (i = 0; i < max_cpus; ++i) {
989 if (pkg_id != get_physical_package_id(i) || die_id != get_physical_die_id(i))
990 continue;
991 if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
992 fprintf(stderr, "online cpu %d\n", i);
993 set_cpu_online_offline(i, 1);
994 } else {
995 fprintf(stderr, "offline cpu %d\n", i);
996 set_cpu_online_offline(i, 0);
1004 static void set_tdp_level(int arg)
1006 if (cmd_help) {
1007 fprintf(stderr, "Set Config TDP level\n");
1008 fprintf(stderr,
1009 "\t Arguments: -l|--level : Specify tdp level\n");
1010 fprintf(stderr,
1011 "\t Optional Arguments: -o | online : online/offline for the tdp level\n");
1012 exit(0);
1015 if (tdp_level == 0xff) {
1016 fprintf(outf, "Invalid command: specify tdp_level\n");
1017 exit(1);
1019 isst_ctdp_display_information_start(outf);
1020 if (max_target_cpus)
1021 for_each_online_target_cpu_in_set(set_tdp_level_for_cpu, NULL,
1022 NULL, NULL, NULL);
1023 else
1024 for_each_online_package_in_set(set_tdp_level_for_cpu, NULL,
1025 NULL, NULL, NULL);
1026 isst_ctdp_display_information_end(outf);
1029 static void clx_n_dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2,
1030 void *arg3, void *arg4)
1032 int ret;
1034 ret = clx_n_config(cpu);
1035 if (ret) {
1036 perror("isst_get_process_ctdp");
1037 } else {
1038 struct isst_pkg_ctdp_level_info *ctdp_level;
1039 struct isst_pbf_info *pbf_info;
1041 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1042 pbf_info = &ctdp_level->pbf_info;
1043 isst_pbf_display_information(cpu, outf, tdp_level, pbf_info);
1044 free_cpu_set(ctdp_level->core_cpumask);
1045 free_cpu_set(pbf_info->core_cpumask);
1049 static void dump_pbf_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1050 void *arg4)
1052 struct isst_pbf_info pbf_info;
1053 int ret;
1055 ret = isst_get_pbf_info(cpu, tdp_level, &pbf_info);
1056 if (ret) {
1057 perror("isst_get_pbf_info");
1058 } else {
1059 isst_pbf_display_information(cpu, outf, tdp_level, &pbf_info);
1060 isst_get_pbf_info_complete(&pbf_info);
1064 static void dump_pbf_config(int arg)
1066 void *fn;
1068 if (cmd_help) {
1069 fprintf(stderr,
1070 "Print Intel(R) Speed Select Technology base frequency configuration for a TDP level\n");
1071 fprintf(stderr,
1072 "\tArguments: -l|--level : Specify tdp level\n");
1073 exit(0);
1076 if (tdp_level == 0xff) {
1077 fprintf(outf, "Invalid command: specify tdp_level\n");
1078 exit(1);
1081 if (!is_clx_n_platform())
1082 fn = dump_pbf_config_for_cpu;
1083 else
1084 fn = clx_n_dump_pbf_config_for_cpu;
1086 isst_ctdp_display_information_start(outf);
1088 if (max_target_cpus)
1089 for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
1090 else
1091 for_each_online_package_in_set(fn, NULL, NULL, NULL, NULL);
1093 isst_ctdp_display_information_end(outf);
1096 static int set_clos_param(int cpu, int clos, int epp, int wt, int min, int max)
1098 struct isst_clos_config clos_config;
1099 int ret;
1101 ret = isst_pm_get_clos(cpu, clos, &clos_config);
1102 if (ret) {
1103 perror("isst_pm_get_clos");
1104 return ret;
1106 clos_config.clos_min = min;
1107 clos_config.clos_max = max;
1108 clos_config.epp = epp;
1109 clos_config.clos_prop_prio = wt;
1110 ret = isst_set_clos(cpu, clos, &clos_config);
1111 if (ret) {
1112 perror("isst_pm_set_clos");
1113 return ret;
1116 return 0;
1119 static int set_cpufreq_scaling_min_max(int cpu, int max, int freq)
1121 char buffer[128], freq_str[16];
1122 int fd, ret, len;
1124 if (max)
1125 snprintf(buffer, sizeof(buffer),
1126 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
1127 else
1128 snprintf(buffer, sizeof(buffer),
1129 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
1131 fd = open(buffer, O_WRONLY);
1132 if (fd < 0)
1133 return fd;
1135 snprintf(freq_str, sizeof(freq_str), "%d", freq);
1136 len = strlen(freq_str);
1137 ret = write(fd, freq_str, len);
1138 if (ret == -1) {
1139 close(fd);
1140 return ret;
1142 close(fd);
1144 return 0;
1147 static int set_clx_pbf_cpufreq_scaling_min_max(int cpu)
1149 struct isst_pkg_ctdp_level_info *ctdp_level;
1150 struct isst_pbf_info *pbf_info;
1151 int i, pkg_id, die_id, freq, freq_high, freq_low;
1152 int ret;
1154 ret = clx_n_config(cpu);
1155 if (ret) {
1156 perror("set_clx_pbf_cpufreq_scaling_min_max");
1157 return ret;
1160 ctdp_level = &clx_n_pkg_dev.ctdp_level[0];
1161 pbf_info = &ctdp_level->pbf_info;
1162 freq_high = pbf_info->p1_high * 100000;
1163 freq_low = pbf_info->p1_low * 100000;
1165 pkg_id = get_physical_package_id(cpu);
1166 die_id = get_physical_die_id(cpu);
1167 for (i = 0; i < get_topo_max_cpus(); ++i) {
1168 if (pkg_id != get_physical_package_id(i) ||
1169 die_id != get_physical_die_id(i))
1170 continue;
1172 if (CPU_ISSET_S(i, pbf_info->core_cpumask_size,
1173 pbf_info->core_cpumask))
1174 freq = freq_high;
1175 else
1176 freq = freq_low;
1178 set_cpufreq_scaling_min_max(i, 1, freq);
1179 set_cpufreq_scaling_min_max(i, 0, freq);
1182 return 0;
1185 static int set_cpufreq_scaling_min_max_from_cpuinfo(int cpu, int cpuinfo_max, int scaling_max)
1187 char buffer[128], min_freq[16];
1188 int fd, ret, len;
1190 if (!CPU_ISSET_S(cpu, present_cpumask_size, present_cpumask))
1191 return -1;
1193 if (cpuinfo_max)
1194 snprintf(buffer, sizeof(buffer),
1195 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu);
1196 else
1197 snprintf(buffer, sizeof(buffer),
1198 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", cpu);
1200 fd = open(buffer, O_RDONLY);
1201 if (fd < 0)
1202 return fd;
1204 len = read(fd, min_freq, sizeof(min_freq));
1205 close(fd);
1207 if (len < 0)
1208 return len;
1210 if (scaling_max)
1211 snprintf(buffer, sizeof(buffer),
1212 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
1213 else
1214 snprintf(buffer, sizeof(buffer),
1215 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
1217 fd = open(buffer, O_WRONLY);
1218 if (fd < 0)
1219 return fd;
1221 len = strlen(min_freq);
1222 ret = write(fd, min_freq, len);
1223 if (ret == -1) {
1224 close(fd);
1225 return ret;
1227 close(fd);
1229 return 0;
1232 static void set_scaling_min_to_cpuinfo_max(int cpu)
1234 int i, pkg_id, die_id;
1236 pkg_id = get_physical_package_id(cpu);
1237 die_id = get_physical_die_id(cpu);
1238 for (i = 0; i < get_topo_max_cpus(); ++i) {
1239 if (pkg_id != get_physical_package_id(i) ||
1240 die_id != get_physical_die_id(i))
1241 continue;
1243 set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 0);
1247 static void set_scaling_min_to_cpuinfo_min(int cpu)
1249 int i, pkg_id, die_id;
1251 pkg_id = get_physical_package_id(cpu);
1252 die_id = get_physical_die_id(cpu);
1253 for (i = 0; i < get_topo_max_cpus(); ++i) {
1254 if (pkg_id != get_physical_package_id(i) ||
1255 die_id != get_physical_die_id(i))
1256 continue;
1258 set_cpufreq_scaling_min_max_from_cpuinfo(i, 0, 0);
1262 static void set_scaling_max_to_cpuinfo_max(int cpu)
1264 int i, pkg_id, die_id;
1266 pkg_id = get_physical_package_id(cpu);
1267 die_id = get_physical_die_id(cpu);
1268 for (i = 0; i < get_topo_max_cpus(); ++i) {
1269 if (pkg_id != get_physical_package_id(i) ||
1270 die_id != get_physical_die_id(i))
1271 continue;
1273 set_cpufreq_scaling_min_max_from_cpuinfo(i, 1, 1);
1277 static int set_core_priority_and_min(int cpu, int mask_size,
1278 cpu_set_t *cpu_mask, int min_high,
1279 int min_low)
1281 int pkg_id, die_id, ret, i;
1283 if (!CPU_COUNT_S(mask_size, cpu_mask))
1284 return -1;
1286 ret = set_clos_param(cpu, 0, 0, 0, min_high, 0xff);
1287 if (ret)
1288 return ret;
1290 ret = set_clos_param(cpu, 1, 15, 15, min_low, 0xff);
1291 if (ret)
1292 return ret;
1294 ret = set_clos_param(cpu, 2, 15, 15, min_low, 0xff);
1295 if (ret)
1296 return ret;
1298 ret = set_clos_param(cpu, 3, 15, 15, min_low, 0xff);
1299 if (ret)
1300 return ret;
1302 pkg_id = get_physical_package_id(cpu);
1303 die_id = get_physical_die_id(cpu);
1304 for (i = 0; i < get_topo_max_cpus(); ++i) {
1305 int clos;
1307 if (pkg_id != get_physical_package_id(i) ||
1308 die_id != get_physical_die_id(i))
1309 continue;
1311 if (CPU_ISSET_S(i, mask_size, cpu_mask))
1312 clos = 0;
1313 else
1314 clos = 3;
1316 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
1317 ret = isst_clos_associate(i, clos);
1318 if (ret) {
1319 perror("isst_clos_associate");
1320 return ret;
1324 return 0;
1327 static int set_pbf_core_power(int cpu)
1329 struct isst_pbf_info pbf_info;
1330 struct isst_pkg_ctdp pkg_dev;
1331 int ret;
1333 ret = isst_get_ctdp_levels(cpu, &pkg_dev);
1334 if (ret) {
1335 perror("isst_get_ctdp_levels");
1336 return ret;
1338 debug_printf("Current_level: %d\n", pkg_dev.current_level);
1340 ret = isst_get_pbf_info(cpu, pkg_dev.current_level, &pbf_info);
1341 if (ret) {
1342 perror("isst_get_pbf_info");
1343 return ret;
1345 debug_printf("p1_high: %d p1_low: %d\n", pbf_info.p1_high,
1346 pbf_info.p1_low);
1348 ret = set_core_priority_and_min(cpu, pbf_info.core_cpumask_size,
1349 pbf_info.core_cpumask,
1350 pbf_info.p1_high, pbf_info.p1_low);
1351 if (ret) {
1352 perror("set_core_priority_and_min");
1353 return ret;
1356 ret = isst_pm_qos_config(cpu, 1, 1);
1357 if (ret) {
1358 perror("isst_pm_qos_config");
1359 return ret;
1362 return 0;
1365 static void set_pbf_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1366 void *arg4)
1368 int ret;
1369 int status = *(int *)arg4;
1371 if (is_clx_n_platform()) {
1372 if (status) {
1373 ret = 0;
1374 if (auto_mode)
1375 set_clx_pbf_cpufreq_scaling_min_max(cpu);
1377 } else {
1378 ret = -1;
1379 if (auto_mode) {
1380 set_scaling_max_to_cpuinfo_max(cpu);
1381 set_scaling_min_to_cpuinfo_min(cpu);
1384 goto disp_result;
1387 if (auto_mode && status) {
1388 ret = set_pbf_core_power(cpu);
1389 if (ret)
1390 goto disp_result;
1393 ret = isst_set_pbf_fact_status(cpu, 1, status);
1394 if (ret) {
1395 perror("isst_set_pbf");
1396 if (auto_mode)
1397 isst_pm_qos_config(cpu, 0, 0);
1398 } else {
1399 if (auto_mode) {
1400 if (status)
1401 set_scaling_min_to_cpuinfo_max(cpu);
1402 else
1403 set_scaling_min_to_cpuinfo_min(cpu);
1407 if (auto_mode && !status)
1408 isst_pm_qos_config(cpu, 0, 0);
1410 disp_result:
1411 if (status)
1412 isst_display_result(cpu, outf, "base-freq", "enable",
1413 ret);
1414 else
1415 isst_display_result(cpu, outf, "base-freq", "disable",
1416 ret);
1419 static void set_pbf_enable(int arg)
1421 int enable = arg;
1423 if (cmd_help) {
1424 if (enable) {
1425 fprintf(stderr,
1426 "Enable Intel Speed Select Technology base frequency feature\n");
1427 fprintf(stderr,
1428 "\tOptional Arguments: -a|--auto : Use priority of cores to set core-power associations\n");
1429 } else {
1431 fprintf(stderr,
1432 "Disable Intel Speed Select Technology base frequency feature\n");
1433 fprintf(stderr,
1434 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1436 exit(0);
1439 isst_ctdp_display_information_start(outf);
1440 if (max_target_cpus)
1441 for_each_online_target_cpu_in_set(set_pbf_for_cpu, NULL, NULL,
1442 NULL, &enable);
1443 else
1444 for_each_online_package_in_set(set_pbf_for_cpu, NULL, NULL,
1445 NULL, &enable);
1446 isst_ctdp_display_information_end(outf);
1449 static void dump_fact_config_for_cpu(int cpu, void *arg1, void *arg2,
1450 void *arg3, void *arg4)
1452 struct isst_fact_info fact_info;
1453 int ret;
1455 ret = isst_get_fact_info(cpu, tdp_level, &fact_info);
1456 if (ret)
1457 perror("isst_get_fact_bucket_info");
1458 else
1459 isst_fact_display_information(cpu, outf, tdp_level, fact_bucket,
1460 fact_avx, &fact_info);
1463 static void dump_fact_config(int arg)
1465 if (cmd_help) {
1466 fprintf(stderr,
1467 "Print complete Intel Speed Select Technology turbo frequency configuration for a TDP level. Other arguments are optional.\n");
1468 fprintf(stderr,
1469 "\tArguments: -l|--level : Specify tdp level\n");
1470 fprintf(stderr,
1471 "\tArguments: -b|--bucket : Bucket index to dump\n");
1472 fprintf(stderr,
1473 "\tArguments: -r|--trl-type : Specify trl type: sse|avx2|avx512\n");
1474 exit(0);
1477 if (tdp_level == 0xff) {
1478 fprintf(outf, "Invalid command: specify tdp_level\n");
1479 exit(1);
1482 isst_ctdp_display_information_start(outf);
1483 if (max_target_cpus)
1484 for_each_online_target_cpu_in_set(dump_fact_config_for_cpu,
1485 NULL, NULL, NULL, NULL);
1486 else
1487 for_each_online_package_in_set(dump_fact_config_for_cpu, NULL,
1488 NULL, NULL, NULL);
1489 isst_ctdp_display_information_end(outf);
1492 static void set_fact_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1493 void *arg4)
1495 int ret;
1496 int status = *(int *)arg4;
1498 if (auto_mode && status) {
1499 ret = isst_pm_qos_config(cpu, 1, 1);
1500 if (ret)
1501 goto disp_results;
1504 ret = isst_set_pbf_fact_status(cpu, 0, status);
1505 if (ret) {
1506 perror("isst_set_fact");
1507 if (auto_mode)
1508 isst_pm_qos_config(cpu, 0, 0);
1510 goto disp_results;
1513 /* Set TRL */
1514 if (status) {
1515 struct isst_pkg_ctdp pkg_dev;
1517 ret = isst_get_ctdp_levels(cpu, &pkg_dev);
1518 if (!ret)
1519 ret = isst_set_trl(cpu, fact_trl);
1520 if (ret && auto_mode)
1521 isst_pm_qos_config(cpu, 0, 0);
1522 } else {
1523 if (auto_mode)
1524 isst_pm_qos_config(cpu, 0, 0);
1527 disp_results:
1528 if (status) {
1529 isst_display_result(cpu, outf, "turbo-freq", "enable", ret);
1530 } else {
1531 /* Since we modified TRL during Fact enable, restore it */
1532 isst_set_trl_from_current_tdp(cpu, fact_trl);
1533 isst_display_result(cpu, outf, "turbo-freq", "disable", ret);
1537 static void set_fact_enable(int arg)
1539 int i, ret, enable = arg;
1541 if (cmd_help) {
1542 if (enable) {
1543 fprintf(stderr,
1544 "Enable Intel Speed Select Technology Turbo frequency feature\n");
1545 fprintf(stderr,
1546 "Optional: -t|--trl : Specify turbo ratio limit\n");
1547 fprintf(stderr,
1548 "\tOptional Arguments: -a|--auto : Designate specified target CPUs with");
1549 fprintf(stderr,
1550 "-C|--cpu option as as high priority using core-power feature\n");
1551 } else {
1552 fprintf(stderr,
1553 "Disable Intel Speed Select Technology turbo frequency feature\n");
1554 fprintf(stderr,
1555 "Optional: -t|--trl : Specify turbo ratio limit\n");
1556 fprintf(stderr,
1557 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1559 exit(0);
1562 isst_ctdp_display_information_start(outf);
1563 if (max_target_cpus)
1564 for_each_online_target_cpu_in_set(set_fact_for_cpu, NULL, NULL,
1565 NULL, &enable);
1566 else
1567 for_each_online_package_in_set(set_fact_for_cpu, NULL, NULL,
1568 NULL, &enable);
1569 isst_ctdp_display_information_end(outf);
1571 if (enable && auto_mode) {
1573 * When we adjust CLOS param, we have to set for siblings also.
1574 * So for the each user specified CPU, also add the sibling
1575 * in the present_cpu_mask.
1577 for (i = 0; i < get_topo_max_cpus(); ++i) {
1578 char buffer[128], sibling_list[128], *cpu_str;
1579 int fd, len;
1581 if (!CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
1582 continue;
1584 snprintf(buffer, sizeof(buffer),
1585 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i);
1587 fd = open(buffer, O_RDONLY);
1588 if (fd < 0)
1589 continue;
1591 len = read(fd, sibling_list, sizeof(sibling_list));
1592 close(fd);
1594 if (len < 0)
1595 continue;
1597 cpu_str = strtok(sibling_list, ",");
1598 while (cpu_str != NULL) {
1599 int cpu;
1601 sscanf(cpu_str, "%d", &cpu);
1602 CPU_SET_S(cpu, target_cpumask_size, target_cpumask);
1603 cpu_str = strtok(NULL, ",");
1607 for (i = 0; i < get_topo_max_cpus(); ++i) {
1608 int clos;
1610 if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
1611 continue;
1613 ret = set_clos_param(i, 0, 0, 0, 0, 0xff);
1614 if (ret)
1615 goto error_disp;
1617 ret = set_clos_param(i, 1, 15, 15, 0, 0xff);
1618 if (ret)
1619 goto error_disp;
1621 ret = set_clos_param(i, 2, 15, 15, 0, 0xff);
1622 if (ret)
1623 goto error_disp;
1625 ret = set_clos_param(i, 3, 15, 15, 0, 0xff);
1626 if (ret)
1627 goto error_disp;
1629 if (CPU_ISSET_S(i, target_cpumask_size, target_cpumask))
1630 clos = 0;
1631 else
1632 clos = 3;
1634 debug_printf("Associate cpu: %d clos: %d\n", i, clos);
1635 ret = isst_clos_associate(i, clos);
1636 if (ret)
1637 goto error_disp;
1639 isst_display_result(-1, outf, "turbo-freq --auto", "enable", 0);
1642 return;
1644 error_disp:
1645 isst_display_result(i, outf, "turbo-freq --auto", "enable", ret);
1649 static void enable_clos_qos_config(int cpu, void *arg1, void *arg2, void *arg3,
1650 void *arg4)
1652 int ret;
1653 int status = *(int *)arg4;
1655 ret = isst_pm_qos_config(cpu, status, clos_priority_type);
1656 if (ret)
1657 perror("isst_pm_qos_config");
1659 if (status)
1660 isst_display_result(cpu, outf, "core-power", "enable",
1661 ret);
1662 else
1663 isst_display_result(cpu, outf, "core-power", "disable",
1664 ret);
1667 static void set_clos_enable(int arg)
1669 int enable = arg;
1671 if (cmd_help) {
1672 if (enable) {
1673 fprintf(stderr,
1674 "Enable core-power for a package/die\n");
1675 fprintf(stderr,
1676 "\tClos Enable: Specify priority type with [--priority|-p]\n");
1677 fprintf(stderr, "\t\t 0: Proportional, 1: Ordered\n");
1678 } else {
1679 fprintf(stderr,
1680 "Disable core-power: [No command arguments are required]\n");
1682 exit(0);
1685 if (enable && cpufreq_sysfs_present()) {
1686 fprintf(stderr,
1687 "cpufreq subsystem and core-power enable will interfere with each other!\n");
1690 isst_ctdp_display_information_start(outf);
1691 if (max_target_cpus)
1692 for_each_online_target_cpu_in_set(enable_clos_qos_config, NULL,
1693 NULL, NULL, &enable);
1694 else
1695 for_each_online_package_in_set(enable_clos_qos_config, NULL,
1696 NULL, NULL, &enable);
1697 isst_ctdp_display_information_end(outf);
1700 static void dump_clos_config_for_cpu(int cpu, void *arg1, void *arg2,
1701 void *arg3, void *arg4)
1703 struct isst_clos_config clos_config;
1704 int ret;
1706 ret = isst_pm_get_clos(cpu, current_clos, &clos_config);
1707 if (ret)
1708 perror("isst_pm_get_clos");
1709 else
1710 isst_clos_display_information(cpu, outf, current_clos,
1711 &clos_config);
1714 static void dump_clos_config(int arg)
1716 if (cmd_help) {
1717 fprintf(stderr,
1718 "Print Intel Speed Select Technology core power configuration\n");
1719 fprintf(stderr,
1720 "\tArguments: [-c | --clos]: Specify clos id\n");
1721 exit(0);
1723 if (current_clos < 0 || current_clos > 3) {
1724 fprintf(stderr, "Invalid clos id\n");
1725 exit(0);
1728 isst_ctdp_display_information_start(outf);
1729 if (max_target_cpus)
1730 for_each_online_target_cpu_in_set(dump_clos_config_for_cpu,
1731 NULL, NULL, NULL, NULL);
1732 else
1733 for_each_online_package_in_set(dump_clos_config_for_cpu, NULL,
1734 NULL, NULL, NULL);
1735 isst_ctdp_display_information_end(outf);
1738 static void get_clos_info_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1739 void *arg4)
1741 int enable, ret, prio_type;
1743 ret = isst_clos_get_clos_information(cpu, &enable, &prio_type);
1744 if (ret)
1745 perror("isst_clos_get_info");
1746 else
1747 isst_clos_display_clos_information(cpu, outf, enable, prio_type);
1750 static void dump_clos_info(int arg)
1752 if (cmd_help) {
1753 fprintf(stderr,
1754 "Print Intel Speed Select Technology core power information\n");
1755 fprintf(stderr, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1756 exit(0);
1759 if (!max_target_cpus) {
1760 fprintf(stderr,
1761 "Invalid target cpu. Specify with [-c|--cpu]\n");
1762 exit(0);
1765 isst_ctdp_display_information_start(outf);
1766 for_each_online_target_cpu_in_set(get_clos_info_for_cpu, NULL,
1767 NULL, NULL, NULL);
1768 isst_ctdp_display_information_end(outf);
1772 static void set_clos_config_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1773 void *arg4)
1775 struct isst_clos_config clos_config;
1776 int ret;
1778 clos_config.pkg_id = get_physical_package_id(cpu);
1779 clos_config.die_id = get_physical_die_id(cpu);
1781 clos_config.epp = clos_epp;
1782 clos_config.clos_prop_prio = clos_prop_prio;
1783 clos_config.clos_min = clos_min;
1784 clos_config.clos_max = clos_max;
1785 clos_config.clos_desired = clos_desired;
1786 ret = isst_set_clos(cpu, current_clos, &clos_config);
1787 if (ret)
1788 perror("isst_set_clos");
1789 else
1790 isst_display_result(cpu, outf, "core-power", "config", ret);
1793 static void set_clos_config(int arg)
1795 if (cmd_help) {
1796 fprintf(stderr,
1797 "Set core-power configuration for one of the four clos ids\n");
1798 fprintf(stderr,
1799 "\tSpecify targeted clos id with [--clos|-c]\n");
1800 fprintf(stderr, "\tSpecify clos EPP with [--epp|-e]\n");
1801 fprintf(stderr,
1802 "\tSpecify clos Proportional Priority [--weight|-w]\n");
1803 fprintf(stderr, "\tSpecify clos min in MHz with [--min|-n]\n");
1804 fprintf(stderr, "\tSpecify clos max in MHz with [--max|-m]\n");
1805 fprintf(stderr, "\tSpecify clos desired in MHz with [--desired|-d]\n");
1806 exit(0);
1809 if (current_clos < 0 || current_clos > 3) {
1810 fprintf(stderr, "Invalid clos id\n");
1811 exit(0);
1813 if (clos_epp < 0 || clos_epp > 0x0F) {
1814 fprintf(stderr, "clos epp is not specified, default: 0\n");
1815 clos_epp = 0;
1817 if (clos_prop_prio < 0 || clos_prop_prio > 0x0F) {
1818 fprintf(stderr,
1819 "clos frequency weight is not specified, default: 0\n");
1820 clos_prop_prio = 0;
1822 if (clos_min < 0) {
1823 fprintf(stderr, "clos min is not specified, default: 0\n");
1824 clos_min = 0;
1826 if (clos_max < 0) {
1827 fprintf(stderr, "clos max is not specified, default: 25500 MHz\n");
1828 clos_max = 0xff;
1830 if (clos_desired < 0) {
1831 fprintf(stderr, "clos desired is not specified, default: 0\n");
1832 clos_desired = 0x00;
1835 isst_ctdp_display_information_start(outf);
1836 if (max_target_cpus)
1837 for_each_online_target_cpu_in_set(set_clos_config_for_cpu, NULL,
1838 NULL, NULL, NULL);
1839 else
1840 for_each_online_package_in_set(set_clos_config_for_cpu, NULL,
1841 NULL, NULL, NULL);
1842 isst_ctdp_display_information_end(outf);
1845 static void set_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1846 void *arg4)
1848 int ret;
1850 ret = isst_clos_associate(cpu, current_clos);
1851 if (ret)
1852 perror("isst_clos_associate");
1853 else
1854 isst_display_result(cpu, outf, "core-power", "assoc", ret);
1857 static void set_clos_assoc(int arg)
1859 if (cmd_help) {
1860 fprintf(stderr, "Associate a clos id to a CPU\n");
1861 fprintf(stderr,
1862 "\tSpecify targeted clos id with [--clos|-c]\n");
1863 exit(0);
1866 if (current_clos < 0 || current_clos > 3) {
1867 fprintf(stderr, "Invalid clos id\n");
1868 exit(0);
1870 if (max_target_cpus)
1871 for_each_online_target_cpu_in_set(set_clos_assoc_for_cpu, NULL,
1872 NULL, NULL, NULL);
1873 else {
1874 fprintf(stderr,
1875 "Invalid target cpu. Specify with [-c|--cpu]\n");
1879 static void get_clos_assoc_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
1880 void *arg4)
1882 int clos, ret;
1884 ret = isst_clos_get_assoc_status(cpu, &clos);
1885 if (ret)
1886 perror("isst_clos_get_assoc_status");
1887 else
1888 isst_clos_display_assoc_information(cpu, outf, clos);
1891 static void get_clos_assoc(int arg)
1893 if (cmd_help) {
1894 fprintf(stderr, "Get associate clos id to a CPU\n");
1895 fprintf(stderr, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1896 exit(0);
1899 if (!max_target_cpus) {
1900 fprintf(stderr,
1901 "Invalid target cpu. Specify with [-c|--cpu]\n");
1902 exit(0);
1905 isst_ctdp_display_information_start(outf);
1906 for_each_online_target_cpu_in_set(get_clos_assoc_for_cpu, NULL,
1907 NULL, NULL, NULL);
1908 isst_ctdp_display_information_end(outf);
1911 static struct process_cmd_struct clx_n_cmds[] = {
1912 { "perf-profile", "info", dump_isst_config, 0 },
1913 { "base-freq", "info", dump_pbf_config, 0 },
1914 { "base-freq", "enable", set_pbf_enable, 1 },
1915 { "base-freq", "disable", set_pbf_enable, 0 },
1916 { NULL, NULL, NULL, 0 }
1919 static struct process_cmd_struct isst_cmds[] = {
1920 { "perf-profile", "get-lock-status", get_tdp_locked, 0 },
1921 { "perf-profile", "get-config-levels", get_tdp_levels, 0 },
1922 { "perf-profile", "get-config-version", get_tdp_version, 0 },
1923 { "perf-profile", "get-config-enabled", get_tdp_enabled, 0 },
1924 { "perf-profile", "get-config-current-level", get_tdp_current_level,
1925 0 },
1926 { "perf-profile", "set-config-level", set_tdp_level, 0 },
1927 { "perf-profile", "info", dump_isst_config, 0 },
1928 { "base-freq", "info", dump_pbf_config, 0 },
1929 { "base-freq", "enable", set_pbf_enable, 1 },
1930 { "base-freq", "disable", set_pbf_enable, 0 },
1931 { "turbo-freq", "info", dump_fact_config, 0 },
1932 { "turbo-freq", "enable", set_fact_enable, 1 },
1933 { "turbo-freq", "disable", set_fact_enable, 0 },
1934 { "core-power", "info", dump_clos_info, 0 },
1935 { "core-power", "enable", set_clos_enable, 1 },
1936 { "core-power", "disable", set_clos_enable, 0 },
1937 { "core-power", "config", set_clos_config, 0 },
1938 { "core-power", "get-config", dump_clos_config, 0 },
1939 { "core-power", "assoc", set_clos_assoc, 0 },
1940 { "core-power", "get-assoc", get_clos_assoc, 0 },
1941 { NULL, NULL, NULL }
1945 * parse cpuset with following syntax
1946 * 1,2,4..6,8-10 and set bits in cpu_subset
1948 void parse_cpu_command(char *optarg)
1950 unsigned int start, end;
1951 char *next;
1953 next = optarg;
1955 while (next && *next) {
1956 if (*next == '-') /* no negative cpu numbers */
1957 goto error;
1959 start = strtoul(next, &next, 10);
1961 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
1962 target_cpus[max_target_cpus++] = start;
1964 if (*next == '\0')
1965 break;
1967 if (*next == ',') {
1968 next += 1;
1969 continue;
1972 if (*next == '-') {
1973 next += 1; /* start range */
1974 } else if (*next == '.') {
1975 next += 1;
1976 if (*next == '.')
1977 next += 1; /* start range */
1978 else
1979 goto error;
1982 end = strtoul(next, &next, 10);
1983 if (end <= start)
1984 goto error;
1986 while (++start <= end) {
1987 if (max_target_cpus < MAX_CPUS_IN_ONE_REQ)
1988 target_cpus[max_target_cpus++] = start;
1991 if (*next == ',')
1992 next += 1;
1993 else if (*next != '\0')
1994 goto error;
1997 #ifdef DEBUG
1999 int i;
2001 for (i = 0; i < max_target_cpus; ++i)
2002 printf("cpu [%d] in arg\n", target_cpus[i]);
2004 #endif
2005 return;
2007 error:
2008 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg);
2009 exit(-1);
2012 static void parse_cmd_args(int argc, int start, char **argv)
2014 int opt;
2015 int option_index;
2017 static struct option long_options[] = {
2018 { "bucket", required_argument, 0, 'b' },
2019 { "level", required_argument, 0, 'l' },
2020 { "online", required_argument, 0, 'o' },
2021 { "trl-type", required_argument, 0, 'r' },
2022 { "trl", required_argument, 0, 't' },
2023 { "help", no_argument, 0, 'h' },
2024 { "clos", required_argument, 0, 'c' },
2025 { "desired", required_argument, 0, 'd' },
2026 { "epp", required_argument, 0, 'e' },
2027 { "min", required_argument, 0, 'n' },
2028 { "max", required_argument, 0, 'm' },
2029 { "priority", required_argument, 0, 'p' },
2030 { "weight", required_argument, 0, 'w' },
2031 { "auto", no_argument, 0, 'a' },
2032 { 0, 0, 0, 0 }
2035 option_index = start;
2037 optind = start + 1;
2038 while ((opt = getopt_long(argc, argv, "b:l:t:c:d:e:n:m:p:w:hoa",
2039 long_options, &option_index)) != -1) {
2040 switch (opt) {
2041 case 'a':
2042 auto_mode = 1;
2043 break;
2044 case 'b':
2045 fact_bucket = atoi(optarg);
2046 break;
2047 case 'h':
2048 cmd_help = 1;
2049 break;
2050 case 'l':
2051 tdp_level = atoi(optarg);
2052 break;
2053 case 'o':
2054 force_online_offline = 1;
2055 break;
2056 case 't':
2057 sscanf(optarg, "0x%llx", &fact_trl);
2058 break;
2059 case 'r':
2060 if (!strncmp(optarg, "sse", 3)) {
2061 fact_avx = 0x01;
2062 } else if (!strncmp(optarg, "avx2", 4)) {
2063 fact_avx = 0x02;
2064 } else if (!strncmp(optarg, "avx512", 4)) {
2065 fact_avx = 0x04;
2066 } else {
2067 fprintf(outf, "Invalid sse,avx options\n");
2068 exit(1);
2070 break;
2071 /* CLOS related */
2072 case 'c':
2073 current_clos = atoi(optarg);
2074 break;
2075 case 'd':
2076 clos_desired = atoi(optarg);
2077 clos_desired /= DISP_FREQ_MULTIPLIER;
2078 break;
2079 case 'e':
2080 clos_epp = atoi(optarg);
2081 break;
2082 case 'n':
2083 clos_min = atoi(optarg);
2084 clos_min /= DISP_FREQ_MULTIPLIER;
2085 break;
2086 case 'm':
2087 clos_max = atoi(optarg);
2088 clos_max /= DISP_FREQ_MULTIPLIER;
2089 break;
2090 case 'p':
2091 clos_priority_type = atoi(optarg);
2092 break;
2093 case 'w':
2094 clos_prop_prio = atoi(optarg);
2095 break;
2096 default:
2097 printf("no match\n");
2102 static void isst_help(void)
2104 printf("perf-profile:\tAn architectural mechanism that allows multiple optimized \n\
2105 performance profiles per system via static and/or dynamic\n\
2106 adjustment of core count, workload, Tjmax, and\n\
2107 TDP, etc.\n");
2108 printf("\nCommands : For feature=perf-profile\n");
2109 printf("\tinfo\n");
2111 if (!is_clx_n_platform()) {
2112 printf("\tget-lock-status\n");
2113 printf("\tget-config-levels\n");
2114 printf("\tget-config-version\n");
2115 printf("\tget-config-enabled\n");
2116 printf("\tget-config-current-level\n");
2117 printf("\tset-config-level\n");
2121 static void pbf_help(void)
2123 printf("base-freq:\tEnables users to increase guaranteed base frequency\n\
2124 on certain cores (high priority cores) in exchange for lower\n\
2125 base frequency on remaining cores (low priority cores).\n");
2126 printf("\tcommand : info\n");
2127 printf("\tcommand : enable\n");
2128 printf("\tcommand : disable\n");
2131 static void fact_help(void)
2133 printf("turbo-freq:\tEnables the ability to set different turbo ratio\n\
2134 limits to cores based on priority.\n");
2135 printf("\nCommand: For feature=turbo-freq\n");
2136 printf("\tcommand : info\n");
2137 printf("\tcommand : enable\n");
2138 printf("\tcommand : disable\n");
2141 static void core_power_help(void)
2143 printf("core-power:\tInterface that allows user to define per core/tile\n\
2144 priority.\n");
2145 printf("\nCommands : For feature=core-power\n");
2146 printf("\tinfo\n");
2147 printf("\tenable\n");
2148 printf("\tdisable\n");
2149 printf("\tconfig\n");
2150 printf("\tget-config\n");
2151 printf("\tassoc\n");
2152 printf("\tget-assoc\n");
2155 struct process_cmd_help_struct {
2156 char *feature;
2157 void (*process_fn)(void);
2160 static struct process_cmd_help_struct isst_help_cmds[] = {
2161 { "perf-profile", isst_help },
2162 { "base-freq", pbf_help },
2163 { "turbo-freq", fact_help },
2164 { "core-power", core_power_help },
2165 { NULL, NULL }
2168 static struct process_cmd_help_struct clx_n_help_cmds[] = {
2169 { "perf-profile", isst_help },
2170 { "base-freq", pbf_help },
2171 { NULL, NULL }
2174 void process_command(int argc, char **argv,
2175 struct process_cmd_help_struct *help_cmds,
2176 struct process_cmd_struct *cmds)
2178 int i = 0, matched = 0;
2179 char *feature = argv[optind];
2180 char *cmd = argv[optind + 1];
2182 if (!feature || !cmd)
2183 return;
2185 debug_printf("feature name [%s] command [%s]\n", feature, cmd);
2186 if (!strcmp(cmd, "-h") || !strcmp(cmd, "--help")) {
2187 while (help_cmds[i].feature) {
2188 if (!strcmp(help_cmds[i].feature, feature)) {
2189 help_cmds[i].process_fn();
2190 exit(0);
2192 ++i;
2196 if (!is_clx_n_platform())
2197 create_cpu_map();
2199 i = 0;
2200 while (cmds[i].feature) {
2201 if (!strcmp(cmds[i].feature, feature) &&
2202 !strcmp(cmds[i].command, cmd)) {
2203 parse_cmd_args(argc, optind + 1, argv);
2204 cmds[i].process_fn(cmds[i].arg);
2205 matched = 1;
2206 break;
2208 ++i;
2211 if (!matched)
2212 fprintf(stderr, "Invalid command\n");
2215 static void usage(void)
2217 printf("Intel(R) Speed Select Technology\n");
2218 printf("\nUsage:\n");
2219 printf("intel-speed-select [OPTIONS] FEATURE COMMAND COMMAND_ARGUMENTS\n");
2220 printf("\nUse this tool to enumerate and control the Intel Speed Select Technology features,\n");
2221 printf("\nFEATURE : [perf-profile|base-freq|turbo-freq|core-power]\n");
2222 printf("\nFor help on each feature, use -h|--help\n");
2223 printf("\tFor example: intel-speed-select perf-profile -h\n");
2225 printf("\nFor additional help on each command for a feature, use --h|--help\n");
2226 printf("\tFor example: intel-speed-select perf-profile get-lock-status -h\n");
2227 printf("\t\t This will print help for the command \"get-lock-status\" for the feature \"perf-profile\"\n");
2229 printf("\nOPTIONS\n");
2230 printf("\t[-c|--cpu] : logical cpu number\n");
2231 printf("\t\tDefault: Die scoped for all dies in the system with multiple dies/package\n");
2232 printf("\t\t\t Or Package scoped for all Packages when each package contains one die\n");
2233 printf("\t[-d|--debug] : Debug mode\n");
2234 printf("\t[-h|--help] : Print help\n");
2235 printf("\t[-i|--info] : Print platform information\n");
2236 printf("\t[-o|--out] : Output file\n");
2237 printf("\t\t\tDefault : stderr\n");
2238 printf("\t[-f|--format] : output format [json|text]. Default: text\n");
2239 printf("\t[-v|--version] : Print version\n");
2241 printf("\nResult format\n");
2242 printf("\tResult display uses a common format for each command:\n");
2243 printf("\tResults are formatted in text/JSON with\n");
2244 printf("\t\tPackage, Die, CPU, and command specific results.\n");
2245 exit(1);
2248 static void print_version(void)
2250 fprintf(outf, "Version %s\n", version_str);
2251 fprintf(outf, "Build date %s time %s\n", __DATE__, __TIME__);
2252 exit(0);
2255 static void cmdline(int argc, char **argv)
2257 int opt;
2258 int option_index = 0;
2259 int ret;
2261 static struct option long_options[] = {
2262 { "cpu", required_argument, 0, 'c' },
2263 { "debug", no_argument, 0, 'd' },
2264 { "format", required_argument, 0, 'f' },
2265 { "help", no_argument, 0, 'h' },
2266 { "info", no_argument, 0, 'i' },
2267 { "out", required_argument, 0, 'o' },
2268 { "version", no_argument, 0, 'v' },
2269 { 0, 0, 0, 0 }
2272 progname = argv[0];
2273 while ((opt = getopt_long_only(argc, argv, "+c:df:hio:v", long_options,
2274 &option_index)) != -1) {
2275 switch (opt) {
2276 case 'c':
2277 parse_cpu_command(optarg);
2278 break;
2279 case 'd':
2280 debug_flag = 1;
2281 printf("Debug Mode ON\n");
2282 break;
2283 case 'f':
2284 if (!strncmp(optarg, "json", 4))
2285 out_format_json = 1;
2286 break;
2287 case 'h':
2288 usage();
2289 break;
2290 case 'i':
2291 isst_print_platform_information();
2292 break;
2293 case 'o':
2294 if (outf)
2295 fclose(outf);
2296 outf = fopen_or_exit(optarg, "w");
2297 break;
2298 case 'v':
2299 print_version();
2300 break;
2301 default:
2302 usage();
2306 if (geteuid() != 0) {
2307 fprintf(stderr, "Must run as root\n");
2308 exit(0);
2311 if (optind > (argc - 2)) {
2312 fprintf(stderr, "Feature name and|or command not specified\n");
2313 exit(0);
2315 ret = update_cpu_model();
2316 if (ret)
2317 err(-1, "Invalid CPU model (%d)\n", cpu_model);
2318 printf("Intel(R) Speed Select Technology\n");
2319 printf("Executing on CPU model:%d[0x%x]\n", cpu_model, cpu_model);
2320 set_max_cpu_num();
2321 set_cpu_present_cpu_mask();
2322 set_cpu_target_cpu_mask();
2324 if (!is_clx_n_platform()) {
2325 ret = isst_fill_platform_info();
2326 if (ret)
2327 goto out;
2328 process_command(argc, argv, isst_help_cmds, isst_cmds);
2329 } else {
2330 process_command(argc, argv, clx_n_help_cmds, clx_n_cmds);
2332 out:
2333 free_cpu_set(present_cpumask);
2334 free_cpu_set(target_cpumask);
2337 int main(int argc, char **argv)
2339 outf = stderr;
2340 cmdline(argc, argv);
2341 return 0;