Skip to contentSkip to conversation

cpupower: Add various feature control support for amd_pstate

PATCH In review Wyes Karny 6 participants 18 messages Jun 19, 2023 – Jul 18, 2023 CPU power monitoring

lore
Share & tools
lore

Wyes Karny

author
#0 lore raw

v3 cover cpupower: Add various feature control support for amd_pstate

In this series, three feature control support for amd_pstate has been added.

1. EPP: User can control Energy Performance Preference (EPP) value,
which conveys user's performance vs energy preference to platform. This feature is present on amd_pstate and intel_pstate active mode.

2. amd_pstate mode switch: amd_pstate has various working modes such as
'active', 'passive' and 'guided', which can be changed dynamically.

3. Turbo boost: Turbo boost feature is present in amd_pstate as well as
acpi-cpufreq. By default this is enabled, but user can control this feature dynamically.

These features can be controlled with cpupower set command. The options are respectively --epp, --amd-pstate-mode, --turbo-boost

Also, make cpupower recognise amd-pstate-epp driver.

Changelog:
v2->v3:
- Use common prefix to recognise amd-pstate-epp driver.
- Picked up review tag from Mario.

v1->v2:
- Drop patch 1, which was amd-pstate-epp driver rename change.
- Picked ACKs from Ray.

Wyes Karny (5):
cpupower: Recognise amd-pstate active mode driver
cpupower: Add is_valid_path API
cpupower: Add EPP value change support
cpupower: Add support for amd_pstate mode change
cpupower: Add turbo-boost support in cpupower

 tools/power/cpupower/lib/cpupower.c          |  7 +++
 tools/power/cpupower/lib/cpupower_intern.h   |  1 +
 tools/power/cpupower/utils/cpupower-set.c    | 65 +++++++++++++++++++-
 tools/power/cpupower/utils/helpers/helpers.h | 11 ++++
 tools/power/cpupower/utils/helpers/misc.c    | 57 ++++++++++++++++-
 5 files changed, 138 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/5 cpupower: Recognise amd-pstate active mode driver

amd-pstate active mode driver name is "amd-pstate-epp". Use common prefix for string matching condition to recognise amd-pstate active mode driver.

---
 tools/power/cpupower/utils/helpers/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/utils/helpers/misc.c +1 -1
index 9547b29254a7..0c56fc77f93b 100644
@@ -95,7 +95,7 @@ bool cpupower_amd_pstate_enabled(void)
 	if (!driver)
 		return ret;
 
-	if (!strcmp(driver, "amd-pstate"))
+	if (!strncmp(driver, "amd", 3))
 		ret = true;
 
 	cpufreq_put_driver(driver);
Signature · 1 line
2.34.1
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] cpupower: Recognise amd-pstate active mode driver

Quoted 6 lines · Wyes Karny

amd-pstate active mode driver name is "amd-pstate-epp". Use common prefix for string matching condition to recognise amd-pstate active mode driver.

Quoted 17 lines
---
  tools/power/cpupower/utils/helpers/misc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/utils/helpers/misc.c +1 -1
index 9547b29254a7..0c56fc77f93b 100644
@@ -95,7 +95,7 @@ bool cpupower_amd_pstate_enabled(void)
  	if (!driver)
  		return ret;
 
-	if (!strcmp(driver, "amd-pstate"))
+	if (!strncmp(driver, "amd", 3))
  		ret = true;
 
  	cpufreq_put_driver(driver);
Tested-by on v3 1/5
#3 lore raw

RE: [PATCH v3 1/5] cpupower: Recognise amd-pstate active mode driver

In reply to Wyes Karny

[AMD Official Use Only - General]

Quoted 34 lines

-----Original Message-----
From: Karny, Wyes <[email protected]>
Sent: Tuesday, June 20, 2023 3:05 AM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shenoy, Gautham Ranjal <[email protected]>; Limonciello, Mario <[email protected]>; Huang, Ray <[email protected]>; Yuan, Perry <[email protected]>; Karny, Wyes <[email protected]>
Subject: [PATCH v3 1/5] cpupower: Recognise amd-pstate active mode driver

amd-pstate active mode driver name is "amd-pstate-epp". Use common prefix for string matching condition to recognise amd-pstate active mode driver.

---
 tools/power/cpupower/utils/helpers/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/utils/helpers/misc.c +1 -2
index 9547b29254a7..0c56fc77f93b 100644
@@ -95,7 +95,7 @@ bool cpupower_amd_pstate_enabled(void)
      if (!driver)
              return ret;
 
-     if (!strcmp(driver, "amd-pstate"))
+     if (!strncmp(driver, "amd", 3))
              ret = true;
 
      cpufreq_put_driver(driver);
--
Quoted 1 line

2.34.1

Acked-by on v3 1/5
#4 lore raw

Re: [PATCH v3 1/5] cpupower: Recognise amd-pstate active mode driver

In reply to Wyes Karny
Quoted 6 lines · Wyes

amd-pstate active mode driver name is "amd-pstate-epp". Use common prefix for string matching condition to recognise amd-pstate active mode driver.

