RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-05-20 Thread Penny, Zheng
[Public]

> -Original Message-
> From: Jan Beulich 
> Sent: Tuesday, May 20, 2025 5:16 PM
> To: Penny, Zheng 
> Cc: Huang, Ray ; Andrew Cooper
> ; Anthony PERARD ;
> Orzel, Michal ; Julien Grall ; Roger Pau
> Monné ; Stefano Stabellini ; 
> xen-
> de...@lists.xenproject.org
> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen
> cmdline
>
> On 20.05.2025 10:28, Penny, Zheng wrote:
> > [Public]
> >
> >> -Original Message-
> >> From: Jan Beulich 
> >> Sent: Monday, May 19, 2025 9:19 PM
> >> To: Penny, Zheng 
> >> Cc: Huang, Ray ; Andrew Cooper
> >> ; Anthony PERARD
> >> ; Orzel, Michal ;
> >> Julien Grall ; Roger Pau Monné
> >> ; Stefano Stabellini ;
> >> xen- de...@lists.xenproject.org
> >> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc"
> >> xen cmdline
> >>
> >> On 19.05.2025 10:36, Penny, Zheng wrote:
> >>> [Public]
> >>>
> >>>> -Original Message-
> >>>> From: Jan Beulich 
> >>>> Sent: Tuesday, April 29, 2025 8:52 PM
> >>>> To: Penny, Zheng 
> >>>> Cc: Huang, Ray ; Andrew Cooper
> >>>> ; Anthony PERARD
> >>>> ; Orzel, Michal ;
> >>>> Julien Grall ; Roger Pau Monné
> >>>> ; Stefano Stabellini
> >>>> ;
> >>>> xen- de...@lists.xenproject.org
> >>>> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc"
> >>>> xen cmdline
> >>>>
> >>>> On 14.04.2025 09:40, Penny Zheng wrote:
> >>>>> --- a/xen/include/acpi/cpufreq/processor_perf.h
> >>>>> +++ b/xen/include/acpi/cpufreq/processor_perf.h
> >>>>> @@ -5,6 +5,9 @@
> >>>>>  #include 
> >>>>>  #include 
> >>>>>
> >>>>> +/* ability bits */
> >>>>> +#define XEN_PROCESSOR_PM_CPPC   8
> >>>>
> >>>> This needs correlating (at least via commentary, better by
> >>>> build-time
> >>>> checking) with the other XEN_PROCESSOR_PM_* values. Otherwise
> >> someone
> >>>> adding a new #define in the public header may not (easily) notice a
> >>>> possible conflict. With that in mind I also question whether 8 is
> >>>> actually a good choice: That's the obvious next value to use in the
> >>>> public interface. SIF_PM_MASK is 8 bits wide, so a sensible value
> >>>> to use here
> >> would by e.g. 0x100.
> >>>>
> >>>
> >>> I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in
> >> public header:
> >>>  #define XEN_PROCESSOR_PM_PUBLIC_END
> >> XEN_PROCESSOR_PM_TX
> >>> and will do the following build-time checking:
> >>> BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <=
> >>> XEN_PROCESSOR_PM_PUBLIC_END);
> >>
> >> I don't really see why anything would need to be added to the public
> >> header (and we really should strive to avoid unnecessary additions).
> >
> > If I put such definition
> > "#define XEN_PROCESSOR_PM_PUBLIC_END XEN_PROCESSOR_PM_TX"
> > in internal header, I'm afraid it won't be updated if new ones added in the 
> > public in
> the future.
> > Or any other suggestions to provide build-time checking?
>
> Imo it's sufficient to check that the new #define doesn't overlap with
> SIF_PM_MASK.

Understood!

