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.1";
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
);
1389 ret
= set_pbf_core_power(cpu
);
1393 isst_pm_qos_config(cpu
, 0, 0);
1397 ret
= isst_set_pbf_fact_status(cpu
, 1, status
);
1399 perror("isst_set_pbf");
1401 isst_pm_qos_config(cpu
, 0, 0);
1405 set_scaling_min_to_cpuinfo_max(cpu
);
1407 set_scaling_min_to_cpuinfo_min(cpu
);
1413 isst_display_result(cpu
, outf
, "base-freq", "enable",
1416 isst_display_result(cpu
, outf
, "base-freq", "disable",
1420 static void set_pbf_enable(int arg
)
1427 "Enable Intel Speed Select Technology base frequency feature\n");
1429 "\tOptional Arguments: -a|--auto : Use priority of cores to set core-power associations\n");
1433 "Disable Intel Speed Select Technology base frequency feature\n");
1435 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1440 isst_ctdp_display_information_start(outf
);
1441 if (max_target_cpus
)
1442 for_each_online_target_cpu_in_set(set_pbf_for_cpu
, NULL
, NULL
,
1445 for_each_online_package_in_set(set_pbf_for_cpu
, NULL
, NULL
,
1447 isst_ctdp_display_information_end(outf
);
1450 static void dump_fact_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
1451 void *arg3
, void *arg4
)
1453 struct isst_fact_info fact_info
;
1456 ret
= isst_get_fact_info(cpu
, tdp_level
, &fact_info
);
1458 perror("isst_get_fact_bucket_info");
1460 isst_fact_display_information(cpu
, outf
, tdp_level
, fact_bucket
,
1461 fact_avx
, &fact_info
);
1464 static void dump_fact_config(int arg
)
1468 "Print complete Intel Speed Select Technology turbo frequency configuration for a TDP level. Other arguments are optional.\n");
1470 "\tArguments: -l|--level : Specify tdp level\n");
1472 "\tArguments: -b|--bucket : Bucket index to dump\n");
1474 "\tArguments: -r|--trl-type : Specify trl type: sse|avx2|avx512\n");
1478 if (tdp_level
== 0xff) {
1479 fprintf(outf
, "Invalid command: specify tdp_level\n");
1483 isst_ctdp_display_information_start(outf
);
1484 if (max_target_cpus
)
1485 for_each_online_target_cpu_in_set(dump_fact_config_for_cpu
,
1486 NULL
, NULL
, NULL
, NULL
);
1488 for_each_online_package_in_set(dump_fact_config_for_cpu
, NULL
,
1490 isst_ctdp_display_information_end(outf
);
1493 static void set_fact_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1497 int status
= *(int *)arg4
;
1501 ret
= isst_pm_qos_config(cpu
, 1, 1);
1505 isst_pm_qos_config(cpu
, 0, 0);
1509 ret
= isst_set_pbf_fact_status(cpu
, 0, status
);
1511 perror("isst_set_fact");
1513 isst_pm_qos_config(cpu
, 0, 0);
1520 struct isst_pkg_ctdp pkg_dev
;
1522 ret
= isst_get_ctdp_levels(cpu
, &pkg_dev
);
1524 ret
= isst_set_trl(cpu
, fact_trl
);
1525 if (ret
&& auto_mode
)
1526 isst_pm_qos_config(cpu
, 0, 0);
1531 isst_display_result(cpu
, outf
, "turbo-freq", "enable", ret
);
1533 /* Since we modified TRL during Fact enable, restore it */
1534 isst_set_trl_from_current_tdp(cpu
, fact_trl
);
1535 isst_display_result(cpu
, outf
, "turbo-freq", "disable", ret
);
1539 static void set_fact_enable(int arg
)
1541 int i
, ret
, enable
= arg
;
1546 "Enable Intel Speed Select Technology Turbo frequency feature\n");
1548 "Optional: -t|--trl : Specify turbo ratio limit\n");
1550 "\tOptional Arguments: -a|--auto : Designate specified target CPUs with");
1552 "-C|--cpu option as as high priority using core-power feature\n");
1555 "Disable Intel Speed Select Technology turbo frequency feature\n");
1557 "Optional: -t|--trl : Specify turbo ratio limit\n");
1559 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1564 isst_ctdp_display_information_start(outf
);
1565 if (max_target_cpus
)
1566 for_each_online_target_cpu_in_set(set_fact_for_cpu
, NULL
, NULL
,
1569 for_each_online_package_in_set(set_fact_for_cpu
, NULL
, NULL
,
1571 isst_ctdp_display_information_end(outf
);
1573 if (enable
&& auto_mode
) {
1575 * When we adjust CLOS param, we have to set for siblings also.
1576 * So for the each user specified CPU, also add the sibling
1577 * in the present_cpu_mask.
1579 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1580 char buffer
[128], sibling_list
[128], *cpu_str
;
1583 if (!CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
1586 snprintf(buffer
, sizeof(buffer
),
1587 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i
);
1589 fd
= open(buffer
, O_RDONLY
);
1593 len
= read(fd
, sibling_list
, sizeof(sibling_list
));
1599 cpu_str
= strtok(sibling_list
, ",");
1600 while (cpu_str
!= NULL
) {
1603 sscanf(cpu_str
, "%d", &cpu
);
1604 CPU_SET_S(cpu
, target_cpumask_size
, target_cpumask
);
1605 cpu_str
= strtok(NULL
, ",");
1609 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1612 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
1615 ret
= set_clos_param(i
, 0, 0, 0, 0, 0xff);
1619 ret
= set_clos_param(i
, 1, 15, 15, 0, 0xff);
1623 ret
= set_clos_param(i
, 2, 15, 15, 0, 0xff);
1627 ret
= set_clos_param(i
, 3, 15, 15, 0, 0xff);
1631 if (CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
1636 debug_printf("Associate cpu: %d clos: %d\n", i
, clos
);
1637 ret
= isst_clos_associate(i
, clos
);
1641 isst_display_result(i
, outf
, "turbo-freq --auto", "enable", 0);
1647 isst_display_result(i
, outf
, "turbo-freq --auto", "enable", ret
);
1651 static void enable_clos_qos_config(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1655 int status
= *(int *)arg4
;
1657 ret
= isst_pm_qos_config(cpu
, status
, clos_priority_type
);
1659 perror("isst_pm_qos_config");
1662 isst_display_result(cpu
, outf
, "core-power", "enable",
1665 isst_display_result(cpu
, outf
, "core-power", "disable",
1669 static void set_clos_enable(int arg
)
1676 "Enable core-power for a package/die\n");
1678 "\tClos Enable: Specify priority type with [--priority|-p]\n");
1679 fprintf(stderr
, "\t\t 0: Proportional, 1: Ordered\n");
1682 "Disable core-power: [No command arguments are required]\n");
1687 if (enable
&& cpufreq_sysfs_present()) {
1689 "cpufreq subsystem and core-power enable will interfere with each other!\n");
1692 isst_ctdp_display_information_start(outf
);
1693 if (max_target_cpus
)
1694 for_each_online_target_cpu_in_set(enable_clos_qos_config
, NULL
,
1695 NULL
, NULL
, &enable
);
1697 for_each_online_package_in_set(enable_clos_qos_config
, NULL
,
1698 NULL
, NULL
, &enable
);
1699 isst_ctdp_display_information_end(outf
);
1702 static void dump_clos_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
1703 void *arg3
, void *arg4
)
1705 struct isst_clos_config clos_config
;
1708 ret
= isst_pm_get_clos(cpu
, current_clos
, &clos_config
);
1710 perror("isst_pm_get_clos");
1712 isst_clos_display_information(cpu
, outf
, current_clos
,
1716 static void dump_clos_config(int arg
)
1720 "Print Intel Speed Select Technology core power configuration\n");
1722 "\tArguments: [-c | --clos]: Specify clos id\n");
1725 if (current_clos
< 0 || current_clos
> 3) {
1726 fprintf(stderr
, "Invalid clos id\n");
1730 isst_ctdp_display_information_start(outf
);
1731 if (max_target_cpus
)
1732 for_each_online_target_cpu_in_set(dump_clos_config_for_cpu
,
1733 NULL
, NULL
, NULL
, NULL
);
1735 for_each_online_package_in_set(dump_clos_config_for_cpu
, NULL
,
1737 isst_ctdp_display_information_end(outf
);
1740 static void get_clos_info_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1743 int enable
, ret
, prio_type
;
1745 ret
= isst_clos_get_clos_information(cpu
, &enable
, &prio_type
);
1747 perror("isst_clos_get_info");
1749 isst_clos_display_clos_information(cpu
, outf
, enable
, prio_type
);
1752 static void dump_clos_info(int arg
)
1756 "Print Intel Speed Select Technology core power information\n");
1757 fprintf(stderr
, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1761 if (!max_target_cpus
) {
1763 "Invalid target cpu. Specify with [-c|--cpu]\n");
1767 isst_ctdp_display_information_start(outf
);
1768 for_each_online_target_cpu_in_set(get_clos_info_for_cpu
, NULL
,
1770 isst_ctdp_display_information_end(outf
);
1774 static void set_clos_config_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1777 struct isst_clos_config clos_config
;
1780 clos_config
.pkg_id
= get_physical_package_id(cpu
);
1781 clos_config
.die_id
= get_physical_die_id(cpu
);
1783 clos_config
.epp
= clos_epp
;
1784 clos_config
.clos_prop_prio
= clos_prop_prio
;
1785 clos_config
.clos_min
= clos_min
;
1786 clos_config
.clos_max
= clos_max
;
1787 clos_config
.clos_desired
= clos_desired
;
1788 ret
= isst_set_clos(cpu
, current_clos
, &clos_config
);
1790 perror("isst_set_clos");
1792 isst_display_result(cpu
, outf
, "core-power", "config", ret
);
1795 static void set_clos_config(int arg
)
1799 "Set core-power configuration for one of the four clos ids\n");
1801 "\tSpecify targeted clos id with [--clos|-c]\n");
1802 fprintf(stderr
, "\tSpecify clos EPP with [--epp|-e]\n");
1804 "\tSpecify clos Proportional Priority [--weight|-w]\n");
1805 fprintf(stderr
, "\tSpecify clos min in MHz with [--min|-n]\n");
1806 fprintf(stderr
, "\tSpecify clos max in MHz with [--max|-m]\n");
1807 fprintf(stderr
, "\tSpecify clos desired in MHz with [--desired|-d]\n");
1811 if (current_clos
< 0 || current_clos
> 3) {
1812 fprintf(stderr
, "Invalid clos id\n");
1815 if (clos_epp
< 0 || clos_epp
> 0x0F) {
1816 fprintf(stderr
, "clos epp is not specified, default: 0\n");
1819 if (clos_prop_prio
< 0 || clos_prop_prio
> 0x0F) {
1821 "clos frequency weight is not specified, default: 0\n");
1825 fprintf(stderr
, "clos min is not specified, default: 0\n");
1829 fprintf(stderr
, "clos max is not specified, default: 25500 MHz\n");
1832 if (clos_desired
< 0) {
1833 fprintf(stderr
, "clos desired is not specified, default: 0\n");
1834 clos_desired
= 0x00;
1837 isst_ctdp_display_information_start(outf
);
1838 if (max_target_cpus
)
1839 for_each_online_target_cpu_in_set(set_clos_config_for_cpu
, NULL
,
1842 for_each_online_package_in_set(set_clos_config_for_cpu
, NULL
,
1844 isst_ctdp_display_information_end(outf
);
1847 static void set_clos_assoc_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1852 ret
= isst_clos_associate(cpu
, current_clos
);
1854 perror("isst_clos_associate");
1856 isst_display_result(cpu
, outf
, "core-power", "assoc", ret
);
1859 static void set_clos_assoc(int arg
)
1862 fprintf(stderr
, "Associate a clos id to a CPU\n");
1864 "\tSpecify targeted clos id with [--clos|-c]\n");
1868 if (current_clos
< 0 || current_clos
> 3) {
1869 fprintf(stderr
, "Invalid clos id\n");
1872 if (max_target_cpus
)
1873 for_each_online_target_cpu_in_set(set_clos_assoc_for_cpu
, NULL
,
1877 "Invalid target cpu. Specify with [-c|--cpu]\n");
1881 static void get_clos_assoc_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1886 ret
= isst_clos_get_assoc_status(cpu
, &clos
);
1888 perror("isst_clos_get_assoc_status");
1890 isst_clos_display_assoc_information(cpu
, outf
, clos
);
1893 static void get_clos_assoc(int arg
)
1896 fprintf(stderr
, "Get associate clos id to a CPU\n");
1897 fprintf(stderr
, "\tSpecify targeted cpu id with [--cpu|-c]\n");
1901 if (!max_target_cpus
) {
1903 "Invalid target cpu. Specify with [-c|--cpu]\n");
1907 isst_ctdp_display_information_start(outf
);
1908 for_each_online_target_cpu_in_set(get_clos_assoc_for_cpu
, NULL
,
1910 isst_ctdp_display_information_end(outf
);
1913 static struct process_cmd_struct clx_n_cmds
[] = {
1914 { "perf-profile", "info", dump_isst_config
, 0 },
1915 { "base-freq", "info", dump_pbf_config
, 0 },
1916 { "base-freq", "enable", set_pbf_enable
, 1 },
1917 { "base-freq", "disable", set_pbf_enable
, 0 },
1918 { NULL
, NULL
, NULL
, 0 }
1921 static struct process_cmd_struct isst_cmds
[] = {
1922 { "perf-profile", "get-lock-status", get_tdp_locked
, 0 },
1923 { "perf-profile", "get-config-levels", get_tdp_levels
, 0 },
1924 { "perf-profile", "get-config-version", get_tdp_version
, 0 },
1925 { "perf-profile", "get-config-enabled", get_tdp_enabled
, 0 },
1926 { "perf-profile", "get-config-current-level", get_tdp_current_level
,
1928 { "perf-profile", "set-config-level", set_tdp_level
, 0 },
1929 { "perf-profile", "info", dump_isst_config
, 0 },
1930 { "base-freq", "info", dump_pbf_config
, 0 },
1931 { "base-freq", "enable", set_pbf_enable
, 1 },
1932 { "base-freq", "disable", set_pbf_enable
, 0 },
1933 { "turbo-freq", "info", dump_fact_config
, 0 },
1934 { "turbo-freq", "enable", set_fact_enable
, 1 },
1935 { "turbo-freq", "disable", set_fact_enable
, 0 },
1936 { "core-power", "info", dump_clos_info
, 0 },
1937 { "core-power", "enable", set_clos_enable
, 1 },
1938 { "core-power", "disable", set_clos_enable
, 0 },
1939 { "core-power", "config", set_clos_config
, 0 },
1940 { "core-power", "get-config", dump_clos_config
, 0 },
1941 { "core-power", "assoc", set_clos_assoc
, 0 },
1942 { "core-power", "get-assoc", get_clos_assoc
, 0 },
1943 { NULL
, NULL
, NULL
}
1947 * parse cpuset with following syntax
1948 * 1,2,4..6,8-10 and set bits in cpu_subset
1950 void parse_cpu_command(char *optarg
)
1952 unsigned int start
, end
;
1957 while (next
&& *next
) {
1958 if (*next
== '-') /* no negative cpu numbers */
1961 start
= strtoul(next
, &next
, 10);
1963 if (max_target_cpus
< MAX_CPUS_IN_ONE_REQ
)
1964 target_cpus
[max_target_cpus
++] = start
;
1975 next
+= 1; /* start range */
1976 } else if (*next
== '.') {
1979 next
+= 1; /* start range */
1984 end
= strtoul(next
, &next
, 10);
1988 while (++start
<= end
) {
1989 if (max_target_cpus
< MAX_CPUS_IN_ONE_REQ
)
1990 target_cpus
[max_target_cpus
++] = start
;
1995 else if (*next
!= '\0')
2003 for (i
= 0; i
< max_target_cpus
; ++i
)
2004 printf("cpu [%d] in arg\n", target_cpus
[i
]);
2010 fprintf(stderr
, "\"--cpu %s\" malformed\n", optarg
);
2014 static void parse_cmd_args(int argc
, int start
, char **argv
)
2019 static struct option long_options
[] = {
2020 { "bucket", required_argument
, 0, 'b' },
2021 { "level", required_argument
, 0, 'l' },
2022 { "online", required_argument
, 0, 'o' },
2023 { "trl-type", required_argument
, 0, 'r' },
2024 { "trl", required_argument
, 0, 't' },
2025 { "help", no_argument
, 0, 'h' },
2026 { "clos", required_argument
, 0, 'c' },
2027 { "desired", required_argument
, 0, 'd' },
2028 { "epp", required_argument
, 0, 'e' },
2029 { "min", required_argument
, 0, 'n' },
2030 { "max", required_argument
, 0, 'm' },
2031 { "priority", required_argument
, 0, 'p' },
2032 { "weight", required_argument
, 0, 'w' },
2033 { "auto", no_argument
, 0, 'a' },
2037 option_index
= start
;
2040 while ((opt
= getopt_long(argc
, argv
, "b:l:t:c:d:e:n:m:p:w:hoa",
2041 long_options
, &option_index
)) != -1) {
2047 fact_bucket
= atoi(optarg
);
2053 tdp_level
= atoi(optarg
);
2056 force_online_offline
= 1;
2059 sscanf(optarg
, "0x%llx", &fact_trl
);
2062 if (!strncmp(optarg
, "sse", 3)) {
2064 } else if (!strncmp(optarg
, "avx2", 4)) {
2066 } else if (!strncmp(optarg
, "avx512", 4)) {
2069 fprintf(outf
, "Invalid sse,avx options\n");
2075 current_clos
= atoi(optarg
);
2078 clos_desired
= atoi(optarg
);
2079 clos_desired
/= DISP_FREQ_MULTIPLIER
;
2082 clos_epp
= atoi(optarg
);
2085 clos_min
= atoi(optarg
);
2086 clos_min
/= DISP_FREQ_MULTIPLIER
;
2089 clos_max
= atoi(optarg
);
2090 clos_max
/= DISP_FREQ_MULTIPLIER
;
2093 clos_priority_type
= atoi(optarg
);
2096 clos_prop_prio
= atoi(optarg
);
2099 printf("no match\n");
2104 static void isst_help(void)
2106 printf("perf-profile:\tAn architectural mechanism that allows multiple optimized \n\
2107 performance profiles per system via static and/or dynamic\n\
2108 adjustment of core count, workload, Tjmax, and\n\
2110 printf("\nCommands : For feature=perf-profile\n");
2113 if (!is_clx_n_platform()) {
2114 printf("\tget-lock-status\n");
2115 printf("\tget-config-levels\n");
2116 printf("\tget-config-version\n");
2117 printf("\tget-config-enabled\n");
2118 printf("\tget-config-current-level\n");
2119 printf("\tset-config-level\n");
2123 static void pbf_help(void)
2125 printf("base-freq:\tEnables users to increase guaranteed base frequency\n\
2126 on certain cores (high priority cores) in exchange for lower\n\
2127 base frequency on remaining cores (low priority cores).\n");
2128 printf("\tcommand : info\n");
2129 printf("\tcommand : enable\n");
2130 printf("\tcommand : disable\n");
2133 static void fact_help(void)
2135 printf("turbo-freq:\tEnables the ability to set different turbo ratio\n\
2136 limits to cores based on priority.\n");
2137 printf("\nCommand: For feature=turbo-freq\n");
2138 printf("\tcommand : info\n");
2139 printf("\tcommand : enable\n");
2140 printf("\tcommand : disable\n");
2143 static void core_power_help(void)
2145 printf("core-power:\tInterface that allows user to define per core/tile\n\
2147 printf("\nCommands : For feature=core-power\n");
2149 printf("\tenable\n");
2150 printf("\tdisable\n");
2151 printf("\tconfig\n");
2152 printf("\tget-config\n");
2153 printf("\tassoc\n");
2154 printf("\tget-assoc\n");
2157 struct process_cmd_help_struct
{
2159 void (*process_fn
)(void);
2162 static struct process_cmd_help_struct isst_help_cmds
[] = {
2163 { "perf-profile", isst_help
},
2164 { "base-freq", pbf_help
},
2165 { "turbo-freq", fact_help
},
2166 { "core-power", core_power_help
},
2170 static struct process_cmd_help_struct clx_n_help_cmds
[] = {
2171 { "perf-profile", isst_help
},
2172 { "base-freq", pbf_help
},
2176 void process_command(int argc
, char **argv
,
2177 struct process_cmd_help_struct
*help_cmds
,
2178 struct process_cmd_struct
*cmds
)
2180 int i
= 0, matched
= 0;
2181 char *feature
= argv
[optind
];
2182 char *cmd
= argv
[optind
+ 1];
2184 if (!feature
|| !cmd
)
2187 debug_printf("feature name [%s] command [%s]\n", feature
, cmd
);
2188 if (!strcmp(cmd
, "-h") || !strcmp(cmd
, "--help")) {
2189 while (help_cmds
[i
].feature
) {
2190 if (!strcmp(help_cmds
[i
].feature
, feature
)) {
2191 help_cmds
[i
].process_fn();
2198 if (!is_clx_n_platform())
2202 while (cmds
[i
].feature
) {
2203 if (!strcmp(cmds
[i
].feature
, feature
) &&
2204 !strcmp(cmds
[i
].command
, cmd
)) {
2205 parse_cmd_args(argc
, optind
+ 1, argv
);
2206 cmds
[i
].process_fn(cmds
[i
].arg
);
2214 fprintf(stderr
, "Invalid command\n");
2217 static void usage(void)
2219 printf("Intel(R) Speed Select Technology\n");
2220 printf("\nUsage:\n");
2221 printf("intel-speed-select [OPTIONS] FEATURE COMMAND COMMAND_ARGUMENTS\n");
2222 printf("\nUse this tool to enumerate and control the Intel Speed Select Technology features,\n");
2223 printf("\nFEATURE : [perf-profile|base-freq|turbo-freq|core-power]\n");
2224 printf("\nFor help on each feature, use -h|--help\n");
2225 printf("\tFor example: intel-speed-select perf-profile -h\n");
2227 printf("\nFor additional help on each command for a feature, use --h|--help\n");
2228 printf("\tFor example: intel-speed-select perf-profile get-lock-status -h\n");
2229 printf("\t\t This will print help for the command \"get-lock-status\" for the feature \"perf-profile\"\n");
2231 printf("\nOPTIONS\n");
2232 printf("\t[-c|--cpu] : logical cpu number\n");
2233 printf("\t\tDefault: Die scoped for all dies in the system with multiple dies/package\n");
2234 printf("\t\t\t Or Package scoped for all Packages when each package contains one die\n");
2235 printf("\t[-d|--debug] : Debug mode\n");
2236 printf("\t[-h|--help] : Print help\n");
2237 printf("\t[-i|--info] : Print platform information\n");
2238 printf("\t[-o|--out] : Output file\n");
2239 printf("\t\t\tDefault : stderr\n");
2240 printf("\t[-f|--format] : output format [json|text]. Default: text\n");
2241 printf("\t[-v|--version] : Print version\n");
2243 printf("\nResult format\n");
2244 printf("\tResult display uses a common format for each command:\n");
2245 printf("\tResults are formatted in text/JSON with\n");
2246 printf("\t\tPackage, Die, CPU, and command specific results.\n");
2250 static void print_version(void)
2252 fprintf(outf
, "Version %s\n", version_str
);
2253 fprintf(outf
, "Build date %s time %s\n", __DATE__
, __TIME__
);
2257 static void cmdline(int argc
, char **argv
)
2260 int option_index
= 0;
2263 static struct option long_options
[] = {
2264 { "cpu", required_argument
, 0, 'c' },
2265 { "debug", no_argument
, 0, 'd' },
2266 { "format", required_argument
, 0, 'f' },
2267 { "help", no_argument
, 0, 'h' },
2268 { "info", no_argument
, 0, 'i' },
2269 { "out", required_argument
, 0, 'o' },
2270 { "version", no_argument
, 0, 'v' },
2275 while ((opt
= getopt_long_only(argc
, argv
, "+c:df:hio:v", long_options
,
2276 &option_index
)) != -1) {
2279 parse_cpu_command(optarg
);
2283 printf("Debug Mode ON\n");
2286 if (!strncmp(optarg
, "json", 4))
2287 out_format_json
= 1;
2293 isst_print_platform_information();
2298 outf
= fopen_or_exit(optarg
, "w");
2308 if (geteuid() != 0) {
2309 fprintf(stderr
, "Must run as root\n");
2313 if (optind
> (argc
- 2)) {
2314 fprintf(stderr
, "Feature name and|or command not specified\n");
2317 ret
= update_cpu_model();
2319 err(-1, "Invalid CPU model (%d)\n", cpu_model
);
2320 printf("Intel(R) Speed Select Technology\n");
2321 printf("Executing on CPU model:%d[0x%x]\n", cpu_model
, cpu_model
);
2323 set_cpu_present_cpu_mask();
2324 set_cpu_target_cpu_mask();
2326 if (!is_clx_n_platform()) {
2327 ret
= isst_fill_platform_info();
2330 process_command(argc
, argv
, isst_help_cmds
, isst_cmds
);
2332 process_command(argc
, argv
, clx_n_help_cmds
, clx_n_cmds
);
2335 free_cpu_set(present_cpumask
);
2336 free_cpu_set(target_cpumask
);
2339 int main(int argc
, char **argv
)
2342 cmdline(argc
, argv
);