diff mbox series

[v2,01/13] cpufreq: Allow restricting to internal governors only

Message ID 20220810192944.102135-2-jandryuk@gmail.com (mailing list archive)
State New, archived
Headers show
Series Intel Hardware P-States (HWP) support | expand

Commit Message

Jason Andryuk Aug. 10, 2022, 7:29 p.m. UTC
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 <jandryuk@gmail.com>
---
v2:
Switch to "-internal"
Add blank line in header
---
 xen/drivers/cpufreq/cpufreq.c      | 5 +++++
 xen/include/acpi/cpufreq/cpufreq.h | 2 ++
 2 files changed, 7 insertions(+)

Comments

Jan Beulich Aug. 15, 2022, 2:22 p.m. UTC | #1
On 10.08.2022 21:29, Jason Andryuk wrote:
> 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.

At which point ...

>  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 <jandryuk@gmail.com>
> ---
> v2:
> Switch to "-internal"
> Add blank line in header
> ---
>  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 a94520ee57..1fdd63d7b5 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;

... I expect this can be __initdata? With that adjustment
Acked-by: Jan Beulich <jbeulich@suse.com>

Jan
Jason Andryuk Aug. 15, 2022, 2:47 p.m. UTC | #2
On Mon, Aug 15, 2022 at 10:22 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 10.08.2022 21:29, Jason Andryuk wrote:
> > 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.
>
> At which point ...
>
> >  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 <jandryuk@gmail.com>
> > ---
> > v2:
> > Switch to "-internal"
> > Add blank line in header
> > ---
> >  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 a94520ee57..1fdd63d7b5 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;
>
> ... I expect this can be __initdata? With that adjustment

Patch 09 "xen: Add SET_CPUFREQ_HWP xen_sysctl_pm_op" uses it at
runtime.  But I think it can be dropped since there is a check of the
governor name.  I'll add __initdata.

> Acked-by: Jan Beulich <jbeulich@suse.com>

Thank you,
Jason
diff mbox series

Patch

diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c
index a94520ee57..1fdd63d7b5 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 35dcf21e8f..0da32ef519 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);