>
> Jan


Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-05-20 Thread Jan Beulich
On 20.05.2025 10:28, Penny, Zheng wrote:
> [Public]
> 
>> -Original Message-
>> From: Jan Beulich 
>> Sent: Monday, May 19, 2025 9:19 PM
>> To: Penny, Zheng 
>> Cc: Huang, Ray ; Andrew Cooper
>> ; Anthony PERARD ;
>> Orzel, Michal ; Julien Grall ; Roger 
>> Pau
>> Monné ; Stefano Stabellini ; 
>> xen-
>> de...@lists.xenproject.org
>> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen
>> cmdline
>>
>> On 19.05.2025 10:36, Penny, Zheng wrote:
>>> [Public]
>>>
>>>> -Original Message-
>>>> From: Jan Beulich 
>>>> Sent: Tuesday, April 29, 2025 8:52 PM
>>>> To: Penny, Zheng 
>>>> Cc: Huang, Ray ; Andrew Cooper
>>>> ; Anthony PERARD
>>>> ; Orzel, Michal ;
>>>> Julien Grall ; Roger Pau Monné
>>>> ; Stefano Stabellini ;
>>>> xen- de...@lists.xenproject.org
>>>> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc"
>>>> xen cmdline
>>>>
>>>> On 14.04.2025 09:40, Penny Zheng wrote:
>>>>> --- a/xen/include/acpi/cpufreq/processor_perf.h
>>>>> +++ b/xen/include/acpi/cpufreq/processor_perf.h
>>>>> @@ -5,6 +5,9 @@
>>>>>  #include 
>>>>>  #include 
>>>>>
>>>>> +/* ability bits */
>>>>> +#define XEN_PROCESSOR_PM_CPPC   8
>>>>
>>>> This needs correlating (at least via commentary, better by build-time
>>>> checking) with the other XEN_PROCESSOR_PM_* values. Otherwise
>> someone
>>>> adding a new #define in the public header may not (easily) notice a
>>>> possible conflict. With that in mind I also question whether 8 is
>>>> actually a good choice: That's the obvious next value to use in the
>>>> public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use 
>>>> here
>> would by e.g. 0x100.
>>>>
>>>
>>> I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in
>> public header:
>>>  #define XEN_PROCESSOR_PM_PUBLIC_END
>> XEN_PROCESSOR_PM_TX
>>> and will do the following build-time checking:
>>> BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <=
>>> XEN_PROCESSOR_PM_PUBLIC_END);
>>
>> I don't really see why anything would need to be added to the public header 
>> (and we
>> really should strive to avoid unnecessary additions).
> 
> If I put such definition
> "#define XEN_PROCESSOR_PM_PUBLIC_END XEN_PROCESSOR_PM_TX"
> in internal header, I'm afraid it won't be updated if new ones added in the 
> public in the future.
> Or any other suggestions to provide build-time checking?

Imo it's sufficient to check that the new #define doesn't overlap with
SIF_PM_MASK.

Jan



RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-05-20 Thread Penny, Zheng
[Public]

> -Original Message-
> From: Jan Beulich 
> Sent: Monday, May 19, 2025 9:19 PM
> To: Penny, Zheng 
> Cc: Huang, Ray ; Andrew Cooper
> ; Anthony PERARD ;
> Orzel, Michal ; Julien Grall ; Roger Pau
> Monné ; Stefano Stabellini ; 
> xen-
> de...@lists.xenproject.org
> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen
> cmdline
>
> On 19.05.2025 10:36, Penny, Zheng wrote:
> > [Public]
> >
> >> -Original Message-
> >> From: Jan Beulich 
> >> Sent: Tuesday, April 29, 2025 8:52 PM
> >> To: Penny, Zheng 
> >> Cc: Huang, Ray ; Andrew Cooper
> >> ; Anthony PERARD
> >> ; Orzel, Michal ;
> >> Julien Grall ; Roger Pau Monné
> >> ; Stefano Stabellini ;
> >> xen- de...@lists.xenproject.org
> >> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc"
> >> xen cmdline
> >>
> >> On 14.04.2025 09:40, Penny Zheng wrote:
> >>> --- a/xen/include/acpi/cpufreq/processor_perf.h
> >>> +++ b/xen/include/acpi/cpufreq/processor_perf.h
> >>> @@ -5,6 +5,9 @@
> >>>  #include 
> >>>  #include 
> >>>
> >>> +/* ability bits */
> >>> +#define XEN_PROCESSOR_PM_CPPC   8
> >>
> >> This needs correlating (at least via commentary, better by build-time
> >> checking) with the other XEN_PROCESSOR_PM_* values. Otherwise
> someone
> >> adding a new #define in the public header may not (easily) notice a
> >> possible conflict. With that in mind I also question whether 8 is
> >> actually a good choice: That's the obvious next value to use in the
> >> public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use 
> >> here
> would by e.g. 0x100.
> >>
> >
> > I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in
> public header:
> >  #define XEN_PROCESSOR_PM_PUBLIC_END
> XEN_PROCESSOR_PM_TX
> > and will do the following build-time checking:
> > BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <=
> > XEN_PROCESSOR_PM_PUBLIC_END);
>
> I don't really see why anything would need to be added to the public header 
> (and we
> really should strive to avoid unnecessary additions).

