2022-04-13 17:42:25

by Meng, Li (Jassmine)

[permalink] [raw]
Subject: [PATCH v2 0/3] Add unit test module for AMD P-State driver

Hi all:

AMD P-State unit test(amd_pstate_testmod) is a kernel module for testing
the functions of amd-pstate driver.
It could import as a module to launch some test tasks.

We upstream out AMD P-state driver into Linux kernel and use this unit
test module to verify the required conditions and basic functions of
amd-pstate before integration test.

We use test module in the kselftest frameworks to implement it.
We create amd_pstate_testmod module and tie it into kselftest.

For exmaple: The test case aput_acpi_cpc is used to check whether the
_CPC object is exist in SBIOS.
The amd-pstate initialization will fail if the _CPC in ACPI SBIOS is
not existed at the detected processor, so it is a necessary condition.

At present, its test cases are very simple, and the corresponding test
cases will continue to be added later to improve the test coverage.

See patch series in below git repo:
V1: https://lore.kernel.org/linux-pm/[email protected]/

Changes from V1 -> V2:
- cpufreq: amd-pstate:
- - add a trailing of amd-pstate.h to MAINTAINER AMD PSTATE DRIVER
- selftests: cpufreq
- - add a wrapper shell script for the amd_pstate_testmod module
- selftests: cpufreq:
- - remove amd_pstate_testmod kernel module to .../cpufreq/amd_pstate_testmod
- Documentation: amd-pstate:
- - amd_pstate_testmod rst document is not provided at present.

Thanks,
Jasmine

Meng Li (3):
cpufreq: amd-pstate: Expose struct amd_cpudata
selftests: cpufreq: Add wapper script for test AMD P-State
selftests: cpufreq: Add amd_pstate_testmod kernel module for testing

MAINTAINERS | 1 +
drivers/cpufreq/amd-pstate.c | 60 +---
include/linux/amd-pstate.h | 74 +++++
tools/testing/selftests/cpufreq/Makefile | 2 +-
.../selftests/cpufreq/amd_pstate_testmod.sh | 4 +
.../cpufreq/amd_pstate_testmod/Makefile | 20 ++
.../amd_pstate_testmod/amd_pstate_testmod.c | 302 ++++++++++++++++++
tools/testing/selftests/cpufreq/config | 1 +
8 files changed, 404 insertions(+), 60 deletions(-)
create mode 100644 include/linux/amd-pstate.h
create mode 100755 tools/testing/selftests/cpufreq/amd_pstate_testmod.sh
create mode 100644 tools/testing/selftests/cpufreq/amd_pstate_testmod/Makefile
create mode 100644 tools/testing/selftests/cpufreq/amd_pstate_testmod/amd_pstate_testmod.c

--
2.25.1


2022-04-13 19:12:39

by Meng, Li (Jassmine)

[permalink] [raw]
Subject: [PATCH 1/3] cpufreq: amd-pstate: Expose struct amd_cpudata

Expose struct amd_cpudata to AMD P-State unit test module.

This data struct will be used on the following AMD P-State unit test
(amd-pstate-ut) module. The amd-pstate-ut module can get some AMD
infomations by this data struct. For example: highest perf,
nominal perf, boost supported etc.

Signed-off-by: Meng Li <[email protected]>
---
MAINTAINERS | 1 +
drivers/cpufreq/amd-pstate.c | 60 +----------------------------
include/linux/amd-pstate.h | 74 ++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 59 deletions(-)
create mode 100644 include/linux/amd-pstate.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 9832b607e2e2..f108e83ba851 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1003,6 +1003,7 @@ S: Supported
F: Documentation/admin-guide/pm/amd-pstate.rst
F: drivers/cpufreq/amd-pstate*
F: tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py
+F: include/linux/amd-pstate.h

AMD PTDMA DRIVER
M: Sanjay R Mehta <[email protected]>
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 7be38bc6a673..5f7a00a64f76 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -36,6 +36,7 @@
#include <linux/delay.h>
#include <linux/uaccess.h>
#include <linux/static_call.h>
+#include <linux/amd-pstate.h>