Quoted 20 lines
---
 tools/power/cpupower/utils/helpers/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/utils/helpers/misc.c +1 -1
index 9547b29254a7..0c56fc77f93b 100644
@@ -95,7 +95,7 @@ bool cpupower_amd_pstate_enabled(void)
 	if (!driver)
 		return ret;
 
-	if (!strcmp(driver, "amd-pstate"))
+	if (!strncmp(driver, "amd", 3))
 		ret = true;
 
 	cpufreq_put_driver(driver);
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v3 2/5 cpupower: Add is_valid_path API

In reply to Wyes Karny

Add is_valid_path API to check whether the sysfs file is present or not.

---
 tools/power/cpupower/lib/cpupower.c        | 7 +++++++
 tools/power/cpupower/lib/cpupower_intern.h | 1 +
 2 files changed, 8 insertions(+)
tools/power/cpupower/lib/cpupower.c +7 -0
index 3f7d0c0c5067..7a2ef691b20e 100644
@@ -14,6 +14,13 @@
 #include "cpupower.h"
 #include "cpupower_intern.h"
 
+int is_valid_path(const char *path)
+{
+	if (access(path, F_OK) == -1)
+		return 0;
+	return 1;
+}
+
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen)
 {
 	ssize_t numread;
tools/power/cpupower/lib/cpupower_intern.h +1 -0
index ac1112b956ec..5fdb8620d41b 100644
@@ -7,5 +7,6 @@
 
 #define SYSFS_PATH_MAX 255
 
+int is_valid_path(const char *path);
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);
Signature · 1 line
2.34.1
Tested-by on v3 2/5
#6 lore raw

RE: [PATCH v3 2/5] cpupower: Add is_valid_path API

[AMD Official Use Only - General]

Quoted 52 lines

-----Original Message-----
From: Karny, Wyes <[email protected]>
Sent: Tuesday, June 20, 2023 3:05 AM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shenoy, Gautham Ranjal <[email protected]>; Limonciello, Mario <[email protected]>; Huang, Ray <[email protected]>; Yuan, Perry <[email protected]>; Karny, Wyes <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 2/5] cpupower: Add is_valid_path API

Add is_valid_path API to check whether the sysfs file is present or not.

---
 tools/power/cpupower/lib/cpupower.c        | 7 +++++++
 tools/power/cpupower/lib/cpupower_intern.h | 1 +
 2 files changed, 8 insertions(+)
tools/power/cpupower/lib/cpupower.c +7 -0
index 3f7d0c0c5067..7a2ef691b20e 100644
@@ -14,6 +14,13 @@
 #include "cpupower.h"
 #include "cpupower_intern.h"
 
+int is_valid_path(const char *path)
+{
+     if (access(path, F_OK) == -1)
+             return 0;
+     return 1;
+}
+
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen)  {
      ssize_t numread;
tools/power/cpupower/lib/cpupower_intern.h +1 -1
index ac1112b956ec..5fdb8620d41b 100644
@@ -7,5 +7,6 @@
 
 #define SYSFS_PATH_MAX 255
 
+int is_valid_path(const char *path);
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);
--
Quoted 1 line

2.34.1

Acked-by on v3 2/5
#7 lore raw

Re: [PATCH v3 2/5] cpupower: Add is_valid_path API

In reply to Wyes Karny
Quoted 5 lines · Wyes

Add is_valid_path API to check whether the sysfs file is present or not.

Quoted 37 lines
---
 tools/power/cpupower/lib/cpupower.c        | 7 +++++++
 tools/power/cpupower/lib/cpupower_intern.h | 1 +
 2 files changed, 8 insertions(+)
tools/power/cpupower/lib/cpupower.c +7 -0
index 3f7d0c0c5067..7a2ef691b20e 100644
@@ -14,6 +14,13 @@
 #include "cpupower.h"
 #include "cpupower_intern.h"
 
+int is_valid_path(const char *path)
+{
+	if (access(path, F_OK) == -1)
+		return 0;
+	return 1;
+}
+
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen)
 {
 	ssize_t numread;
tools/power/cpupower/lib/cpupower_intern.h +1 -0
index ac1112b956ec..5fdb8620d41b 100644
@@ -7,5 +7,6 @@
 
 #define SYSFS_PATH_MAX 255
 
+int is_valid_path(const char *path);
 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);
Signature · 1 line
2.34.1
author
#8 lore raw

PATCH v3 3/5 cpupower: Add EPP value change support

In reply to Wyes Karny

amd_pstate and intel_pstate active mode drivers support energy performance preference feature. Through this user can convey it's energy/performance preference to platform. Add this value change capability to cpupower.

To change the EPP value use below command:
cpupower set --epp performance

---
 tools/power/cpupower/utils/cpupower-set.c    | 23 +++++++++++++++++++-
 tools/power/cpupower/utils/helpers/helpers.h |  5 +++++
 tools/power/cpupower/utils/helpers/misc.c    | 19 ++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/cpupower-set.c +22 -1
index 180d5ba877e6..a789b123dbd4 100644
@@ -18,6 +18,7 @@
 
 static struct option set_opts[] = {
 	{"perf-bias", required_argument, NULL, 'b'},
+	{"epp", required_argument, NULL, 'e'},
 	{ },
 };
 