If I put such definition
"#define XEN_PROCESSOR_PM_PUBLIC_END XEN_PROCESSOR_PM_TX"
in internal header, I'm afraid it won't be updated if new ones added in the 
public in the future.
Or any other suggestions to provide build-time checking?

>
> Jan


Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-05-19 Thread Jan Beulich
On 19.05.2025 10:36, Penny, Zheng wrote:
> [Public]
> 
>> -Original Message-
>> From: Jan Beulich 
>> Sent: Tuesday, April 29, 2025 8:52 PM
>> To: Penny, Zheng 
>> Cc: Huang, Ray ; Andrew Cooper
>> ; Anthony PERARD ;
>> Orzel, Michal ; Julien Grall ; Roger 
>> Pau
>> Monné ; Stefano Stabellini ; 
>> xen-
>> de...@lists.xenproject.org
>> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen
>> cmdline
>>
>> On 14.04.2025 09:40, Penny Zheng wrote:
>>> --- a/xen/include/acpi/cpufreq/processor_perf.h
>>> +++ b/xen/include/acpi/cpufreq/processor_perf.h
>>> @@ -5,6 +5,9 @@
>>>  #include 
>>>  #include 
>>>
>>> +/* ability bits */
>>> +#define XEN_PROCESSOR_PM_CPPC   8
>>
>> This needs correlating (at least via commentary, better by build-time 
>> checking) with
>> the other XEN_PROCESSOR_PM_* values. Otherwise someone adding a new
>> #define in the public header may not (easily) notice a possible conflict. 
>> With that in
>> mind I also question whether 8 is actually a good choice: That's the obvious 
>> next
>> value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a 
>> sensible
>> value to use here would by e.g. 0x100.
>>
> 
> I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in public 
> header:
>  #define XEN_PROCESSOR_PM_PUBLIC_ENDXEN_PROCESSOR_PM_TX
> and will do the following build-time checking:
> BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <= XEN_PROCESSOR_PM_PUBLIC_END);

I don't really see why anything would need to be added to the public
header (and we really should strive to avoid unnecessary additions).

Jan



RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-05-19 Thread Penny, Zheng
[Public]

> -Original Message-
> From: Jan Beulich 
> Sent: Tuesday, April 29, 2025 8:52 PM
> To: Penny, Zheng 
> Cc: Huang, Ray ; Andrew Cooper
> ; Anthony PERARD ;
> Orzel, Michal ; Julien Grall ; Roger Pau
> Monné ; Stefano Stabellini ; 
> xen-
> de...@lists.xenproject.org
> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen
> cmdline
>
> On 14.04.2025 09:40, Penny Zheng wrote:
> > --- a/xen/include/acpi/cpufreq/processor_perf.h
> > +++ b/xen/include/acpi/cpufreq/processor_perf.h
> > @@ -5,6 +5,9 @@
> >  #include 
> >  #include 
> >
> > +/* ability bits */
> > +#define XEN_PROCESSOR_PM_CPPC   8
>
> This needs correlating (at least via commentary, better by build-time 
> checking) with
> the other XEN_PROCESSOR_PM_* values. Otherwise someone adding a new
> #define in the public header may not (easily) notice a possible conflict. 
> With that in
> mind I also question whether 8 is actually a good choice: That's the obvious 
> next
> value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a 
> sensible
> value to use here would by e.g. 0x100.
>

I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in public header:
 #define XEN_PROCESSOR_PM_PUBLIC_ENDXEN_PROCESSOR_PM_TX
and will do the following build-time checking:
BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <= XEN_PROCESSOR_PM_PUBLIC_END);

