1 // SPDX-License-Identifier: GPL-2.0
3 * Intel Speed Select -- Enumerate and control features
4 * Copyright (c) 2019 Intel Corporation.
7 #include <linux/isst_if.h>
11 struct process_cmd_struct
{
14 void (*process_fn
)(int arg
);
18 static const char *version_str
= "v1.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
;
26 static int cpu_stepping
;
28 #define MAX_CPUS_IN_ONE_REQ 64
29 static short max_target_cpus
;
30 static unsigned short target_cpus
[MAX_CPUS_IN_ONE_REQ
];
32 static int topo_max_cpus
;
33 static size_t present_cpumask_size
;
34 static cpu_set_t
*present_cpumask
;
35 static size_t target_cpumask_size
;
36 static cpu_set_t
*target_cpumask
;
37 static int tdp_level
= 0xFF;
38 static int fact_bucket
= 0xFF;
39 static int fact_avx
= 0xFF;
40 static unsigned long long fact_trl
;
41 static int out_format_json
;
43 static int force_online_offline
;
47 static int current_clos
= -1;
48 static int clos_epp
= -1;
49 static int clos_prop_prio
= -1;
50 static int clos_min
= -1;
51 static int clos_max
= -1;
52 static int clos_desired
= -1;
53 static int clos_priority_type
;
56 unsigned short core_id
;
57 unsigned short pkg_id
;
58 unsigned short die_id
;
59 unsigned short punit_cpu
;
60 unsigned short punit_cpu_core
;
62 struct _cpu_map
*cpu_map
;
64 void debug_printf(const char *format
, ...)
68 va_start(args
, format
);
71 vprintf(format
, args
);
77 int is_clx_n_platform(void)
79 if (cpu_model
== 0x55)
80 if (cpu_stepping
== 0x6 || cpu_stepping
== 0x7)
85 static int update_cpu_model(void)
87 unsigned int ebx
, ecx
, edx
;
88 unsigned int fms
, family
;
90 __cpuid(1, fms
, ebx
, ecx
, edx
);
91 family
= (fms
>> 8) & 0xf;
92 cpu_model
= (fms
>> 4) & 0xf;
93 if (family
== 6 || family
== 0xf)
94 cpu_model
+= ((fms
>> 16) & 0xf) << 4;
96 cpu_stepping
= fms
& 0xf;
97 /* only three CascadeLake-N models are supported */
98 if (is_clx_n_platform()) {
104 fp
= fopen("/proc/cpuinfo", "r");
106 err(-1, "cannot open /proc/cpuinfo\n");
108 while (getline(&line
, &n
, fp
) > 0) {
109 if (strstr(line
, "model name")) {
110 if (strstr(line
, "6252N") ||
111 strstr(line
, "6230N") ||
112 strstr(line
, "5218N"))
124 /* Open a file, and exit on failure */
125 static FILE *fopen_or_exit(const char *path
, const char *mode
)
127 FILE *filep
= fopen(path
, mode
);
130 err(1, "%s: open failed", path
);
135 /* Parse a file containing a single int */
136 static int parse_int_file(int fatal
, const char *fmt
, ...)
144 vsnprintf(path
, sizeof(path
), fmt
, args
);
147 filep
= fopen_or_exit(path
, "r");
149 filep
= fopen(path
, "r");
153 if (fscanf(filep
, "%d", &value
) != 1)
154 err(1, "%s: failed to parse number from file", path
);
160 int cpufreq_sysfs_present(void)
164 dir
= opendir("/sys/devices/system/cpu/cpu0/cpufreq");
173 int out_format_is_json(void)
175 return out_format_json
;
178 int get_physical_package_id(int cpu
)
180 return parse_int_file(
181 0, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",
185 int get_physical_core_id(int cpu
)
187 return parse_int_file(
188 0, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu
);
191 int get_physical_die_id(int cpu
)
195 ret
= parse_int_file(0, "/sys/devices/system/cpu/cpu%d/topology/die_id",
203 int get_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
)
218 snprintf(buffer
, sizeof(buffer
),
219 "/sys/devices/system/cpu/cpu%d/online", cpu
);
221 fd
= open(buffer
, O_WRONLY
);
223 err(-1, "%s open failed", buffer
);
226 ret
= write(fd
, "1\n", 2);
228 ret
= write(fd
, "0\n", 2);
231 perror("Online/Offline: Operation failed\n");
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 *,
240 void *arg1
, void *arg2
, void *arg3
,
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
))
253 online
= parse_int_file(
254 1, "/sys/devices/system/cpu/cpu%d/online", i
);
257 1; /* online entry for CPU 0 needs some special configs */
259 die_id
= get_physical_die_id(i
);
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
) {
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
)
286 for (i
= 0; i
< topo_max_cpus
; ++i
) {
289 if (!CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
292 online
= parse_int_file(
293 1, "/sys/devices/system/cpu/cpu%d/online", i
);
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)
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
;
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
)
325 _cpu_set
= CPU_ALLOC((topo_max_cpus
+ 1));
326 if (_cpu_set
== NULL
)
328 size
= CPU_ALLOC_SIZE((topo_max_cpus
+ 1));
329 CPU_ZERO_S(size
, _cpu_set
);
335 void free_cpu_set(cpu_set_t
*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)
348 size
= alloc_cpu_set(&present_cpumask
);
349 present_cpumask_size
= size
;
350 for (i
= 0; i
< topo_max_cpus
; ++i
) {
353 snprintf(buffer
, sizeof(buffer
),
354 "/sys/devices/system/cpu/cpu%d", i
);
355 dir
= opendir(buffer
);
359 CPU_SET_S(i
, size
, present_cpumask
);
360 die_id
= get_physical_die_id(i
);
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
);
377 int get_core_count(int pkg_id
, int die_id
)
381 if (pkg_id
< MAX_PACKAGE_COUNT
&& die_id
< MAX_DIE_PER_PACKAGE
) {
384 for (i
= 0; i
< sizeof(long long) * 8; ++i
) {
385 if (core_mask
[pkg_id
][die_id
] & (1ULL << i
))
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
];
401 static void set_cpu_target_cpu_mask(void)
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
,
413 CPU_SET_S(target_cpus
[i
], size
, target_cpumask
);
417 static void create_cpu_map(void)
419 const char *pathname
= "/dev/isst_interface";
421 struct isst_if_cpu_maps map
;
423 cpu_map
= malloc(sizeof(*cpu_map
) * topo_max_cpus
);
427 fd
= open(pathname
, O_RDWR
);
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
))
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
);
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
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
);
464 int find_logical_cpu(int pkg_id
, int die_id
, int punit_core_id
)
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
)
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
)
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
)) {
493 for (j
= 0; j
< topo_max_cpus
; ++j
) {
494 if (!CPU_ISSET_S(j
, present_cpumask_size
, present_cpumask
))
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
,
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
;
519 static int isst_send_mmio_command(unsigned int cpu
, unsigned int reg
, int write
,
522 struct isst_if_io_regs io_regs
;
523 const char *pathname
= "/dev/isst_interface";
527 debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu
, reg
, write
);
529 fd
= open(pathname
, O_RDWR
);
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
;
538 io_regs
.io_reg
[0].read_write
= 1;
539 io_regs
.io_reg
[0].value
= *value
;
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",
550 *value
= io_regs
.io_reg
[0].value
;
553 "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
554 cpu
, reg
, write
, *value
);
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";
568 struct isst_if_mbox_cmds mbox_cmds
= { 0 };
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
) {
577 int clos_id
, core_id
, ret
= 0;
579 debug_printf("CPU %d\n", cpu
);
581 if (parameter
& BIT(MBOX_CMD_WRITE_BIT
)) {
586 switch (sub_command
) {
588 core_id
= parameter
& 0xff;
589 ret
= isst_send_mmio_command(
590 cpu
, PQR_ASSOC_OFFSET
+ core_id
* 4, write
,
596 clos_id
= parameter
& 0x03;
597 ret
= isst_send_mmio_command(
598 cpu
, PM_CLOS_OFFSET
+ clos_id
* 4, write
,
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
);
620 err(-1, "%s open failed", pathname
);
622 if (ioctl(fd
, ISST_IF_MBOX_COMMAND
, &mbox_cmds
) == -1) {
623 perror("ISST_IF_MBOX_COMMAND");
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
);
629 *resp
= mbox_cmds
.mbox_cmd
[0].resp_data
;
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
);
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";
647 fd
= open(pathname
, O_RDWR
);
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
;
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",
664 *req_resp
= msr_cmds
.msr_cmd
[0].data
;
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
);
676 static int isst_fill_platform_info(void)
678 const char *pathname
= "/dev/isst_interface";
681 fd
= open(pathname
, O_RDWR
);
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");
693 if (isst_platform_info
.api_version
> supported_api_ver
) {
694 printf("Incompatible API versions; Upgrade of tool is required\n");
700 static void isst_print_platform_information(void)
702 struct isst_if_platform_info platform_info
;
703 const char *pathname
= "/dev/isst_interface";
706 fd
= open(pathname
, O_RDWR
);
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");
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
);
728 static void exec_on_get_ctdp_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
731 int (*fn_ptr
)(int cpu
, void *arg
);
735 ret
= fn_ptr(cpu
, arg2
);
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; \
750 "Print %s [No command arguments are required]\n", \
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); \
760 for_each_online_package_in_set(exec_on_get_ctdp_cpu, \
761 isst_get_ctdp_##suffix, \
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)
779 char *begin
, *end
, *line
= NULL
;
784 fp
= fopen("/proc/cpuinfo", "r");
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;
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");
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
))
835 if (pkg_id
!= get_physical_package_id(i
) ||
836 die_id
!= get_physical_die_id(i
))
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");
857 if (pbf_info
->p1_low
== 0) {
858 debug_printf("CLX: minimum base frequency not set\n");
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
))
873 if (pkg_id
!= get_physical_package_id(i
) ||
874 die_id
!= get_physical_die_id(i
))
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;
896 free_cpu_set(ctdp_level
->core_cpumask
);
900 static void dump_clx_n_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
901 void *arg3
, void *arg4
)
905 ret
= clx_n_config(cpu
);
907 perror("isst_get_process_ctdp");
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
;
926 memset(&pkg_dev
, 0, sizeof(pkg_dev
));
927 ret
= isst_get_process_ctdp(cpu
, tdp_level
, &pkg_dev
);
929 perror("isst_get_process_ctdp");
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
)
942 "Print Intel(R) Speed Select Technology Performance profile configuration\n");
944 "including base frequency and turbo frequency configurations\n");
945 fprintf(stderr
, "Optional: -l|--level : Specify tdp level\n");
947 "\tIf no arguments, dump information for all TDP levels\n");
951 if (!is_clx_n_platform())
952 fn
= dump_isst_config_for_cpu
;
954 fn
= dump_clx_n_config_for_cpu
;
956 isst_ctdp_display_information_start(outf
);
959 for_each_online_target_cpu_in_set(fn
, NULL
, NULL
, NULL
, NULL
);
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
,
971 ret
= isst_set_tdp_level(cpu
, tdp_level
);
973 perror("set_tdp_level_for_cpu");
975 isst_display_result(cpu
, outf
, "perf-profile", "set_tdp_level",
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
))
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);
995 fprintf(stderr
, "offline cpu %d\n", i
);
996 set_cpu_online_offline(i
, 0);
1004 static void set_tdp_level(int arg
)
1007 fprintf(stderr
, "Set Config TDP level\n");
1009 "\t Arguments: -l|--level : Specify tdp level\n");
1011 "\t Optional Arguments: -o | online : online/offline for the tdp level\n");
1015 if (tdp_level
== 0xff) {
1016 fprintf(outf
, "Invalid command: specify tdp_level\n");
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
,
1024 for_each_online_package_in_set(set_tdp_level_for_cpu
, 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
)
1034 ret
= clx_n_config(cpu
);
1036 perror("isst_get_process_ctdp");
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
,
1052 struct isst_pbf_info pbf_info
;
1055 ret
= isst_get_pbf_info(cpu
, tdp_level
, &pbf_info
);
1057 perror("isst_get_pbf_info");
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
)
1070 "Print Intel(R) Speed Select Technology base frequency configuration for a TDP level\n");
1072 "\tArguments: -l|--level : Specify tdp level\n");
1076 if (tdp_level
== 0xff) {
1077 fprintf(outf
, "Invalid command: specify tdp_level\n");
1081 if (!is_clx_n_platform())
1082 fn
= dump_pbf_config_for_cpu
;
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
);
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
;
1101 ret
= isst_pm_get_clos(cpu
, clos
, &clos_config
);
1103 perror("isst_pm_get_clos");
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
);
1112 perror("isst_pm_set_clos");
1119 static int set_cpufreq_scaling_min_max(int cpu
, int max
, int freq
)
1121 char buffer
[128], freq_str
[16];
1125 snprintf(buffer
, sizeof(buffer
),
1126 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu
);
1128 snprintf(buffer
, sizeof(buffer
),
1129 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu
);
1131 fd
= open(buffer
, O_WRONLY
);
1135 snprintf(freq_str
, sizeof(freq_str
), "%d", freq
);
1136 len
= strlen(freq_str
);
1137 ret
= write(fd
, freq_str
, len
);
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
;
1154 ret
= clx_n_config(cpu
);
1156 perror("set_clx_pbf_cpufreq_scaling_min_max");
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
))
1172 if (CPU_ISSET_S(i
, pbf_info
->core_cpumask_size
,
1173 pbf_info
->core_cpumask
))
1178 set_cpufreq_scaling_min_max(i
, 1, freq
);
1179 set_cpufreq_scaling_min_max(i
, 0, freq
);
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];
1190 if (!CPU_ISSET_S(cpu
, present_cpumask_size
, present_cpumask
))
1194 snprintf(buffer
, sizeof(buffer
),
1195 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu
);
1197 snprintf(buffer
, sizeof(buffer
),
1198 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", cpu
);
1200 fd
= open(buffer
, O_RDONLY
);
1204 len
= read(fd
, min_freq
, sizeof(min_freq
));
1211 snprintf(buffer
, sizeof(buffer
),
1212 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu
);
1214 snprintf(buffer
, sizeof(buffer
),
1215 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu
);
1217 fd
= open(buffer
, O_WRONLY
);
1221 len
= strlen(min_freq
);
1222 ret
= write(fd
, min_freq
, len
);
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
))
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
))
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
))
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
,
1281 int pkg_id
, die_id
, ret
, i
;
1283 if (!CPU_COUNT_S(mask_size
, cpu_mask
))
1286 ret
= set_clos_param(cpu
, 0, 0, 0, min_high
, 0xff);
1290 ret
= set_clos_param(cpu
, 1, 15, 15, min_low
, 0xff);
1294 ret
= set_clos_param(cpu
, 2, 15, 15, min_low
, 0xff);
1298 ret
= set_clos_param(cpu
, 3, 15, 15, min_low
, 0xff);
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
) {
1307 if (pkg_id
!= get_physical_package_id(i
) ||
1308 die_id
!= get_physical_die_id(i
))
1311 if (CPU_ISSET_S(i
, mask_size
, cpu_mask
))
1316 debug_printf("Associate cpu: %d clos: %d\n", i
, clos
);
1317 ret
= isst_clos_associate(i
, clos
);
1319 perror("isst_clos_associate");
1327 static int set_pbf_core_power(int cpu
)
1329 struct isst_pbf_info pbf_info
;
1330 struct isst_pkg_ctdp pkg_dev
;
1333 ret
= isst_get_ctdp_levels(cpu
, &pkg_dev
);
1335 perror("isst_get_ctdp_levels");
1338 debug_printf("Current_level: %d\n", pkg_dev
.current_level
);
1340 ret
= isst_get_pbf_info(cpu
, pkg_dev
.current_level
, &pbf_info
);
1342 perror("isst_get_pbf_info");
1345 debug_printf("p1_high: %d p1_low: %d\n", pbf_info
.p1_high
,
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
);
1352 perror("set_core_priority_and_min");
1356 ret
= isst_pm_qos_config(cpu
, 1, 1);
1358 perror("isst_pm_qos_config");
1365 static void set_pbf_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1369 int status
= *(int *)arg4
;
1371 if (is_clx_n_platform()) {
1375 set_clx_pbf_cpufreq_scaling_min_max(cpu
);
1380 set_scaling_max_to_cpuinfo_max(cpu
);
1381 set_scaling_min_to_cpuinfo_min(cpu
);
1387 if (auto_mode
&& status
) {
1388 ret
= set_pbf_core_power(cpu
);
1393 ret
= isst_set_pbf_fact_status(cpu
, 1, status
);
1395 perror("isst_set_pbf");
1397 isst_pm_qos_config(cpu
, 0, 0);
1401 set_scaling_min_to_cpuinfo_max(cpu
);
1403 set_scaling_min_to_cpuinfo_min(cpu
);
1407 if (auto_mode
&& !status
)
1408 isst_pm_qos_config(cpu
, 0, 0);
1412 isst_display_result(cpu
, outf
, "base-freq", "enable",
1415 isst_display_result(cpu
, outf
, "base-freq", "disable",
1419 static void set_pbf_enable(int arg
)
1426 "Enable Intel Speed Select Technology base frequency feature\n");
1428 "\tOptional Arguments: -a|--auto : Use priority of cores to set core-power associations\n");
1432 "Disable Intel Speed Select Technology base frequency feature\n");
1434 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
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
,
1444 for_each_online_package_in_set(set_pbf_for_cpu
, NULL
, NULL
,
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
;
1455 ret
= isst_get_fact_info(cpu
, tdp_level
, &fact_info
);
1457 perror("isst_get_fact_bucket_info");
1459 isst_fact_display_information(cpu
, outf
, tdp_level
, fact_bucket
,
1460 fact_avx
, &fact_info
);
1463 static void dump_fact_config(int arg
)
1467 "Print complete Intel Speed Select Technology turbo frequency configuration for a TDP level. Other arguments are optional.\n");
1469 "\tArguments: -l|--level : Specify tdp level\n");
1471 "\tArguments: -b|--bucket : Bucket index to dump\n");
1473 "\tArguments: -r|--trl-type : Specify trl type: sse|avx2|avx512\n");
1477 if (tdp_level
== 0xff) {
1478 fprintf(outf
, "Invalid command: specify tdp_level\n");
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
);
1487 for_each_online_package_in_set(dump_fact_config_for_cpu
, NULL
,
1489 isst_ctdp_display_information_end(outf
);
1492 static void set_fact_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1496 int status
= *(int *)arg4
;
1498 if (auto_mode
&& status
) {
1499 ret
= isst_pm_qos_config(cpu
, 1, 1);
1504 ret
= isst_set_pbf_fact_status(cpu
, 0, status
);
1506 perror("isst_set_fact");
1508 isst_pm_qos_config(cpu
, 0, 0);
1515 struct isst_pkg_ctdp pkg_dev
;
1517 ret
= isst_get_ctdp_levels(cpu
, &pkg_dev
);
1519 ret
= isst_set_trl(cpu
, fact_trl
);
1520 if (ret
&& auto_mode
)
1521 isst_pm_qos_config(cpu
, 0, 0);
1524 isst_pm_qos_config(cpu
, 0, 0);
1529 isst_display_result(cpu
, outf
, "turbo-freq", "enable", ret
);
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
;
1544 "Enable Intel Speed Select Technology Turbo frequency feature\n");
1546 "Optional: -t|--trl : Specify turbo ratio limit\n");
1548 "\tOptional Arguments: -a|--auto : Designate specified target CPUs with");
1550 "-C|--cpu option as as high priority using core-power feature\n");
1553 "Disable Intel Speed Select Technology turbo frequency feature\n");
1555 "Optional: -t|--trl : Specify turbo ratio limit\n");
1557 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
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
,
1567 for_each_online_package_in_set(set_fact_for_cpu
, NULL
, NULL
,
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
;
1581 if (!CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
1584 snprintf(buffer
, sizeof(buffer
),
1585 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i
);
1587 fd
= open(buffer
, O_RDONLY
);
1591 len
= read(fd
, sibling_list
, sizeof(sibling_list
));
1597 cpu_str
= strtok(sibling_list
, ",");
1598 while (cpu_str
!= NULL
) {
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
) {
1610 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
1613 ret
= set_clos_param(i
, 0, 0, 0, 0, 0xff);
1617 ret
= set_clos_param(i
, 1, 15, 15, 0, 0xff);
1621 ret
= set_clos_param(i
, 2, 15, 15, 0, 0xff);
1625 ret
= set_clos_param(i
, 3, 15, 15, 0, 0xff);
1629 if (CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
1634 debug_printf("Associate cpu: %d clos: %d\n", i
, clos
);
1635 ret
= isst_clos_associate(i
, clos
);
1639 isst_display_result(-1, outf
, "turbo-freq --auto", "enable", 0);
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
,
1653 int status
= *(int *)arg4
;
1655 ret
= isst_pm_qos_config(cpu
, status
, clos_priority_type
);
1657 perror("isst_pm_qos_config");
1660 isst_display_result(cpu
, outf
, "core-power", "enable",
1663 isst_display_result(cpu
, outf
, "core-power", "disable",
1667 static void set_clos_enable(int arg
)
1674 "Enable core-power for a package/die\n");
1676 "\tClos Enable: Specify priority type with [--priority|-p]\n");
1677 fprintf(stderr
, "\t\t 0: Proportional, 1: Ordered\n");
1680 "Disable core-power: [No command arguments are required]\n");
1685 if (enable
&& cpufreq_sysfs_present()) {
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
);
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
;
1706 ret
= isst_pm_get_clos(cpu
, current_clos
, &clos_config
);
1708 perror("isst_pm_get_clos");
1710 isst_clos_display_information(cpu
, outf
, current_clos
,
1714 static void dump_clos_config(int arg
)
1718 "Print Intel Speed Select Technology core power configuration\n");
1720 "\tArguments: [-c | --clos]: Specify clos id\n");
1723 if (current_clos
< 0 || current_clos
> 3) {
1724 fprintf(stderr
, "Invalid clos id\n");
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
);
1733 for_each_online_package_in_set(dump_clos_config_for_cpu
, NULL
,
1735 isst_ctdp_display_information_end(outf
);
1738 static void get_clos_info_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1741 int enable
, ret
, prio_type
;
1743 ret
= isst_clos_get_clos_information(cpu
, &enable
, &prio_type
);
1745 perror("isst_clos_get_info");
1747 isst_clos_display_clos_information(cpu
, outf
, enable
, prio_type
);
1750 static void dump_clos_info(int arg
)
1754 "Print Intel Speed Select Technology core power information\n");
1755 fprintf(stderr
, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1759 if (!max_target_cpus
) {
1761 "Invalid target cpu. Specify with [-c|--cpu]\n");
1765 isst_ctdp_display_information_start(outf
);
1766 for_each_online_target_cpu_in_set(get_clos_info_for_cpu
, NULL
,
1768 isst_ctdp_display_information_end(outf
);
1772 static void set_clos_config_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1775 struct isst_clos_config clos_config
;
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
);
1788 perror("isst_set_clos");
1790 isst_display_result(cpu
, outf
, "core-power", "config", ret
);
1793 static void set_clos_config(int arg
)
1797 "Set core-power configuration for one of the four clos ids\n");
1799 "\tSpecify targeted clos id with [--clos|-c]\n");
1800 fprintf(stderr
, "\tSpecify clos EPP with [--epp|-e]\n");
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");
1809 if (current_clos
< 0 || current_clos
> 3) {
1810 fprintf(stderr
, "Invalid clos id\n");
1813 if (clos_epp
< 0 || clos_epp
> 0x0F) {
1814 fprintf(stderr
, "clos epp is not specified, default: 0\n");
1817 if (clos_prop_prio
< 0 || clos_prop_prio
> 0x0F) {
1819 "clos frequency weight is not specified, default: 0\n");
1823 fprintf(stderr
, "clos min is not specified, default: 0\n");
1827 fprintf(stderr
, "clos max is not specified, default: 25500 MHz\n");
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
,
1840 for_each_online_package_in_set(set_clos_config_for_cpu
, NULL
,
1842 isst_ctdp_display_information_end(outf
);
1845 static void set_clos_assoc_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1850 ret
= isst_clos_associate(cpu
, current_clos
);
1852 perror("isst_clos_associate");
1854 isst_display_result(cpu
, outf
, "core-power", "assoc", ret
);
1857 static void set_clos_assoc(int arg
)
1860 fprintf(stderr
, "Associate a clos id to a CPU\n");
1862 "\tSpecify targeted clos id with [--clos|-c]\n");
1866 if (current_clos
< 0 || current_clos
> 3) {
1867 fprintf(stderr
, "Invalid clos id\n");
1870 if (max_target_cpus
)
1871 for_each_online_target_cpu_in_set(set_clos_assoc_for_cpu
, NULL
,
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
,
1884 ret
= isst_clos_get_assoc_status(cpu
, &clos
);
1886 perror("isst_clos_get_assoc_status");
1888 isst_clos_display_assoc_information(cpu
, outf
, clos
);
1891 static void get_clos_assoc(int arg
)
1894 fprintf(stderr
, "Get associate clos id to a CPU\n");
1895 fprintf(stderr
, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1899 if (!max_target_cpus
) {
1901 "Invalid target cpu. Specify with [-c|--cpu]\n");
1905 isst_ctdp_display_information_start(outf
);
1906 for_each_online_target_cpu_in_set(get_clos_assoc_for_cpu
, 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
,
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
;
1955 while (next
&& *next
) {
1956 if (*next
== '-') /* no negative cpu numbers */
1959 start
= strtoul(next
, &next
, 10);
1961 if (max_target_cpus
< MAX_CPUS_IN_ONE_REQ
)
1962 target_cpus
[max_target_cpus
++] = start
;
1973 next
+= 1; /* start range */
1974 } else if (*next
== '.') {
1977 next
+= 1; /* start range */
1982 end
= strtoul(next
, &next
, 10);
1986 while (++start
<= end
) {
1987 if (max_target_cpus
< MAX_CPUS_IN_ONE_REQ
)
1988 target_cpus
[max_target_cpus
++] = start
;
1993 else if (*next
!= '\0')
2001 for (i
= 0; i
< max_target_cpus
; ++i
)
2002 printf("cpu [%d] in arg\n", target_cpus
[i
]);
2008 fprintf(stderr
, "\"--cpu %s\" malformed\n", optarg
);
2012 static void parse_cmd_args(int argc
, int start
, char **argv
)
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' },
2035 option_index
= start
;
2038 while ((opt
= getopt_long(argc
, argv
, "b:l:t:c:d:e:n:m:p:w:hoa",
2039 long_options
, &option_index
)) != -1) {
2045 fact_bucket
= atoi(optarg
);
2051 tdp_level
= atoi(optarg
);
2054 force_online_offline
= 1;
2057 sscanf(optarg
, "0x%llx", &fact_trl
);
2060 if (!strncmp(optarg
, "sse", 3)) {
2062 } else if (!strncmp(optarg
, "avx2", 4)) {
2064 } else if (!strncmp(optarg
, "avx512", 4)) {
2067 fprintf(outf
, "Invalid sse,avx options\n");
2073 current_clos
= atoi(optarg
);
2076 clos_desired
= atoi(optarg
);
2077 clos_desired
/= DISP_FREQ_MULTIPLIER
;
2080 clos_epp
= atoi(optarg
);
2083 clos_min
= atoi(optarg
);
2084 clos_min
/= DISP_FREQ_MULTIPLIER
;
2087 clos_max
= atoi(optarg
);
2088 clos_max
/= DISP_FREQ_MULTIPLIER
;
2091 clos_priority_type
= atoi(optarg
);
2094 clos_prop_prio
= atoi(optarg
);
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\
2108 printf("\nCommands : For feature=perf-profile\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\
2145 printf("\nCommands : For feature=core-power\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
{
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
},
2168 static struct process_cmd_help_struct clx_n_help_cmds
[] = {
2169 { "perf-profile", isst_help
},
2170 { "base-freq", pbf_help
},
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
)
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();
2196 if (!is_clx_n_platform())
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
);
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");
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__
);
2255 static void cmdline(int argc
, char **argv
)
2258 int option_index
= 0;
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' },
2273 while ((opt
= getopt_long_only(argc
, argv
, "+c:df:hio:v", long_options
,
2274 &option_index
)) != -1) {
2277 parse_cpu_command(optarg
);
2281 printf("Debug Mode ON\n");
2284 if (!strncmp(optarg
, "json", 4))
2285 out_format_json
= 1;
2291 isst_print_platform_information();
2296 outf
= fopen_or_exit(optarg
, "w");
2306 if (geteuid() != 0) {
2307 fprintf(stderr
, "Must run as root\n");
2311 if (optind
> (argc
- 2)) {
2312 fprintf(stderr
, "Feature name and|or command not specified\n");
2315 ret
= update_cpu_model();
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
);
2321 set_cpu_present_cpu_mask();
2322 set_cpu_target_cpu_mask();
2324 if (!is_clx_n_platform()) {
2325 ret
= isst_fill_platform_info();
2328 process_command(argc
, argv
, isst_help_cmds
, isst_cmds
);
2330 process_command(argc
, argv
, clx_n_help_cmds
, clx_n_cmds
);
2333 free_cpu_set(present_cpumask
);
2334 free_cpu_set(target_cpumask
);
2337 int main(int argc
, char **argv
)
2340 cmdline(argc
, argv
);