Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpupower: Introduce idle-set subcommand and C-state enabling/disabling

Example:

cpupower idle-set -d 3

will disable C-state 3 on all processors (set commands are active on
all CPUs by default), same as:

cpupower -c all idle-set -d 3

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Thomas Renninger and committed by
Rafael J. Wysocki
c4f3610e 0924c369

+142 -9
+2 -1
tools/power/cpupower/Makefile
··· 131 131 utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \ 132 132 utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \ 133 133 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ 134 - utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o 134 + utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \ 135 + utils/cpuidle-set.o 135 136 136 137 UTIL_SRC := $(UTIL_OBJS:.o=.c) 137 138
+9 -1
tools/power/cpupower/man/cpupower-monitor.1
··· 110 110 kernel frequency driver periodically cleared aperf/mperf registers in those 111 111 kernels. 112 112 113 - .SS "Nehalem" "SandyBridge" 113 + .SS "Nehalem" "SandyBridge" "HaswellExtended" 114 114 Intel Core and Package sleep state counters. 115 115 Threads (hyperthreaded cores) may not be able to enter deeper core states if 116 116 its sibling is utilized. 117 117 Deepest package sleep states may in reality show up as machine/platform wide 118 118 sleep states and can only be entered if all cores are idle. Look up Intel 119 119 manuals (some are provided in the References section) for further details. 120 + The monitors are named after the CPU family where the sleep state capabilities 121 + got introduced and may not match exactly the CPU name of the platform. 122 + For example an IvyBridge processor has sleep state capabilities which got 123 + introduced in Nehalem and SandyBridge processor families. 124 + Thus on an IvyBridge processor one will get Nehalem and SandyBridge sleep 125 + state monitors. 126 + HaswellExtended extra package sleep state capabilities are available only in a 127 + specific Haswell (family 0x45) and probably also other future processors. 120 128 121 129 .SS "Fam_12h" "Fam_14h" 122 130 AMD laptop and desktop processor (family 12h and 14h) sleep state counters.
+1
tools/power/cpupower/utils/builtin.h
··· 5 5 extern int cmd_info(int argc, const char **argv); 6 6 extern int cmd_freq_set(int argc, const char **argv); 7 7 extern int cmd_freq_info(int argc, const char **argv); 8 + extern int cmd_idle_set(int argc, const char **argv); 8 9 extern int cmd_idle_info(int argc, const char **argv); 9 10 extern int cmd_monitor(int argc, const char **argv); 10 11
+5 -1
tools/power/cpupower/utils/cpuidle-info.c
··· 48 48 return; 49 49 50 50 for (idlestate = 0; idlestate < idlestates; idlestate++) { 51 + int disabled = sysfs_is_idlestate_disabled(cpu, idlestate); 52 + /* Disabled interface not supported on older kernels */ 53 + if (disabled < 0) 54 + disabled = 0; 51 55 tmp = sysfs_get_idlestate_name(cpu, idlestate); 52 56 if (!tmp) 53 57 continue; 54 - printf("%s:\n", tmp); 58 + printf("%s%s:\n", tmp, (disabled) ? " (DISABLED) " : ""); 55 59 free(tmp); 56 60 57 61 tmp = sysfs_get_idlestate_desc(cpu, idlestate);
+118
tools/power/cpupower/utils/cpuidle-set.c
··· 1 + #include <unistd.h> 2 + #include <stdio.h> 3 + #include <errno.h> 4 + #include <stdlib.h> 5 + #include <limits.h> 6 + #include <string.h> 7 + #include <ctype.h> 8 + 9 + #include <getopt.h> 10 + 11 + #include "cpufreq.h" 12 + #include "helpers/helpers.h" 13 + #include "helpers/sysfs.h" 14 + 15 + static struct option info_opts[] = { 16 + { .name = "disable", .has_arg = required_argument, .flag = NULL, .val = 'd'}, 17 + { .name = "enable", .has_arg = required_argument, .flag = NULL, .val = 'e'}, 18 + { }, 19 + }; 20 + 21 + 22 + int cmd_idle_set(int argc, char **argv) 23 + { 24 + extern char *optarg; 25 + extern int optind, opterr, optopt; 26 + int ret = 0, cont = 1, param = 0, idlestate = 0; 27 + unsigned int cpu = 0; 28 + 29 + do { 30 + ret = getopt_long(argc, argv, "d:e:", info_opts, NULL); 31 + if (ret == -1) 32 + break; 33 + switch (ret) { 34 + case '?': 35 + param = '?'; 36 + cont = 0; 37 + break; 38 + case 'd': 39 + if (param) { 40 + param = -1; 41 + cont = 0; 42 + break; 43 + } 44 + param = ret; 45 + idlestate = atoi(optarg); 46 + break; 47 + case 'e': 48 + if (param) { 49 + param = -1; 50 + cont = 0; 51 + break; 52 + } 53 + param = ret; 54 + idlestate = atoi(optarg); 55 + break; 56 + case -1: 57 + cont = 0; 58 + break; 59 + } 60 + } while (cont); 61 + 62 + switch (param) { 63 + case -1: 64 + printf(_("You can't specify more than one " 65 + "output-specific argument\n")); 66 + exit(EXIT_FAILURE); 67 + case '?': 68 + printf(_("invalid or unknown argument\n")); 69 + exit(EXIT_FAILURE); 70 + } 71 + 72 + /* Default is: set all CPUs */ 73 + if (bitmask_isallclear(cpus_chosen)) 74 + bitmask_setall(cpus_chosen); 75 + 76 + for (cpu = bitmask_first(cpus_chosen); 77 + cpu <= bitmask_last(cpus_chosen); cpu++) { 78 + 79 + if (!bitmask_isbitset(cpus_chosen, cpu)) 80 + continue; 81 + 82 + switch (param) { 83 + 84 + case 'd': 85 + ret = sysfs_idlestate_disable(cpu, idlestate, 1); 86 + if (ret == 0) 87 + printf(_("Idlestate %u disabled on CPU %u\n"), idlestate, cpu); 88 + else if (ret == -1) 89 + printf(_("Idlestate %u not available on CPU %u\n"), 90 + idlestate, cpu); 91 + else if (ret == -2) 92 + printf(_("Idlestate disabling not supported by kernel\n")); 93 + else 94 + printf(_("Idlestate %u not disabled on CPU %u\n"), 95 + idlestate, cpu); 96 + break; 97 + case 'e': 98 + ret = sysfs_idlestate_disable(cpu, idlestate, 0); 99 + if (ret == 0) 100 + printf(_("Idlestate %u enabled on CPU %u\n"), idlestate, cpu); 101 + else if (ret == -1) 102 + printf(_("Idlestate %u not available on CPU %u\n"), 103 + idlestate, cpu); 104 + else if (ret == -2) 105 + printf(_("Idlestate enabling not supported by kernel\n")); 106 + else 107 + printf(_("Idlestate %u not enabled on CPU %u\n"), 108 + idlestate, cpu); 109 + break; 110 + default: 111 + /* Not reachable with proper args checking */ 112 + printf(_("Invalid or unknown argument\n")); 113 + exit(EXIT_FAILURE); 114 + break; 115 + } 116 + } 117 + return EXIT_SUCCESS; 118 + }
+7 -6
tools/power/cpupower/utils/cpupower.c
··· 17 17 #include "helpers/helpers.h" 18 18 #include "helpers/bitmask.h" 19 19 20 - struct cmd_struct { 21 - const char *cmd; 22 - int (*main)(int, const char **); 23 - int needs_root; 24 - }; 25 - 26 20 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 27 21 28 22 static int cmd_help(int argc, const char **argv); ··· 37 43 38 44 static void print_help(void); 39 45 46 + struct cmd_struct { 47 + const char *cmd; 48 + int (*main)(int, const char **); 49 + int needs_root; 50 + }; 51 + 40 52 static struct cmd_struct commands[] = { 41 53 { "frequency-info", cmd_freq_info, 0 }, 42 54 { "frequency-set", cmd_freq_set, 1 }, 43 55 { "idle-info", cmd_idle_info, 0 }, 56 + { "idle-set", cmd_idle_set, 1 }, 44 57 { "set", cmd_set, 1 }, 45 58 { "info", cmd_info, 0 }, 46 59 { "monitor", cmd_monitor, 0 },