@@ -37,11 +38,13 @@ int cmd_set(int argc, char **argv)
 	union {
 		struct {
 			int perf_bias:1;
+			int epp:1;
 		};
 		int params;
 	} params;
 	int perf_bias = 0;
 	int ret = 0;
+	char epp[30];
 
 	ret = uname(&uts);
 	if (!ret && (!strcmp(uts.machine, "ppc64le") ||
@@ -55,7 +58,7 @@ int cmd_set(int argc, char **argv)
 
 	params.params = 0;
 	/* parameter parsing */
-	while ((ret = getopt_long(argc, argv, "b:",
+	while ((ret = getopt_long(argc, argv, "b:e:",
 						set_opts, NULL)) != -1) {
 		switch (ret) {
 		case 'b':
@@ -69,6 +72,15 @@ int cmd_set(int argc, char **argv)
 			}
 			params.perf_bias = 1;
 			break;
+		case 'e':
+			if (params.epp)
+				print_wrong_arg_exit();
+			if (sscanf(optarg, "%29s", epp) != 1) {
+				print_wrong_arg_exit();
+				return -EINVAL;
+			}
+			params.epp = 1;
+			break;
 		default:
 			print_wrong_arg_exit();
 		}
@@ -102,6 +114,15 @@ int cmd_set(int argc, char **argv)
 				break;
 			}
 		}
+
+		if (params.epp) {
+			ret = cpupower_set_epp(cpu, epp);
+			if (ret) {
+				fprintf(stderr,
+					"Error setting epp value on CPU %d\n", cpu);
+				break;
+			}
+		}
 	}
 	return ret;
 }
tools/power/cpupower/utils/helpers/helpers.h +5 -0
index 96e4bede078b..5d998de2d291 100644
@@ -116,6 +116,8 @@ extern int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val);
 extern int cpupower_intel_get_perf_bias(unsigned int cpu);
 extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
 
+extern int cpupower_set_epp(unsigned int cpu, char *epp);
+
 /* Read/Write msr ****************************/
 
 /* PCI stuff ****************************/
@@ -173,6 +175,9 @@ static inline int cpupower_intel_get_perf_bias(unsigned int cpu)
 static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
 { return 0; };
 
+static inline int cpupower_set_epp(unsigned int cpu, char *epp)
+{ return -1; };
+
 /* Read/Write msr ****************************/
 
 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
tools/power/cpupower/utils/helpers/misc.c +19 -0
index 0c56fc77f93b..583df38ab13c 100644
@@ -87,6 +87,25 @@ int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)
 	return 0;
 }
 
+int cpupower_set_epp(unsigned int cpu, char *epp)
+{
+	char path[SYSFS_PATH_MAX];
+	char linebuf[30] = {};
+
+	snprintf(path, sizeof(path),
+		PATH_TO_CPU "cpu%u/cpufreq/energy_performance_preference", cpu);
+
+	if (!is_valid_path(path))
+		return -1;
+
+	snprintf(linebuf, sizeof(linebuf), "%s", epp);
+
+	if (cpupower_write_sysfs(path, linebuf, 30) <= 0)
+		return -1;
+
+	return 0;
+}
+
 bool cpupower_amd_pstate_enabled(void)
 {
 	char *driver = cpufreq_get_driver(0);
Signature · 1 line
2.34.1
Tested-by on v3 3/5
#9 lore raw

RE: [PATCH v3 3/5] cpupower: Add EPP value change support

[AMD Official Use Only - General]

Quoted 151 lines

-----Original Message-----
From: Karny, Wyes <[email protected]>
Sent: Tuesday, June 20, 2023 3:05 AM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shenoy, Gautham Ranjal <[email protected]>; Limonciello, Mario <[email protected]>; Huang, Ray <[email protected]>; Yuan, Perry <[email protected]>; Karny, Wyes <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 3/5] cpupower: Add EPP value change support

amd_pstate and intel_pstate active mode drivers support energy performance preference feature. Through this user can convey it's energy/performance preference to platform. Add this value change capability to cpupower.

To change the EPP value use below command:
cpupower set --epp performance

---
 tools/power/cpupower/utils/cpupower-set.c    | 23 +++++++++++++++++++-
 tools/power/cpupower/utils/helpers/helpers.h |  5 +++++
 tools/power/cpupower/utils/helpers/misc.c    | 19 ++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/cpupower-set.c +3 -0
index 180d5ba877e6..a789b123dbd4 100644
@@ -18,6 +18,7 @@
 
 static struct option set_opts[] = {
      {"perf-bias", required_argument, NULL, 'b'},
+     {"epp", required_argument, NULL, 'e'},
      { },
 };
 
@@ -37,11 +38,13 @@ int cmd_set(int argc, char **argv)
      union {
              struct {
                      int perf_bias:1;
+                     int epp:1;
              };
              int params;
      } params;
      int perf_bias = 0;
      int ret = 0;