> Jan


Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-05-12 Thread Jan Beulich
On 07.05.2025 07:27, Penny, Zheng wrote:
>> -Original Message-
>> From: Jan Beulich 
>> Sent: Tuesday, April 29, 2025 8:52 PM
>>
>> On 14.04.2025 09:40, Penny Zheng wrote:
>>> @@ -573,6 +576,14 @@ ret_t do_platform_op(
>>>  }
>>>
>>>  case XEN_PM_CPPC:
>>> +if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) )
>>> +{
>>> +ret = -EOPNOTSUPP;
>>> +break;
>>> +}
>>
>> While at least you no longer use -ENOSYS here, I question this behavior, 
>> including
>> that for the pre-existing cases: How is the caller supposed to know whether 
>> to
>> invoke this sub-op? Ignoring errors is generally not a good idea, so it 
>> would be
>> better if the caller could blindly issue this request, getting back success 
>> unless
>> there really was an issue with the data provided.
>>
> 
> Understood.
> I will change it to ret = 0. Do you think we shall add warning info here?

No, for precisely ...

> Dom0 will send the CPPC data whenever it could.

... this reason.

Jan

> XEN_PROCESSOR_PM_CPPC
> is not set could largely be users choosing not to. In such case, silently 
> getting back success
> shall be enough.
> 
> 
>> Jan




RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-05-06 Thread Penny, Zheng
[Public]

Hi,

> -Original Message-
> From: Jan Beulich 
> Sent: Tuesday, April 29, 2025 8:52 PM
> To: Penny, Zheng 
> Cc: Huang, Ray ; Andrew Cooper
> ; Anthony PERARD ;
> Orzel, Michal ; Julien Grall ; Roger
> Pau Monné ; Stefano Stabellini ;
> xen-devel@lists.xenproject.org
> Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen
> cmdline
>
> On 14.04.2025 09:40, Penny Zheng wrote:
> > @@ -514,5 +515,16 @@ acpi_cpufreq_driver = {
> >
> >  int __init acpi_cpufreq_register(void)  {
> > -return cpufreq_register_driver(&acpi_cpufreq_driver);
> > +int ret;
> > +
> > +ret = cpufreq_register_driver(&acpi_cpufreq_driver);
> > +if ( ret )
> > +return ret;
> > +/*
> > + * After cpufreq driver registeration, XEN_PROCESSOR_PM_CPPC
> > + * and XEN_PROCESSOR_PM_PX shall become exclusive flags
> > + */
> > +xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
> > +
> > +return ret;
> >  }
>
> Why is no similar adjustment needed in powernow_register_driver()? In 
> principle I
> would have expected that it's not each individual driver which needs to care 
> about
> this aspect, but that the framework is taking care of this.
>

Then maybe we shall add this here, to extract the codes from each specific 
driver:
```
diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c 
b/xen/arch/x86/acpi/cpufreq/cpufreq.c
index eac1c125a3..9276241291 100644
--- a/xen/arch/x86/acpi/cpufreq/cpufreq.c
+++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c
@@ -190,6 +190,25 @@ static int __init cf_check cpufreq_driver_init(void)
 if ( ret != -ENODEV )
 break;
 }
+
+if ( !ret && i < cpufreq_xen_cnt )
+{
+switch ( cpufreq_xen_opts[i] )
+{
+case CPUFREQ_amd_cppc:
+xen_processor_pmbits &= ~XEN_PROCESSOR_PM_XEN;
+break;
+
+case CPUFREQ_xen:
+xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
+break;
+
+case CPUFREQ_none:
+default:
+break;
+}
+}
+
 break;
 }
 }
```

> > @@ -573,6 +576,14 @@ ret_t do_platform_op(
> >  }
> >
> >  case XEN_PM_CPPC:
> > +if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) )
> > +{
> > +ret = -EOPNOTSUPP;
> > +break;
> > +}
>
> While at least you no longer use -ENOSYS here, I question this behavior, 
> including
> that for the pre-existing cases: How is the caller supposed to know whether to
> invoke this sub-op? Ignoring errors is generally not a good idea, so it would 
> be
> better if the caller could blindly issue this request, getting back success 
> unless
> there really was an issue with the data provided.
>

Understood.
I will change it to ret = 0. Do you think we shall add warning info here?
Dom0 will send the CPPC data whenever it could. XEN_PROCESSOR_PM_CPPC
is not set could largely be users choosing not to. In such case, silently 
getting back success
shall be enough.


> Jan


Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