#include <acpi/processor.h>
#include <acpi/cppc_acpi.h>
@@ -65,65 +66,6 @@ MODULE_PARM_DESC(shared_mem,

static struct cpufreq_driver amd_pstate_driver;

-/**
- * struct amd_aperf_mperf
- * @aperf: actual performance frequency clock count
- * @mperf: maximum performance frequency clock count
- * @tsc: time stamp counter
- */
-struct amd_aperf_mperf {
- u64 aperf;
- u64 mperf;
- u64 tsc;
-};
-
-/**
- * struct amd_cpudata - private CPU data for AMD P-State
- * @cpu: CPU number
- * @req: constraint request to apply
- * @cppc_req_cached: cached performance request hints
- * @highest_perf: the maximum performance an individual processor may reach,
- * assuming ideal conditions
- * @nominal_perf: the maximum sustained performance level of the processor,
- * assuming ideal operating conditions
- * @lowest_nonlinear_perf: the lowest performance level at which nonlinear power
- * savings are achieved
- * @lowest_perf: the absolute lowest performance level of the processor
- * @max_freq: the frequency that mapped to highest_perf
- * @min_freq: the frequency that mapped to lowest_perf
- * @nominal_freq: the frequency that mapped to nominal_perf
- * @lowest_nonlinear_freq: the frequency that mapped to lowest_nonlinear_perf
- * @cur: Difference of Aperf/Mperf/tsc count between last and current sample
- * @prev: Last Aperf/Mperf/tsc count value read from register
- * @freq: current cpu frequency value
- * @boost_supported: check whether the Processor or SBIOS supports boost mode
- *
- * The amd_cpudata is key private data for each CPU thread in AMD P-State, and
- * represents all the attributes and goals that AMD P-State requests at runtime.
- */
-struct amd_cpudata {
- int cpu;
-
- struct freq_qos_request req[2];
- u64 cppc_req_cached;
-
- u32 highest_perf;
- u32 nominal_perf;
- u32 lowest_nonlinear_perf;
- u32 lowest_perf;
-
- u32 max_freq;
- u32 min_freq;
- u32 nominal_freq;
- u32 lowest_nonlinear_freq;
-
- struct amd_aperf_mperf cur;
- struct amd_aperf_mperf prev;
-
- u64 freq;
- bool boost_supported;
-};
-
static inline int pstate_enable(bool enable)
{
return wrmsrl_safe(MSR_AMD_CPPC_ENABLE, enable);
diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
new file mode 100644
index 000000000000..790b04c9000b
--- /dev/null
+++ b/include/linux/amd-pstate.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * linux/include/linux/amd-pstate.h
+ *
+ * Copyright (C) 2007-2010 Advanced Micro Devices, Inc.
+ * Author: Meng Li <[email protected]>
+ */
+#ifndef _LINUX_AMD_PSTATE_H
+#define _LINUX_AMD_PSTATE_H
+
+#include <linux/pm_qos.h>
+/*********************************************************************
+ * AMD P-state INTERFACE *
+ *********************************************************************/
+/**
+ * struct amd_aperf_mperf
+ * @aperf: actual performance frequency clock count
+ * @mperf: maximum performance frequency clock count
+ * @tsc: time stamp counter
+ */
+struct amd_aperf_mperf {
+ u64 aperf;
+ u64 mperf;
+ u64 tsc;
+};
+
+/**
+ * struct amd_cpudata - private CPU data for AMD P-State
+ * @cpu: CPU number
+ * @req: constraint request to apply
+ * @cppc_req_cached: cached performance request hints
+ * @highest_perf: the maximum performance an individual processor may reach,
+ * assuming ideal conditions
+ * @nominal_perf: the maximum sustained performance level of the processor,
+ * assuming ideal operating conditions
+ * @lowest_nonlinear_perf: the lowest performance level at which nonlinear power
+ * savings are achieved
+ * @lowest_perf: the absolute lowest performance level of the processor
+ * @max_freq: the frequency that mapped to highest_perf
+ * @min_freq: the frequency that mapped to lowest_perf
+ * @nominal_freq: the frequency that mapped to nominal_perf
+ * @lowest_nonlinear_freq: the frequency that mapped to lowest_nonlinear_perf
+ * @cur: Difference of Aperf/Mperf/tsc count between last and current sample
+ * @prev: Last Aperf/Mperf/tsc count value read from register
+ * @freq: current cpu frequency value
+ * @boost_supported: check whether the Processor or SBIOS supports boost mode
+ *
+ * The amd_cpudata is key private data for each CPU thread in AMD P-State, and
+ * represents all the attributes and goals that AMD P-State requests at runtime.
+ */
+struct amd_cpudata {
+ int cpu;
+
+ struct freq_qos_request req[2];
+ u64 cppc_req_cached;
+
+ u32 highest_perf;
+ u32 nominal_perf;
+ u32 lowest_nonlinear_perf;
+ u32 lowest_perf;
+
+ u32 max_freq;
+ u32 min_freq;
+ u32 nominal_freq;
+ u32 lowest_nonlinear_freq;
+
+ struct amd_aperf_mperf cur;
+ struct amd_aperf_mperf prev;
+
+ u64 freq;
+ bool boost_supported;
+};
+
+#endif /* _LINUX_AMD_PSTATE_H */
--
2.25.1

2022-04-13 21:12:43

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] Add unit test module for AMD P-State driver

On Wed, Apr 13, 2022 at 11:06 AM Meng Li <[email protected]> wrote:
>
> Hi all:
>
> AMD P-State unit test(amd_pstate_testmod) is a kernel module for testing
> the functions of amd-pstate driver.
> It could import as a module to launch some test tasks.
>
> We upstream out AMD P-state driver into Linux kernel and use this unit
> test module to verify the required conditions and basic functions of
> amd-pstate before integration test.
>
> We use test module in the kselftest frameworks to implement it.
> We create amd_pstate_testmod module and tie it into kselftest.
>
> For exmaple: The test case aput_acpi_cpc is used to check whether the
> _CPC object is exist in SBIOS.
> The amd-pstate initialization will fail if the _CPC in ACPI SBIOS is
> not existed at the detected processor, so it is a necessary condition.
>
> At present, its test cases are very simple, and the corresponding test
> cases will continue to be added later to improve the test coverage.
>
> See patch series in below git repo:
> V1: https://lore.kernel.org/linux-pm/[email protected]/
>
> Changes from V1 -> V2:
> - cpufreq: amd-pstate:
> - - add a trailing of amd-pstate.h to MAINTAINER AMD PSTATE DRIVER
> - selftests: cpufreq
> - - add a wrapper shell script for the amd_pstate_testmod module
> - selftests: cpufreq:
> - - remove amd_pstate_testmod kernel module to .../cpufreq/amd_pstate_testmod
> - Documentation: amd-pstate:
> - - amd_pstate_testmod rst document is not provided at present.
>
> Thanks,
> Jasmine
>
> Meng Li (3):
> cpufreq: amd-pstate: Expose struct amd_cpudata

Please collect an ACK from Ray for this one as per MAINTAINERS and I
will leave the series to Shuah as it is selftests mostly.

Thanks!

> selftests: cpufreq: Add wapper script for test AMD P-State
> selftests: cpufreq: Add amd_pstate_testmod kernel module for testing
>
> MAINTAINERS | 1 +
> drivers/cpufreq/amd-pstate.c | 60 +---
> include/linux/amd-pstate.h | 74 +++++
> tools/testing/selftests/cpufreq/Makefile | 2 +-
> .../selftests/cpufreq/amd_pstate_testmod.sh | 4 +
> .../cpufreq/amd_pstate_testmod/Makefile | 20 ++
> .../amd_pstate_testmod/amd_pstate_testmod.c | 302 ++++++++++++++++++
> tools/testing/selftests/cpufreq/config | 1 +
> 8 files changed, 404 insertions(+), 60 deletions(-)
> create mode 100644 include/linux/amd-pstate.h
> create mode 100755 tools/testing/selftests/cpufreq/amd_pstate_testmod.sh
> create mode 100644 tools/testing/selftests/cpufreq/amd_pstate_testmod/Makefile
> create mode 100644 tools/testing/selftests/cpufreq/amd_pstate_testmod/amd_pstate_testmod.c
>
> --
> 2.25.1
>

2022-04-18 00:53:43

by Huang Rui

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] Add unit test module for AMD P-State driver

