Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include support for Intel HWP #158

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions 0631-cpufreq-Allow-restricting-to-internal-governors-only.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From c0a69ba8e4210bf42cc545afd02ad7fe1135fe96 Mon Sep 17 00:00:00 2001
From: Jason Andryuk <[email protected]>
Date: Wed, 10 Aug 2022 15:29:32 -0400
Subject: [PATCH 01/13] cpufreq: Allow restricting to internal governors only

For hwp, the standard governors are not usable, and only the internal
one is applicable. Add the cpufreq_governor_internal boolean to
indicate when an internal governor, like hwp-internal, will be used.
This is set during presmp_initcall, so that it can suppress governor
registration during initcall. Only a governor with a name containing
"-internal" will be allowed in that case.

This way, the unuseable governors are not registered, so they internal
one is the only one returned to userspace. This means incompatible
governors won't be advertised to userspace.

Signed-off-by: Jason Andryuk <[email protected]>
Acked-by: Jan Beulich <[email protected]>
---
xen/drivers/cpufreq/cpufreq.c | 5 +++++
xen/include/acpi/cpufreq/cpufreq.h | 2 ++
2 files changed, 7 insertions(+)

diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c
index a94520ee57ac..1fdd63d7b564 100644
--- a/xen/drivers/cpufreq/cpufreq.c
+++ b/xen/drivers/cpufreq/cpufreq.c
@@ -57,6 +57,7 @@ struct cpufreq_dom {
};
static LIST_HEAD_READ_MOSTLY(cpufreq_dom_list_head);

+bool __read_mostly cpufreq_governor_internal;
struct cpufreq_governor *__read_mostly cpufreq_opt_governor;
LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);

@@ -122,6 +123,10 @@ int __init cpufreq_register_governor(struct cpufreq_governor *governor)
if (!governor)
return -EINVAL;

+ if (cpufreq_governor_internal &&
+ strstr(governor->name, "-internal") == NULL)
+ return -EINVAL;
+
if (__find_governor(governor->name) != NULL)
return -EEXIST;

diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h
index 35dcf21e8f0c..0da32ef51903 100644
--- a/xen/include/acpi/cpufreq/cpufreq.h
+++ b/xen/include/acpi/cpufreq/cpufreq.h
@@ -114,6 +114,8 @@ extern struct cpufreq_governor cpufreq_gov_userspace;
extern struct cpufreq_governor cpufreq_gov_performance;
extern struct cpufreq_governor cpufreq_gov_powersave;

+extern bool cpufreq_governor_internal;
+
extern struct list_head cpufreq_governor_list;

extern int cpufreq_register_governor(struct cpufreq_governor *governor);
--
2.37.3

61 changes: 61 additions & 0 deletions 0632-cpufreq-Add-perf_freq-to-cpuinfo.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From fed49894b171851eefce5a91900217a57cac396e Mon Sep 17 00:00:00 2001
From: Jason Andryuk <[email protected]>
Date: Wed, 10 Aug 2022 15:29:33 -0400
Subject: [PATCH 02/13] cpufreq: Add perf_freq to cpuinfo

acpi-cpufreq scales the aperf/mperf measurements by max_freq, but HWP
needs to scale by base frequency. Settings max_freq to base_freq
"works" but the code is not obvious, and returning values to userspace
is tricky. Add an additonal perf_freq member which is used for scaling
aperf/mperf measurements.

Signed-off-by: Jason Andryuk <[email protected]>
Acked-by: Jan Beulich <[email protected]>
---
xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +-
xen/drivers/cpufreq/utility.c | 1 +
xen/include/acpi/cpufreq/cpufreq.h | 3 +++
3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c
index c27cbb2304f2..ded0150b3b00 100644
--- a/xen/arch/x86/acpi/cpufreq/cpufreq.c
+++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c
@@ -317,7 +317,7 @@ unsigned int get_measured_perf(unsigned int cpu, unsigned int flag)
else
perf_percent = 0;

- return policy->cpuinfo.max_freq * perf_percent / 100;
+ return policy->cpuinfo.perf_freq * perf_percent / 100;
}

static unsigned int cf_check get_cur_freq_on_cpu(unsigned int cpu)
diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c
index 9eb7ecedcd29..6831f62851cd 100644
--- a/xen/drivers/cpufreq/utility.c
+++ b/xen/drivers/cpufreq/utility.c
@@ -236,6 +236,7 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,

policy->min = policy->cpuinfo.min_freq = min_freq;
policy->max = policy->cpuinfo.max_freq = max_freq;
+ policy->cpuinfo.perf_freq = max_freq;
policy->cpuinfo.second_max_freq = second_max_freq;

if (policy->min == ~0)
diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h
index 0da32ef51903..a06aa92f6209 100644
--- a/xen/include/acpi/cpufreq/cpufreq.h
+++ b/xen/include/acpi/cpufreq/cpufreq.h
@@ -37,6 +37,9 @@ extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS];
struct cpufreq_cpuinfo {
unsigned int max_freq;
unsigned int second_max_freq; /* P1 if Turbo Mode is on */
+ unsigned int perf_freq; /* Scaling freq for aperf/mpref.
+ acpi-cpufreq uses max_freq, but HWP uses
+ base_freq.*/
unsigned int min_freq;
unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
};
--
2.37.3

55 changes: 55 additions & 0 deletions 0633-cpufreq-Export-intel_feature_detect.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
From 6b5101014c6e4ee32d13993e0d3d19857817c228 Mon Sep 17 00:00:00 2001
From: Jason Andryuk <[email protected]>
Date: Wed, 10 Aug 2022 15:29:34 -0400
Subject: [PATCH 03/13] cpufreq: Export intel_feature_detect

Export feature_detect as intel_feature_detect so it can be re-used by
HWP.

Signed-off-by: Jason Andryuk <[email protected]>
---
xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 ++++++--
xen/include/acpi/cpufreq/cpufreq.h | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c
index ded0150b3b00..b5eb869227a7 100644
--- a/xen/arch/x86/acpi/cpufreq/cpufreq.c
+++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c
@@ -340,9 +340,8 @@ static unsigned int cf_check get_cur_freq_on_cpu(unsigned int cpu)
return extract_freq(get_cur_val(cpumask_of(cpu)), data);
}

-static void cf_check feature_detect(void *info)
+void intel_feature_detect(struct cpufreq_policy *policy)
{
- struct cpufreq_policy *policy = info;
unsigned int eax;

eax = cpuid_eax(6);
@@ -354,6 +353,11 @@ static void cf_check feature_detect(void *info)
}
}

+static void cf_check feature_detect(void *info)
+{
+ intel_feature_detect((struct cpufreq_policy *)info);
+}
+
static unsigned int check_freqs(const cpumask_t *mask, unsigned int freq,
struct acpi_cpufreq_data *data)
{
diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h
index a06aa92f6209..0f334d2a432b 100644
--- a/xen/include/acpi/cpufreq/cpufreq.h
+++ b/xen/include/acpi/cpufreq/cpufreq.h
@@ -243,4 +243,6 @@ int write_userspace_scaling_setspeed(unsigned int cpu, unsigned int freq);
void cpufreq_dbs_timer_suspend(void);
void cpufreq_dbs_timer_resume(void);

+void intel_feature_detect(struct cpufreq_policy *policy);
+
#endif /* __XEN_CPUFREQ_PM_H__ */
--
2.37.3

Loading