tools/power/x86/intel-speed-select: Add options to force online
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Mon, 29 Mar 2021 17:24:41 +0000 (10:24 -0700)
committerHans de Goede <hdegoede@redhat.com>
Wed, 7 Apr 2021 17:47:22 +0000 (19:47 +0200)
It is possible that users manually offlined CPUs via sysfs interface
and then started this utility. In this case we will not be able to get
package and die id of the those CPUs. So add an option to force online
if required for some commands.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
tools/power/x86/intel-speed-select/isst-config.c

index 7b98a4a52d9ea8a95bfad39f27f047d5c5947427..398938879e9f3b071d6df39b7023f272a0fe4b68 100644 (file)
@@ -381,6 +381,18 @@ static void set_cpu_online_offline(int cpu, int state)
        close(fd);
 }
 
+static void force_all_cpus_online(void)
+{
+       int i;
+
+       fprintf(stderr, "Forcing all CPUs online\n");
+
+       for (i = 0; i < topo_max_cpus; ++i)
+               set_cpu_online_offline(i, 1);
+
+       unlink("/var/run/isst_cpu_topology.dat");
+}
+
 #define MAX_PACKAGE_COUNT 8
 #define MAX_DIE_PER_PACKAGE 2
 static void for_each_online_package_in_set(void (*callback)(int, void *, void *,
@@ -2767,6 +2779,7 @@ static void usage(void)
        printf("\t[-f|--format] : output format [json|text]. Default: text\n");
        printf("\t[-h|--help] : Print help\n");
        printf("\t[-i|--info] : Print platform information\n");
+       printf("\t[-a|--all-cpus-online] : Force online every CPU in the system\n");
        printf("\t[-o|--out] : Output file\n");
        printf("\t\t\tDefault : stderr\n");
        printf("\t[-p|--pause] : Delay between two mail box commands in milliseconds\n");
@@ -2804,11 +2817,12 @@ static void cmdline(int argc, char **argv)
        const char *pathname = "/dev/isst_interface";
        char *ptr;
        FILE *fp;
-       int opt;
+       int opt, force_cpus_online = 0;
        int option_index = 0;
        int ret;
 
        static struct option long_options[] = {
+               { "all-cpus-online", no_argument, 0, 'a' },
                { "cpu", required_argument, 0, 'c' },
                { "debug", no_argument, 0, 'd' },
                { "format", required_argument, 0, 'f' },
@@ -2844,9 +2858,12 @@ static void cmdline(int argc, char **argv)
        }
 
        progname = argv[0];
-       while ((opt = getopt_long_only(argc, argv, "+c:df:hio:v", long_options,
+       while ((opt = getopt_long_only(argc, argv, "+c:df:hio:va", long_options,
                                       &option_index)) != -1) {
                switch (opt) {
+               case 'a':
+                       force_cpus_online = 1;
+                       break;
                case 'c':
                        parse_cpu_command(optarg);
                        break;
@@ -2896,6 +2913,8 @@ static void cmdline(int argc, char **argv)
                exit(0);
        }
        set_max_cpu_num();
+       if (force_cpus_online)
+               force_all_cpus_online();
        store_cpu_topology();
        set_cpu_present_cpu_mask();
        set_cpu_target_cpu_mask();