On Wed, Apr 13, 2022 at 11:41:44PM +0800, Rafael J. Wysocki wrote:
> On Wed, Apr 13, 2022 at 11:06 AM Meng Li <[email protected]> wrote:
> >
> > Hi all:
> >
> > AMD P-State unit test(amd_pstate_testmod) is a kernel module for testing
> > the functions of amd-pstate driver.
> > It could import as a module to launch some test tasks.
> >
> > We upstream out AMD P-state driver into Linux kernel and use this unit
> > test module to verify the required conditions and basic functions of
> > amd-pstate before integration test.
> >
> > We use test module in the kselftest frameworks to implement it.
> > We create amd_pstate_testmod module and tie it into kselftest.
> >
> > For exmaple: The test case aput_acpi_cpc is used to check whether the
> > _CPC object is exist in SBIOS.
> > The amd-pstate initialization will fail if the _CPC in ACPI SBIOS is
> > not existed at the detected processor, so it is a necessary condition.
> >
> > At present, its test cases are very simple, and the corresponding test
> > cases will continue to be added later to improve the test coverage.
> >
> > See patch series in below git repo:
> > V1: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flinux-pm%2F20220323071502.2674156-1-li.meng%40amd.com%2F&amp;data=04%7C01%7Cray.huang%40amd.com%7C7a5d4998e2ca413a215b08da1d6425e4%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637854613222577975%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=8fAzN5hea4sVO5E7%2B9Uh9VSsyt29gM2%2FCkMXHS0%2FfP4%3D&amp;reserved=0
> >
> > Changes from V1 -> V2:
> > - cpufreq: amd-pstate:
> > - - add a trailing of amd-pstate.h to MAINTAINER AMD PSTATE DRIVER
> > - selftests: cpufreq
> > - - add a wrapper shell script for the amd_pstate_testmod module
> > - selftests: cpufreq:
> > - - remove amd_pstate_testmod kernel module to .../cpufreq/amd_pstate_testmod
> > - Documentation: amd-pstate:
> > - - amd_pstate_testmod rst document is not provided at present.
> >
> > Thanks,
> > Jasmine
> >
> > Meng Li (3):
> > cpufreq: amd-pstate: Expose struct amd_cpudata
>
> Please collect an ACK from Ray for this one as per MAINTAINERS and I
> will leave the series to Shuah as it is selftests mostly.
>
> Thanks!
>

