diff mbox series

[v1,06/11] xen/cpufreq: introduce policy type when cpufreq_driver->setpolicy exists

Message ID 20241203081111.463400-7-Penny.Zheng@amd.com (mailing list archive)
State New
Headers show
Series amd-pstate CPU Performance Scaling Driver | expand

Commit Message

Penny Zheng Dec. 3, 2024, 8:11 a.m. UTC
From: Penny Zheng <penny.zheng@amd.com>

If cpufreq_driver->target exists, the ->governor decides what frequency
within the limits is used. But when cpufreq_driver->setpolicy exists,
the CPUFreq scaling driver bypasses the governor layer and implement
their own performance scaling algorithms. And we introduce the following
two generic policies CPUFREQ_POLICY_POWERSAVE and CPUFREQ_POLICY_PERFORMANCE,
to have 1:1 map with governor info, to still benefit from cpufreq_opt_governor
cmdline.

Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
---
 xen/drivers/cpufreq/utility.c      | 11 +++++++++++
 xen/include/acpi/cpufreq/cpufreq.h | 11 +++++++++++
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c
index e690a484f1..2503ce6243 100644
--- a/xen/drivers/cpufreq/utility.c
+++ b/xen/drivers/cpufreq/utility.c
@@ -484,3 +484,14 @@  int __cpufreq_set_policy(struct cpufreq_policy *data,
 
     return __cpufreq_governor(data, CPUFREQ_GOV_LIMITS);
 }
+
+unsigned int cpufreq_parse_policy(struct cpufreq_governor *gov)
+{
+    if ( !strncasecmp(gov->name, "performance", CPUFREQ_NAME_LEN) )
+        return CPUFREQ_POLICY_PERFORMANCE;
+
+    if ( !strncasecmp(gov->name, "powersave", CPUFREQ_NAME_LEN) )
+        return CPUFREQ_POLICY_POWERSAVE;
+
+    return CPUFREQ_POLICY_UNKNOWN;
+}
diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h
index acf133430b..cad27f6811 100644
--- a/xen/include/acpi/cpufreq/cpufreq.h
+++ b/xen/include/acpi/cpufreq/cpufreq.h
@@ -133,6 +133,17 @@  extern int cpufreq_register_governor(struct cpufreq_governor *governor);
 extern struct cpufreq_governor *__find_governor(const char *governor);
 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_dbs
 
+#define CPUFREQ_POLICY_UNKNOWN      0
+/*
+ * If cpufreq_driver->target() exists, the ->governor decides what frequency
+ * within the limits is used. If cpufreq_driver->setpolicy() exists, these
+ * two generic policies are available:
+ */
+#define CPUFREQ_POLICY_POWERSAVE    1
+#define CPUFREQ_POLICY_PERFORMANCE  2
+
+unsigned int cpufreq_parse_policy(struct cpufreq_governor *gov);
+
 /* pass a target to the cpufreq driver */
 extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
                                    unsigned int target_freq,