2022-12-19 07:10:26

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()

There are some other amd pstate driver working mode to be supported.
Here we use cppc_state var to indicate which mode is enabled.
This change will help to simplify the the amd_pstate_param() to choose
which mode used for the following driver registeration.

Signed-off-by: Perry Yuan <[email protected]>
Signed-off-by: Wyes Karny <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 35 +++++++++++++++++++++++++++--------
include/linux/amd-pstate.h | 29 +++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index c17bd845f5fc..861a905f9324 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -60,7 +60,18 @@
* module parameter to be able to enable it manually for debugging.
*/
static struct cpufreq_driver amd_pstate_driver;
-static int cppc_load __initdata;
+static int cppc_state = AMD_PSTATE_DISABLE;
+
+static inline int get_mode_idx_from_str(const char *str, size_t size)
+{
+ int i;
+
+ for (i=0; i < AMD_PSTATE_MAX; i++) {
+ if (!strncmp(str, amd_pstate_mode_string[i], size))
+ return i;
+ }
+ return -EINVAL;
+}

static inline int pstate_enable(bool enable)
{
@@ -628,7 +639,7 @@ static int __init amd_pstate_init(void)
* enable the amd_pstate passive mode driver explicitly
* with amd_pstate=passive in kernel command line
*/
- if (!cppc_load) {
+ if (cppc_state == AMD_PSTATE_DISABLE) {
pr_debug("driver load is disabled, boot with amd_pstate=passive to enable this\n");
return -ENODEV;
}
@@ -671,16 +682,24 @@ device_initcall(amd_pstate_init);

static int __init amd_pstate_param(char *str)
{
+ size_t size;
+ int mode_idx;
+
if (!str)
return -EINVAL;

- if (!strcmp(str, "disable")) {
- cppc_load = 0;
- pr_info("driver is explicitly disabled\n");
- } else if (!strcmp(str, "passive"))
- cppc_load = 1;
+ size = strlen(str);
+ mode_idx = get_mode_idx_from_str(str, size);

- return 0;
+ if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
+ cppc_state = mode_idx;
+ if (cppc_state == AMD_PSTATE_DISABLE)
+ pr_info("driver is explicitly disabled\n");
+
+ return 0;
+ }
+
+ return -EINVAL;
}
early_param("amd_pstate", amd_pstate_param);

diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
index 1c4b8659f171..922d05a13902 100644
--- a/include/linux/amd-pstate.h
+++ b/include/linux/amd-pstate.h
@@ -74,4 +74,33 @@ struct amd_cpudata {
bool boost_supported;
};

+/**
+ * enum amd_pstate_mode - driver working mode of amd pstate
+ */
+
+enum amd_pstate_mode {
+ /** @AMD_PSTATE_DISABLE: Driver mode is disabled */
+ AMD_PSTATE_DISABLE = 0,
+
+ /** @AMD_PSTATE_PASSIVE: Drier mode is passive mode */
+ AMD_PSTATE_PASSIVE = 1,
+
+ /** @AMD_PSTATE_ACTIVE: Driver mode is active mode */
+ AMD_PSTATE_ACTIVE = 2,
+
+ /** @AMD_PSTATE_GUIDE: Driver mode is guided mode */
+ AMD_PSTATE_GUIDE = 3,
+
+ /** @AMD_PSTATE_MAX */
+ AMD_PSTATE_MAX = 4,
+};
+
+static const char * const amd_pstate_mode_string[] = {
+ [AMD_PSTATE_DISABLE] = "disable",
+ [AMD_PSTATE_PASSIVE] = "passive",
+ [AMD_PSTATE_ACTIVE] = "active",
+ [AMD_PSTATE_GUIDE] = "guide",
+ NULL,
+};
+
#endif /* _LINUX_AMD_PSTATE_H */
--
2.34.1


2022-12-19 11:44:07

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()

Hi Perry,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linus/master v6.1 next-20221219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Perry-Yuan/Implement-AMD-Pstate-EPP-Driver/20221219-144514
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20221219064042.661122-6-perry.yuan%40amd.com
patch subject: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()
config: x86_64-randconfig-a002-20221219
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/ca2aa3065157d1fc7ec6aec4c463143c99cb5325
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Perry-Yuan/Implement-AMD-Pstate-EPP-Driver/20221219-144514
git checkout ca2aa3065157d1fc7ec6aec4c463143c99cb5325
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/cpufreq/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

In file included from drivers/cpufreq/amd-pstate-ut.c:29:
>> include/linux/amd-pstate.h:98:27: warning: 'amd_pstate_mode_string' defined but not used [-Wunused-const-variable=]
98 | static const char * const amd_pstate_mode_string[] = {
| ^~~~~~~~~~~~~~~~~~~~~~


vim +/amd_pstate_mode_string +98 include/linux/amd-pstate.h

97
> 98 static const char * const amd_pstate_mode_string[] = {
99 [AMD_PSTATE_DISABLE] = "disable",
100 [AMD_PSTATE_PASSIVE] = "passive",
101 [AMD_PSTATE_ACTIVE] = "active",
102 [AMD_PSTATE_GUIDE] = "guide",
103 NULL,
104 };
105

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.30 kB)
config (156.39 kB)
Download all attachments

2022-12-19 23:48:19

by Mario Limonciello

[permalink] [raw]
Subject: Re: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()

On 12/19/2022 00:40, Perry Yuan wrote:
> There are some other amd pstate driver working mode to be supported.

Perhaps:

The amd-pstate driver may support multiple working modes. Introduce a
variable to keep track of which mode is currently enabled.

> Here we use cppc_state var to indicate which mode is enabled.
> This change will help to simplify the the amd_pstate_param() to choose
> which mode used for the following driver registeration.

s/registeration/registration/

>
> Signed-off-by: Perry Yuan <[email protected]>
> Signed-off-by: Wyes Karny <[email protected]>
> ---
> drivers/cpufreq/amd-pstate.c | 35 +++++++++++++++++++++++++++--------
> include/linux/amd-pstate.h | 29 +++++++++++++++++++++++++++++
> 2 files changed, 56 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index c17bd845f5fc..861a905f9324 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -60,7 +60,18 @@
> * module parameter to be able to enable it manually for debugging.
> */
> static struct cpufreq_driver amd_pstate_driver;
> -static int cppc_load __initdata;
> +static int cppc_state = AMD_PSTATE_DISABLE;
> +
> +static inline int get_mode_idx_from_str(const char *str, size_t size)
> +{
> + int i;
> +
> + for (i=0; i < AMD_PSTATE_MAX; i++) {
> + if (!strncmp(str, amd_pstate_mode_string[i], size))
> + return i;
> + }
> + return -EINVAL;
> +}
>
> static inline int pstate_enable(bool enable)
> {
> @@ -628,7 +639,7 @@ static int __init amd_pstate_init(void)
> * enable the amd_pstate passive mode driver explicitly
> * with amd_pstate=passive in kernel command line
> */
> - if (!cppc_load) {
> + if (cppc_state == AMD_PSTATE_DISABLE) {
> pr_debug("driver load is disabled, boot with amd_pstate=passive to enable this\n");

Presumably this message needs to be changed since there are different
modes that can be used to enable it now.

> return -ENODEV;
> }
> @@ -671,16 +682,24 @@ device_initcall(amd_pstate_init);
>
> static int __init amd_pstate_param(char *str)
> {
> + size_t size;
> + int mode_idx;
> +
> if (!str)
> return -EINVAL;
>
> - if (!strcmp(str, "disable")) {
> - cppc_load = 0;
> - pr_info("driver is explicitly disabled\n");
> - } else if (!strcmp(str, "passive"))
> - cppc_load = 1;
> + size = strlen(str);
> + mode_idx = get_mode_idx_from_str(str, size);
>
> - return 0;
> + if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
> + cppc_state = mode_idx;
> + if (cppc_state == AMD_PSTATE_DISABLE)
> + pr_info("driver is explicitly disabled\n");
> +
> + return 0;
> + }
> +
> + return -EINVAL;
> }
> early_param("amd_pstate", amd_pstate_param);
>
> diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
> index 1c4b8659f171..922d05a13902 100644
> --- a/include/linux/amd-pstate.h
> +++ b/include/linux/amd-pstate.h
> @@ -74,4 +74,33 @@ struct amd_cpudata {
> bool boost_supported;
> };
>
> +/**
> + * enum amd_pstate_mode - driver working mode of amd pstate
> + */
> +
> +enum amd_pstate_mode {
> + /** @AMD_PSTATE_DISABLE: Driver mode is disabled */
> + AMD_PSTATE_DISABLE = 0,
> +
> + /** @AMD_PSTATE_PASSIVE: Drier mode is passive mode */

s/Drier/Driver/

> + AMD_PSTATE_PASSIVE = 1,
> +
> + /** @AMD_PSTATE_ACTIVE: Driver mode is active mode */
> + AMD_PSTATE_ACTIVE = 2,
> +
> + /** @AMD_PSTATE_GUIDE: Driver mode is guided mode */
> + AMD_PSTATE_GUIDE = 3,
> +
> + /** @AMD_PSTATE_MAX */
> + AMD_PSTATE_MAX = 4,
> +};
> +
> +static const char * const amd_pstate_mode_string[] = {
> + [AMD_PSTATE_DISABLE] = "disable",
> + [AMD_PSTATE_PASSIVE] = "passive",
> + [AMD_PSTATE_ACTIVE] = "active",
> + [AMD_PSTATE_GUIDE] = "guide",

I get the intent here, but guided mode isn't actually part of the v8
series under review.

I think it should either be folded into the series or this patch
should be split into two across the two patch-sets:
1) introduce the state machine (part of the EPP patch-set)
2) add guided mode support (part of the guided mode patch-set).

> + NULL,
> +};
> +
> #endif /* _LINUX_AMD_PSTATE_H */