Thanks, Rafael!

Jassmine, I think you can mark all patches as "v2" not only the cover
letter. Then we can separate these series easily.

Thanks,
Ray

> > selftests: cpufreq: Add wapper script for test AMD P-State
> > selftests: cpufreq: Add amd_pstate_testmod kernel module for testing
> >
> > MAINTAINERS | 1 +
> > drivers/cpufreq/amd-pstate.c | 60 +---
> > include/linux/amd-pstate.h | 74 +++++
> > tools/testing/selftests/cpufreq/Makefile | 2 +-
> > .../selftests/cpufreq/amd_pstate_testmod.sh | 4 +
> > .../cpufreq/amd_pstate_testmod/Makefile | 20 ++
> > .../amd_pstate_testmod/amd_pstate_testmod.c | 302 ++++++++++++++++++
> > tools/testing/selftests/cpufreq/config | 1 +
> > 8 files changed, 404 insertions(+), 60 deletions(-)
> > create mode 100644 include/linux/amd-pstate.h
> > create mode 100755 tools/testing/selftests/cpufreq/amd_pstate_testmod.sh
> > create mode 100644 tools/testing/selftests/cpufreq/amd_pstate_testmod/Makefile
> > create mode 100644 tools/testing/selftests/cpufreq/amd_pstate_testmod/amd_pstate_testmod.c
> >
> > --
> > 2.25.1
> >

