Skip to contentSkip to conversation

Implement AMD Pstate EPP Driver

PATCH Superseded Perry Yuan 6 participants 48 messages Dec 19, 2022 – Dec 25, 2022 Page 2 of 2

Subsystems (7)

v8 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#32 lore raw

Re: [PATCH v8 09/13] cpufreq: amd-pstate: add driver working mode switch support

In reply to Perry Yuan
Quoted 54 lines · Perry Yuan

From: Perry Yuan <[email protected]>

While amd-pstate driver was loaded with specific driver mode, it will need to check which mode is enabled for the pstate driver,add this sysfs entry to show the current status

$ cat /sys/devices/system/cpu/amd-pstate/status
active

Meanwhile, user can switch the pstate driver mode with writing mode string to sysfs entry as below.

Enable passive mode:

$ sudo bash -c "echo passive >  /sys/devices/system/cpu/amd-pstate/status"

Enable active mode (EPP driver mode):

$ sudo bash -c "echo active > /sys/devices/system/cpu/amd-pstate/status"
---
  drivers/cpufreq/amd-pstate.c | 128 +++++++++++++++++++++++++++++++++++
  1 file changed, 128 insertions(+)
drivers/cpufreq/amd-pstate.c +5 -0
index fc12d35bc7bd..e8996e937e63 100644
@@ -64,6 +64,7 @@ static struct cpufreq_driver amd_pstate_driver;
  static struct cpufreq_driver amd_pstate_epp_driver;
  static struct amd_cpudata **all_cpu_data;
  static int cppc_state = AMD_PSTATE_DISABLE;
