Skip to content

Commit 922607a

Browse files
Lifeng Zhengrafaeljw
authored andcommitted
cpufreq: CPPC: Add support for autonomous selection
Add sysfs interfaces for CPPC autonomous selection in the cppc_cpufreq driver. Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com> Reviewed-by: Sumit Gupta <sumitg@nvidia.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://patch.msgid.link/20250507031941.2812701-1-zhenglifeng1@huawei.com [ rjw: Subject edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 1da98dc commit 922607a

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

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

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

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

272326
What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1}
273327
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

0 commit comments

Comments
 (0)