cpupower: Add turbo-boost support in cpupower
authorWyes Karny <wyes.karny@amd.com>
Mon, 19 Jun 2023 19:05:03 +0000 (19:05 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 18 Jul 2023 22:07:01 +0000 (16:07 -0600)
If boost sysfs (/sys/devices/system/cpu/cpufreq/boost) file is present
turbo-boost is feature is supported in the hardware. By default this
feature should be enabled. But to disable/enable it write to the sysfs
file. Use the same to control this feature via cpupower.

To enable:
cpupower set --turbo-boost 1

To disable:
cpupower set --turbo-boost 0

Acked-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Wyes Karny <wyes.karny@amd.com>
Tested-by: Perry Yuan <Perry.Yuan@amd.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/power/cpupower/utils/cpupower-set.c
tools/power/cpupower/utils/helpers/helpers.h
tools/power/cpupower/utils/helpers/misc.c

index c2ba69b7ea545d706c64012cebc8ef825a83cd8c..0677b58374abf15c35ed0bd2cd2bc8641d10d972 100644 (file)
@@ -20,6 +20,7 @@ static struct option set_opts[] = {
        {"perf-bias", required_argument, NULL, 'b'},
        {"epp", required_argument, NULL, 'e'},
        {"amd-pstate-mode", required_argument, NULL, 'm'},
+       {"turbo-boost", required_argument, NULL, 't'},
        { },
 };
 
@@ -41,10 +42,11 @@ int cmd_set(int argc, char **argv)
                        int perf_bias:1;
                        int epp:1;
                        int mode:1;
+                       int turbo_boost:1;
                };
                int params;
        } params;
-       int perf_bias = 0;
+       int perf_bias = 0, turbo_boost = 1;
        int ret = 0;
        char epp[30], mode[20];
 
@@ -94,6 +96,18 @@ int cmd_set(int argc, char **argv)
                        }
                        params.mode = 1;
                        break;
+               case 't':
+                       if (params.turbo_boost)
+                               print_wrong_arg_exit();
+                       turbo_boost = atoi(optarg);
+                       if (turbo_boost < 0 || turbo_boost > 1) {
+                               printf("--turbo-boost param out of range [0-1]\n");
+                               print_wrong_arg_exit();
+                       }
+                       params.turbo_boost = 1;
+                       break;
+
+
                default:
                        print_wrong_arg_exit();
                }
@@ -108,6 +122,12 @@ int cmd_set(int argc, char **argv)
                        fprintf(stderr, "Error setting mode\n");
        }
 
+       if (params.turbo_boost) {
+               ret = cpupower_set_turbo_boost(turbo_boost);
+               if (ret)
+                       fprintf(stderr, "Error setting turbo-boost\n");
+       }
+
        /* Default is: set all CPUs */
        if (bitmask_isallclear(cpus_chosen))
                bitmask_setall(cpus_chosen);
index d35596631eefeec4fca220c8b683f15b28ac3f09..95749b8ee475e805f53e2d1133fe44bc83de9ffd 100644 (file)
@@ -118,6 +118,7 @@ extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
 
 extern int cpupower_set_epp(unsigned int cpu, char *epp);
 extern int cpupower_set_amd_pstate_mode(char *mode);
+extern int cpupower_set_turbo_boost(int turbo_boost);
 
 /* Read/Write msr ****************************/
 
@@ -180,6 +181,8 @@ static inline int cpupower_set_epp(unsigned int cpu, char *epp)
 { return -1; };
 static inline int cpupower_set_amd_pstate_mode(char *mode)
 { return -1; };
+static inline int cpupower_set_turbo_boost(int turbo_boost)
+{ return -1; };
 
 /* Read/Write msr ****************************/
 
index 075c136a100c49a7e7f08d6efd8a900c1ba9f1d3..76e461ff4f74031dc9a353d471ae734bcc401248 100644 (file)
@@ -124,6 +124,24 @@ int cpupower_set_amd_pstate_mode(char *mode)
        return 0;
 }
 
+int cpupower_set_turbo_boost(int turbo_boost)
+{
+       char path[SYSFS_PATH_MAX];
+       char linebuf[2] = {};
+
+       snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost");
+
+       if (!is_valid_path(path))
+               return -1;
+
+       snprintf(linebuf, sizeof(linebuf), "%d", turbo_boost);
+
+       if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
+               return -1;
+
+       return 0;
+}
+
 bool cpupower_amd_pstate_enabled(void)
 {
        char *driver = cpufreq_get_driver(0);