+struct kobject *amd_pstate_kobj;
 
  static inline int get_mode_idx_from_str(const char *str, size_t size)
  {
@@ -90,6 +91,8 @@ static struct amd_pstate_params global_params;
  static DEFINE_MUTEX(amd_pstate_limits_lock);
  static DEFINE_MUTEX(amd_pstate_driver_lock);
 
+static DEFINE_SPINLOCK(cppc_notify_lock);
+
  static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached)
  {
  	u64 epp;
@@ -644,6 +647,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
  	policy->driver_data = cpudata;
 
  	amd_pstate_boost_init(cpudata);
+	if (!default_pstate_driver->adjust_perf)
+		default_pstate_driver->adjust_perf = amd_pstate_adjust_perf;
 
  	return 0;
 

drivers/cpufreq/amd-pstate.c static ssize_t show_energy_performance_preference( · line 798

Quoted 10 lines
drivers/cpufreq/amd-pstate.c +7 -0
@@ -784,12 +789,106 @@ static ssize_t show_energy_performance_preference(
  	return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);
  }
 
+static ssize_t amd_pstate_show_status(char *buf)
+{
+	if (!default_pstate_driver)
+		return sysfs_emit(buf, "off\n");
+
+	return sysfs_emit(buf, "%s\n", default_pstate_driver == &amd_pstate_epp_driver ?
+					"active" : "passive");

Didn't you introduce const strings for this in an earlier patch from the series?

How about using the indices from that rather than hardcoding /another/ string.

Also keep in mind guided mode will be coming so
"case ? true_val : false_val"

So perhaps you should just have have some if cases so you don't have to switch the whole thing out.

Quoted 12 lines
drivers/cpufreq/amd-pstate.c +12 -0
+}
+
+static void amd_pstate_driver_cleanup(void)
+{
+	unsigned int cpu;
+
+	cpus_read_lock();
+	for_each_online_cpu(cpu) {
+		if (all_cpu_data[cpu]) {
+			spin_lock(&cppc_notify_lock);
+			kfree(all_cpu_data[cpu]);
+			WRITE_ONCE(all_cpu_data[cpu], NULL);

drivers/cpufreq/amd-pstate.c static ssize_t show_energy_performance_preference( · line 820

Quoted 10 lines
drivers/cpufreq/amd-pstate.c +10 -0
+			spin_unlock(&cppc_notify_lock);
+		}
+	}
+	cpus_read_unlock();
+
+	default_pstate_driver = NULL;
+}
+
+static int amd_pstate_update_status(const char *buf, size_t size)
+{

Rather than looking at each size for each case, how about you just look at the boundaries once? Something like this:

if (size > 7 || size < 3)

	return -EINVAL;

Then you should be able to run strncmp for each of your cases.

drivers/cpufreq/amd-pstate.c static ssize_t show_energy_performance_preference( · line 821

Quoted 1 line
drivers/cpufreq/amd-pstate.c +1 -0
+	if (size == 3 && !strncmp(buf, "off", size)) {

This seems like another case that would be good to use the const strings you already introduced for state machine checking.

drivers/cpufreq/amd-pstate.c static ssize_t show_energy_performance_preference( · line 833

Quoted 12 lines
drivers/cpufreq/amd-pstate.c +12 -0
+		if (!default_pstate_driver)
+			return -EINVAL;
+
+		if (cppc_state == AMD_PSTATE_ACTIVE)
+			return -EBUSY;
+
+		cpufreq_unregister_driver(default_pstate_driver);
+		amd_pstate_driver_cleanup();
+		return 0;
+	}
+
+	if (size == 6 && !strncmp(buf, "active", size)) {

This seems like another case that would be good to use the const strings you already introduced for state machine checking.

drivers/cpufreq/amd-pstate.c static ssize_t show_energy_performance_preference( · line 845

Quoted 12 lines
drivers/cpufreq/amd-pstate.c +12 -0
+		if (default_pstate_driver) {
+			if (default_pstate_driver == &amd_pstate_epp_driver)
+				return 0;
+			cpufreq_unregister_driver(default_pstate_driver);
+			default_pstate_driver = &amd_pstate_epp_driver;
+			cppc_state = AMD_PSTATE_ACTIVE;
+		}
+
+		return cpufreq_register_driver(default_pstate_driver);
+	}
+
+	if (size == 7 && !strncmp(buf, "passive", size)) {

This seems like another case that would be good to use the const strings you already introduced for state machine checking.

Quoted 92 lines
drivers/cpufreq/amd-pstate.c +69 -0
+		if (default_pstate_driver) {
+			if (default_pstate_driver == &amd_pstate_driver)
+				return 0;
+			cpufreq_unregister_driver(default_pstate_driver);
+			cppc_state = AMD_PSTATE_PASSIVE;
+			default_pstate_driver = &amd_pstate_driver;
+		}
+
+		return cpufreq_register_driver(default_pstate_driver);
+	}
+
+	return -EINVAL;
+}
+
+static ssize_t show_status(struct kobject *kobj,
+			   struct kobj_attribute *attr, char *buf)
+{
+	ssize_t ret;
+
+	mutex_lock(&amd_pstate_driver_lock);
+	ret = amd_pstate_show_status(buf);
+	mutex_unlock(&amd_pstate_driver_lock);
+
+	return ret;
+}
+
+static ssize_t store_status(struct kobject *a, struct kobj_attribute *b,
+			    const char *buf, size_t count)
+{
+	char *p = memchr(buf, '\n', count);
+	int ret;
+
+	mutex_lock(&amd_pstate_driver_lock);
+	ret = amd_pstate_update_status(buf, p ? p - buf : count);
+	mutex_unlock(&amd_pstate_driver_lock);
+
+	return ret < 0 ? ret : count;
+}
+
  cpufreq_freq_attr_ro(amd_pstate_max_freq);
  cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
 
  cpufreq_freq_attr_ro(amd_pstate_highest_perf);
  cpufreq_freq_attr_rw(energy_performance_preference);
  cpufreq_freq_attr_ro(energy_performance_available_preferences);
+define_one_global_rw(status);
 
  static struct freq_attr *amd_pstate_attr[] = {
  	&amd_pstate_max_freq,
@@ -807,6 +906,15 @@ static struct freq_attr *amd_pstate_epp_attr[] = {
  	NULL,
  };
 
+static struct attribute *pstate_global_attributes[] = {
+	&status.attr,
+	NULL
+};
+
+static const struct attribute_group amd_pstate_global_attr_group = {
+	.attrs = pstate_global_attributes,
+};
+
  static inline void update_boost_state(void)
  {
  	u64 misc_en;
@@ -1228,6 +1336,26 @@ static int __init amd_pstate_init(void)
  	if (ret)
  		pr_err("failed to register with return %d\n", ret);
 
+	amd_pstate_kobj = kobject_create_and_add("amd-pstate", &cpu_subsys.dev_root->kobj);
+	if (!amd_pstate_kobj) {
+		ret = -EINVAL;
+		pr_err("global sysfs registration failed.\n");
+		goto kobject_free;
+	}
+
+	ret = sysfs_create_group(amd_pstate_kobj, &amd_pstate_global_attr_group);
+	if (ret) {
+		pr_err("sysfs attribute export failed with error %d.\n", ret);
+		goto global_attr_free;
+	}
+
+	return ret;
+
+global_attr_free:
+	kobject_put(amd_pstate_kobj);
+kobject_free:
+	kfree(cpudata);
+	cpufreq_unregister_driver(default_pstate_driver);
  	return ret;
  }
  device_initcall(amd_pstate_init);
maintainer
#33 lore raw

Re: [PATCH v8 09/13] cpufreq: amd-pstate: add driver working mode switch support

In reply to Perry Yuan
Quoted 45 lines · Perry

From: Perry Yuan <[email protected]>

While amd-pstate driver was loaded with specific driver mode, it will need to check which mode is enabled for the pstate driver,add this sysfs entry to show the current status

$ cat /sys/devices/system/cpu/amd-pstate/status
active

Meanwhile, user can switch the pstate driver mode with writing mode string to sysfs entry as below.

Enable passive mode:

$ sudo bash -c "echo passive >  /sys/devices/system/cpu/amd-pstate/status"

Enable active mode (EPP driver mode):

$ sudo bash -c "echo active > /sys/devices/system/cpu/amd-pstate/status"
---
 drivers/cpufreq/amd-pstate.c | 128 +++++++++++++++++++++++++++++++++++
 1 file changed, 128 insertions(+)
drivers/cpufreq/amd-pstate.c +3 -0
index fc12d35bc7bd..e8996e937e63 100644
@@ -64,6 +64,7 @@ static struct cpufreq_driver amd_pstate_driver;
 static struct cpufreq_driver amd_pstate_epp_driver;
 static struct amd_cpudata **all_cpu_data;
 static int cppc_state = AMD_PSTATE_DISABLE;
+struct kobject *amd_pstate_kobj;
 
 static inline int get_mode_idx_from_str(const char *str, size_t size)
 {
@@ -90,6 +91,8 @@ static struct amd_pstate_params global_params;
 static DEFINE_MUTEX(amd_pstate_limits_lock);
 static DEFINE_MUTEX(amd_pstate_driver_lock);
 
+static DEFINE_SPINLOCK(cppc_notify_lock);
+
 static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached)
 {
 	u64 epp;

drivers/cpufreq/amd-pstate.c static int amd_pstate_cpu_init(struct cpufreq_policy *policy) · line 651

Quoted 5 lines
drivers/cpufreq/amd-pstate.c +2 -0
@@ -644,6 +647,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
 	policy->driver_data = cpudata;
 
 	amd_pstate_boost_init(cpudata);
+	if (!default_pstate_driver->adjust_perf)
+		default_pstate_driver->adjust_perf = amd_pstate_adjust_perf;

If default_driver is passive driver, it will be programed as amd_pstate_adjust_perf. If not, the epp driver won't need adjust_perf.

Thanks,
Ray

Quoted 156 lines
drivers/cpufreq/amd-pstate.c +123 -0
 	return 0;
 
@@ -784,12 +789,106 @@ static ssize_t show_energy_performance_preference(
 	return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);
 }
 
+static ssize_t amd_pstate_show_status(char *buf)
+{
+	if (!default_pstate_driver)
+		return sysfs_emit(buf, "off\n");
+
+	return sysfs_emit(buf, "%s\n", default_pstate_driver == &amd_pstate_epp_driver ?
+					"active" : "passive");
+}
+
+static void amd_pstate_driver_cleanup(void)
+{
+	unsigned int cpu;
+
+	cpus_read_lock();
+	for_each_online_cpu(cpu) {
+		if (all_cpu_data[cpu]) {
+			spin_lock(&cppc_notify_lock);
+			kfree(all_cpu_data[cpu]);
+			WRITE_ONCE(all_cpu_data[cpu], NULL);
+			spin_unlock(&cppc_notify_lock);
+		}
+	}
+	cpus_read_unlock();
+
+	default_pstate_driver = NULL;
+}
+
+static int amd_pstate_update_status(const char *buf, size_t size)
+{
+	if (size == 3 && !strncmp(buf, "off", size)) {
+		if (!default_pstate_driver)
+			return -EINVAL;
+
+		if (cppc_state == AMD_PSTATE_ACTIVE)
+			return -EBUSY;
+
+		cpufreq_unregister_driver(default_pstate_driver);
+		amd_pstate_driver_cleanup();
+		return 0;
+	}
+
+	if (size == 6 && !strncmp(buf, "active", size)) {
+		if (default_pstate_driver) {
+			if (default_pstate_driver == &amd_pstate_epp_driver)
+				return 0;
+			cpufreq_unregister_driver(default_pstate_driver);
+			default_pstate_driver = &amd_pstate_epp_driver;
+			cppc_state = AMD_PSTATE_ACTIVE;
+		}
+
+		return cpufreq_register_driver(default_pstate_driver);
+	}
+
+	if (size == 7 && !strncmp(buf, "passive", size)) {
+		if (default_pstate_driver) {
+			if (default_pstate_driver == &amd_pstate_driver)
+				return 0;
+			cpufreq_unregister_driver(default_pstate_driver);
+			cppc_state = AMD_PSTATE_PASSIVE;
+			default_pstate_driver = &amd_pstate_driver;
+		}
+
+		return cpufreq_register_driver(default_pstate_driver);
+	}
+
+	return -EINVAL;
+}
+
+static ssize_t show_status(struct kobject *kobj,
+			   struct kobj_attribute *attr, char *buf)
+{
+	ssize_t ret;
+
+	mutex_lock(&amd_pstate_driver_lock);
+	ret = amd_pstate_show_status(buf);
+	mutex_unlock(&amd_pstate_driver_lock);
+
+	return ret;
+}
+
+static ssize_t store_status(struct kobject *a, struct kobj_attribute *b,
+			    const char *buf, size_t count)
+{
+	char *p = memchr(buf, '\n', count);
+	int ret;
+
+	mutex_lock(&amd_pstate_driver_lock);
+	ret = amd_pstate_update_status(buf, p ? p - buf : count);
+	mutex_unlock(&amd_pstate_driver_lock);
+
+	return ret < 0 ? ret : count;
+}
+
 cpufreq_freq_attr_ro(amd_pstate_max_freq);
 cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
 
 cpufreq_freq_attr_ro(amd_pstate_highest_perf);
 cpufreq_freq_attr_rw(energy_performance_preference);
 cpufreq_freq_attr_ro(energy_performance_available_preferences);
+define_one_global_rw(status);
 
 static struct freq_attr *amd_pstate_attr[] = {
 	&amd_pstate_max_freq,
@@ -807,6 +906,15 @@ static struct freq_attr *amd_pstate_epp_attr[] = {
 	NULL,
 };
 
+static struct attribute *pstate_global_attributes[] = {
+	&status.attr,
+	NULL
+};
+
+static const struct attribute_group amd_pstate_global_attr_group = {
+	.attrs = pstate_global_attributes,
+};
+
 static inline void update_boost_state(void)
 {
 	u64 misc_en;
@@ -1228,6 +1336,26 @@ static int __init amd_pstate_init(void)
 	if (ret)
 		pr_err("failed to register with return %d\n", ret);
 
+	amd_pstate_kobj = kobject_create_and_add("amd-pstate", &cpu_subsys.dev_root->kobj);
+	if (!amd_pstate_kobj) {
+		ret = -EINVAL;
+		pr_err("global sysfs registration failed.\n");
+		goto kobject_free;
+	}
+
+	ret = sysfs_create_group(amd_pstate_kobj, &amd_pstate_global_attr_group);
+	if (ret) {
+		pr_err("sysfs attribute export failed with error %d.\n", ret);
+		goto global_attr_free;
+	}
+
+	return ret;
+
+global_attr_free:
+	kobject_put(amd_pstate_kobj);
+kobject_free:
+	kfree(cpudata);
+	cpufreq_unregister_driver(default_pstate_driver);
 	return ret;
 }
 device_initcall(amd_pstate_init);
Signature · 1 line
2.34.1
author reviewer
#34 lore raw

RE: [PATCH v8 09/13] cpufreq: amd-pstate: add driver working mode switch support

[AMD Official Use Only - General]

Quoted 71 lines

-----Original Message-----
From: Huang, Ray <[email protected]>
Sent: Friday, December 23, 2022 4:56 PM
To: Yuan, Perry <[email protected]>
Cc: [email protected]; Limonciello, Mario <[email protected]>; [email protected]; Sharma, Deepak <[email protected]>; Fontenot, Nathan <[email protected]>; Deucher, Alexander <[email protected]>; Huang, Shimmer <[email protected]>; Du, Xiaojian <[email protected]>; Meng, Li (Jassmine) <[email protected]>; Karny, Wyes <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v8 09/13] cpufreq: amd-pstate: add driver working mode switch support

Quoted 6 lines · Perry

From: Perry Yuan <[email protected]>

While amd-pstate driver was loaded with specific driver mode, it will need to check which mode is enabled for the pstate driver,add this sysfs entry to show the current status

Quoted 8 lines
$ cat /sys/devices/system/cpu/amd-pstate/status
active

Meanwhile, user can switch the pstate driver mode with writing mode string to sysfs entry as below.

Enable passive mode:

$ sudo bash -c "echo passive >  /sys/devices/system/cpu/amd-

pstate/status"

Quoted 4 lines

Enable active mode (EPP driver mode):

$ sudo bash -c "echo active > /sys/devices/system/cpu/amd-pstate/status"
Quoted 8 lines
---
 drivers/cpufreq/amd-pstate.c | 128
+++++++++++++++++++++++++++++++++++
 1 file changed, 128 insertions(+)
(quoted diff) +0 -0

b/drivers/cpufreq/amd-pstate.c index fc12d35bc7bd..e8996e937e63

100644

drivers/cpufreq/amd-pstate.c static int amd_pstate_cpu_init(struct

Quoted 19 lines
drivers/cpufreq/amd-pstate.c +0 -0
@@ -64,6 +64,7 @@ static struct cpufreq_driver amd_pstate_driver;

static struct cpufreq_driver amd_pstate_epp_driver; static struct amd_cpudata **all_cpu_data; static int cppc_state = AMD_PSTATE_DISABLE;
+struct kobject *amd_pstate_kobj;

static inline int get_mode_idx_from_str(const char *str, size_t size)
{ @@ -90,6 +91,8 @@ static struct amd_pstate_params global_params; static DEFINE_MUTEX(amd_pstate_limits_lock);
static DEFINE_MUTEX(amd_pstate_driver_lock);

drivers/cpufreq/amd-pstate.c +2 -0
+static DEFINE_SPINLOCK(cppc_notify_lock);
+
 static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64

cppc_req_cached) {

drivers/cpufreq/amd-pstate.c +0 -0
 	u64 epp;
@@ -644,6 +647,8 @@ static int amd_pstate_cpu_init(struct

cpufreq_policy *policy)

drivers/cpufreq/amd-pstate.c static int amd_pstate_cpu_init(struct cpufreq_policy *policy)

Quoted 5 lines
drivers/cpufreq/amd-pstate.c +2 -0
 	policy->driver_data = cpudata;
 
 	amd_pstate_boost_init(cpudata);
+	if (!default_pstate_driver->adjust_perf)
+		default_pstate_driver->adjust_perf =

amd_pstate_adjust_perf;

Quoted 5 lines

If default_driver is passive driver, it will be programed as amd_pstate_adjust_perf. If not, the epp driver won't need adjust_perf.

Thanks,
Ray

The adjust_perf() should be set again when switching from epp to cppc driver.
The above amd_pstate_cpu_init () is called when amd-pstate driver loading, epp driver will not load it.

Quoted 155 lines

drivers/cpufreq/amd-pstate.c static ssize_t

Quoted 5 lines
drivers/cpufreq/amd-pstate.c +0 -0
 	return 0;
 
@@ -784,12 +789,106 @@ static ssize_t

show_energy_performance_preference(

drivers/cpufreq/amd-pstate.c static ssize_t show_energy_performance_preference(

Quoted 7 lines
drivers/cpufreq/amd-pstate.c +5 -0
 	return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);  }
 
+static ssize_t amd_pstate_show_status(char *buf) {
+	if (!default_pstate_driver)
+		return sysfs_emit(buf, "off\n");
+
+	return sysfs_emit(buf, "%s\n", default_pstate_driver ==

&amd_pstate_epp_driver ?

Quoted 26 lines
drivers/cpufreq/amd-pstate.c +26 -0
+					"active" : "passive");
+}
+
+static void amd_pstate_driver_cleanup(void) {
+	unsigned int cpu;
+
+	cpus_read_lock();
+	for_each_online_cpu(cpu) {
+		if (all_cpu_data[cpu]) {
+			spin_lock(&cppc_notify_lock);
+			kfree(all_cpu_data[cpu]);
+			WRITE_ONCE(all_cpu_data[cpu], NULL);
+			spin_unlock(&cppc_notify_lock);
+		}
+	}
+	cpus_read_unlock();
+
+	default_pstate_driver = NULL;
+}
+
+static int amd_pstate_update_status(const char *buf, size_t size) {
+	if (size == 3 && !strncmp(buf, "off", size)) {
+		if (!default_pstate_driver)
+			return -EINVAL;
+
+		if (cppc_state == AMD_PSTATE_ACTIVE)

drivers/cpufreq/amd-pstate.c static ssize_t show_energy_performance_preference(

Quoted 10 lines
drivers/cpufreq/amd-pstate.c +10 -0
+			return -EBUSY;
+
+		cpufreq_unregister_driver(default_pstate_driver);
+		amd_pstate_driver_cleanup();
+		return 0;
+	}
+
+	if (size == 6 && !strncmp(buf, "active", size)) {
+		if (default_pstate_driver) {
+			if (default_pstate_driver ==

&amd_pstate_epp_driver)

Quoted 73 lines
drivers/cpufreq/amd-pstate.c +57 -0
+				return 0;
+			cpufreq_unregister_driver(default_pstate_driver);
+			default_pstate_driver = &amd_pstate_epp_driver;
+			cppc_state = AMD_PSTATE_ACTIVE;
+		}
+
+		return cpufreq_register_driver(default_pstate_driver);
+	}
+
+	if (size == 7 && !strncmp(buf, "passive", size)) {
+		if (default_pstate_driver) {
+			if (default_pstate_driver == &amd_pstate_driver)
+				return 0;
+			cpufreq_unregister_driver(default_pstate_driver);
+			cppc_state = AMD_PSTATE_PASSIVE;
+			default_pstate_driver = &amd_pstate_driver;
+		}
+
+		return cpufreq_register_driver(default_pstate_driver);
+	}
+
+	return -EINVAL;
+}
+
+static ssize_t show_status(struct kobject *kobj,
+			   struct kobj_attribute *attr, char *buf) {
+	ssize_t ret;
+
+	mutex_lock(&amd_pstate_driver_lock);
+	ret = amd_pstate_show_status(buf);
+	mutex_unlock(&amd_pstate_driver_lock);
+
+	return ret;
+}
+
+static ssize_t store_status(struct kobject *a, struct kobj_attribute *b,
+			    const char *buf, size_t count) {
+	char *p = memchr(buf, '\n', count);
+	int ret;
+
+	mutex_lock(&amd_pstate_driver_lock);
+	ret = amd_pstate_update_status(buf, p ? p - buf : count);
+	mutex_unlock(&amd_pstate_driver_lock);
+
+	return ret < 0 ? ret : count;
+}
+
 cpufreq_freq_attr_ro(amd_pstate_max_freq);
 cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
 
 cpufreq_freq_attr_ro(amd_pstate_highest_perf);
 cpufreq_freq_attr_rw(energy_performance_preference);
 cpufreq_freq_attr_ro(energy_performance_available_preferences);
+define_one_global_rw(status);
 
 static struct freq_attr *amd_pstate_attr[] = {
 	&amd_pstate_max_freq,
@@ -807,6 +906,15 @@ static struct freq_attr *amd_pstate_epp_attr[] = {
 	NULL,
 };
 
+static struct attribute *pstate_global_attributes[] = {
+	&status.attr,
+	NULL
+};
+
+static const struct attribute_group amd_pstate_global_attr_group = {
+	.attrs = pstate_global_attributes,
+};
+
 static inline void update_boost_state(void)  {
 	u64 misc_en;

drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void) · line 1339

Quoted 4 lines
drivers/cpufreq/amd-pstate.c +1 -0
@@ -1228,6 +1336,26 @@ static int __init amd_pstate_init(void)
 	if (ret)
 		pr_err("failed to register with return %d\n", ret);
 
+	amd_pstate_kobj = kobject_create_and_add("amd-pstate",

&cpu_subsys.dev_root->kobj);

drivers/cpufreq/amd-pstate.c static int __init amd_pstate_init(void)

Quoted 7 lines
drivers/cpufreq/amd-pstate.c +7 -0
+	if (!amd_pstate_kobj) {
+		ret = -EINVAL;
+		pr_err("global sysfs registration failed.\n");
+		goto kobject_free;
+	}
+
+	ret = sysfs_create_group(amd_pstate_kobj,

&amd_pstate_global_attr_group);

Quoted 18 lines
drivers/cpufreq/amd-pstate.c +12 -1
+	if (ret) {
+		pr_err("sysfs attribute export failed with error %d.\n", ret);
+		goto global_attr_free;
+	}
+
+	return ret;
+
+global_attr_free:
+	kobject_put(amd_pstate_kobj);
+kobject_free:
+	kfree(cpudata);
+	cpufreq_unregister_driver(default_pstate_driver);
 	return ret;
 }
 device_initcall(amd_pstate_init);
--

2.34.1

author reviewer
#35 lore raw

PATCH v8 10/13 Documentation: amd-pstate: add amd pstate driver mode introduction

In reply to Perry Yuan

From: Perry Yuan <[email protected]>

Introduce ``amd-pstate`` CPPC has two operation modes:
* CPPC Autonomous (active) mode
* CPPC non-autonomous (passive) mode.
active mode and passive mode can be chosen by different kernel parameters.

---
 Documentation/admin-guide/pm/amd-pstate.rst | 26 +++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
Documentation/admin-guide/pm/amd-pstate.rst +24 -2
index 33ab8ec8fc2f..62744dae3c5f 100644
@@ -299,8 +299,30 @@ module which supports the new AMD P-States mechanism on most of the future AMD
 platforms. The AMD P-States mechanism is the more performance and energy
 efficiency frequency management method on AMD processors.
 
-Kernel Module Options for ``amd-pstate``
-=========================================
+
+AMD Pstate Driver Operation Modes
+=================================
+
+``amd_pstate`` CPPC has two operation modes: CPPC Autonomous(active) mode and
+CPPC non-autonomous(passive) mode.
+active mode and passive mode can be chosen by different kernel parameters.
+When in Autonomous mode, CPPC ignores requests done in the Desired Performance
+Target register and takes into account only the values set to the Minimum requested
+performance, Maximum requested performance, and Energy Performance Preference
+registers. When Autonomous is disabled, it only considers the Desired Performance Target.
+
+Active Mode
+------------
+
+``amd_pstate=active``
+
+This is the low-level firmware control mode which is implemented by ``amd_pstate_epp``
+driver with ``amd_pstate=active`` passed to the kernel in the command line.
+In this mode, ``amd_pstate_epp`` driver provides a hint to the hardware if software
+wants to bias toward performance (0x0) or energy efficiency (0xff) to the CPPC firmware.
+then CPPC power algorithm will calculate the runtime workload and adjust the realtime
+cores frequency according to the power supply and thermal, core voltage and some other
+hardware conditions.
 
 Passive Mode
 ------------
Signature · 1 line
2.34.1
maintainer Reviewed-by on v8 10/13
#36 lore raw

Re: [PATCH v8 10/13] Documentation: amd-pstate: add amd pstate driver mode introduction

Quoted 3 lines · Perry Yuan

From: Perry Yuan <[email protected]>

Introduce ``amd-pstate`` CPPC has two operation modes:

Drop the word Introduce.

Quoted 5 lines

* CPPC Autonomous (active) mode
* CPPC non-autonomous (passive) mode.
active mode and passive mode can be chosen by different kernel parameters.

With nit fixed:

Quoted 41 lines
---
  Documentation/admin-guide/pm/amd-pstate.rst | 26 +++++++++++++++++++--
  1 file changed, 24 insertions(+), 2 deletions(-)
Documentation/admin-guide/pm/amd-pstate.rst +24 -2
index 33ab8ec8fc2f..62744dae3c5f 100644
@@ -299,8 +299,30 @@ module which supports the new AMD P-States mechanism on most of the future AMD
  platforms. The AMD P-States mechanism is the more performance and energy
  efficiency frequency management method on AMD processors.
 
-Kernel Module Options for ``amd-pstate``
-=========================================
+
+AMD Pstate Driver Operation Modes
+=================================
+
+``amd_pstate`` CPPC has two operation modes: CPPC Autonomous(active) mode and
+CPPC non-autonomous(passive) mode.
+active mode and passive mode can be chosen by different kernel parameters.
+When in Autonomous mode, CPPC ignores requests done in the Desired Performance
+Target register and takes into account only the values set to the Minimum requested
+performance, Maximum requested performance, and Energy Performance Preference
+registers. When Autonomous is disabled, it only considers the Desired Performance Target.
+
+Active Mode
+------------
+
+``amd_pstate=active``
+
+This is the low-level firmware control mode which is implemented by ``amd_pstate_epp``
+driver with ``amd_pstate=active`` passed to the kernel in the command line.
+In this mode, ``amd_pstate_epp`` driver provides a hint to the hardware if software
+wants to bias toward performance (0x0) or energy efficiency (0xff) to the CPPC firmware.
+then CPPC power algorithm will calculate the runtime workload and adjust the realtime
+cores frequency according to the power supply and thermal, core voltage and some other
+hardware conditions.
 
  Passive Mode
  ------------
author reviewer
#37 lore raw

PATCH v8 11/13 Documentation: introduce amd pstate active mode kernel command line options

In reply to Perry Yuan

AMD Pstate driver support another firmware based autonomous mode with "amd_pstate=active" added to the kernel command line. In autonomous mode SMU firmware decides frequencies at 1 ms timescale based on workload utilization, usage in other IPs, infrastructure limits such as power, thermals and so on.

---
 Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index 42af9ca0127e..73a02816f6f8 100644
@@ -6970,3 +6970,10 @@
 			  management firmware translates the requests into actual
 			  hardware states (core frequency, data fabric and memory
 			  clocks etc.)
+			active
+			  Use amd_pstate_epp driver instance as the scaling driver,
+			  driver provides a hint to the hardware if software wants
+			  to bias toward performance (0x0) or energy efficiency (0xff)
+			  to the CPPC firmware. then CPPC power algorithm will
+			  calculate the runtime workload and adjust the realtime cores
+			  frequency.
Signature · 1 line
2.34.1
maintainer Reviewed-by on v8 11/13
#38 lore raw

Re: [PATCH v8 11/13] Documentation: introduce amd pstate active mode kernel command line options

Quoted 3 lines · Perry Yuan

AMD Pstate driver support another firmware based autonomous mode with "amd_pstate=active" added to the kernel command line. In autonomous mode SMU firmware decides frequencies at 1 ms timescale

This might be the case right now, but I don't know that it will always be this timescale. Suggest to drop drop "at 1ms timescale".

Quoted 4 lines

based on workload utilization, usage in other IPs, infrastructure limits such as power, thermals and so on.

With nit fixed:

Quoted 19 lines
---
  Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
  1 file changed, 7 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index 42af9ca0127e..73a02816f6f8 100644
@@ -6970,3 +6970,10 @@
  			  management firmware translates the requests into actual
  			  hardware states (core frequency, data fabric and memory
  			  clocks etc.)
+			active
+			  Use amd_pstate_epp driver instance as the scaling driver,
+			  driver provides a hint to the hardware if software wants
+			  to bias toward performance (0x0) or energy efficiency (0xff)
+			  to the CPPC firmware. then CPPC power algorithm will
+			  calculate the runtime workload and adjust the realtime cores
+			  frequency.
author reviewer
#39 lore raw

PATCH v8 12/13 cpufreq: amd-pstate: convert sprintf with sysfs_emit()

In reply to Perry Yuan

replace the sprintf with a more generic sysfs_emit function

No potential function impact

---
 drivers/cpufreq/amd-pstate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpufreq/amd-pstate.c +3 -3
index e8996e937e63..d8b182614c18 100644
@@ -709,7 +709,7 @@ static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
 	if (max_freq < 0)
 		return max_freq;
 
-	return sprintf(&buf[0], "%u\n", max_freq);
+	return sysfs_emit(buf, "%u\n", max_freq);
 }
 
 static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
@@ -722,7 +722,7 @@ static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *poli
 	if (freq < 0)
 		return freq;
 
-	return sprintf(&buf[0], "%u\n", freq);
+	return sysfs_emit(buf, "%u\n", freq);
 }
 
 /*
@@ -737,7 +737,7 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy,
 
 	perf = READ_ONCE(cpudata->highest_perf);
 
-	return sprintf(&buf[0], "%u\n", perf);
+	return sysfs_emit(buf, "%u\n", perf);
 }
 
 static ssize_t show_energy_performance_available_preferences(
Signature · 1 line
2.34.1
maintainer Reviewed-by on v8 12/13
#40 lore raw

Re: [PATCH v8 12/13] cpufreq: amd-pstate: convert sprintf with sysfs_emit()

Quoted 3 lines · Perry Yuan

replace the sprintf with a more generic sysfs_emit function

No potential function impact

Anything is possible! "No intended functional impact." I believe is what you meant =)

Quoted 2 lines

With commit message fixed:

Quoted 35 lines
---
  drivers/cpufreq/amd-pstate.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpufreq/amd-pstate.c +3 -3
index e8996e937e63..d8b182614c18 100644
@@ -709,7 +709,7 @@ static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
  	if (max_freq < 0)
  		return max_freq;
 
-	return sprintf(&buf[0], "%u\n", max_freq);
+	return sysfs_emit(buf, "%u\n", max_freq);
  }
 
  static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
@@ -722,7 +722,7 @@ static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *poli
  	if (freq < 0)
  		return freq;
 
-	return sprintf(&buf[0], "%u\n", freq);
+	return sysfs_emit(buf, "%u\n", freq);
  }
 
  /*
@@ -737,7 +737,7 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy,
 
  	perf = READ_ONCE(cpudata->highest_perf);
 
-	return sprintf(&buf[0], "%u\n", perf);
+	return sysfs_emit(buf, "%u\n", perf);
  }
 
  static ssize_t show_energy_performance_available_preferences(
author reviewer
#41 lore raw

RE: [PATCH v8 12/13] cpufreq: amd-pstate: convert sprintf with sysfs_emit()

[AMD Official Use Only - General]

Hi Mario.

Quoted 23 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Tuesday, December 20, 2022 7:31 AM
To: Yuan, Perry <[email protected]>; [email protected]; Huang, Ray <[email protected]>; [email protected]
Cc: Sharma, Deepak <[email protected]>; Fontenot, Nathan <[email protected]>; Deucher, Alexander <[email protected]>; Huang, Shimmer <[email protected]>; Du, Xiaojian <[email protected]>; Meng, Li (Jassmine) <[email protected]>; Karny, Wyes <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v8 12/13] cpufreq: amd-pstate: convert sprintf with sysfs_emit()

Quoted 3 lines · Perry Yuan

replace the sprintf with a more generic sysfs_emit function

No potential function impact

Anything is possible! "No intended functional impact." I believe is what you meant =)

Quoted 1 line
Quoted 5 lines
Quoted 1 line

With commit message fixed:

Thanks for your review , all the R-B flags have been picked up in v9 . And other feedbacks from you have been changed in v9 as well.

Perry.

Quoted 41 lines
Quoted 7 lines
---
  drivers/cpufreq/amd-pstate.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/cpufreq/amd-pstate.c index e8996e937e63..d8b182614c18

100644

drivers/cpufreq/amd-pstate.c static ssize_t show_amd_pstate_max_freq(struct

Quoted 3 lines
drivers/cpufreq/amd-pstate.c +0 -0
@@ -709,7 +709,7 @@ static ssize_t show_amd_pstate_max_freq(struct

cpufreq_policy *policy,

Quoted 9 lines
drivers/cpufreq/amd-pstate.c +1 -1
  	if (max_freq < 0)
  		return max_freq;
 
-	return sprintf(&buf[0], "%u\n", max_freq);
+	return sysfs_emit(buf, "%u\n", max_freq);
  }
 
  static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct

cpufreq_policy *policy, @@ -722,7 +722,7 @@ static ssize_t

show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *poli

drivers/cpufreq/amd-pstate.c static ssize_t

Quoted 9 lines

if (freq < 0)
return freq;

drivers/cpufreq/amd-pstate.c +1 -1
-	return sprintf(&buf[0], "%u\n", freq);
+	return sysfs_emit(buf, "%u\n", freq);
  }
 
  /*
@@ -737,7 +737,7 @@ static ssize_t

show_amd_pstate_highest_perf(struct

Quoted 9 lines
drivers/cpufreq/amd-pstate.c +1 -1
 cpufreq_policy *policy,
 
  	perf = READ_ONCE(cpudata->highest_perf);
 
-	return sprintf(&buf[0], "%u\n", perf);
+	return sysfs_emit(buf, "%u\n", perf);
  }
 

static ssize_t show_energy_performance_available_preferences(

maintainer Acked-by on v8 12/13
#42 lore raw

Re: [PATCH v8 12/13] cpufreq: amd-pstate: convert sprintf with sysfs_emit()

In reply to Perry Yuan
Quoted 5 lines · Perry

replace the sprintf with a more generic sysfs_emit function

No potential function impact

Quoted 38 lines
---
 drivers/cpufreq/amd-pstate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpufreq/amd-pstate.c +3 -3
index e8996e937e63..d8b182614c18 100644
@@ -709,7 +709,7 @@ static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
 	if (max_freq < 0)
 		return max_freq;
 
-	return sprintf(&buf[0], "%u\n", max_freq);
+	return sysfs_emit(buf, "%u\n", max_freq);
 }
 
 static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
@@ -722,7 +722,7 @@ static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *poli
 	if (freq < 0)
 		return freq;
 
-	return sprintf(&buf[0], "%u\n", freq);
+	return sysfs_emit(buf, "%u\n", freq);
 }
 
 /*
@@ -737,7 +737,7 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy,
 
 	perf = READ_ONCE(cpudata->highest_perf);
 
-	return sprintf(&buf[0], "%u\n", perf);
+	return sysfs_emit(buf, "%u\n", perf);
 }
 
 static ssize_t show_energy_performance_available_preferences(
Signature · 1 line
2.34.1
author reviewer
#43 lore raw

PATCH v8 13/13 Documentation: amd-pstate: introduce new global sysfs attributes

In reply to Perry Yuan

The new amd-pstate driver support to switch the driver working mode and use can switch the driver mode within the sysfs attributes in the below path and check current mode

$ cd /sys/devices/system/cpu/amd-pstate

check driver mode:

$ cat /sys/devices/system/cpu/amd-pstate/status

switch mode:

$ sudo bash -c "echo passive  > /sys/devices/system/cpu/amd-pstate/status"
or
$ sudo bash -c "echo active  > /sys/devices/system/cpu/amd-pstate/status"
---
 Documentation/admin-guide/pm/amd-pstate.rst | 28 +++++++++++++++++++++
 1 file changed, 28 insertions(+)
Documentation/admin-guide/pm/amd-pstate.rst +28 -0
index 62744dae3c5f..f3a8f8a66783 100644
@@ -339,6 +339,34 @@ processor must provide at least nominal performance requested and go higher if c
 operating conditions allow.
 
 
+User Space Interface in ``sysfs``
+=================================
+
+Global Attributes
+-----------------
+
+``amd-pstate`` exposes several global attributes (files) in ``sysfs`` to
+control its functionality at the system level.  They are located in the
+``/sys/devices/system/cpu/amd-pstate/`` directory and affect all CPUs.
+
+``status``
+	Operation mode of the driver: "active", "passive" or "off".
+
+	"active"
+		The driver is functional and in the ``active mode``
+
+	"passive"
+		The driver is functional and in the ``passive mode``
+
+	"off"
+		The driver is unregistered and not functional now.
+
+	This attribute can be written to in order to change the driver's
+	operation mode or to unregister it.  The string written to it must be
+	one of the possible values of it and, if successful, the write will
+	cause the driver to switch over to the operation mode represented by
+	that string - or to be unregistered in the "off" case.
+
 ``cpupower`` tool support for ``amd-pstate``
 ===============================================
 
Signature · 1 line
2.34.1
#44 lore raw

Re: [PATCH v8 13/13] Documentation: amd-pstate: introduce new global sysfs attributes

Quoted 1 line · Perry Yuan

The new amd-pstate driver support to switch the driver working mode and

Words like "new" don't age well.

Quoted 2 lines

use can switch the driver mode within the sysfs attributes in the below path and check current mode

Perhaps "The amd-pstate driver supports switching working modes at runtime. Users can view and change modes by interacting with the "status" sysfs attribute.

Quoted 3 lines
$ cd /sys/devices/system/cpu/amd-pstate

No need to change directories; you're demonstrating below using full paths.

Quoted 7 lines

check driver mode:

$ cat /sys/devices/system/cpu/amd-pstate/status

switch mode:

$ sudo bash -c "echo passive  > /sys/devices/system/cpu/amd-pstate/status"
or
$ sudo bash -c "echo active  > /sys/devices/system/cpu/amd-pstate/status"

Another way you could suggest this:

# echo "passive" | sudo tee /sys/devices/system/cpu/amd-pstate/status
or
# echo "active" | sudo tee /sys/devices/system/cpu/amd-pstate/status

I don't feel strongly which way to suggest though.

Quoted 29 lines
---
  Documentation/admin-guide/pm/amd-pstate.rst | 28 +++++++++++++++++++++
  1 file changed, 28 insertions(+)
Documentation/admin-guide/pm/amd-pstate.rst +15 -0
index 62744dae3c5f..f3a8f8a66783 100644
@@ -339,6 +339,34 @@ processor must provide at least nominal performance requested and go higher if c
  operating conditions allow.
 
 
+User Space Interface in ``sysfs``
+=================================
+
+Global Attributes
+-----------------
+
+``amd-pstate`` exposes several global attributes (files) in ``sysfs`` to
+control its functionality at the system level.  They are located in the
+``/sys/devices/system/cpu/amd-pstate/`` directory and affect all CPUs.
+
+``status``
+	Operation mode of the driver: "active", "passive" or "off".
+
+	"active"
+		The driver is functional and in the ``active mode``

Documentation/admin-guide/pm/amd-pstate.rst processor must provide at least nominal performance requested and go higher if c · line 366

Quoted 10 lines
Documentation/admin-guide/pm/amd-pstate.rst +10 -0
+
+	"passive"
+		The driver is functional and in the ``passive mode``
+
+	"off"
+		The driver is unregistered and not functional now.
+
+	This attribute can be written to in order to change the driver's
+	operation mode or to unregister it.  The string written to it must be
+	one of the possible values of it and, if successful, the write will

I think this is implied that you wrote a possible value and if it returns success something happens. That's how all sysfs files work and it's needlessly wordy.

Documentation/admin-guide/pm/amd-pstate.rst processor must provide at least nominal performance requested and go higher if c · line 368

Quoted 2 lines
Documentation/admin-guide/pm/amd-pstate.rst +2 -0
+	cause the driver to switch over to the operation mode represented by
+	that string - or to be unregistered in the "off" case.

Considering the implication of my above comment I think you can reword this as:

"Writing one of these values to the sysfs file will cause the driver to..."

Quoted 4 lines
Documentation/admin-guide/pm/amd-pstate.rst +1 -0
+
  ``cpupower`` tool support for ``amd-pstate``
  ===============================================
 
#45 lore raw
In reply to Perry Yuan
Quoted 9 lines · Perry Yuan

Hi all,

This patchset implements one new AMD CPU frequency driver
amd-pstate-epp instance for better performance and power control.
CPPC has a parameter called energy preference performance (EPP).
The EPP is used in the CCLK DPM controller to drive the frequency that a core is going to operate during short periods of activity.
EPP values will be utilized for different OS profiles (balanced, performance, power savings).

Using v8 and clang-15 on 6.1 I get:

---
ld.lld: error: undefined symbol: energy_perf_strings

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

referenced by amd-pstate.c:789 (/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:789)
vmlinux.o:(show_energy_performance_preference)
referenced by amd-pstate.c:768 (/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:768)
vmlinux.o:(store_energy_performance_preference)
referenced by amd-pstate.c:749 (/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:749)
vmlinux.o:(show_energy_performance_available_preferences)
referenced 1 more times
did you mean: energy_perf_strings
defined in: vmlinux.o

ld.lld: error: undefined symbol: epp_values

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by amd-pstate.c:189 (/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:189)
vmlinux.o:(store_energy_performance_preference)

---

and a few warnings:

---
drivers/cpufreq/amd-pstate.c:966:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

        if (rc)
            ^~
drivers/cpufreq/amd-pstate.c:1025:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/cpufreq/amd-pstate.c:966:2: note: remove the 'if' if its condition is always false
        if (rc)
        ^~~~~~~
drivers/cpufreq/amd-pstate.c:962:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (!dev)
            ^~~~
drivers/cpufreq/amd-pstate.c:1025:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/cpufreq/amd-pstate.c:962:2: note: remove the 'if' if its condition is always false
        if (!dev)
        ^~~~~~~~~
drivers/cpufreq/amd-pstate.c:949:66: note: initialize the variable 'ret' to silence this warning
        int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
                                                                        ^

= 0
drivers/cpufreq/amd-pstate.c:996:52: warning: variable 'value' is uninitialized when used here [-Wuninitialized]

        cpudata->epp_cached = amd_pstate_get_epp(cpudata, value);
                                                          ^~~~~
drivers/cpufreq/amd-pstate.c:953:11: note: initialize the variable 'value' to silence this warning
        u64 value;
                 ^
                  = 0
drivers/cpufreq/amd-pstate.c:1085:6: warning: variable 'epp' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (cpudata->epp_policy == cpudata->policy)
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cpufreq/amd-pstate.c:1110:30: note: uninitialized use occurs here
        amd_pstate_set_epp(cpudata, epp);
                                    ^~~
drivers/cpufreq/amd-pstate.c:1085:2: note: remove the 'if' if its condition is always false
        if (cpudata->epp_policy == cpudata->policy)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cpufreq/amd-pstate.c:1064:9: note: initialize the variable 'epp' to silence this warning
        s16 epp;
               ^
                = 0

---

Cheers,

Tor Vic

#46 lore raw
Quoted 12 lines · Tor Vic
Quoted 9 lines · Perry Yuan

Hi all,

This patchset implements one new AMD CPU frequency driver
amd-pstate-epp instance for better performance and power control.
CPPC has a parameter called energy preference performance (EPP).
The EPP is used in the CCLK DPM controller to drive the frequency that a core is going to operate during short periods of activity.
EPP values will be utilized for different OS profiles (balanced, performance, power savings).

Quoted 2 lines

Using v8 and clang-15 on 6.1 I get:

Got it.
Mario was right. INTEL_PSTATE must be selected, it has become a dependency.

That doesn't seem correct.

With it selected, it builds just fine. Not tested though.

Quoted 74 lines

---
ld.lld: error: undefined symbol: energy_perf_strings

Quoted 1 line
Quoted 1 line
Quoted 1 line

referenced by amd-pstate.c:789

(/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:789)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

               vmlinux.o:(show_energy_performance_preference) referenced by amd-pstate.c:768

(/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:768)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

               vmlinux.o:(store_energy_performance_preference) referenced by amd-pstate.c:749

(/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:749)

Quoted 1 line
Quoted 1 line
Quoted 1 line

vmlinux.o:(show_energy_performance_available_preferences)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

referenced 1 more times
did you mean: energy_perf_strings
defined in: vmlinux.o

ld.lld: error: undefined symbol: epp_values

Quoted 1 line
Quoted 1 line
Quoted 1 line

referenced by amd-pstate.c:189

(/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c:189)

Quoted 1 line
Quoted 1 line
Quoted 1 line

               vmlinux.o:(store_energy_performance_preference)

---

and a few warnings:

---
drivers/cpufreq/amd-pstate.c:966:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (rc)
            ^~
drivers/cpufreq/amd-pstate.c:1025:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/cpufreq/amd-pstate.c:966:2: note: remove the 'if' if its condition is always false
        if (rc)
        ^~~~~~~
drivers/cpufreq/amd-pstate.c:962:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (!dev)
            ^~~~
drivers/cpufreq/amd-pstate.c:1025:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/cpufreq/amd-pstate.c:962:2: note: remove the 'if' if its condition is always false
        if (!dev)
        ^~~~~~~~~
drivers/cpufreq/amd-pstate.c:949:66: note: initialize the variable 'ret' to silence this warning
        int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
                                                                        ^

 = 0
drivers/cpufreq/amd-pstate.c:996:52: warning: variable 'value' is uninitialized when used here [-Wuninitialized]
        cpudata->epp_cached = amd_pstate_get_epp(cpudata, value);
                                                          ^~~~~
drivers/cpufreq/amd-pstate.c:953:11: note: initialize the variable 'value' to silence this warning
        u64 value;
                 ^
                  = 0
drivers/cpufreq/amd-pstate.c:1085:6: warning: variable 'epp' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (cpudata->epp_policy == cpudata->policy)
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cpufreq/amd-pstate.c:1110:30: note: uninitialized use occurs here
        amd_pstate_set_epp(cpudata, epp);
                                    ^~~
drivers/cpufreq/amd-pstate.c:1085:2: note: remove the 'if' if its condition is always false
        if (cpudata->epp_policy == cpudata->policy)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cpufreq/amd-pstate.c:1064:9: note: initialize the variable 'epp' to silence this warning
        s16 epp;
               ^
                = 0
---

Cheers,

Tor Vic

author reviewer
#47 lore raw

[AMD Official Use Only - General]

Quoted 32 lines

-----Original Message-----
From: Tor Vic <[email protected]>
Sent: Wednesday, December 21, 2022 2:53 AM
To: Yuan, Perry <[email protected]>; [email protected]; Limonciello, Mario <[email protected]>; Huang, Ray <[email protected]>; [email protected]
Cc: Sharma, Deepak <[email protected]>; Fontenot, Nathan <[email protected]>; Deucher, Alexander <[email protected]>; Huang, Shimmer <[email protected]>; Du, Xiaojian <[email protected]>; Meng, Li (Jassmine) <[email protected]>; Karny, Wyes <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v8 00/13] Implement AMD Pstate EPP Driver

Quoted 13 lines · Tor Vic
Quoted 10 lines · Perry Yuan

Hi all,

This patchset implements one new AMD CPU frequency driver amd-pstate-epp instance for better performance and power control. CPPC has a parameter called energy preference performance (EPP). The EPP is used in the CCLK DPM controller to drive the frequency that a core is going to operate during short periods of activity. EPP values will be utilized for different OS profiles (balanced, performance, power savings).

Quoted 2 lines

Using v8 and clang-15 on 6.1 I get:

Quoted 7 lines

Got it.
Mario was right. INTEL_PSTATE must be selected, it has become a dependency.

That doesn't seem correct.

With it selected, it builds just fine. Not tested though.

Yeah, I will make it in v9.
Thanks for your feedback!

Quoted 96 lines
Quoted 7 lines

---
ld.lld: error: undefined symbol: energy_perf_strings >>> referenced by amd-pstate.c:789 (/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c :789) >>>
vmlinux.o:(show_energy_performance_preference)

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

referenced by amd-pstate.c:768

(/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c :768) >>>
vmlinux.o:(store_energy_performance_preference)

Quoted 1 line
Quoted 1 line
Quoted 1 line

referenced by amd-pstate.c:749

(/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-

pstate.c:749)

Quoted 82 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

vmlinux.o:(show_energy_performance_available_preferences)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced 1 more times
did you mean: energy_perf_strings >>> defined in: vmlinux.o

ld.lld: error: undefined symbol: epp_values >>> referenced by amd-pstate.c:189 (/tmp/makepkg/linux61-vd/src/linux-stable/drivers/cpufreq/amd-pstate.c :189) >>>
vmlinux.o:(store_energy_performance_preference)
---

and a few warnings:

---
drivers/cpufreq/amd-pstate.c:966:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (rc)
            ^~
drivers/cpufreq/amd-pstate.c:1025:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/cpufreq/amd-pstate.c:966:2: note: remove the 'if' if its condition is always false
        if (rc)
        ^~~~~~~
drivers/cpufreq/amd-pstate.c:962:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (!dev)
            ^~~~
drivers/cpufreq/amd-pstate.c:1025:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/cpufreq/amd-pstate.c:962:2: note: remove the 'if' if its condition is always false
        if (!dev)
        ^~~~~~~~~
drivers/cpufreq/amd-pstate.c:949:66: note: initialize the variable 'ret' to silence this warning
        int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq,
ret;

^

 = 0
drivers/cpufreq/amd-pstate.c:996:52: warning: variable 'value' is uninitialized when used here [-Wuninitialized]
        cpudata->epp_cached = amd_pstate_get_epp(cpudata, value); ^~~~~
drivers/cpufreq/amd-pstate.c:953:11: note: initialize the variable 'value' to silence this warning
        u64 value;
                 ^
                  = 0
drivers/cpufreq/amd-pstate.c:1085:6: warning: variable 'epp' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (cpudata->epp_policy == cpudata->policy) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cpufreq/amd-pstate.c:1110:30: note: uninitialized use occurs here
        amd_pstate_set_epp(cpudata, epp);
                                    ^~~
drivers/cpufreq/amd-pstate.c:1085:2: note: remove the 'if' if its condition is always false
        if (cpudata->epp_policy == cpudata->policy) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cpufreq/amd-pstate.c:1064:9: note: initialize the variable 'epp' to silence this warning
        s16 epp;
               ^
                = 0
---

Cheers,

Tor Vic