+     char epp[30];
 
      ret = uname(&uts);
      if (!ret && (!strcmp(uts.machine, "ppc64le") || @@ -55,7 +58,7 @@

int cmd_set(int argc, char **argv)

      params.params = 0;
      /* parameter parsing */
tools/power/cpupower/utils/cpupower-set.c +19 -1
-     while ((ret = getopt_long(argc, argv, "b:",
+     while ((ret = getopt_long(argc, argv, "b:e:",
                                              set_opts, NULL)) != -1) {
              switch (ret) {
              case 'b':
@@ -69,6 +72,15 @@ int cmd_set(int argc, char **argv)
                      }
                      params.perf_bias = 1;
                      break;
+             case 'e':
+                     if (params.epp)
+                             print_wrong_arg_exit();
+                     if (sscanf(optarg, "%29s", epp) != 1) {
+                             print_wrong_arg_exit();
+                             return -EINVAL;
+                     }
+                     params.epp = 1;
+                     break;
              default:
                      print_wrong_arg_exit();
              }
@@ -102,6 +114,15 @@ int cmd_set(int argc, char **argv)
                              break;
                      }
              }
+
+             if (params.epp) {
+                     ret = cpupower_set_epp(cpu, epp);
+                     if (ret) {
+                             fprintf(stderr,
+                                     "Error setting epp value on
 CPU %d\n", cpu);
+                             break;
+                     }
+             }
      }
      return ret;

}

tools/power/cpupower/utils/helpers/helpers.h +0 -0
index 96e4bede078b..5d998de2d291 100644
@@ -116,6 +116,8 @@ extern int cpupower_intel_set_perf_bias(unsigned int

cpu, unsigned int val); extern int cpupower_intel_get_perf_bias(unsigned int cpu); extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);

tools/power/cpupower/utils/helpers/helpers.h +2 -0
+extern int cpupower_set_epp(unsigned int cpu, char *epp);
+
 /* Read/Write msr ****************************/
 
 /* PCI stuff ****************************/ @@ -173,6 +175,9 @@ static

inline int cpupower_intel_get_perf_bias(unsigned int cpu) static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu) { return 0; };

tools/power/cpupower/utils/helpers/helpers.h +3 -1
+static inline int cpupower_set_epp(unsigned int cpu, char *epp) {
+return -1; };
+
 /* Read/Write msr ****************************/
 
 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support, diff
--git a/tools/power/cpupower/utils/helpers/misc.c

b/tools/power/cpupower/utils/helpers/misc.c
index 0c56fc77f93b..583df38ab13c 100644

tools/power/cpupower/utils/helpers/misc.c +18 -1
@@ -87,6 +87,25 @@ int cpupower_intel_set_perf_bias(unsigned int cpu,
 unsigned int val)
      return 0;
 }
 
+int cpupower_set_epp(unsigned int cpu, char *epp) {
+     char path[SYSFS_PATH_MAX];
+     char linebuf[30] = {};
+
+     snprintf(path, sizeof(path),
+             PATH_TO_CPU
 "cpu%u/cpufreq/energy_performance_preference", cpu);
+
+     if (!is_valid_path(path))
+             return -1;
+
+     snprintf(linebuf, sizeof(linebuf), "%s", epp);
+
+     if (cpupower_write_sysfs(path, linebuf, 30) <= 0)
+             return -1;
+
+     return 0;
+}
+
 bool cpupower_amd_pstate_enabled(void)
 {
      char *driver = cpufreq_get_driver(0);
--
Quoted 1 line

2.34.1

Acked-by on v3 3/5
#10 lore raw

Re: [PATCH v3 3/5] cpupower: Add EPP value change support

In reply to Wyes Karny
Quoted 10 lines · Wyes

amd_pstate and intel_pstate active mode drivers support energy performance preference feature. Through this user can convey it's energy/performance preference to platform. Add this value change capability to cpupower.

To change the EPP value use below command:
cpupower set --epp performance

Quoted 129 lines
---
 tools/power/cpupower/utils/cpupower-set.c    | 23 +++++++++++++++++++-
 tools/power/cpupower/utils/helpers/helpers.h |  5 +++++
 tools/power/cpupower/utils/helpers/misc.c    | 19 ++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/cpupower-set.c +22 -1
index 180d5ba877e6..a789b123dbd4 100644
@@ -18,6 +18,7 @@
 
 static struct option set_opts[] = {
 	{"perf-bias", required_argument, NULL, 'b'},
+	{"epp", required_argument, NULL, 'e'},
 	{ },
 };
 
@@ -37,11 +38,13 @@ int cmd_set(int argc, char **argv)
 	union {
 		struct {
 			int perf_bias:1;
+			int epp:1;
 		};
 		int params;
 	} params;
 	int perf_bias = 0;
 	int ret = 0;
+	char epp[30];
 
 	ret = uname(&uts);
 	if (!ret && (!strcmp(uts.machine, "ppc64le") ||
@@ -55,7 +58,7 @@ int cmd_set(int argc, char **argv)
 
 	params.params = 0;
 	/* parameter parsing */
-	while ((ret = getopt_long(argc, argv, "b:",
+	while ((ret = getopt_long(argc, argv, "b:e:",
 						set_opts, NULL)) != -1) {
 		switch (ret) {
 		case 'b':
@@ -69,6 +72,15 @@ int cmd_set(int argc, char **argv)
 			}
 			params.perf_bias = 1;
 			break;
+		case 'e':
+			if (params.epp)
+				print_wrong_arg_exit();
+			if (sscanf(optarg, "%29s", epp) != 1) {
+				print_wrong_arg_exit();
+				return -EINVAL;
+			}
+			params.epp = 1;
+			break;
 		default:
 			print_wrong_arg_exit();
 		}
@@ -102,6 +114,15 @@ int cmd_set(int argc, char **argv)
 				break;
 			}
 		}
+
+		if (params.epp) {
+			ret = cpupower_set_epp(cpu, epp);
+			if (ret) {
+				fprintf(stderr,
+					"Error setting epp value on CPU %d\n", cpu);
+				break;
+			}
+		}
 	}
 	return ret;
 }
tools/power/cpupower/utils/helpers/helpers.h +5 -0
index 96e4bede078b..5d998de2d291 100644
@@ -116,6 +116,8 @@ extern int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val);
 extern int cpupower_intel_get_perf_bias(unsigned int cpu);
 extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
 
+extern int cpupower_set_epp(unsigned int cpu, char *epp);
+
 /* Read/Write msr ****************************/
 
 /* PCI stuff ****************************/
@@ -173,6 +175,9 @@ static inline int cpupower_intel_get_perf_bias(unsigned int cpu)
 static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
 { return 0; };
 
+static inline int cpupower_set_epp(unsigned int cpu, char *epp)
+{ return -1; };
+
 /* Read/Write msr ****************************/
 
 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
tools/power/cpupower/utils/helpers/misc.c +19 -0
index 0c56fc77f93b..583df38ab13c 100644
@@ -87,6 +87,25 @@ int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)
 	return 0;
 }
 
