summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>2019-09-14 15:45:44 -0400
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>2019-09-19 07:51:29 -0400
commit3c64c81ad1f06823b603e9143193dcb4f3121a2f (patch)
tree73d2814f8eb8cd50175459bd79ded56cfe776e77 /tools
parent44460efe44e05eae2f21e57d06d542bbbb792e65 (diff)
tools/power/x86/intel-speed-select: Allow online/offline based on tdp
Using enable core mask, do online offline CPUs. There is a new option --online|-o for set-config-level. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/power/x86/intel-speed-select/isst-config.c60
-rw-r--r--tools/power/x86/intel-speed-select/isst.h2
2 files changed, 58 insertions, 4 deletions
diff --git a/tools/power/x86/intel-speed-select/isst-config.c b/tools/power/x86/intel-speed-select/isst-config.c
index 83ac72902b36..e505aaf2beef 100644
--- a/tools/power/x86/intel-speed-select/isst-config.c
+++ b/tools/power/x86/intel-speed-select/isst-config.c
@@ -38,6 +38,7 @@ static int fact_avx = 0xFF;
38static unsigned long long fact_trl; 38static unsigned long long fact_trl;
39static int out_format_json; 39static int out_format_json;
40static int cmd_help; 40static int cmd_help;
41static int force_online_offline;
41 42
42/* clos related */ 43/* clos related */
43static int current_clos = -1; 44static int current_clos = -1;
@@ -138,14 +139,14 @@ int out_format_is_json(void)
138int get_physical_package_id(int cpu) 139int get_physical_package_id(int cpu)
139{ 140{
140 return parse_int_file( 141 return parse_int_file(
141 1, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", 142 0, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",
142 cpu); 143 cpu);
143} 144}
144 145
145int get_physical_core_id(int cpu) 146int get_physical_core_id(int cpu)
146{ 147{
147 return parse_int_file( 148 return parse_int_file(
148 1, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); 149 0, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu);
149} 150}
150 151
151int get_physical_die_id(int cpu) 152int get_physical_die_id(int cpu)
@@ -165,6 +166,26 @@ int get_topo_max_cpus(void)
165 return topo_max_cpus; 166 return topo_max_cpus;
166} 167}
167 168
169static void set_cpu_online_offline(int cpu, int state)
170{
171 char buffer[128];
172 int fd;
173
174 snprintf(buffer, sizeof(buffer),
175 "/sys/devices/system/cpu/cpu%d/online", cpu);
176
177 fd = open(buffer, O_WRONLY);
178 if (fd < 0)
179 err(-1, "%s open failed", buffer);
180
181 if (state)
182 write(fd, "1\n", 2);
183 else
184 write(fd, "0\n", 2);
185
186 close(fd);
187}
188
168#define MAX_PACKAGE_COUNT 8 189#define MAX_PACKAGE_COUNT 8
169#define MAX_DIE_PER_PACKAGE 2 190#define MAX_DIE_PER_PACKAGE 2
170static void for_each_online_package_in_set(void (*callback)(int, void *, void *, 191static void for_each_online_package_in_set(void (*callback)(int, void *, void *,
@@ -736,9 +757,34 @@ static void set_tdp_level_for_cpu(int cpu, void *arg1, void *arg2, void *arg3,
736 ret = isst_set_tdp_level(cpu, tdp_level); 757 ret = isst_set_tdp_level(cpu, tdp_level);
737 if (ret) 758 if (ret)
738 perror("set_tdp_level_for_cpu"); 759 perror("set_tdp_level_for_cpu");
739 else 760 else {
740 isst_display_result(cpu, outf, "perf-profile", "set_tdp_level", 761 isst_display_result(cpu, outf, "perf-profile", "set_tdp_level",
741 ret); 762 ret);
763 if (force_online_offline) {
764 struct isst_pkg_ctdp_level_info ctdp_level;
765 int pkg_id = get_physical_package_id(cpu);
766 int die_id = get_physical_die_id(cpu);
767
768 fprintf(stderr, "Option is set to online/offline\n");
769 ctdp_level.core_cpumask_size =
770 alloc_cpu_set(&ctdp_level.core_cpumask);
771 isst_get_coremask_info(cpu, tdp_level, &ctdp_level);
772 if (ctdp_level.cpu_count) {
773 int i, max_cpus = get_topo_max_cpus();
774 for (i = 0; i < max_cpus; ++i) {
775 if (pkg_id != get_physical_package_id(i) || die_id != get_physical_die_id(i))
776 continue;
777 if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
778 fprintf(stderr, "online cpu %d\n", i);
779 set_cpu_online_offline(i, 1);
780 } else {
781 fprintf(stderr, "offline cpu %d\n", i);
782 set_cpu_online_offline(i, 0);
783 }
784 }
785 }
786 }
787 }
742} 788}
743 789
744static void set_tdp_level(void) 790static void set_tdp_level(void)
@@ -747,6 +793,8 @@ static void set_tdp_level(void)
747 fprintf(stderr, "Set Config TDP level\n"); 793 fprintf(stderr, "Set Config TDP level\n");
748 fprintf(stderr, 794 fprintf(stderr,
749 "\t Arguments: -l|--level : Specify tdp level\n"); 795 "\t Arguments: -l|--level : Specify tdp level\n");
796 fprintf(stderr,
797 "\t Optional Arguments: -o | online : online/offline for the tdp level\n");
750 exit(0); 798 exit(0);
751 } 799 }
752 800
@@ -1319,6 +1367,7 @@ static void parse_cmd_args(int argc, int start, char **argv)
1319 static struct option long_options[] = { 1367 static struct option long_options[] = {
1320 { "bucket", required_argument, 0, 'b' }, 1368 { "bucket", required_argument, 0, 'b' },
1321 { "level", required_argument, 0, 'l' }, 1369 { "level", required_argument, 0, 'l' },
1370 { "online", required_argument, 0, 'o' },
1322 { "trl-type", required_argument, 0, 'r' }, 1371 { "trl-type", required_argument, 0, 'r' },
1323 { "trl", required_argument, 0, 't' }, 1372 { "trl", required_argument, 0, 't' },
1324 { "help", no_argument, 0, 'h' }, 1373 { "help", no_argument, 0, 'h' },
@@ -1335,7 +1384,7 @@ static void parse_cmd_args(int argc, int start, char **argv)
1335 option_index = start; 1384 option_index = start;
1336 1385
1337 optind = start + 1; 1386 optind = start + 1;
1338 while ((opt = getopt_long(argc, argv, "b:l:t:c:d:e:n:m:p:w:h", 1387 while ((opt = getopt_long(argc, argv, "b:l:t:c:d:e:n:m:p:w:ho",
1339 long_options, &option_index)) != -1) { 1388 long_options, &option_index)) != -1) {
1340 switch (opt) { 1389 switch (opt) {
1341 case 'b': 1390 case 'b':
@@ -1347,6 +1396,9 @@ static void parse_cmd_args(int argc, int start, char **argv)
1347 case 'l': 1396 case 'l':
1348 tdp_level = atoi(optarg); 1397 tdp_level = atoi(optarg);
1349 break; 1398 break;
1399 case 'o':
1400 force_online_offline = 1;
1401 break;
1350 case 't': 1402 case 't':
1351 sscanf(optarg, "0x%llx", &fact_trl); 1403 sscanf(optarg, "0x%llx", &fact_trl);
1352 break; 1404 break;
diff --git a/tools/power/x86/intel-speed-select/isst.h b/tools/power/x86/intel-speed-select/isst.h
index 2f7f62765eb6..668f914d077f 100644
--- a/tools/power/x86/intel-speed-select/isst.h
+++ b/tools/power/x86/intel-speed-select/isst.h
@@ -187,6 +187,8 @@ extern int isst_send_msr_command(unsigned int cpu, unsigned int command,
187 int write, unsigned long long *req_resp); 187 int write, unsigned long long *req_resp);
188 188
189extern int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev); 189extern int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev);
190extern int isst_get_coremask_info(int cpu, int config_index,
191 struct isst_pkg_ctdp_level_info *ctdp_level);
190extern int isst_get_process_ctdp(int cpu, int tdp_level, 192extern int isst_get_process_ctdp(int cpu, int tdp_level,
191 struct isst_pkg_ctdp *pkg_dev); 193 struct isst_pkg_ctdp *pkg_dev);
192extern void isst_get_process_ctdp_complete(int cpu, 194extern void isst_get_process_ctdp_complete(int cpu,