2022-04-18 12:47:46

by Huang Rui

[permalink] [raw]
Subject: Re: [PATCH 1/3] cpufreq: amd-pstate: Expose struct amd_cpudata

On Wed, Apr 13, 2022 at 05:05:08PM +0800, Meng Li wrote:
> Expose struct amd_cpudata to AMD P-State unit test module.
>
> This data struct will be used on the following AMD P-State unit test
> (amd-pstate-ut) module. The amd-pstate-ut module can get some AMD
> infomations by this data struct. For example: highest perf,
> nominal perf, boost supported etc.
>
> Signed-off-by: Meng Li <[email protected]>

Acked-by: Huang Rui <[email protected]>

> ---
> MAINTAINERS | 1 +
> drivers/cpufreq/amd-pstate.c | 60 +----------------------------
> include/linux/amd-pstate.h | 74 ++++++++++++++++++++++++++++++++++++
> 3 files changed, 76 insertions(+), 59 deletions(-)
> create mode 100644 include/linux/amd-pstate.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9832b607e2e2..f108e83ba851 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1003,6 +1003,7 @@ S: Supported
> F: Documentation/admin-guide/pm/amd-pstate.rst
> F: drivers/cpufreq/amd-pstate*
> F: tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py
> +F: include/linux/amd-pstate.h
>
> AMD PTDMA DRIVER
> M: Sanjay R Mehta <[email protected]>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 7be38bc6a673..5f7a00a64f76 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -36,6 +36,7 @@
> #include <linux/delay.h>
> #include <linux/uaccess.h>
> #include <linux/static_call.h>
> +#include <linux/amd-pstate.h>
>
> #include <acpi/processor.h>
> #include <acpi/cppc_acpi.h>
> @@ -65,65 +66,6 @@ MODULE_PARM_DESC(shared_mem,
>
> static struct cpufreq_driver amd_pstate_driver;
>
> -/**
> - * struct amd_aperf_mperf
> - * @aperf: actual performance frequency clock count
> - * @mperf: maximum performance frequency clock count
> - * @tsc: time stamp counter
> - */
> -struct amd_aperf_mperf {
> - u64 aperf;
> - u64 mperf;
> - u64 tsc;
> -};
> -
> -/**
> - * struct amd_cpudata - private CPU data for AMD P-State
> - * @cpu: CPU number
> - * @req: constraint request to apply
> - * @cppc_req_cached: cached performance request hints
> - * @highest_perf: the maximum performance an individual processor may reach,
> - * assuming ideal conditions
> - * @nominal_perf: the maximum sustained performance level of the processor,
> - * assuming ideal operating conditions
> - * @lowest_nonlinear_perf: the lowest performance level at which nonlinear power
> - * savings are achieved
> - * @lowest_perf: the absolute lowest performance level of the processor
> - * @max_freq: the frequency that mapped to highest_perf
> - * @min_freq: the frequency that mapped to lowest_perf
> - * @nominal_freq: the frequency that mapped to nominal_perf
> - * @lowest_nonlinear_freq: the frequency that mapped to lowest_nonlinear_perf
> - * @cur: Difference of Aperf/Mperf/tsc count between last and current sample
> - * @prev: Last Aperf/Mperf/tsc count value read from register
> - * @freq: current cpu frequency value
> - * @boost_supported: check whether the Processor or SBIOS supports boost mode
> - *
> - * The amd_cpudata is key private data for each CPU thread in AMD P-State, and
> - * represents all the attributes and goals that AMD P-State requests at runtime.
> - */
> -struct amd_cpudata {
> - int cpu;
> -
> - struct freq_qos_request req[2];
> - u64 cppc_req_cached;
> -
> - u32 highest_perf;
> - u32 nominal_perf;
> - u32 lowest_nonlinear_perf;
> - u32 lowest_perf;
> -
> - u32 max_freq;
> - u32 min_freq;
> - u32 nominal_freq;
> - u32 lowest_nonlinear_freq;
> -
> - struct amd_aperf_mperf cur;
> - struct amd_aperf_mperf prev;
> -
> - u64 freq;
> - bool boost_supported;
> -};
> -
> static inline int pstate_enable(bool enable)
> {
> return wrmsrl_safe(MSR_AMD_CPPC_ENABLE, enable);
> diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
> new file mode 100644
> index 000000000000..790b04c9000b
> --- /dev/null
> +++ b/include/linux/amd-pstate.h
> @@ -0,0 +1,74 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * linux/include/linux/amd-pstate.h
> + *
> + * Copyright (C) 2007-2010 Advanced Micro Devices, Inc.
> + * Author: Meng Li <[email protected]>
> + */
> +#ifndef _LINUX_AMD_PSTATE_H
> +#define _LINUX_AMD_PSTATE_H
> +
> +#include <linux/pm_qos.h>
> +/*********************************************************************
> + * AMD P-state INTERFACE *
> + *********************************************************************/
> +/**
> + * struct amd_aperf_mperf
> + * @aperf: actual performance frequency clock count
> + * @mperf: maximum performance frequency clock count
> + * @tsc: time stamp counter
> + */
> +struct amd_aperf_mperf {
> + u64 aperf;
> + u64 mperf;
> + u64 tsc;
> +};
> +
> +/**
> + * struct amd_cpudata - private CPU data for AMD P-State
> + * @cpu: CPU number
> + * @req: constraint request to apply
> + * @cppc_req_cached: cached performance request hints
> + * @highest_perf: the maximum performance an individual processor may reach,
> + * assuming ideal conditions
> + * @nominal_perf: the maximum sustained performance level of the processor,
> + * assuming ideal operating conditions
> + * @lowest_nonlinear_perf: the lowest performance level at which nonlinear power
> + * savings are achieved
> + * @lowest_perf: the absolute lowest performance level of the processor
> + * @max_freq: the frequency that mapped to highest_perf
> + * @min_freq: the frequency that mapped to lowest_perf
> + * @nominal_freq: the frequency that mapped to nominal_perf
> + * @lowest_nonlinear_freq: the frequency that mapped to lowest_nonlinear_perf
> + * @cur: Difference of Aperf/Mperf/tsc count between last and current sample
> + * @prev: Last Aperf/Mperf/tsc count value read from register
> + * @freq: current cpu frequency value
> + * @boost_supported: check whether the Processor or SBIOS supports boost mode
> + *
> + * The amd_cpudata is key private data for each CPU thread in AMD P-State, and
> + * represents all the attributes and goals that AMD P-State requests at runtime.
> + */
> +struct amd_cpudata {
> + int cpu;
> +
> + struct freq_qos_request req[2];
> + u64 cppc_req_cached;
> +
> + u32 highest_perf;
> + u32 nominal_perf;
> + u32 lowest_nonlinear_perf;
> + u32 lowest_perf;
> +
> + u32 max_freq;
> + u32 min_freq;
> + u32 nominal_freq;
> + u32 lowest_nonlinear_freq;
> +
> + struct amd_aperf_mperf cur;
> + struct amd_aperf_mperf prev;
> +
> + u64 freq;
> + bool boost_supported;
> +};
> +
> +#endif /* _LINUX_AMD_PSTATE_H */
> --
> 2.25.1
>