+int cpupower_set_epp(unsigned int cpu, char *epp)
+{
+	char path[SYSFS_PATH_MAX];
+	char linebuf[30] = {};
+
+	snprintf(path, sizeof(path),
+		PATH_TO_CPU "cpu%u/cpufreq/energy_performance_preference", cpu);
+
+	if (!is_valid_path(path))
+		return -1;
+
+	snprintf(linebuf, sizeof(linebuf), "%s", epp);
+
+	if (cpupower_write_sysfs(path, linebuf, 30) <= 0)
+		return -1;
+
+	return 0;
+}
+
 bool cpupower_amd_pstate_enabled(void)
 {
 	char *driver = cpufreq_get_driver(0);
Signature · 1 line
2.34.1
author
#11 lore raw

PATCH v3 4/5 cpupower: Add support for amd_pstate mode change

In reply to Wyes Karny

amd_pstate supports changing of its mode dynamically via status sysfs file. Add the same capability in cpupower. To change the mode to active mode use below command:

cpupower set --amd-pstate-mode active

---
 tools/power/cpupower/utils/cpupower-set.c    | 24 ++++++++++++++++++--
 tools/power/cpupower/utils/helpers/helpers.h |  3 +++
 tools/power/cpupower/utils/helpers/misc.c    | 18 +++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
tools/power/cpupower/utils/cpupower-set.c +22 -2
index a789b123dbd4..c2ba69b7ea54 100644
@@ -19,6 +19,7 @@
 static struct option set_opts[] = {
 	{"perf-bias", required_argument, NULL, 'b'},
 	{"epp", required_argument, NULL, 'e'},
+	{"amd-pstate-mode", required_argument, NULL, 'm'},
 	{ },
 };
 
@@ -39,12 +40,13 @@ int cmd_set(int argc, char **argv)
 		struct {
 			int perf_bias:1;
 			int epp:1;
+			int mode:1;
 		};
 		int params;
 	} params;
 	int perf_bias = 0;
 	int ret = 0;
-	char epp[30];
+	char epp[30], mode[20];
 
 	ret = uname(&uts);
 	if (!ret && (!strcmp(uts.machine, "ppc64le") ||
@@ -58,7 +60,7 @@ int cmd_set(int argc, char **argv)
 
 	params.params = 0;
 	/* parameter parsing */
-	while ((ret = getopt_long(argc, argv, "b:e:",
+	while ((ret = getopt_long(argc, argv, "b:e:m:",
 						set_opts, NULL)) != -1) {
 		switch (ret) {
 		case 'b':
@@ -81,6 +83,17 @@ int cmd_set(int argc, char **argv)
 			}
 			params.epp = 1;
 			break;
+		case 'm':
+			if (cpupower_cpu_info.vendor != X86_VENDOR_AMD)
+				print_wrong_arg_exit();
+			if (params.mode)
+				print_wrong_arg_exit();
+			if (sscanf(optarg, "%19s", mode) != 1) {
+				print_wrong_arg_exit();
+				return -EINVAL;
+			}
+			params.mode = 1;
+			break;
 		default:
 			print_wrong_arg_exit();
 		}
@@ -89,6 +102,12 @@ int cmd_set(int argc, char **argv)
 	if (!params.params)
 		print_wrong_arg_exit();
 
+	if (params.mode) {
+		ret = cpupower_set_amd_pstate_mode(mode);
+		if (ret)
+			fprintf(stderr, "Error setting mode\n");
+	}
+
 	/* Default is: set all CPUs */
 	if (bitmask_isallclear(cpus_chosen))
 		bitmask_setall(cpus_chosen);
@@ -123,6 +142,7 @@ int cmd_set(int argc, char **argv)
 				break;
 			}
 		}
+
 	}
 	return ret;
 }
tools/power/cpupower/utils/helpers/helpers.h +3 -0
index 5d998de2d291..d35596631eef 100644
@@ -117,6 +117,7 @@ extern int cpupower_intel_get_perf_bias(unsigned int cpu);
 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);
 
 /* Read/Write msr ****************************/
 
