Message ID | 49204c6d4a334c0bfbc589dda79b5cd7c4c28b7c.1715152592.git.perry.yuan@amd.com |
---|---|
State | Superseded |
Headers | show |
Series | AMD Pstate Driver Core Performance Boost | expand |
On středa 8. května 2024 11:34:21, SELČ Oleksandr Natalenko wrote: > Hello. > > On středa 8. května 2024 9:21:11, SELČ Perry Yuan wrote: > > Add a new sysfs attribute file to support per CPU frequency boost > > control, allowing individual CPUs to enable or disable CPB separately. > > > > The new sysfs attribute file is located at below path, > > `/sys/devices/system/cpu/cpuX/cpufreq/boost`, > > where `X` represents the CPU number. > > > > To disable CPB for a specific CPU, you can use the following command: > > $ sudo bash -c "echo 0 > /sys/devices/system/cpu/cpuX/cpufreq/boost" > > > > After disabling CPB, the CPU frequency will no longer boost beyond > > the base frequency for that particular CPU. > > > > for example: > > ---------------------------------------------------------------------- > > CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ MHZ > > 0 0 0 0 0:0:0:0 yes 4208.0000 400.0000 1666.7740 > > 1 0 0 0 0:0:0:0 yes 4208.0000 400.0000 400.0000 > > > > ---------------------------------------------------------------------- > > $ sudo bash -c "echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/boost" > > > > CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ MHZ > > 0 0 0 0 0:0:0:0 yes 3501.0000 400.0000 4154.3140 > > 1 0 0 0 0:0:0:0 yes 4208.0000 400.0000 400.0000 > > > > Please be aware that modifying the global variable > > `amd_pstate_global_params.cpb_boost` will overwrite the individual CPU settings. > > > > Signed-off-by: Perry Yuan <perry.yuan@amd.com> > > --- > > drivers/cpufreq/amd-pstate.c | 27 +++++++++++++++++++++++++++ > > 1 file changed, 27 insertions(+) > > > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > > index 11bce2c1db32..cb0055e7c842 100644 > > --- a/drivers/cpufreq/amd-pstate.c > > +++ b/drivers/cpufreq/amd-pstate.c > > @@ -1371,6 +1371,30 @@ static int amd_pstate_cpu_boost(int cpu, bool state) > > return ret < 0 ? ret : 0; > > } > > > > +static ssize_t show_boost(struct cpufreq_policy *policy, char *buf) > > +{ > > + struct amd_cpudata *cpudata = policy->driver_data; > > + bool boost_val; > > + > > + boost_val = READ_ONCE(cpudata->boost_state); > > + > > + return sysfs_emit(buf, "%u\n", boost_val); > > +} > > + > > +static ssize_t store_boost( > > + struct cpufreq_policy *policy, const char *buf, size_t count) > > +{ > > + bool boost_val; > > + int ret; > > + > > + if (sscanf(buf, "%d", &boost_val) != 1) > > This will generate warning. IIUC, sscanf() doesn't work with booleans directly, so you'd probably want to read the value into an (unsigned) integer, and then cast it to bool. …or maybe just use kstrtobool()? > > > + return -EINVAL; > > + > > + ret = amd_pstate_cpu_boost(policy->cpu, boost_val); > > + > > + return ret < 0 ? ret : count; > > +} > > + > > static ssize_t cpb_boost_show(struct device *dev, > > struct device_attribute *attr, char *buf) > > { > > @@ -1416,6 +1440,7 @@ cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking); > > cpufreq_freq_attr_ro(amd_pstate_hw_prefcore); > > cpufreq_freq_attr_rw(energy_performance_preference); > > cpufreq_freq_attr_ro(energy_performance_available_preferences); > > +cpufreq_freq_attr_rw(boost); > > static DEVICE_ATTR_RW(status); > > static DEVICE_ATTR_RO(prefcore); > > static DEVICE_ATTR_RW(cpb_boost); > > @@ -1426,6 +1451,7 @@ static struct freq_attr *amd_pstate_attr[] = { > > &amd_pstate_highest_perf, > > &amd_pstate_prefcore_ranking, > > &amd_pstate_hw_prefcore, > > + &boost, > > NULL, > > }; > > > > @@ -1437,6 +1463,7 @@ static struct freq_attr *amd_pstate_epp_attr[] = { > > &amd_pstate_hw_prefcore, > > &energy_performance_preference, > > &energy_performance_available_preferences, > > + &boost, > > NULL, > > }; > > > > > > >
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 11bce2c1db32..cb0055e7c842 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1371,6 +1371,30 @@ static int amd_pstate_cpu_boost(int cpu, bool state) return ret < 0 ? ret : 0; } +static ssize_t show_boost(struct cpufreq_policy *policy, char *buf) +{ + struct amd_cpudata *cpudata = policy->driver_data; + bool boost_val; + + boost_val = READ_ONCE(cpudata->boost_state); + + return sysfs_emit(buf, "%u\n", boost_val); +} + +static ssize_t store_boost( + struct cpufreq_policy *policy, const char *buf, size_t count) +{ + bool boost_val; + int ret; + + if (sscanf(buf, "%d", &boost_val) != 1) + return -EINVAL; + + ret = amd_pstate_cpu_boost(policy->cpu, boost_val); + + return ret < 0 ? ret : count; +} + static ssize_t cpb_boost_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1416,6 +1440,7 @@ cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking); cpufreq_freq_attr_ro(amd_pstate_hw_prefcore); cpufreq_freq_attr_rw(energy_performance_preference); cpufreq_freq_attr_ro(energy_performance_available_preferences); +cpufreq_freq_attr_rw(boost); static DEVICE_ATTR_RW(status); static DEVICE_ATTR_RO(prefcore); static DEVICE_ATTR_RW(cpb_boost); @@ -1426,6 +1451,7 @@ static struct freq_attr *amd_pstate_attr[] = { &amd_pstate_highest_perf, &amd_pstate_prefcore_ranking, &amd_pstate_hw_prefcore, + &boost, NULL, }; @@ -1437,6 +1463,7 @@ static struct freq_attr *amd_pstate_epp_attr[] = { &amd_pstate_hw_prefcore, &energy_performance_preference, &energy_performance_available_preferences, + &boost, NULL, };
Add a new sysfs attribute file to support per CPU frequency boost control, allowing individual CPUs to enable or disable CPB separately. The new sysfs attribute file is located at below path, `/sys/devices/system/cpu/cpuX/cpufreq/boost`, where `X` represents the CPU number. To disable CPB for a specific CPU, you can use the following command: $ sudo bash -c "echo 0 > /sys/devices/system/cpu/cpuX/cpufreq/boost" After disabling CPB, the CPU frequency will no longer boost beyond the base frequency for that particular CPU. for example: ---------------------------------------------------------------------- CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ MHZ 0 0 0 0 0:0:0:0 yes 4208.0000 400.0000 1666.7740 1 0 0 0 0:0:0:0 yes 4208.0000 400.0000 400.0000 ---------------------------------------------------------------------- $ sudo bash -c "echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/boost" CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ MHZ 0 0 0 0 0:0:0:0 yes 3501.0000 400.0000 4154.3140 1 0 0 0 0:0:0:0 yes 4208.0000 400.0000 400.0000 Please be aware that modifying the global variable `amd_pstate_global_params.cpb_boost` will overwrite the individual CPU settings. Signed-off-by: Perry Yuan <perry.yuan@amd.com> --- drivers/cpufreq/amd-pstate.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)