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.7";
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 256
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
;
45 static int fact_enable_fail
;
47 static int mbox_delay
;
48 static int mbox_retries
= 3;
51 static int current_clos
= -1;
52 static int clos_epp
= -1;
53 static int clos_prop_prio
= -1;
54 static int clos_min
= -1;
55 static int clos_max
= -1;
56 static int clos_desired
= -1;
57 static int clos_priority_type
;
60 unsigned short core_id
;
61 unsigned short pkg_id
;
62 unsigned short die_id
;
63 unsigned short punit_cpu
;
64 unsigned short punit_cpu_core
;
66 struct _cpu_map
*cpu_map
;
75 FILE *get_output_file(void)
80 void debug_printf(const char *format
, ...)
84 va_start(args
, format
);
87 vprintf(format
, args
);
93 int is_clx_n_platform(void)
95 if (cpu_model
== 0x55)
96 if (cpu_stepping
== 0x6 || cpu_stepping
== 0x7)
101 int is_skx_based_platform(void)
103 if (cpu_model
== 0x55)
109 static int update_cpu_model(void)
111 unsigned int ebx
, ecx
, edx
;
112 unsigned int fms
, family
;
114 __cpuid(1, fms
, ebx
, ecx
, edx
);
115 family
= (fms
>> 8) & 0xf;
116 cpu_model
= (fms
>> 4) & 0xf;
117 if (family
== 6 || family
== 0xf)
118 cpu_model
+= ((fms
>> 16) & 0xf) << 4;
120 cpu_stepping
= fms
& 0xf;
121 /* only three CascadeLake-N models are supported */
122 if (is_clx_n_platform()) {
128 fp
= fopen("/proc/cpuinfo", "r");
130 err(-1, "cannot open /proc/cpuinfo\n");
132 while (getline(&line
, &n
, fp
) > 0) {
133 if (strstr(line
, "model name")) {
134 if (strstr(line
, "6252N") ||
135 strstr(line
, "6230N") ||
136 strstr(line
, "5218N"))
148 /* Open a file, and exit on failure */
149 static FILE *fopen_or_exit(const char *path
, const char *mode
)
151 FILE *filep
= fopen(path
, mode
);
154 err(1, "%s: open failed", path
);
159 /* Parse a file containing a single int */
160 static int parse_int_file(int fatal
, const char *fmt
, ...)
168 vsnprintf(path
, sizeof(path
), fmt
, args
);
171 filep
= fopen_or_exit(path
, "r");
173 filep
= fopen(path
, "r");
177 if (fscanf(filep
, "%d", &value
) != 1)
178 err(1, "%s: failed to parse number from file", path
);
184 int cpufreq_sysfs_present(void)
188 dir
= opendir("/sys/devices/system/cpu/cpu0/cpufreq");
197 int out_format_is_json(void)
199 return out_format_json
;
202 static int get_stored_topology_info(int cpu
, int *core_id
, int *pkg_id
, int *die_id
)
204 const char *pathname
= "/var/run/isst_cpu_topology.dat";
205 struct cpu_topology cpu_top
;
209 fp
= fopen(pathname
, "rb");
213 ret
= fseek(fp
, cpu
* sizeof(cpu_top
), SEEK_SET
);
217 ret
= fread(&cpu_top
, sizeof(cpu_top
), 1, fp
);
223 *pkg_id
= cpu_top
.pkg_id
;
224 *core_id
= cpu_top
.core_id
;
225 *die_id
= cpu_top
.die_id
;
234 static void store_cpu_topology(void)
236 const char *pathname
= "/var/run/isst_cpu_topology.dat";
240 fp
= fopen(pathname
, "rb");
242 /* Mapping already exists */
247 fp
= fopen(pathname
, "wb");
249 fprintf(stderr
, "Can't create file:%s\n", pathname
);
253 fprintf(stderr
, "Caching topology information\n");
255 for (i
= 0; i
< topo_max_cpus
; ++i
) {
256 struct cpu_topology cpu_top
;
258 cpu_top
.core_id
= parse_int_file(0,
259 "/sys/devices/system/cpu/cpu%d/topology/core_id", i
);
260 if (cpu_top
.core_id
< 0)
261 cpu_top
.core_id
= -1;
263 cpu_top
.pkg_id
= parse_int_file(0,
264 "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", i
);
265 if (cpu_top
.pkg_id
< 0)
268 cpu_top
.die_id
= parse_int_file(0,
269 "/sys/devices/system/cpu/cpu%d/topology/die_id", i
);
270 if (cpu_top
.die_id
< 0)
275 if (fwrite(&cpu_top
, sizeof(cpu_top
), 1, fp
) != 1) {
276 fprintf(stderr
, "Can't write to:%s\n", pathname
);
284 int get_physical_package_id(int cpu
)
288 ret
= parse_int_file(0,
289 "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",
292 int core_id
, pkg_id
, die_id
;
294 ret
= get_stored_topology_info(cpu
, &core_id
, &pkg_id
, &die_id
);
302 int get_physical_core_id(int cpu
)
306 ret
= parse_int_file(0,
307 "/sys/devices/system/cpu/cpu%d/topology/core_id",
310 int core_id
, pkg_id
, die_id
;
312 ret
= get_stored_topology_info(cpu
, &core_id
, &pkg_id
, &die_id
);
320 int get_physical_die_id(int cpu
)
324 ret
= parse_int_file(0,
325 "/sys/devices/system/cpu/cpu%d/topology/die_id",
328 int core_id
, pkg_id
, die_id
;
330 ret
= get_stored_topology_info(cpu
, &core_id
, &pkg_id
, &die_id
);
345 int get_cpufreq_base_freq(int cpu
)
347 return parse_int_file(0, "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency", cpu
);
350 int get_topo_max_cpus(void)
352 return topo_max_cpus
;
355 static void set_cpu_online_offline(int cpu
, int state
)
360 snprintf(buffer
, sizeof(buffer
),
361 "/sys/devices/system/cpu/cpu%d/online", cpu
);
363 fd
= open(buffer
, O_WRONLY
);
366 fprintf(stderr
, "This system is not configured for CPU 0 online/offline\n");
367 fprintf(stderr
, "Ignoring online request for CPU 0 as this is already online\n");
370 err(-1, "%s open failed", buffer
);
374 ret
= write(fd
, "1\n", 2);
376 ret
= write(fd
, "0\n", 2);
379 perror("Online/Offline: Operation failed\n");
384 #define MAX_PACKAGE_COUNT 8
385 #define MAX_DIE_PER_PACKAGE 2
386 static void for_each_online_package_in_set(void (*callback
)(int, void *, void *,
388 void *arg1
, void *arg2
, void *arg3
,
391 int max_packages
[MAX_PACKAGE_COUNT
* MAX_PACKAGE_COUNT
];
392 int pkg_index
= 0, i
;
394 memset(max_packages
, 0xff, sizeof(max_packages
));
395 for (i
= 0; i
< topo_max_cpus
; ++i
) {
396 int j
, online
, pkg_id
, die_id
= 0, skip
= 0;
398 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
401 online
= parse_int_file(
402 1, "/sys/devices/system/cpu/cpu%d/online", i
);
405 1; /* online entry for CPU 0 needs some special configs */
407 die_id
= get_physical_die_id(i
);
411 pkg_id
= parse_int_file(0,
412 "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", i
);
416 /* Create an unique id for package, die combination to store */
417 pkg_id
= (MAX_PACKAGE_COUNT
* pkg_id
+ die_id
);
419 for (j
= 0; j
< pkg_index
; ++j
) {
420 if (max_packages
[j
] == pkg_id
) {
426 if (!skip
&& online
&& callback
) {
427 callback(i
, arg1
, arg2
, arg3
, arg4
);
428 max_packages
[pkg_index
++] = pkg_id
;
433 static void for_each_online_target_cpu_in_set(
434 void (*callback
)(int, void *, void *, void *, void *), void *arg1
,
435 void *arg2
, void *arg3
, void *arg4
)
439 for (i
= 0; i
< topo_max_cpus
; ++i
) {
442 if (!CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
445 online
= parse_int_file(
446 1, "/sys/devices/system/cpu/cpu%d/online", i
);
449 1; /* online entry for CPU 0 needs some special configs */
451 if (online
&& callback
) {
452 callback(i
, arg1
, arg2
, arg3
, arg4
);
458 fprintf(stderr
, "No valid CPU in the list\n");
461 #define BITMASK_SIZE 32
462 static void set_max_cpu_num(void)
469 for (i
= 0; i
< 256; ++i
) {
472 snprintf(path
, sizeof(path
),
473 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", i
);
474 filep
= fopen(path
, "r");
480 fprintf(stderr
, "Can't get max cpu number\n");
484 while (fscanf(filep
, "%lx,", &dummy
) == 1)
485 topo_max_cpus
+= BITMASK_SIZE
;
488 debug_printf("max cpus %d\n", topo_max_cpus
);
491 size_t alloc_cpu_set(cpu_set_t
**cpu_set
)
496 _cpu_set
= CPU_ALLOC((topo_max_cpus
+ 1));
497 if (_cpu_set
== NULL
)
499 size
= CPU_ALLOC_SIZE((topo_max_cpus
+ 1));
500 CPU_ZERO_S(size
, _cpu_set
);
506 void free_cpu_set(cpu_set_t
*cpu_set
)
511 static int cpu_cnt
[MAX_PACKAGE_COUNT
][MAX_DIE_PER_PACKAGE
];
512 static long long core_mask
[MAX_PACKAGE_COUNT
][MAX_DIE_PER_PACKAGE
];
513 static void set_cpu_present_cpu_mask(void)
519 size
= alloc_cpu_set(&present_cpumask
);
520 present_cpumask_size
= size
;
521 for (i
= 0; i
< topo_max_cpus
; ++i
) {
524 snprintf(buffer
, sizeof(buffer
),
525 "/sys/devices/system/cpu/cpu%d", i
);
526 dir
= opendir(buffer
);
530 CPU_SET_S(i
, size
, present_cpumask
);
531 die_id
= get_physical_die_id(i
);
535 pkg_id
= get_physical_package_id(i
);
537 fprintf(stderr
, "Failed to get package id, CPU %d may be offline\n", i
);
540 if (pkg_id
< MAX_PACKAGE_COUNT
&&
541 die_id
< MAX_DIE_PER_PACKAGE
) {
542 int core_id
= get_physical_core_id(i
);
544 cpu_cnt
[pkg_id
][die_id
]++;
545 core_mask
[pkg_id
][die_id
] |= (1ULL << core_id
);
552 int get_max_punit_core_id(int pkg_id
, int die_id
)
557 for (i
= 0; i
< topo_max_cpus
; ++i
)
559 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
562 if (cpu_map
[i
].pkg_id
== pkg_id
&&
563 cpu_map
[i
].die_id
== die_id
&&
564 cpu_map
[i
].punit_cpu_core
> max_id
)
565 max_id
= cpu_map
[i
].punit_cpu_core
;
571 int get_cpu_count(int pkg_id
, int die_id
)
573 if (pkg_id
< MAX_PACKAGE_COUNT
&& die_id
< MAX_DIE_PER_PACKAGE
)
574 return cpu_cnt
[pkg_id
][die_id
];
579 static void set_cpu_target_cpu_mask(void)
584 size
= alloc_cpu_set(&target_cpumask
);
585 target_cpumask_size
= size
;
586 for (i
= 0; i
< max_target_cpus
; ++i
) {
587 if (!CPU_ISSET_S(target_cpus
[i
], present_cpumask_size
,
591 CPU_SET_S(target_cpus
[i
], size
, target_cpumask
);
595 static void create_cpu_map(void)
597 const char *pathname
= "/dev/isst_interface";
599 struct isst_if_cpu_maps map
;
601 cpu_map
= malloc(sizeof(*cpu_map
) * topo_max_cpus
);
605 fd
= open(pathname
, O_RDWR
);
607 err(-1, "%s open failed", pathname
);
609 for (i
= 0; i
< topo_max_cpus
; ++i
) {
610 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
614 map
.cpu_map
[0].logical_cpu
= i
;
616 debug_printf(" map logical_cpu:%d\n",
617 map
.cpu_map
[0].logical_cpu
);
618 if (ioctl(fd
, ISST_IF_GET_PHY_ID
, &map
) == -1) {
619 perror("ISST_IF_GET_PHY_ID");
620 fprintf(outf
, "Error: map logical_cpu:%d\n",
621 map
.cpu_map
[0].logical_cpu
);
624 cpu_map
[i
].core_id
= get_physical_core_id(i
);
625 cpu_map
[i
].pkg_id
= get_physical_package_id(i
);
626 cpu_map
[i
].die_id
= get_physical_die_id(i
);
627 cpu_map
[i
].punit_cpu
= map
.cpu_map
[0].physical_cpu
;
628 cpu_map
[i
].punit_cpu_core
= (map
.cpu_map
[0].physical_cpu
>>
629 1); // shift to get core id
632 "map logical_cpu:%d core: %d die:%d pkg:%d punit_cpu:%d punit_core:%d\n",
633 i
, cpu_map
[i
].core_id
, cpu_map
[i
].die_id
,
634 cpu_map
[i
].pkg_id
, cpu_map
[i
].punit_cpu
,
635 cpu_map
[i
].punit_cpu_core
);
642 int find_logical_cpu(int pkg_id
, int die_id
, int punit_core_id
)
646 for (i
= 0; i
< topo_max_cpus
; ++i
) {
647 if (cpu_map
[i
].pkg_id
== pkg_id
&&
648 cpu_map
[i
].die_id
== die_id
&&
649 cpu_map
[i
].punit_cpu_core
== punit_core_id
)
656 void set_cpu_mask_from_punit_coremask(int cpu
, unsigned long long core_mask
,
657 size_t core_cpumask_size
,
658 cpu_set_t
*core_cpumask
, int *cpu_cnt
)
664 die_id
= get_physical_die_id(cpu
);
665 pkg_id
= get_physical_package_id(cpu
);
667 for (i
= 0; i
< 64; ++i
) {
668 if (core_mask
& BIT_ULL(i
)) {
671 for (j
= 0; j
< topo_max_cpus
; ++j
) {
672 if (!CPU_ISSET_S(j
, present_cpumask_size
, present_cpumask
))
675 if (cpu_map
[j
].pkg_id
== pkg_id
&&
676 cpu_map
[j
].die_id
== die_id
&&
677 cpu_map
[j
].punit_cpu_core
== i
) {
678 CPU_SET_S(j
, core_cpumask_size
,
689 int find_phy_core_num(int logical_cpu
)
691 if (logical_cpu
< topo_max_cpus
)
692 return cpu_map
[logical_cpu
].punit_cpu_core
;
697 static int isst_send_mmio_command(unsigned int cpu
, unsigned int reg
, int write
,
700 struct isst_if_io_regs io_regs
;
701 const char *pathname
= "/dev/isst_interface";
705 debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu
, reg
, write
);
707 fd
= open(pathname
, O_RDWR
);
709 err(-1, "%s open failed", pathname
);
711 io_regs
.req_count
= 1;
712 io_regs
.io_reg
[0].logical_cpu
= cpu
;
713 io_regs
.io_reg
[0].reg
= reg
;
714 cmd
= ISST_IF_IO_CMD
;
716 io_regs
.io_reg
[0].read_write
= 1;
717 io_regs
.io_reg
[0].value
= *value
;
719 io_regs
.io_reg
[0].read_write
= 0;
722 if (ioctl(fd
, cmd
, &io_regs
) == -1) {
723 if (errno
== ENOTTY
) {
724 perror("ISST_IF_IO_COMMAND\n");
725 fprintf(stderr
, "Check presence of kernel modules: isst_if_mmio\n");
728 fprintf(outf
, "Error: mmio_cmd cpu:%d reg:%x read_write:%x\n",
732 *value
= io_regs
.io_reg
[0].value
;
735 "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
736 cpu
, reg
, write
, *value
);
744 int isst_send_mbox_command(unsigned int cpu
, unsigned char command
,
745 unsigned char sub_command
, unsigned int parameter
,
746 unsigned int req_data
, unsigned int *resp
)
748 const char *pathname
= "/dev/isst_interface";
750 struct isst_if_mbox_cmds mbox_cmds
= { 0 };
753 "mbox_send: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
754 cpu
, command
, sub_command
, parameter
, req_data
);
756 if (!is_skx_based_platform() && command
== CONFIG_CLOS
&&
757 sub_command
!= CLOS_PM_QOS_CONFIG
) {
760 int clos_id
, core_id
, ret
= 0;
762 debug_printf("CPU %d\n", cpu
);
764 if (parameter
& BIT(MBOX_CMD_WRITE_BIT
)) {
769 switch (sub_command
) {
771 core_id
= parameter
& 0xff;
772 ret
= isst_send_mmio_command(
773 cpu
, PQR_ASSOC_OFFSET
+ core_id
* 4, write
,
779 clos_id
= parameter
& 0x03;
780 ret
= isst_send_mmio_command(
781 cpu
, PM_CLOS_OFFSET
+ clos_id
* 4, write
,
794 mbox_cmds
.cmd_count
= 1;
795 mbox_cmds
.mbox_cmd
[0].logical_cpu
= cpu
;
796 mbox_cmds
.mbox_cmd
[0].command
= command
;
797 mbox_cmds
.mbox_cmd
[0].sub_command
= sub_command
;
798 mbox_cmds
.mbox_cmd
[0].parameter
= parameter
;
799 mbox_cmds
.mbox_cmd
[0].req_data
= req_data
;
802 usleep(mbox_delay
* 1000);
804 fd
= open(pathname
, O_RDWR
);
806 err(-1, "%s open failed", pathname
);
808 retry
= mbox_retries
;
811 if (ioctl(fd
, ISST_IF_MBOX_COMMAND
, &mbox_cmds
) == -1) {
812 if (errno
== ENOTTY
) {
813 perror("ISST_IF_MBOX_COMMAND\n");
814 fprintf(stderr
, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n");
818 "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n",
819 cpu
, command
, sub_command
, parameter
, req_data
, errno
);
822 *resp
= mbox_cmds
.mbox_cmd
[0].resp_data
;
824 "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
825 cpu
, command
, sub_command
, parameter
, req_data
, *resp
);
833 debug_printf("Failed mbox command even after retries\n");
840 int isst_send_msr_command(unsigned int cpu
, unsigned int msr
, int write
,
841 unsigned long long *req_resp
)
843 struct isst_if_msr_cmds msr_cmds
;
844 const char *pathname
= "/dev/isst_interface";
847 fd
= open(pathname
, O_RDWR
);
849 err(-1, "%s open failed", pathname
);
851 msr_cmds
.cmd_count
= 1;
852 msr_cmds
.msr_cmd
[0].logical_cpu
= cpu
;
853 msr_cmds
.msr_cmd
[0].msr
= msr
;
854 msr_cmds
.msr_cmd
[0].read_write
= write
;
856 msr_cmds
.msr_cmd
[0].data
= *req_resp
;
858 if (ioctl(fd
, ISST_IF_MSR_COMMAND
, &msr_cmds
) == -1) {
859 perror("ISST_IF_MSR_COMMAND");
860 fprintf(outf
, "Error: msr_cmd cpu:%d msr:%x read_write:%d\n",
864 *req_resp
= msr_cmds
.msr_cmd
[0].data
;
867 "msr_cmd response: cpu:%d msr:%x rd_write:%x resp:%llx %llx\n",
868 cpu
, msr
, write
, *req_resp
, msr_cmds
.msr_cmd
[0].data
);
876 static int isst_fill_platform_info(void)
878 const char *pathname
= "/dev/isst_interface";
881 fd
= open(pathname
, O_RDWR
);
883 err(-1, "%s open failed", pathname
);
885 if (ioctl(fd
, ISST_IF_GET_PLATFORM_INFO
, &isst_platform_info
) == -1) {
886 perror("ISST_IF_GET_PLATFORM_INFO");
893 if (isst_platform_info
.api_version
> supported_api_ver
) {
894 printf("Incompatible API versions; Upgrade of tool is required\n");
900 static void isst_print_extended_platform_info(void)
902 int cp_state
, cp_cap
, fact_support
= 0, pbf_support
= 0;
903 struct isst_pkg_ctdp_level_info ctdp_level
;
904 struct isst_pkg_ctdp pkg_dev
;
908 for (i
= 0; i
< 256; ++i
) {
911 snprintf(path
, sizeof(path
),
912 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", i
);
913 filep
= fopen(path
, "r");
923 ret
= isst_get_ctdp_levels(i
, &pkg_dev
);
927 if (pkg_dev
.enabled
) {
928 fprintf(outf
, "Intel(R) SST-PP (feature perf-profile) is supported\n");
930 fprintf(outf
, "Intel(R) SST-PP (feature perf-profile) is not supported\n");
931 fprintf(outf
, "Only performance level 0 (base level) is present\n");
935 fprintf(outf
, "TDP level change control is locked\n");
937 fprintf(outf
, "TDP level change control is unlocked, max level: %d \n", pkg_dev
.levels
);
939 for (j
= 0; j
<= pkg_dev
.levels
; ++j
) {
940 ret
= isst_get_ctdp_control(i
, j
, &ctdp_level
);
944 if (!fact_support
&& ctdp_level
.fact_support
)
947 if (!pbf_support
&& ctdp_level
.pbf_support
)
952 fprintf(outf
, "Intel(R) SST-TF (feature turbo-freq) is supported\n");
954 fprintf(outf
, "Intel(R) SST-TF (feature turbo-freq) is not supported\n");
957 fprintf(outf
, "Intel(R) SST-BF (feature base-freq) is supported\n");
959 fprintf(outf
, "Intel(R) SST-BF (feature base-freq) is not supported\n");
961 ret
= isst_read_pm_config(i
, &cp_state
, &cp_cap
);
963 fprintf(outf
, "Intel(R) SST-CP (feature core-power) is supported\n");
965 fprintf(outf
, "Intel(R) SST-CP (feature core-power) is not supported\n");
968 static void isst_print_platform_information(void)
970 struct isst_if_platform_info platform_info
;
971 const char *pathname
= "/dev/isst_interface";
974 if (is_clx_n_platform()) {
975 fprintf(stderr
, "\nThis option in not supported on this platform\n");
979 fd
= open(pathname
, O_RDWR
);
981 err(-1, "%s open failed", pathname
);
983 if (ioctl(fd
, ISST_IF_GET_PLATFORM_INFO
, &platform_info
) == -1) {
984 perror("ISST_IF_GET_PLATFORM_INFO");
986 fprintf(outf
, "Platform: API version : %d\n",
987 platform_info
.api_version
);
988 fprintf(outf
, "Platform: Driver version : %d\n",
989 platform_info
.driver_version
);
990 fprintf(outf
, "Platform: mbox supported : %d\n",
991 platform_info
.mbox_supported
);
992 fprintf(outf
, "Platform: mmio supported : %d\n",
993 platform_info
.mmio_supported
);
994 isst_print_extended_platform_info();
1002 static char *local_str0
, *local_str1
;
1003 static void exec_on_get_ctdp_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1006 int (*fn_ptr
)(int cpu
, void *arg
);
1010 ret
= fn_ptr(cpu
, arg2
);
1012 isst_display_error_info_message(1, "get_tdp_* failed", 0, 0);
1014 isst_ctdp_display_core_info(cpu
, outf
, arg3
,
1015 *(unsigned int *)arg4
,
1016 local_str0
, local_str1
);
1019 #define _get_tdp_level(desc, suffix, object, help, str0, str1) \
1020 static void get_tdp_##object(int arg) \
1022 struct isst_pkg_ctdp ctdp; \
1026 "Print %s [No command arguments are required]\n", \
1030 local_str0 = str0; \
1031 local_str1 = str1; \
1032 isst_ctdp_display_information_start(outf); \
1033 if (max_target_cpus) \
1034 for_each_online_target_cpu_in_set( \
1035 exec_on_get_ctdp_cpu, isst_get_ctdp_##suffix, \
1036 &ctdp, desc, &ctdp.object); \
1038 for_each_online_package_in_set(exec_on_get_ctdp_cpu, \
1039 isst_get_ctdp_##suffix, \
1042 isst_ctdp_display_information_end(outf); \
1045 _get_tdp_level("get-config-levels", levels
, levels
, "Max TDP level", NULL
, NULL
);
1046 _get_tdp_level("get-config-version", levels
, version
, "TDP version", NULL
, NULL
);
1047 _get_tdp_level("get-config-enabled", levels
, enabled
, "perf-profile enable status", "disabled", "enabled");
1048 _get_tdp_level("get-config-current_level", levels
, current_level
,
1049 "Current TDP Level", NULL
, NULL
);
1050 _get_tdp_level("get-lock-status", levels
, locked
, "TDP lock status", "unlocked", "locked");
1052 struct isst_pkg_ctdp clx_n_pkg_dev
;
1054 static int clx_n_get_base_ratio(void)
1057 char *begin
, *end
, *line
= NULL
;
1062 fp
= fopen("/proc/cpuinfo", "r");
1064 err(-1, "cannot open /proc/cpuinfo\n");
1066 while (getline(&line
, &n
, fp
) > 0) {
1067 if (strstr(line
, "model name")) {
1068 /* this is true for CascadeLake-N */
1069 begin
= strstr(line
, "@ ") + 2;
1070 end
= strstr(line
, "GHz");
1071 strncpy(number
, begin
, end
- begin
);
1072 value
= atof(number
) * 10;
1079 return (int)(value
);
1082 static int clx_n_config(int cpu
)
1084 int i
, ret
, pkg_id
, die_id
;
1085 unsigned long cpu_bf
;
1086 struct isst_pkg_ctdp_level_info
*ctdp_level
;
1087 struct isst_pbf_info
*pbf_info
;
1089 ctdp_level
= &clx_n_pkg_dev
.ctdp_level
[0];
1090 pbf_info
= &ctdp_level
->pbf_info
;
1091 ctdp_level
->core_cpumask_size
=
1092 alloc_cpu_set(&ctdp_level
->core_cpumask
);
1094 /* find the frequency base ratio */
1095 ctdp_level
->tdp_ratio
= clx_n_get_base_ratio();
1096 if (ctdp_level
->tdp_ratio
== 0) {
1097 debug_printf("CLX: cn base ratio is zero\n");
1102 /* find the high and low priority frequencies */
1103 pbf_info
->p1_high
= 0;
1104 pbf_info
->p1_low
= ~0;
1106 pkg_id
= get_physical_package_id(cpu
);
1107 die_id
= get_physical_die_id(cpu
);
1109 for (i
= 0; i
< topo_max_cpus
; i
++) {
1110 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
1113 if (pkg_id
!= get_physical_package_id(i
) ||
1114 die_id
!= get_physical_die_id(i
))
1117 CPU_SET_S(i
, ctdp_level
->core_cpumask_size
,
1118 ctdp_level
->core_cpumask
);
1120 cpu_bf
= parse_int_file(1,
1121 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
1123 if (cpu_bf
> pbf_info
->p1_high
)
1124 pbf_info
->p1_high
= cpu_bf
;
1125 if (cpu_bf
< pbf_info
->p1_low
)
1126 pbf_info
->p1_low
= cpu_bf
;
1129 if (pbf_info
->p1_high
== ~0UL) {
1130 debug_printf("CLX: maximum base frequency not set\n");
1135 if (pbf_info
->p1_low
== 0) {
1136 debug_printf("CLX: minimum base frequency not set\n");
1141 /* convert frequencies back to ratios */
1142 pbf_info
->p1_high
= pbf_info
->p1_high
/ 100000;
1143 pbf_info
->p1_low
= pbf_info
->p1_low
/ 100000;
1145 /* create high priority cpu mask */
1146 pbf_info
->core_cpumask_size
= alloc_cpu_set(&pbf_info
->core_cpumask
);
1147 for (i
= 0; i
< topo_max_cpus
; i
++) {
1148 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
1151 if (pkg_id
!= get_physical_package_id(i
) ||
1152 die_id
!= get_physical_die_id(i
))
1155 cpu_bf
= parse_int_file(1,
1156 "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency",
1158 cpu_bf
= cpu_bf
/ 100000;
1159 if (cpu_bf
== pbf_info
->p1_high
)
1160 CPU_SET_S(i
, pbf_info
->core_cpumask_size
,
1161 pbf_info
->core_cpumask
);
1164 /* extra ctdp & pbf struct parameters */
1165 ctdp_level
->processed
= 1;
1166 ctdp_level
->pbf_support
= 1; /* PBF is always supported and enabled */
1167 ctdp_level
->pbf_enabled
= 1;
1168 ctdp_level
->fact_support
= 0; /* FACT is never supported */
1169 ctdp_level
->fact_enabled
= 0;
1174 free_cpu_set(ctdp_level
->core_cpumask
);
1178 static void dump_clx_n_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
1179 void *arg3
, void *arg4
)
1183 if (tdp_level
!= 0xff && tdp_level
!= 0) {
1184 isst_display_error_info_message(1, "Invalid level", 1, tdp_level
);
1188 ret
= clx_n_config(cpu
);
1190 debug_printf("clx_n_config failed");
1192 struct isst_pkg_ctdp_level_info
*ctdp_level
;
1193 struct isst_pbf_info
*pbf_info
;
1195 ctdp_level
= &clx_n_pkg_dev
.ctdp_level
[0];
1196 pbf_info
= &ctdp_level
->pbf_info
;
1197 clx_n_pkg_dev
.processed
= 1;
1198 isst_ctdp_display_information(cpu
, outf
, tdp_level
, &clx_n_pkg_dev
);
1199 free_cpu_set(ctdp_level
->core_cpumask
);
1200 free_cpu_set(pbf_info
->core_cpumask
);
1204 static void dump_isst_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
1205 void *arg3
, void *arg4
)
1207 struct isst_pkg_ctdp pkg_dev
;
1210 memset(&pkg_dev
, 0, sizeof(pkg_dev
));
1211 ret
= isst_get_process_ctdp(cpu
, tdp_level
, &pkg_dev
);
1213 isst_display_error_info_message(1, "Failed to get perf-profile info on cpu", 1, cpu
);
1214 isst_ctdp_display_information_end(outf
);
1217 isst_ctdp_display_information(cpu
, outf
, tdp_level
, &pkg_dev
);
1218 isst_get_process_ctdp_complete(cpu
, &pkg_dev
);
1222 static void dump_isst_config(int arg
)
1228 "Print Intel(R) Speed Select Technology Performance profile configuration\n");
1230 "including base frequency and turbo frequency configurations\n");
1231 fprintf(stderr
, "Optional: -l|--level : Specify tdp level\n");
1233 "\tIf no arguments, dump information for all TDP levels\n");
1237 if (!is_clx_n_platform())
1238 fn
= dump_isst_config_for_cpu
;
1240 fn
= dump_clx_n_config_for_cpu
;
1242 isst_ctdp_display_information_start(outf
);
1244 if (max_target_cpus
)
1245 for_each_online_target_cpu_in_set(fn
, NULL
, NULL
, NULL
, NULL
);
1247 for_each_online_package_in_set(fn
, NULL
, NULL
, NULL
, NULL
);
1249 isst_ctdp_display_information_end(outf
);
1252 static void set_tdp_level_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1257 ret
= isst_set_tdp_level(cpu
, tdp_level
);
1259 isst_display_error_info_message(1, "Set TDP level failed", 0, 0);
1260 isst_ctdp_display_information_end(outf
);
1263 isst_display_result(cpu
, outf
, "perf-profile", "set_tdp_level",
1265 if (force_online_offline
) {
1266 struct isst_pkg_ctdp_level_info ctdp_level
;
1267 int pkg_id
= get_physical_package_id(cpu
);
1268 int die_id
= get_physical_die_id(cpu
);
1270 fprintf(stderr
, "Option is set to online/offline\n");
1271 ctdp_level
.core_cpumask_size
=
1272 alloc_cpu_set(&ctdp_level
.core_cpumask
);
1273 ret
= isst_get_coremask_info(cpu
, tdp_level
, &ctdp_level
);
1275 isst_display_error_info_message(1, "Can't get coremask, online/offline option is ignored", 0, 0);
1278 if (ctdp_level
.cpu_count
) {
1279 int i
, max_cpus
= get_topo_max_cpus();
1280 for (i
= 0; i
< max_cpus
; ++i
) {
1281 if (pkg_id
!= get_physical_package_id(i
) || die_id
!= get_physical_die_id(i
))
1283 if (CPU_ISSET_S(i
, ctdp_level
.core_cpumask_size
, ctdp_level
.core_cpumask
)) {
1284 fprintf(stderr
, "online cpu %d\n", i
);
1285 set_cpu_online_offline(i
, 1);
1287 fprintf(stderr
, "offline cpu %d\n", i
);
1288 set_cpu_online_offline(i
, 0);
1296 static void set_tdp_level(int arg
)
1299 fprintf(stderr
, "Set Config TDP level\n");
1301 "\t Arguments: -l|--level : Specify tdp level\n");
1303 "\t Optional Arguments: -o | online : online/offline for the tdp level\n");
1305 "\t online/offline operation has limitations, refer to Linux hotplug documentation\n");
1309 if (tdp_level
== 0xff) {
1310 isst_display_error_info_message(1, "Invalid command: specify tdp_level", 0, 0);
1313 isst_ctdp_display_information_start(outf
);
1314 if (max_target_cpus
)
1315 for_each_online_target_cpu_in_set(set_tdp_level_for_cpu
, NULL
,
1318 for_each_online_package_in_set(set_tdp_level_for_cpu
, NULL
,
1320 isst_ctdp_display_information_end(outf
);
1323 static void clx_n_dump_pbf_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
1324 void *arg3
, void *arg4
)
1328 ret
= clx_n_config(cpu
);
1330 isst_display_error_info_message(1, "clx_n_config failed", 0, 0);
1332 struct isst_pkg_ctdp_level_info
*ctdp_level
;
1333 struct isst_pbf_info
*pbf_info
;
1335 ctdp_level
= &clx_n_pkg_dev
.ctdp_level
[0];
1336 pbf_info
= &ctdp_level
->pbf_info
;
1337 isst_pbf_display_information(cpu
, outf
, tdp_level
, pbf_info
);
1338 free_cpu_set(ctdp_level
->core_cpumask
);
1339 free_cpu_set(pbf_info
->core_cpumask
);
1343 static void dump_pbf_config_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1346 struct isst_pbf_info pbf_info
;
1349 ret
= isst_get_pbf_info(cpu
, tdp_level
, &pbf_info
);
1351 isst_display_error_info_message(1, "Failed to get base-freq info at this level", 1, tdp_level
);
1352 isst_ctdp_display_information_end(outf
);
1355 isst_pbf_display_information(cpu
, outf
, tdp_level
, &pbf_info
);
1356 isst_get_pbf_info_complete(&pbf_info
);
1360 static void dump_pbf_config(int arg
)
1366 "Print Intel(R) Speed Select Technology base frequency configuration for a TDP level\n");
1368 "\tArguments: -l|--level : Specify tdp level\n");
1372 if (tdp_level
== 0xff) {
1373 isst_display_error_info_message(1, "Invalid command: specify tdp_level", 0, 0);
1377 if (!is_clx_n_platform())
1378 fn
= dump_pbf_config_for_cpu
;
1380 fn
= clx_n_dump_pbf_config_for_cpu
;
1382 isst_ctdp_display_information_start(outf
);
1384 if (max_target_cpus
)
1385 for_each_online_target_cpu_in_set(fn
, NULL
, NULL
, NULL
, NULL
);
1387 for_each_online_package_in_set(fn
, NULL
, NULL
, NULL
, NULL
);
1389 isst_ctdp_display_information_end(outf
);
1392 static int set_clos_param(int cpu
, int clos
, int epp
, int wt
, int min
, int max
)
1394 struct isst_clos_config clos_config
;
1397 ret
= isst_pm_get_clos(cpu
, clos
, &clos_config
);
1399 isst_display_error_info_message(1, "isst_pm_get_clos failed", 0, 0);
1402 clos_config
.clos_min
= min
;
1403 clos_config
.clos_max
= max
;
1404 clos_config
.epp
= epp
;
1405 clos_config
.clos_prop_prio
= wt
;
1406 ret
= isst_set_clos(cpu
, clos
, &clos_config
);
1408 isst_display_error_info_message(1, "isst_set_clos failed", 0, 0);
1415 static int set_cpufreq_scaling_min_max(int cpu
, int max
, int freq
)
1417 char buffer
[128], freq_str
[16];
1421 snprintf(buffer
, sizeof(buffer
),
1422 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu
);
1424 snprintf(buffer
, sizeof(buffer
),
1425 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu
);
1427 fd
= open(buffer
, O_WRONLY
);
1431 snprintf(freq_str
, sizeof(freq_str
), "%d", freq
);
1432 len
= strlen(freq_str
);
1433 ret
= write(fd
, freq_str
, len
);
1443 static int set_clx_pbf_cpufreq_scaling_min_max(int cpu
)
1445 struct isst_pkg_ctdp_level_info
*ctdp_level
;
1446 struct isst_pbf_info
*pbf_info
;
1447 int i
, pkg_id
, die_id
, freq
, freq_high
, freq_low
;
1450 ret
= clx_n_config(cpu
);
1452 debug_printf("cpufreq_scaling_min_max failed for CLX");
1456 ctdp_level
= &clx_n_pkg_dev
.ctdp_level
[0];
1457 pbf_info
= &ctdp_level
->pbf_info
;
1458 freq_high
= pbf_info
->p1_high
* 100000;
1459 freq_low
= pbf_info
->p1_low
* 100000;
1461 pkg_id
= get_physical_package_id(cpu
);
1462 die_id
= get_physical_die_id(cpu
);
1463 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1464 if (pkg_id
!= get_physical_package_id(i
) ||
1465 die_id
!= get_physical_die_id(i
))
1468 if (CPU_ISSET_S(i
, pbf_info
->core_cpumask_size
,
1469 pbf_info
->core_cpumask
))
1474 set_cpufreq_scaling_min_max(i
, 1, freq
);
1475 set_cpufreq_scaling_min_max(i
, 0, freq
);
1481 static int set_cpufreq_scaling_min_max_from_cpuinfo(int cpu
, int cpuinfo_max
, int scaling_max
)
1483 char buffer
[128], min_freq
[16];
1486 if (!CPU_ISSET_S(cpu
, present_cpumask_size
, present_cpumask
))
1490 snprintf(buffer
, sizeof(buffer
),
1491 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu
);
1493 snprintf(buffer
, sizeof(buffer
),
1494 "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", cpu
);
1496 fd
= open(buffer
, O_RDONLY
);
1500 len
= read(fd
, min_freq
, sizeof(min_freq
));
1507 snprintf(buffer
, sizeof(buffer
),
1508 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu
);
1510 snprintf(buffer
, sizeof(buffer
),
1511 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu
);
1513 fd
= open(buffer
, O_WRONLY
);
1517 len
= strlen(min_freq
);
1518 ret
= write(fd
, min_freq
, len
);
1528 static void set_scaling_min_to_cpuinfo_max(int cpu
)
1530 int i
, pkg_id
, die_id
;
1532 pkg_id
= get_physical_package_id(cpu
);
1533 die_id
= get_physical_die_id(cpu
);
1534 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1535 if (pkg_id
!= get_physical_package_id(i
) ||
1536 die_id
!= get_physical_die_id(i
))
1539 set_cpufreq_scaling_min_max_from_cpuinfo(i
, 1, 0);
1543 static void set_scaling_min_to_cpuinfo_min(int cpu
)
1545 int i
, pkg_id
, die_id
;
1547 pkg_id
= get_physical_package_id(cpu
);
1548 die_id
= get_physical_die_id(cpu
);
1549 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1550 if (pkg_id
!= get_physical_package_id(i
) ||
1551 die_id
!= get_physical_die_id(i
))
1554 set_cpufreq_scaling_min_max_from_cpuinfo(i
, 0, 0);
1558 static void set_scaling_max_to_cpuinfo_max(int cpu
)
1560 int i
, pkg_id
, die_id
;
1562 pkg_id
= get_physical_package_id(cpu
);
1563 die_id
= get_physical_die_id(cpu
);
1564 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1565 if (pkg_id
!= get_physical_package_id(i
) ||
1566 die_id
!= get_physical_die_id(i
))
1569 set_cpufreq_scaling_min_max_from_cpuinfo(i
, 1, 1);
1573 static int set_core_priority_and_min(int cpu
, int mask_size
,
1574 cpu_set_t
*cpu_mask
, int min_high
,
1577 int pkg_id
, die_id
, ret
, i
;
1579 if (!CPU_COUNT_S(mask_size
, cpu_mask
))
1582 ret
= set_clos_param(cpu
, 0, 0, 0, min_high
, 0xff);
1586 ret
= set_clos_param(cpu
, 1, 15, 15, min_low
, 0xff);
1590 ret
= set_clos_param(cpu
, 2, 15, 15, min_low
, 0xff);
1594 ret
= set_clos_param(cpu
, 3, 15, 15, min_low
, 0xff);
1598 pkg_id
= get_physical_package_id(cpu
);
1599 die_id
= get_physical_die_id(cpu
);
1600 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1603 if (pkg_id
!= get_physical_package_id(i
) ||
1604 die_id
!= get_physical_die_id(i
))
1607 if (CPU_ISSET_S(i
, mask_size
, cpu_mask
))
1612 debug_printf("Associate cpu: %d clos: %d\n", i
, clos
);
1613 ret
= isst_clos_associate(i
, clos
);
1615 isst_display_error_info_message(1, "isst_clos_associate failed", 0, 0);
1623 static int set_pbf_core_power(int cpu
)
1625 struct isst_pbf_info pbf_info
;
1626 struct isst_pkg_ctdp pkg_dev
;
1629 ret
= isst_get_ctdp_levels(cpu
, &pkg_dev
);
1631 debug_printf("isst_get_ctdp_levels failed");
1634 debug_printf("Current_level: %d\n", pkg_dev
.current_level
);
1636 ret
= isst_get_pbf_info(cpu
, pkg_dev
.current_level
, &pbf_info
);
1638 debug_printf("isst_get_pbf_info failed");
1641 debug_printf("p1_high: %d p1_low: %d\n", pbf_info
.p1_high
,
1644 ret
= set_core_priority_and_min(cpu
, pbf_info
.core_cpumask_size
,
1645 pbf_info
.core_cpumask
,
1646 pbf_info
.p1_high
, pbf_info
.p1_low
);
1648 debug_printf("set_core_priority_and_min failed");
1652 ret
= isst_pm_qos_config(cpu
, 1, 1);
1654 debug_printf("isst_pm_qos_config failed");
1661 static void set_pbf_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1664 struct isst_pkg_ctdp_level_info ctdp_level
;
1665 struct isst_pkg_ctdp pkg_dev
;
1667 int status
= *(int *)arg4
;
1669 if (is_clx_n_platform()) {
1672 set_clx_pbf_cpufreq_scaling_min_max(cpu
);
1675 set_scaling_max_to_cpuinfo_max(cpu
);
1676 set_scaling_min_to_cpuinfo_min(cpu
);
1681 ret
= isst_get_ctdp_levels(cpu
, &pkg_dev
);
1683 isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
1687 ret
= isst_get_ctdp_control(cpu
, pkg_dev
.current_level
, &ctdp_level
);
1689 isst_display_error_info_message(1, "Failed to get current level", 0, 0);
1693 if (!ctdp_level
.pbf_support
) {
1694 isst_display_error_info_message(1, "base-freq feature is not present at this level", 1, pkg_dev
.current_level
);
1699 if (auto_mode
&& status
) {
1700 ret
= set_pbf_core_power(cpu
);
1705 ret
= isst_set_pbf_fact_status(cpu
, 1, status
);
1707 debug_printf("isst_set_pbf_fact_status failed");
1709 isst_pm_qos_config(cpu
, 0, 0);
1713 set_scaling_min_to_cpuinfo_max(cpu
);
1715 set_scaling_min_to_cpuinfo_min(cpu
);
1719 if (auto_mode
&& !status
)
1720 isst_pm_qos_config(cpu
, 0, 1);
1724 isst_display_result(cpu
, outf
, "base-freq", "enable",
1727 isst_display_result(cpu
, outf
, "base-freq", "disable",
1731 static void set_pbf_enable(int arg
)
1738 "Enable Intel Speed Select Technology base frequency feature\n");
1739 if (is_clx_n_platform()) {
1741 "\tOn this platform this command doesn't enable feature in the hardware.\n");
1743 "\tIt updates the cpufreq scaling_min_freq to match cpufreq base_frequency.\n");
1748 "\tOptional Arguments: -a|--auto : Use priority of cores to set core-power associations\n");
1751 if (is_clx_n_platform()) {
1753 "\tOn this platform this command doesn't disable feature in the hardware.\n");
1755 "\tIt updates the cpufreq scaling_min_freq to match cpuinfo_min_freq\n");
1759 "Disable Intel Speed Select Technology base frequency feature\n");
1761 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1766 isst_ctdp_display_information_start(outf
);
1767 if (max_target_cpus
)
1768 for_each_online_target_cpu_in_set(set_pbf_for_cpu
, NULL
, NULL
,
1771 for_each_online_package_in_set(set_pbf_for_cpu
, NULL
, NULL
,
1773 isst_ctdp_display_information_end(outf
);
1776 static void dump_fact_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
1777 void *arg3
, void *arg4
)
1779 struct isst_fact_info fact_info
;
1782 ret
= isst_get_fact_info(cpu
, tdp_level
, fact_bucket
, &fact_info
);
1784 isst_display_error_info_message(1, "Failed to get turbo-freq info at this level", 1, tdp_level
);
1785 isst_ctdp_display_information_end(outf
);
1788 isst_fact_display_information(cpu
, outf
, tdp_level
, fact_bucket
,
1789 fact_avx
, &fact_info
);
1793 static void dump_fact_config(int arg
)
1797 "Print complete Intel Speed Select Technology turbo frequency configuration for a TDP level. Other arguments are optional.\n");
1799 "\tArguments: -l|--level : Specify tdp level\n");
1801 "\tArguments: -b|--bucket : Bucket index to dump\n");
1803 "\tArguments: -r|--trl-type : Specify trl type: sse|avx2|avx512\n");
1807 if (tdp_level
== 0xff) {
1808 isst_display_error_info_message(1, "Invalid command: specify tdp_level\n", 0, 0);
1812 isst_ctdp_display_information_start(outf
);
1813 if (max_target_cpus
)
1814 for_each_online_target_cpu_in_set(dump_fact_config_for_cpu
,
1815 NULL
, NULL
, NULL
, NULL
);
1817 for_each_online_package_in_set(dump_fact_config_for_cpu
, NULL
,
1819 isst_ctdp_display_information_end(outf
);
1822 static void set_fact_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
1825 struct isst_pkg_ctdp_level_info ctdp_level
;
1826 struct isst_pkg_ctdp pkg_dev
;
1828 int status
= *(int *)arg4
;
1830 ret
= isst_get_ctdp_levels(cpu
, &pkg_dev
);
1832 isst_display_error_info_message(1, "Failed to get number of levels", 0, 0);
1836 ret
= isst_get_ctdp_control(cpu
, pkg_dev
.current_level
, &ctdp_level
);
1838 isst_display_error_info_message(1, "Failed to get current level", 0, 0);
1842 if (!ctdp_level
.fact_support
) {
1843 isst_display_error_info_message(1, "turbo-freq feature is not present at this level", 1, pkg_dev
.current_level
);
1849 ret
= isst_pm_qos_config(cpu
, 1, 1);
1854 ret
= isst_set_pbf_fact_status(cpu
, 0, status
);
1856 debug_printf("isst_set_pbf_fact_status failed");
1858 isst_pm_qos_config(cpu
, 0, 0);
1865 struct isst_pkg_ctdp pkg_dev
;
1867 ret
= isst_get_ctdp_levels(cpu
, &pkg_dev
);
1869 ret
= isst_set_trl(cpu
, fact_trl
);
1870 if (ret
&& auto_mode
)
1871 isst_pm_qos_config(cpu
, 0, 0);
1874 isst_pm_qos_config(cpu
, 0, 0);
1879 isst_display_result(cpu
, outf
, "turbo-freq", "enable", ret
);
1881 fact_enable_fail
= ret
;
1883 /* Since we modified TRL during Fact enable, restore it */
1884 isst_set_trl_from_current_tdp(cpu
, fact_trl
);
1885 isst_display_result(cpu
, outf
, "turbo-freq", "disable", ret
);
1889 static void set_fact_enable(int arg
)
1891 int i
, ret
, enable
= arg
;
1896 "Enable Intel Speed Select Technology Turbo frequency feature\n");
1898 "Optional: -t|--trl : Specify turbo ratio limit\n");
1900 "\tOptional Arguments: -a|--auto : Designate specified target CPUs with");
1902 "-C|--cpu option as as high priority using core-power feature\n");
1905 "Disable Intel Speed Select Technology turbo frequency feature\n");
1907 "Optional: -t|--trl : Specify turbo ratio limit\n");
1909 "\tOptional Arguments: -a|--auto : Also disable core-power associations\n");
1914 isst_ctdp_display_information_start(outf
);
1915 if (max_target_cpus
)
1916 for_each_online_target_cpu_in_set(set_fact_for_cpu
, NULL
, NULL
,
1919 for_each_online_package_in_set(set_fact_for_cpu
, NULL
, NULL
,
1921 isst_ctdp_display_information_end(outf
);
1923 if (!fact_enable_fail
&& enable
&& auto_mode
) {
1925 * When we adjust CLOS param, we have to set for siblings also.
1926 * So for the each user specified CPU, also add the sibling
1927 * in the present_cpu_mask.
1929 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1930 char buffer
[128], sibling_list
[128], *cpu_str
;
1933 if (!CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
1936 snprintf(buffer
, sizeof(buffer
),
1937 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i
);
1939 fd
= open(buffer
, O_RDONLY
);
1943 len
= read(fd
, sibling_list
, sizeof(sibling_list
));
1949 cpu_str
= strtok(sibling_list
, ",");
1950 while (cpu_str
!= NULL
) {
1953 sscanf(cpu_str
, "%d", &cpu
);
1954 CPU_SET_S(cpu
, target_cpumask_size
, target_cpumask
);
1955 cpu_str
= strtok(NULL
, ",");
1959 for (i
= 0; i
< get_topo_max_cpus(); ++i
) {
1962 if (!CPU_ISSET_S(i
, present_cpumask_size
, present_cpumask
))
1965 ret
= set_clos_param(i
, 0, 0, 0, 0, 0xff);
1969 ret
= set_clos_param(i
, 1, 15, 15, 0, 0xff);
1973 ret
= set_clos_param(i
, 2, 15, 15, 0, 0xff);
1977 ret
= set_clos_param(i
, 3, 15, 15, 0, 0xff);
1981 if (CPU_ISSET_S(i
, target_cpumask_size
, target_cpumask
))
1986 debug_printf("Associate cpu: %d clos: %d\n", i
, clos
);
1987 ret
= isst_clos_associate(i
, clos
);
1991 isst_display_result(-1, outf
, "turbo-freq --auto", "enable", 0);
1997 isst_display_result(i
, outf
, "turbo-freq --auto", "enable", ret
);
2001 static void enable_clos_qos_config(int cpu
, void *arg1
, void *arg2
, void *arg3
,
2005 int status
= *(int *)arg4
;
2007 if (is_skx_based_platform())
2008 clos_priority_type
= 1;
2010 ret
= isst_pm_qos_config(cpu
, status
, clos_priority_type
);
2012 isst_display_error_info_message(1, "isst_pm_qos_config failed", 0, 0);
2015 isst_display_result(cpu
, outf
, "core-power", "enable",
2018 isst_display_result(cpu
, outf
, "core-power", "disable",
2022 static void set_clos_enable(int arg
)
2029 "Enable core-power for a package/die\n");
2030 if (!is_skx_based_platform()) {
2032 "\tClos Enable: Specify priority type with [--priority|-p]\n");
2033 fprintf(stderr
, "\t\t 0: Proportional, 1: Ordered\n");
2037 "Disable core-power: [No command arguments are required]\n");
2042 if (enable
&& cpufreq_sysfs_present()) {
2044 "cpufreq subsystem and core-power enable will interfere with each other!\n");
2047 isst_ctdp_display_information_start(outf
);
2048 if (max_target_cpus
)
2049 for_each_online_target_cpu_in_set(enable_clos_qos_config
, NULL
,
2050 NULL
, NULL
, &enable
);
2052 for_each_online_package_in_set(enable_clos_qos_config
, NULL
,
2053 NULL
, NULL
, &enable
);
2054 isst_ctdp_display_information_end(outf
);
2057 static void dump_clos_config_for_cpu(int cpu
, void *arg1
, void *arg2
,
2058 void *arg3
, void *arg4
)
2060 struct isst_clos_config clos_config
;
2063 ret
= isst_pm_get_clos(cpu
, current_clos
, &clos_config
);
2065 isst_display_error_info_message(1, "isst_pm_get_clos failed", 0, 0);
2067 isst_clos_display_information(cpu
, outf
, current_clos
,
2071 static void dump_clos_config(int arg
)
2075 "Print Intel Speed Select Technology core power configuration\n");
2077 "\tArguments: [-c | --clos]: Specify clos id\n");
2080 if (current_clos
< 0 || current_clos
> 3) {
2081 isst_display_error_info_message(1, "Invalid clos id\n", 0, 0);
2082 isst_ctdp_display_information_end(outf
);
2086 isst_ctdp_display_information_start(outf
);
2087 if (max_target_cpus
)
2088 for_each_online_target_cpu_in_set(dump_clos_config_for_cpu
,
2089 NULL
, NULL
, NULL
, NULL
);
2091 for_each_online_package_in_set(dump_clos_config_for_cpu
, NULL
,
2093 isst_ctdp_display_information_end(outf
);
2096 static void get_clos_info_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
2099 int enable
, ret
, prio_type
;
2101 ret
= isst_clos_get_clos_information(cpu
, &enable
, &prio_type
);
2103 isst_display_error_info_message(1, "isst_clos_get_info failed", 0, 0);
2105 int cp_state
, cp_cap
;
2107 isst_read_pm_config(cpu
, &cp_state
, &cp_cap
);
2108 isst_clos_display_clos_information(cpu
, outf
, enable
, prio_type
,
2113 static void dump_clos_info(int arg
)
2117 "Print Intel Speed Select Technology core power information\n");
2118 fprintf(stderr
, "\t Optionally specify targeted cpu id with [--cpu|-c]\n");
2122 isst_ctdp_display_information_start(outf
);
2123 if (max_target_cpus
)
2124 for_each_online_target_cpu_in_set(get_clos_info_for_cpu
, NULL
,
2127 for_each_online_package_in_set(get_clos_info_for_cpu
, NULL
,
2129 isst_ctdp_display_information_end(outf
);
2133 static void set_clos_config_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
2136 struct isst_clos_config clos_config
;
2139 clos_config
.pkg_id
= get_physical_package_id(cpu
);
2140 clos_config
.die_id
= get_physical_die_id(cpu
);
2142 clos_config
.epp
= clos_epp
;
2143 clos_config
.clos_prop_prio
= clos_prop_prio
;
2144 clos_config
.clos_min
= clos_min
;
2145 clos_config
.clos_max
= clos_max
;
2146 clos_config
.clos_desired
= clos_desired
;
2147 ret
= isst_set_clos(cpu
, current_clos
, &clos_config
);
2149 isst_display_error_info_message(1, "isst_set_clos failed", 0, 0);
2151 isst_display_result(cpu
, outf
, "core-power", "config", ret
);
2154 static void set_clos_config(int arg
)
2158 "Set core-power configuration for one of the four clos ids\n");
2160 "\tSpecify targeted clos id with [--clos|-c]\n");
2161 if (!is_skx_based_platform()) {
2162 fprintf(stderr
, "\tSpecify clos EPP with [--epp|-e]\n");
2164 "\tSpecify clos Proportional Priority [--weight|-w]\n");
2166 fprintf(stderr
, "\tSpecify clos min in MHz with [--min|-n]\n");
2167 fprintf(stderr
, "\tSpecify clos max in MHz with [--max|-m]\n");
2171 if (current_clos
< 0 || current_clos
> 3) {
2172 isst_display_error_info_message(1, "Invalid clos id\n", 0, 0);
2175 if (!is_skx_based_platform() && (clos_epp
< 0 || clos_epp
> 0x0F)) {
2176 fprintf(stderr
, "clos epp is not specified or invalid, default: 0\n");
2179 if (!is_skx_based_platform() && (clos_prop_prio
< 0 || clos_prop_prio
> 0x0F)) {
2181 "clos frequency weight is not specified or invalid, default: 0\n");
2185 fprintf(stderr
, "clos min is not specified, default: 0\n");
2189 fprintf(stderr
, "clos max is not specified, default: Max frequency (ratio 0xff)\n");
2193 fprintf(stderr
, "clos desired is not supported on this platform\n");
2194 clos_desired
= 0x00;
2197 isst_ctdp_display_information_start(outf
);
2198 if (max_target_cpus
)
2199 for_each_online_target_cpu_in_set(set_clos_config_for_cpu
, NULL
,
2202 for_each_online_package_in_set(set_clos_config_for_cpu
, NULL
,
2204 isst_ctdp_display_information_end(outf
);
2207 static void set_clos_assoc_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
2212 ret
= isst_clos_associate(cpu
, current_clos
);
2214 debug_printf("isst_clos_associate failed");
2216 isst_display_result(cpu
, outf
, "core-power", "assoc", ret
);
2219 static void set_clos_assoc(int arg
)
2222 fprintf(stderr
, "Associate a clos id to a CPU\n");
2224 "\tSpecify targeted clos id with [--clos|-c]\n");
2226 "\tFor example to associate clos 1 to CPU 0: issue\n");
2228 "\tintel-speed-select --cpu 0 core-power assoc --clos 1\n");
2232 if (current_clos
< 0 || current_clos
> 3) {
2233 isst_display_error_info_message(1, "Invalid clos id\n", 0, 0);
2236 if (max_target_cpus
)
2237 for_each_online_target_cpu_in_set(set_clos_assoc_for_cpu
, NULL
,
2240 isst_display_error_info_message(1, "Invalid target cpu. Specify with [-c|--cpu]", 0, 0);
2244 static void get_clos_assoc_for_cpu(int cpu
, void *arg1
, void *arg2
, void *arg3
,
2249 ret
= isst_clos_get_assoc_status(cpu
, &clos
);
2251 isst_display_error_info_message(1, "isst_clos_get_assoc_status failed", 0, 0);
2253 isst_clos_display_assoc_information(cpu
, outf
, clos
);
2256 static void get_clos_assoc(int arg
)
2259 fprintf(stderr
, "Get associate clos id to a CPU\n");
2260 fprintf(stderr
, "\tSpecify targeted cpu id with [--cpu|-c]\n");
2264 if (!max_target_cpus
) {
2265 isst_display_error_info_message(1, "Invalid target cpu. Specify with [-c|--cpu]", 0, 0);
2269 isst_ctdp_display_information_start(outf
);
2270 for_each_online_target_cpu_in_set(get_clos_assoc_for_cpu
, NULL
,
2272 isst_ctdp_display_information_end(outf
);
2275 static struct process_cmd_struct clx_n_cmds
[] = {
2276 { "perf-profile", "info", dump_isst_config
, 0 },
2277 { "base-freq", "info", dump_pbf_config
, 0 },
2278 { "base-freq", "enable", set_pbf_enable
, 1 },
2279 { "base-freq", "disable", set_pbf_enable
, 0 },
2280 { NULL
, NULL
, NULL
, 0 }
2283 static struct process_cmd_struct isst_cmds
[] = {
2284 { "perf-profile", "get-lock-status", get_tdp_locked
, 0 },
2285 { "perf-profile", "get-config-levels", get_tdp_levels
, 0 },
2286 { "perf-profile", "get-config-version", get_tdp_version
, 0 },
2287 { "perf-profile", "get-config-enabled", get_tdp_enabled
, 0 },
2288 { "perf-profile", "get-config-current-level", get_tdp_current_level
,
2290 { "perf-profile", "set-config-level", set_tdp_level
, 0 },
2291 { "perf-profile", "info", dump_isst_config
, 0 },
2292 { "base-freq", "info", dump_pbf_config
, 0 },
2293 { "base-freq", "enable", set_pbf_enable
, 1 },
2294 { "base-freq", "disable", set_pbf_enable
, 0 },
2295 { "turbo-freq", "info", dump_fact_config
, 0 },
2296 { "turbo-freq", "enable", set_fact_enable
, 1 },
2297 { "turbo-freq", "disable", set_fact_enable
, 0 },
2298 { "core-power", "info", dump_clos_info
, 0 },
2299 { "core-power", "enable", set_clos_enable
, 1 },
2300 { "core-power", "disable", set_clos_enable
, 0 },
2301 { "core-power", "config", set_clos_config
, 0 },
2302 { "core-power", "get-config", dump_clos_config
, 0 },
2303 { "core-power", "assoc", set_clos_assoc
, 0 },
2304 { "core-power", "get-assoc", get_clos_assoc
, 0 },
2305 { NULL
, NULL
, NULL
}
2309 * parse cpuset with following syntax
2310 * 1,2,4..6,8-10 and set bits in cpu_subset
2312 void parse_cpu_command(char *optarg
)
2314 unsigned int start
, end
;
2319 while (next
&& *next
) {
2320 if (*next
== '-') /* no negative cpu numbers */
2323 start
= strtoul(next
, &next
, 10);
2325 if (max_target_cpus
< MAX_CPUS_IN_ONE_REQ
)
2326 target_cpus
[max_target_cpus
++] = start
;
2337 next
+= 1; /* start range */
2338 } else if (*next
== '.') {
2341 next
+= 1; /* start range */
2346 end
= strtoul(next
, &next
, 10);
2350 while (++start
<= end
) {
2351 if (max_target_cpus
< MAX_CPUS_IN_ONE_REQ
)
2352 target_cpus
[max_target_cpus
++] = start
;
2357 else if (*next
!= '\0')
2365 for (i
= 0; i
< max_target_cpus
; ++i
)
2366 printf("cpu [%d] in arg\n", target_cpus
[i
]);
2372 fprintf(stderr
, "\"--cpu %s\" malformed\n", optarg
);
2376 static void parse_cmd_args(int argc
, int start
, char **argv
)
2381 static struct option long_options
[] = {
2382 { "bucket", required_argument
, 0, 'b' },
2383 { "level", required_argument
, 0, 'l' },
2384 { "online", required_argument
, 0, 'o' },
2385 { "trl-type", required_argument
, 0, 'r' },
2386 { "trl", required_argument
, 0, 't' },
2387 { "help", no_argument
, 0, 'h' },
2388 { "clos", required_argument
, 0, 'c' },
2389 { "desired", required_argument
, 0, 'd' },
2390 { "epp", required_argument
, 0, 'e' },
2391 { "min", required_argument
, 0, 'n' },
2392 { "max", required_argument
, 0, 'm' },
2393 { "priority", required_argument
, 0, 'p' },
2394 { "weight", required_argument
, 0, 'w' },
2395 { "auto", no_argument
, 0, 'a' },
2399 option_index
= start
;
2402 while ((opt
= getopt_long(argc
, argv
, "b:l:t:c:d:e:n:m:p:w:r:hoa",
2403 long_options
, &option_index
)) != -1) {
2409 fact_bucket
= atoi(optarg
);
2415 tdp_level
= atoi(optarg
);
2418 force_online_offline
= 1;
2421 sscanf(optarg
, "0x%llx", &fact_trl
);
2424 if (!strncmp(optarg
, "sse", 3)) {
2426 } else if (!strncmp(optarg
, "avx2", 4)) {
2428 } else if (!strncmp(optarg
, "avx512", 6)) {
2431 fprintf(outf
, "Invalid sse,avx options\n");
2437 current_clos
= atoi(optarg
);
2440 clos_desired
= atoi(optarg
);
2441 clos_desired
/= DISP_FREQ_MULTIPLIER
;
2444 clos_epp
= atoi(optarg
);
2445 if (is_skx_based_platform()) {
2446 isst_display_error_info_message(1, "epp can't be specified on this platform", 0, 0);
2451 clos_min
= atoi(optarg
);
2452 clos_min
/= DISP_FREQ_MULTIPLIER
;
2455 clos_max
= atoi(optarg
);
2456 clos_max
/= DISP_FREQ_MULTIPLIER
;
2459 clos_priority_type
= atoi(optarg
);
2460 if (is_skx_based_platform() && !clos_priority_type
) {
2461 isst_display_error_info_message(1, "Invalid clos priority type: proportional for this platform", 0, 0);
2466 clos_prop_prio
= atoi(optarg
);
2467 if (is_skx_based_platform()) {
2468 isst_display_error_info_message(1, "weight can't be specified on this platform", 0, 0);
2473 printf("Unknown option: ignore\n");
2478 printf("Garbage at the end of command: ignore\n");
2481 static void isst_help(void)
2483 printf("perf-profile:\tAn architectural mechanism that allows multiple optimized \n\
2484 performance profiles per system via static and/or dynamic\n\
2485 adjustment of core count, workload, Tjmax, and\n\
2487 printf("\nCommands : For feature=perf-profile\n");
2490 if (!is_clx_n_platform()) {
2491 printf("\tget-lock-status\n");
2492 printf("\tget-config-levels\n");
2493 printf("\tget-config-version\n");
2494 printf("\tget-config-enabled\n");
2495 printf("\tget-config-current-level\n");
2496 printf("\tset-config-level\n");
2500 static void pbf_help(void)
2502 printf("base-freq:\tEnables users to increase guaranteed base frequency\n\
2503 on certain cores (high priority cores) in exchange for lower\n\
2504 base frequency on remaining cores (low priority cores).\n");
2505 printf("\tcommand : info\n");
2506 printf("\tcommand : enable\n");
2507 printf("\tcommand : disable\n");
2510 static void fact_help(void)
2512 printf("turbo-freq:\tEnables the ability to set different turbo ratio\n\
2513 limits to cores based on priority.\n");
2514 printf("\nCommand: For feature=turbo-freq\n");
2515 printf("\tcommand : info\n");
2516 printf("\tcommand : enable\n");
2517 printf("\tcommand : disable\n");
2520 static void core_power_help(void)
2522 printf("core-power:\tInterface that allows user to define per core/tile\n\
2524 printf("\nCommands : For feature=core-power\n");
2526 printf("\tenable\n");
2527 printf("\tdisable\n");
2528 printf("\tconfig\n");
2529 printf("\tget-config\n");
2530 printf("\tassoc\n");
2531 printf("\tget-assoc\n");
2534 struct process_cmd_help_struct
{
2536 void (*process_fn
)(void);
2539 static struct process_cmd_help_struct isst_help_cmds
[] = {
2540 { "perf-profile", isst_help
},
2541 { "base-freq", pbf_help
},
2542 { "turbo-freq", fact_help
},
2543 { "core-power", core_power_help
},
2547 static struct process_cmd_help_struct clx_n_help_cmds
[] = {
2548 { "perf-profile", isst_help
},
2549 { "base-freq", pbf_help
},
2553 void process_command(int argc
, char **argv
,
2554 struct process_cmd_help_struct
*help_cmds
,
2555 struct process_cmd_struct
*cmds
)
2557 int i
= 0, matched
= 0;
2558 char *feature
= argv
[optind
];
2559 char *cmd
= argv
[optind
+ 1];
2561 if (!feature
|| !cmd
)
2564 debug_printf("feature name [%s] command [%s]\n", feature
, cmd
);
2565 if (!strcmp(cmd
, "-h") || !strcmp(cmd
, "--help")) {
2566 while (help_cmds
[i
].feature
) {
2567 if (!strcmp(help_cmds
[i
].feature
, feature
)) {
2568 help_cmds
[i
].process_fn();
2575 if (!is_clx_n_platform())
2579 while (cmds
[i
].feature
) {
2580 if (!strcmp(cmds
[i
].feature
, feature
) &&
2581 !strcmp(cmds
[i
].command
, cmd
)) {
2582 parse_cmd_args(argc
, optind
+ 1, argv
);
2583 cmds
[i
].process_fn(cmds
[i
].arg
);
2591 fprintf(stderr
, "Invalid command\n");
2594 static void usage(void)
2596 if (is_clx_n_platform()) {
2597 fprintf(stderr
, "\nThere is limited support of Intel Speed Select features on this platform.\n");
2598 fprintf(stderr
, "Everything is pre-configured using BIOS options, this tool can't enable any feature in the hardware.\n\n");
2601 printf("\nUsage:\n");
2602 printf("intel-speed-select [OPTIONS] FEATURE COMMAND COMMAND_ARGUMENTS\n");
2603 printf("\nUse this tool to enumerate and control the Intel Speed Select Technology features:\n");
2604 if (is_clx_n_platform())
2605 printf("\nFEATURE : [perf-profile|base-freq]\n");
2607 printf("\nFEATURE : [perf-profile|base-freq|turbo-freq|core-power]\n");
2608 printf("\nFor help on each feature, use -h|--help\n");
2609 printf("\tFor example: intel-speed-select perf-profile -h\n");
2611 printf("\nFor additional help on each command for a feature, use --h|--help\n");
2612 printf("\tFor example: intel-speed-select perf-profile get-lock-status -h\n");
2613 printf("\t\t This will print help for the command \"get-lock-status\" for the feature \"perf-profile\"\n");
2615 printf("\nOPTIONS\n");
2616 printf("\t[-c|--cpu] : logical cpu number\n");
2617 printf("\t\tDefault: Die scoped for all dies in the system with multiple dies/package\n");
2618 printf("\t\t\t Or Package scoped for all Packages when each package contains one die\n");
2619 printf("\t[-d|--debug] : Debug mode\n");
2620 printf("\t[-f|--format] : output format [json|text]. Default: text\n");
2621 printf("\t[-h|--help] : Print help\n");
2622 printf("\t[-i|--info] : Print platform information\n");
2623 printf("\t[-o|--out] : Output file\n");
2624 printf("\t\t\tDefault : stderr\n");
2625 printf("\t[-p|--pause] : Delay between two mail box commands in milliseconds\n");
2626 printf("\t[-r|--retry] : Retry count for mail box commands on failure, default 3\n");
2627 printf("\t[-v|--version] : Print version\n");
2629 printf("\nResult format\n");
2630 printf("\tResult display uses a common format for each command:\n");
2631 printf("\tResults are formatted in text/JSON with\n");
2632 printf("\t\tPackage, Die, CPU, and command specific results.\n");
2634 printf("\nExamples\n");
2635 printf("\tTo get platform information:\n");
2636 printf("\t\tintel-speed-select --info\n");
2637 printf("\tTo get full perf-profile information dump:\n");
2638 printf("\t\tintel-speed-select perf-profile info\n");
2639 printf("\tTo get full base-freq information dump:\n");
2640 printf("\t\tintel-speed-select base-freq info -l 0\n");
2641 if (!is_clx_n_platform()) {
2642 printf("\tTo get full turbo-freq information dump:\n");
2643 printf("\t\tintel-speed-select turbo-freq info -l 0\n");
2648 static void print_version(void)
2650 fprintf(outf
, "Version %s\n", version_str
);
2651 fprintf(outf
, "Build date %s time %s\n", __DATE__
, __TIME__
);
2655 static void cmdline(int argc
, char **argv
)
2657 const char *pathname
= "/dev/isst_interface";
2661 int option_index
= 0;
2664 static struct option long_options
[] = {
2665 { "cpu", required_argument
, 0, 'c' },
2666 { "debug", no_argument
, 0, 'd' },
2667 { "format", required_argument
, 0, 'f' },
2668 { "help", no_argument
, 0, 'h' },
2669 { "info", no_argument
, 0, 'i' },
2670 { "pause", required_argument
, 0, 'p' },
2671 { "out", required_argument
, 0, 'o' },
2672 { "retry", required_argument
, 0, 'r' },
2673 { "version", no_argument
, 0, 'v' },
2677 if (geteuid() != 0) {
2678 fprintf(stderr
, "Must run as root\n");
2682 ret
= update_cpu_model();
2684 err(-1, "Invalid CPU model (%d)\n", cpu_model
);
2685 printf("Intel(R) Speed Select Technology\n");
2686 printf("Executing on CPU model:%d[0x%x]\n", cpu_model
, cpu_model
);
2688 if (!is_clx_n_platform()) {
2689 fp
= fopen(pathname
, "rb");
2691 fprintf(stderr
, "Intel speed select drivers are not loaded on this system.\n");
2692 fprintf(stderr
, "Verify that kernel config includes CONFIG_INTEL_SPEED_SELECT_INTERFACE.\n");
2693 fprintf(stderr
, "If the config is included then this is not a supported platform.\n");
2700 while ((opt
= getopt_long_only(argc
, argv
, "+c:df:hio:v", long_options
,
2701 &option_index
)) != -1) {
2704 parse_cpu_command(optarg
);
2708 printf("Debug Mode ON\n");
2711 if (!strncmp(optarg
, "json", 4))
2712 out_format_json
= 1;
2718 isst_print_platform_information();
2723 outf
= fopen_or_exit(optarg
, "w");
2726 ret
= strtol(optarg
, &ptr
, 10);
2728 fprintf(stderr
, "Invalid pause interval, ignore\n");
2733 ret
= strtol(optarg
, &ptr
, 10);
2735 fprintf(stderr
, "Invalid retry count, ignore\n");
2747 if (optind
> (argc
- 2)) {
2752 store_cpu_topology();
2753 set_cpu_present_cpu_mask();
2754 set_cpu_target_cpu_mask();
2756 if (!is_clx_n_platform()) {
2757 ret
= isst_fill_platform_info();
2760 process_command(argc
, argv
, isst_help_cmds
, isst_cmds
);
2762 process_command(argc
, argv
, clx_n_help_cmds
, clx_n_cmds
);
2765 free_cpu_set(present_cpumask
);
2766 free_cpu_set(target_cpumask
);
2769 int main(int argc
, char **argv
)
2772 cmdline(argc
, argv
);