@@ -177,6 +178,8 @@ static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
 
 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; };
 
 /* Read/Write msr ****************************/
 
tools/power/cpupower/utils/helpers/misc.c +18 -0
index 583df38ab13c..075c136a100c 100644
@@ -106,6 +106,24 @@ int cpupower_set_epp(unsigned int cpu, char *epp)
 	return 0;
 }
 
+int cpupower_set_amd_pstate_mode(char *mode)
+{
+	char path[SYSFS_PATH_MAX];
+	char linebuf[20] = {};
+
+	snprintf(path, sizeof(path), PATH_TO_CPU "amd_pstate/status");
+
+	if (!is_valid_path(path))
+		return -1;
+
+	snprintf(linebuf, sizeof(linebuf), "%s\n", mode);
+
+	if (cpupower_write_sysfs(path, linebuf, 20) <= 0)
+		return -1;
+
+	return 0;
+}
+
 bool cpupower_amd_pstate_enabled(void)
 {
 	char *driver = cpufreq_get_driver(0);
Signature · 1 line
2.34.1
Tested-by on v3 4/5
#12 lore raw

RE: [PATCH v3 4/5] cpupower: Add support for amd_pstate mode change

[AMD Official Use Only - General]

Quoted 156 lines

-----Original Message-----
From: Karny, Wyes <[email protected]>
Sent: Tuesday, June 20, 2023 3:05 AM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shenoy, Gautham Ranjal <[email protected]>; Limonciello, Mario <[email protected]>; Huang, Ray <[email protected]>; Yuan, Perry <[email protected]>; Karny, Wyes <[email protected]>; Huang, Ray <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 4/5] cpupower: Add support for amd_pstate mode change

amd_pstate supports changing of its mode dynamically via status sysfs file. Add the same capability in cpupower. To change the mode to active mode use below command:

cpupower set --amd-pstate-mode active

---
 tools/power/cpupower/utils/cpupower-set.c    | 24 ++++++++++++++++++--
 tools/power/cpupower/utils/helpers/helpers.h |  3 +++
 tools/power/cpupower/utils/helpers/misc.c    | 18 +++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
tools/power/cpupower/utils/cpupower-set.c +3 -1
index a789b123dbd4..c2ba69b7ea54 100644
@@ -19,6 +19,7 @@
 static struct option set_opts[] = {
      {"perf-bias", required_argument, NULL, 'b'},
      {"epp", required_argument, NULL, 'e'},
+     {"amd-pstate-mode", required_argument, NULL, 'm'},
      { },
 };
 
@@ -39,12 +40,13 @@ int cmd_set(int argc, char **argv)
              struct {
                      int perf_bias:1;
                      int epp:1;
+                     int mode:1;
              };
              int params;
      } params;
      int perf_bias = 0;
      int ret = 0;
-     char epp[30];
+     char epp[30], mode[20];
 
      ret = uname(&uts);
      if (!ret && (!strcmp(uts.machine, "ppc64le") || @@ -58,7 +60,7 @@

int cmd_set(int argc, char **argv)

      params.params = 0;
      /* parameter parsing */
tools/power/cpupower/utils/cpupower-set.c +19 -1
-     while ((ret = getopt_long(argc, argv, "b:e:",
+     while ((ret = getopt_long(argc, argv, "b:e:m:",
                                              set_opts, NULL)) != -1) {
              switch (ret) {
              case 'b':
@@ -81,6 +83,17 @@ int cmd_set(int argc, char **argv)
                      }
                      params.epp = 1;
                      break;
+             case 'm':
+                     if (cpupower_cpu_info.vendor != X86_VENDOR_AMD)
+                             print_wrong_arg_exit();
+                     if (params.mode)
+                             print_wrong_arg_exit();
+                     if (sscanf(optarg, "%19s", mode) != 1) {
+                             print_wrong_arg_exit();
+                             return -EINVAL;
+                     }
+                     params.mode = 1;
+                     break;
              default:
                      print_wrong_arg_exit();
              }
@@ -89,6 +102,12 @@ int cmd_set(int argc, char **argv)
      if (!params.params)
              print_wrong_arg_exit();
 
+     if (params.mode) {
+             ret = cpupower_set_amd_pstate_mode(mode);
+             if (ret)
+                     fprintf(stderr, "Error setting mode\n");
+     }
+
      /* Default is: set all CPUs */
      if (bitmask_isallclear(cpus_chosen))
              bitmask_setall(cpus_chosen);
@@ -123,6 +142,7 @@ int cmd_set(int argc, char **argv)
                              break;
                      }
              }
+
      }
      return ret;
 }
tools/power/cpupower/utils/helpers/helpers.h +3 -0
index 5d998de2d291..d35596631eef 100644
@@ -117,6 +117,7 @@ extern int cpupower_intel_get_perf_bias(unsigned int
 cpu);  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);
 
 /* Read/Write msr ****************************/
 