2025-04-29 Thread Jan Beulich
On 14.04.2025 09:40, Penny Zheng wrote:
> @@ -514,5 +515,16 @@ acpi_cpufreq_driver = {
>  
>  int __init acpi_cpufreq_register(void)
>  {
> -return cpufreq_register_driver(&acpi_cpufreq_driver);
> +int ret;
> +
> +ret = cpufreq_register_driver(&acpi_cpufreq_driver);
> +if ( ret )
> +return ret;
> +/*
> + * After cpufreq driver registeration, XEN_PROCESSOR_PM_CPPC
> + * and XEN_PROCESSOR_PM_PX shall become exclusive flags
> + */
> +xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
> +
> +return ret;
>  }

Why is no similar adjustment needed in powernow_register_driver()? In principle
I would have expected that it's not each individual driver which needs to care
about this aspect, but that the framework is taking care of this.

> --- /dev/null
> +++ b/xen/arch/x86/acpi/cpufreq/amd-cppc.c
> @@ -0,0 +1,81 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * amd-cppc.c - AMD Processor CPPC Frequency Driver
> + *
> + * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved.
> + *
> + * Author: Penny Zheng 
> + *
> + * AMD CPPC cpufreq driver introduces a new CPU performance scaling design
> + * for AMD processors using the ACPI Collaborative Performance and Power
> + * Control (CPPC) feature which provides finer grained frequency control 
> range.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static bool __init amd_cppc_handle_option(const char *s, const char *end)
> +{
> +int ret;
> +
> +ret = parse_boolean("verbose", s, end);
> +if ( ret >= 0 )
> +{
> +cpufreq_verbose = ret;
> +return true;
> +}
> +
> +return false;
> +}
> +
> +int __init amd_cppc_cmdline_parse(const char *s, const char *e)
> +{
> +do
> +{

Nit (style): Brace placement is special here, just like it is ...

> +const char *end = strpbrk(s, ",;");
> +
> +if ( !amd_cppc_handle_option(s, end) )
> +{
> +printk(XENLOG_WARNING
> +   "cpufreq/amd-cppc: option '%.*s' not recognized\n",
> +   (int)((end ?: e) - s), s);
> +
> +return -EINVAL;
> +}
> +
> +s = end ? end + 1 : NULL;
> +} while ( s && s < e );

... here.

> --- a/xen/arch/x86/platform_hypercall.c
> +++ b/xen/arch/x86/platform_hypercall.c
> @@ -542,6 +542,9 @@ ret_t do_platform_op(
>  ret = -ENOSYS;
>  break;
>  }
> +/* Xen doesn't support mixed mode */
> +ASSERT((xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) == 0);

Please prefer ! over "== 0" in such purely boolean contexts.

> @@ -573,6 +576,14 @@ ret_t do_platform_op(
>  }
>  
>  case XEN_PM_CPPC:
> +if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) )
> +{
> +ret = -EOPNOTSUPP;
> +break;
> +}

While at least you no longer use -ENOSYS here, I question this behavior,
including that for the pre-existing cases: How is the caller supposed to know
whether to invoke this sub-op? Ignoring errors is generally not a good idea,
so it would be better if the caller could blindly issue this request, getting
back success unless there really was an issue with the data provided.

> @@ -102,6 +103,9 @@ static int __init handle_cpufreq_cmdline(enum 
> cpufreq_xen_opt option)
>  cpufreq_xen_opts[cpufreq_xen_cnt++] = option;
>  switch ( option )
>  {
> +case CPUFREQ_amd_cppc:
> +xen_processor_pmbits |= XEN_PROCESSOR_PM_CPPC;
> +break;
>  case CPUFREQ_hwp:
>  case CPUFREQ_xen:
>  xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;

Here and (about) everywhere else: Blank line please between non-fall-through
case blocks. I guess I'm not going to repeat this any further. There are
very tiny switch() statements where it is okay to violate this principle, but
as a rule of thumb - if in doubt, put a blank line there.

> --- a/xen/include/acpi/cpufreq/processor_perf.h
> +++ b/xen/include/acpi/cpufreq/processor_perf.h
> @@ -5,6 +5,9 @@
>  #include 
>  #include 
>  
> +/* ability bits */
> +#define XEN_PROCESSOR_PM_CPPC   8

This needs correlating (at least via commentary, better by build-time checking)
with the other XEN_PROCESSOR_PM_* values. Otherwise someone adding a new #define
in the public header may not (easily) notice a possible conflict. With that in
mind I also question whether 8 is actually a good choice: That's the obvious
next value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a
sensible value to use here would by e.g. 0x100.

Jan