Skip to content

Commit 6937e87

Browse files
committed
Merge branch 'pm-cpufreq' into linux-next
* pm-cpufreq: cpufreq: CPPC: Add support for autonomous selection cpufreq: Update sscanf() to kstrtouint() cpufreq: Replace magic number
2 parents e8ea543 + 922607a commit 6937e87

3 files changed

Lines changed: 167 additions & 4 deletions

File tree

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,60 @@ Description: Discover CPUs in the same CPU frequency coordination domain
273273
This file is only present if the acpi-cpufreq or the cppc-cpufreq
274274
drivers are in use.
275275

276+
What: /sys/devices/system/cpu/cpuX/cpufreq/auto_select
277+
Date: May 2025
278+
Contact: linux-pm@vger.kernel.org
279+
Description: Autonomous selection enable
280+
281+
Read/write interface to control autonomous selection enable
282+
Read returns autonomous selection status:
283+
0: autonomous selection is disabled
284+
1: autonomous selection is enabled
285+
286+
Write 'y' or '1' or 'on' to enable autonomous selection.
287+
Write 'n' or '0' or 'off' to disable autonomous selection.
288+
289+
This file is only present if the cppc-cpufreq driver is in use.
290+
291+
What: /sys/devices/system/cpu/cpuX/cpufreq/auto_act_window
292+
Date: May 2025
293+
Contact: linux-pm@vger.kernel.org
294+
Description: Autonomous activity window
295+
296+
This file indicates a moving utilization sensitivity window to
297+
the platform's autonomous selection policy.
298+
299+
Read/write an integer represents autonomous activity window (in
300+
microseconds) from/to this file. The max value to write is
301+
1270000000 but the max significand is 127. This means that if 128
302+
is written to this file, 127 will be stored. If the value is
303+
greater than 130, only the first two digits will be saved as
304+
significand.
305+
306+
Writing a zero value to this file enable the platform to
307+
determine an appropriate Activity Window depending on the workload.
308+
309+
Writing to this file only has meaning when Autonomous Selection is
310+
enabled.
311+
312+
This file is only present if the cppc-cpufreq driver is in use.
313+
314+
What: /sys/devices/system/cpu/cpuX/cpufreq/energy_performance_preference_val
315+
Date: May 2025
316+
Contact: linux-pm@vger.kernel.org
317+
Description: Energy performance preference
318+
319+
Read/write an 8-bit integer from/to this file. This file
320+
represents a range of values from 0 (performance preference) to
321+
0xFF (energy efficiency preference) that influences the rate of
322+
performance increase/decrease and the result of the hardware's
323+
energy efficiency and performance optimization policies.
324+
325+
Writing to this file only has meaning when Autonomous Selection is
326+
enabled.
327+
328+
This file is only present if the cppc-cpufreq driver is in use.
329+
276330

277331
What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1}
278332
Date: August 2008

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,119 @@ static ssize_t show_freqdomain_cpus(struct cpufreq_policy *policy, char *buf)
808808

809809
return cpufreq_show_cpus(cpu_data->shared_cpu_map, buf);
810810
}
811+
812+
static ssize_t show_auto_select(struct cpufreq_policy *policy, char *buf)
813+
{
814+
bool val;
815+
int ret;
816+
817+
ret = cppc_get_auto_sel(policy->cpu, &val);
818+
819+
/* show "<unsupported>" when this register is not supported by cpc */
820+
if (ret == -EOPNOTSUPP)
821+
return sysfs_emit(buf, "<unsupported>\n");
822+
823+
if (ret)
824+
return ret;
825+
826+
return sysfs_emit(buf, "%d\n", val);
827+
}
828+
829+
static ssize_t store_auto_select(struct cpufreq_policy *policy,
830+
const char *buf, size_t count)
831+
{
832+
bool val;
833+
int ret;
834+
835+
ret = kstrtobool(buf, &val);
836+
if (ret)
837+
return ret;
838+
839+
ret = cppc_set_auto_sel(policy->cpu, val);
840+
if (ret)
841+
return ret;
842+
843+
return count;
844+
}
845+
846+
static ssize_t show_auto_act_window(struct cpufreq_policy *policy, char *buf)
847+
{
848+
u64 val;
849+
int ret;
850+
851+
ret = cppc_get_auto_act_window(policy->cpu, &val);
852+
853+
/* show "<unsupported>" when this register is not supported by cpc */
854+
if (ret == -EOPNOTSUPP)
855+
return sysfs_emit(buf, "<unsupported>\n");
856+
857+
if (ret)
858+
return ret;
859+
860+
return sysfs_emit(buf, "%llu\n", val);
861+
}
862+
863+
static ssize_t store_auto_act_window(struct cpufreq_policy *policy,
864+
const char *buf, size_t count)
865+
{
866+
u64 usec;
867+
int ret;
868+
869+
ret = kstrtou64(buf, 0, &usec);
870+
if (ret)
871+
return ret;
872+
873+
ret = cppc_set_auto_act_window(policy->cpu, usec);
874+
if (ret)
875+
return ret;
876+
877+
return count;
878+
}
879+
880+
static ssize_t show_energy_performance_preference_val(struct cpufreq_policy *policy, char *buf)
881+
{
882+
u64 val;
883+
int ret;
884+
885+
ret = cppc_get_epp_perf(policy->cpu, &val);
886+
887+
/* show "<unsupported>" when this register is not supported by cpc */
888+
if (ret == -EOPNOTSUPP)
889+
return sysfs_emit(buf, "<unsupported>\n");
890+
891+
if (ret)
892+
return ret;
893+
894+
return sysfs_emit(buf, "%llu\n", val);
895+
}
896+
897+
static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *policy,
898+
const char *buf, size_t count)
899+
{
900+
u64 val;
901+
int ret;
902+
903+
ret = kstrtou64(buf, 0, &val);
904+
if (ret)
905+
return ret;
906+
907+
ret = cppc_set_epp(policy->cpu, val);
908+
if (ret)
909+
return ret;
910+
911+
return count;
912+
}
913+
811914
cpufreq_freq_attr_ro(freqdomain_cpus);
915+
cpufreq_freq_attr_rw(auto_select);
916+
cpufreq_freq_attr_rw(auto_act_window);
917+
cpufreq_freq_attr_rw(energy_performance_preference_val);
812918

813919
static struct freq_attr *cppc_cpufreq_attr[] = {
814920
&freqdomain_cpus,
921+
&auto_select,
922+
&auto_act_window,
923+
&energy_performance_preference_val,
815924
NULL,
816925
};
817926

drivers/cpufreq/cpufreq.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
806806
static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
807807
const char *buf, size_t count)
808808
{
809-
char str_governor[16];
809+
char str_governor[CPUFREQ_NAME_LEN];
810810
int ret;
811811

812812
ret = sscanf(buf, "%15s", str_governor);
@@ -917,9 +917,9 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
917917
if (!policy->governor || !policy->governor->store_setspeed)
918918
return -EINVAL;
919919

920-
ret = sscanf(buf, "%u", &freq);
921-
if (ret != 1)
922-
return -EINVAL;
920+
ret = kstrtouint(buf, 0, &freq);
921+
if (ret)
922+
return ret;
923923

924924
policy->governor->store_setspeed(policy, freq);
925925

0 commit comments

Comments
 (0)