@@ -177,6 +178,8 @@ static inline unsigned long long
 msr_intel_get_turbo_ratio(unsigned int cpu)
 
 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;
+};
 
 /* Read/Write msr ****************************/
 
tools/power/cpupower/utils/helpers/misc.c +17 -1
index 583df38ab13c..075c136a100c 100644
@@ -106,6 +106,24 @@ int cpupower_set_epp(unsigned int cpu, char *epp)
      return 0;
 }
 
+int cpupower_set_amd_pstate_mode(char *mode) {
+     char path[SYSFS_PATH_MAX];
+     char linebuf[20] = {};
+
+     snprintf(path, sizeof(path), PATH_TO_CPU "amd_pstate/status");
+
+     if (!is_valid_path(path))
+             return -1;
+
+     snprintf(linebuf, sizeof(linebuf), "%s\n", mode);
+
+     if (cpupower_write_sysfs(path, linebuf, 20) <= 0)
+             return -1;
+
+     return 0;
+}
+
 bool cpupower_amd_pstate_enabled(void)
 {
      char *driver = cpufreq_get_driver(0);
--
Quoted 1 line

2.34.1

author
#13 lore raw

PATCH v3 5/5 cpupower: Add turbo-boost support in cpupower

In reply to Wyes Karny

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

---
 tools/power/cpupower/utils/cpupower-set.c    | 22 +++++++++++++++++++-
 tools/power/cpupower/utils/helpers/helpers.h |  3 +++
 tools/power/cpupower/utils/helpers/misc.c    | 18 ++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/cpupower-set.c +21 -1
index c2ba69b7ea54..0677b58374ab 100644
@@ -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);
tools/power/cpupower/utils/helpers/helpers.h +3 -0
index d35596631eef..95749b8ee475 100644
@@ -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 ****************************/
 
tools/power/cpupower/utils/helpers/misc.c +18 -0
index 075c136a100c..76e461ff4f74 100644
@@ -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);
Signature · 1 line
2.34.1
Tested-by on v3 5/5
#14 lore raw

RE: [PATCH v3 5/5] cpupower: Add turbo-boost support in cpupower

[AMD Official Use Only - General]

Hi Wyes.

Quoted 144 lines

-----Original Message-----
From: Karny, Wyes <[email protected]>
Sent: Tuesday, June 20, 2023 3:05 AM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shenoy, Gautham Ranjal <[email protected]>; Limonciello, Mario <[email protected]>; Huang, Ray <[email protected]>; Yuan, Perry <[email protected]>; Karny, Wyes <[email protected]>; Huang, Ray <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 5/5] cpupower: Add turbo-boost support in cpupower

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

---
 tools/power/cpupower/utils/cpupower-set.c    | 22 +++++++++++++++++++-
 tools/power/cpupower/utils/helpers/helpers.h |  3 +++
 tools/power/cpupower/utils/helpers/misc.c    | 18 ++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/cpupower-set.c +15 -1
index c2ba69b7ea54..0677b58374ab 100644
@@ -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();
              }
tools/power/cpupower/utils/cpupower-set.c +6 -0
@@ -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);
tools/power/cpupower/utils/helpers/helpers.h +1 -0
index d35596631eef..95749b8ee475 100644
@@ -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; };

tools/power/cpupower/utils/helpers/helpers.h +2 -0
+static inline int cpupower_set_turbo_boost(int turbo_boost) { return
+-1; };
 
 /* Read/Write msr ****************************/
tools/power/cpupower/utils/helpers/misc.c +17 -1
index 075c136a100c..76e461ff4f74 100644
@@ -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);
--
Quoted 1 line

2.34.1

Thanks for the new commands for pstate driver

author
#15 lore raw

Re: [PATCH v3 5/5] cpupower: Add turbo-boost support in cpupower

Quoted 152 lines · Perry

[AMD Official Use Only - General]

Hi Wyes.

Quoted 144 lines

-----Original Message-----
From: Karny, Wyes <[email protected]>
Sent: Tuesday, June 20, 2023 3:05 AM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Shenoy, Gautham Ranjal <[email protected]>; Limonciello, Mario <[email protected]>; Huang, Ray <[email protected]>; Yuan, Perry <[email protected]>; Karny, Wyes <[email protected]>; Huang, Ray <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 5/5] cpupower: Add turbo-boost support in cpupower

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

---
 tools/power/cpupower/utils/cpupower-set.c    | 22 +++++++++++++++++++-
 tools/power/cpupower/utils/helpers/helpers.h |  3 +++
 tools/power/cpupower/utils/helpers/misc.c    | 18 ++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/cpupower-set.c +15 -1