2022-12-23 04:54:14

by Huang Rui

[permalink] [raw]
Subject: Re: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()

On Mon, Dec 19, 2022 at 02:40:34PM +0800, Yuan, Perry wrote:
> There are some other amd pstate driver working mode to be supported.
> Here we use cppc_state var to indicate which mode is enabled.
> This change will help to simplify the the amd_pstate_param() to choose
> which mode used for the following driver registeration.
>
> Signed-off-by: Perry Yuan <[email protected]>
> Signed-off-by: Wyes Karny <[email protected]>

The most of codes for this patch should be inherited by below patch:

https://lore.kernel.org/lkml/[email protected]/

So I believe Wyes should be the author of this patch, please use git commit
--amend --author="Wyes Karny <[email protected]>" to update.

Thanks,
Ray

> ---
> drivers/cpufreq/amd-pstate.c | 35 +++++++++++++++++++++++++++--------
> include/linux/amd-pstate.h | 29 +++++++++++++++++++++++++++++
> 2 files changed, 56 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index c17bd845f5fc..861a905f9324 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -60,7 +60,18 @@
> * module parameter to be able to enable it manually for debugging.
> */
> static struct cpufreq_driver amd_pstate_driver;
> -static int cppc_load __initdata;
> +static int cppc_state = AMD_PSTATE_DISABLE;
> +
> +static inline int get_mode_idx_from_str(const char *str, size_t size)
> +{
> + int i;
> +
> + for (i=0; i < AMD_PSTATE_MAX; i++) {
> + if (!strncmp(str, amd_pstate_mode_string[i], size))
> + return i;
> + }
> + return -EINVAL;
> +}
>
> static inline int pstate_enable(bool enable)
> {
> @@ -628,7 +639,7 @@ static int __init amd_pstate_init(void)
> * enable the amd_pstate passive mode driver explicitly
> * with amd_pstate=passive in kernel command line
> */
> - if (!cppc_load) {
> + if (cppc_state == AMD_PSTATE_DISABLE) {
> pr_debug("driver load is disabled, boot with amd_pstate=passive to enable this\n");
> return -ENODEV;
> }
> @@ -671,16 +682,24 @@ device_initcall(amd_pstate_init);
>
> static int __init amd_pstate_param(char *str)
> {
> + size_t size;
> + int mode_idx;
> +
> if (!str)
> return -EINVAL;
>
> - if (!strcmp(str, "disable")) {
> - cppc_load = 0;
> - pr_info("driver is explicitly disabled\n");
> - } else if (!strcmp(str, "passive"))
> - cppc_load = 1;
> + size = strlen(str);
> + mode_idx = get_mode_idx_from_str(str, size);
>
> - return 0;
> + if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
> + cppc_state = mode_idx;
> + if (cppc_state == AMD_PSTATE_DISABLE)
> + pr_info("driver is explicitly disabled\n");
> +
> + return 0;
> + }
> +
> + return -EINVAL;
> }
> early_param("amd_pstate", amd_pstate_param);
>
> diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
> index 1c4b8659f171..922d05a13902 100644
> --- a/include/linux/amd-pstate.h
> +++ b/include/linux/amd-pstate.h
> @@ -74,4 +74,33 @@ struct amd_cpudata {
> bool boost_supported;
> };
>
> +/**
> + * enum amd_pstate_mode - driver working mode of amd pstate
> + */
> +
> +enum amd_pstate_mode {
> + /** @AMD_PSTATE_DISABLE: Driver mode is disabled */
> + AMD_PSTATE_DISABLE = 0,
> +
> + /** @AMD_PSTATE_PASSIVE: Drier mode is passive mode */
> + AMD_PSTATE_PASSIVE = 1,
> +
> + /** @AMD_PSTATE_ACTIVE: Driver mode is active mode */
> + AMD_PSTATE_ACTIVE = 2,
> +
> + /** @AMD_PSTATE_GUIDE: Driver mode is guided mode */
> + AMD_PSTATE_GUIDE = 3,
> +
> + /** @AMD_PSTATE_MAX */
> + AMD_PSTATE_MAX = 4,
> +};
> +
> +static const char * const amd_pstate_mode_string[] = {
> + [AMD_PSTATE_DISABLE] = "disable",
> + [AMD_PSTATE_PASSIVE] = "passive",
> + [AMD_PSTATE_ACTIVE] = "active",
> + [AMD_PSTATE_GUIDE] = "guide",
> + NULL,
> +};
> +
> #endif /* _LINUX_AMD_PSTATE_H */
> --
> 2.34.1
>

2022-12-23 10:31:49

by Wyes Karny

[permalink] [raw]
Subject: Re: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()



On 12/19/2022 12:10 PM, Perry Yuan wrote:
--------------------->8-----------------------------
>
> +/**
> + * enum amd_pstate_mode - driver working mode of amd pstate
> + */
> +
> +enum amd_pstate_mode {
> + /** @AMD_PSTATE_DISABLE: Driver mode is disabled */
> + AMD_PSTATE_DISABLE = 0,
> +
> + /** @AMD_PSTATE_PASSIVE: Drier mode is passive mode */
> + AMD_PSTATE_PASSIVE = 1,
> +
> + /** @AMD_PSTATE_ACTIVE: Driver mode is active mode */
> + AMD_PSTATE_ACTIVE = 2,
> +
> + /** @AMD_PSTATE_GUIDE: Driver mode is guided mode */
> + AMD_PSTATE_GUIDE = 3,
> +
> + /** @AMD_PSTATE_MAX */
> + AMD_PSTATE_MAX = 4,
> +};

IMO the above enum is self explanatory we don't need to annotate.

what about below?

/**
* enum amd_pstate_mode - driver working mode
* All supported modes are explained in kernel-parameters.txt
*/
enum amd_pstate_mode {
AMD_PSTATE_DISABLE = 0,
AMD_PSTATE_PASSIVE,
AMD_PSTATE_ACTIVE,
AMD_PSTATE_MAX,
};

Plz remove GUIDED mode here because it allows user to pass "amd_pstate=guided"
in kernel cmdline. Therefore it breaks the driver flow without guided patches.
I can update the enum in my guided patch.

> +
> +static const char * const amd_pstate_mode_string[] = {
> + [AMD_PSTATE_DISABLE] = "disable",
> + [AMD_PSTATE_PASSIVE] = "passive",
> + [AMD_PSTATE_ACTIVE] = "active",
> + [AMD_PSTATE_GUIDE] = "guide",
> + NULL,
> +};
> +
> #endif /* _LINUX_AMD_PSTATE_H */

--
Thanks & Regards,
Wyes

2022-12-25 16:45:03

by Yuan, Perry

[permalink] [raw]
Subject: RE: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()

[AMD Official Use Only - General]



> -----Original Message-----
> From: Karny, Wyes <[email protected]>
> Sent: Friday, December 23, 2022 5:45 PM
> To: Yuan, Perry <[email protected]>; [email protected];
> Limonciello, Mario <[email protected]>; Huang, Ray
> <[email protected]>; [email protected]
> Cc: Sharma, Deepak <[email protected]>; Fontenot, Nathan
> <[email protected]>; Deucher, Alexander
> <[email protected]>; Huang, Shimmer
> <[email protected]>; Du, Xiaojian <[email protected]>; Meng,
> Li (Jassmine) <[email protected]>; [email protected]; linux-
> [email protected]
> Subject: Re: [PATCH v8 05/13] cpufreq: amd-pstate: optimize driver working
> mode selection in amd_pstate_param()
>
>
>
> On 12/19/2022 12:10 PM, Perry Yuan wrote:
> --------------------->8-----------------------------
> >
> > +/**
> > + * enum amd_pstate_mode - driver working mode of amd pstate */
> > +
> > +enum amd_pstate_mode {
> > + /** @AMD_PSTATE_DISABLE: Driver mode is disabled */
> > + AMD_PSTATE_DISABLE = 0,
> > +
> > + /** @AMD_PSTATE_PASSIVE: Drier mode is passive mode */
> > + AMD_PSTATE_PASSIVE = 1,
> > +
> > + /** @AMD_PSTATE_ACTIVE: Driver mode is active mode */
> > + AMD_PSTATE_ACTIVE = 2,
> > +
> > + /** @AMD_PSTATE_GUIDE: Driver mode is guided mode */
> > + AMD_PSTATE_GUIDE = 3,
> > +
> > + /** @AMD_PSTATE_MAX */
> > + AMD_PSTATE_MAX = 4,
> > +};
>
> IMO the above enum is self explanatory we don't need to annotate.
>
> what about below?
>
> /**
> * enum amd_pstate_mode - driver working mode
> * All supported modes are explained in kernel-parameters.txt */ enum
> amd_pstate_mode {
> AMD_PSTATE_DISABLE = 0,
> AMD_PSTATE_PASSIVE,
> AMD_PSTATE_ACTIVE,
> AMD_PSTATE_MAX,
> };

Sure , changed it in v9 like you suggested.

>
> Plz remove GUIDED mode here because it allows user to pass
> "amd_pstate=guided"
> in kernel cmdline. Therefore it breaks the driver flow without guided patches.
> I can update the enum in my guided patch.
>

Removed

> > +
> > +static const char * const amd_pstate_mode_string[] = {
> > + [AMD_PSTATE_DISABLE] = "disable",
> > + [AMD_PSTATE_PASSIVE] = "passive",
> > + [AMD_PSTATE_ACTIVE] = "active",
> > + [AMD_PSTATE_GUIDE] = "guide",
> > + NULL,
> > +};
> > +
> > #endif /* _LINUX_AMD_PSTATE_H */
>
> --
> Thanks & Regards,
> Wyes