index c2ba69b7ea54..0677b58374ab 100644
@@ -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();
              }
tools/power/cpupower/utils/cpupower-set.c +6 -0
@@ -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);
tools/power/cpupower/utils/helpers/helpers.h +1 -0
index d35596631eef..95749b8ee475 100644
@@ -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; };

tools/power/cpupower/utils/helpers/helpers.h +2 -0
+static inline int cpupower_set_turbo_boost(int turbo_boost) { return
+-1; };
 
 /* Read/Write msr ****************************/
tools/power/cpupower/utils/helpers/misc.c +17 -1
index 075c136a100c..76e461ff4f74 100644
@@ -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);
--
Quoted 1 line

2.34.1

Thanks for the new commands for pstate driver

Quoted 1 line

Thanks Perry for the tested-by.

Regards,
Wyes

#16 lore raw
In reply to Wyes Karny

Hi,

sorry for the late answer, I wanted to give this a test, but could not make it (yet).

My 2 cents on this one:

what Ray already mentioned is greatly appreciated: Find common APIs, not only AMD vs Intel, but general ones, outside of the driver specific sysfs dir, e.g.:
/sys/devices/system/cpu/cpufreq/...

But not at all costs and if the epp part is (AMD) specific and varies to others in meaning or in values, it has to be a specific file/API.

(Another Example/Request at the end)

And...: It would be nice to see some documentation in form of manpage enhancements. At least for the newly introduced arguments.
If not yet, there should be: possible value range, which machines (CPU flags, Zen 4, ...), if more complex technology, some kind of introduction or reference where to find things would be really great.

I wonder whether it could be possible to connect this with:
Documentation/admin-guide/pm/intel_pstate.rst Documentation/admin-guide/pm/amd-pstate.rst

I guess there is a static web site address people could rely on where above kernel docs are hosted forever?
Then it would make sense to link the cpupower manpage with it and keep the description short and avoid duplication?

Thomas

Another Example/Request at the end:

One example I recently got asked for, the bug is private:
"cpupower is not returning max turbo active cores information on latest Intel processors."

Here are examples of 2 newer cpus that don't return the active core information like this:
3600 MHz max turbo 4 active cores
3600 MHz max turbo 3 active cores
3700 MHz max turbo 2 active cores
3800 MHz max turbo 1 active cores

Not sure whether there finally is some kind of consolidation on turbo/boost/ dynamic/hw/bios interfaces in respect to turbo/boosting technology. But if anyhow possible and it makes sense, it would be really great to see one sysfs file exposed to userspace to read/enable/disable.

Possible cpufreqs (including or only) boost freqs, maybe with active cores if this is a general technique optionally added if avail?

Nothing which has to be implemented at all costs and right now, just an idea on how things could be consolidated at some point of time which might be wise to think about now already...

maintainer
#17 lore raw
Quoted 52 lines · Thomas Renninger

Hi,

sorry for the late answer, I wanted to give this a test, but could not make it (yet).

My 2 cents on this one:

what Ray already mentioned is greatly appreciated: Find common APIs, not only AMD vs Intel, but general ones, outside of the driver specific sysfs dir, e.g.:
/sys/devices/system/cpu/cpufreq/...

But not at all costs and if the epp part is (AMD) specific and varies to others in meaning or in values, it has to be a specific file/API.

(Another Example/Request at the end)

And...: It would be nice to see some documentation in form of manpage enhancements. At least for the newly introduced arguments.
If not yet, there should be: possible value range, which machines (CPU flags, Zen 4, ...), if more complex technology, some kind of introduction or reference where to find things would be really great.

I wonder whether it could be possible to connect this with:
Documentation/admin-guide/pm/intel_pstate.rst Documentation/admin-guide/pm/amd-pstate.rst

I guess there is a static web site address people could rely on where above kernel docs are hosted forever?
Then it would make sense to link the cpupower manpage with it and keep the description short and avoid duplication?

Thomas

Another Example/Request at the end:

One example I recently got asked for, the bug is private:
"cpupower is not returning max turbo active cores information on latest Intel processors."

Here are examples of 2 newer cpus that don't return the active core information like this:
3600 MHz max turbo 4 active cores
3600 MHz max turbo 3 active cores
3700 MHz max turbo 2 active cores
3800 MHz max turbo 1 active cores

Not sure whether there finally is some kind of consolidation on turbo/boost/ dynamic/hw/bios interfaces in respect to turbo/boosting technology. But if anyhow possible and it makes sense, it would be really great to see one sysfs file exposed to userspace to read/enable/disable.

Quoted 7 lines

Possible cpufreqs (including or only) boost freqs, maybe with active cores if this is a general technique optionally added if avail?

Nothing which has to be implemented at all costs and right now, just an idea on how things could be consolidated at some point of time which might be wise to think about now already...

I applied these for Linux 6.6-rc1 - ran quick tests.

Please act on feedback from Thomas and send me patches on top of

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git/log/?h=cpupower

thanks,
-- Shuah