* [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support
2024-11-30 14:06 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
@ 2024-11-30 14:07 ` Mario Limonciello
0 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 14:07 UTC (permalink / raw)
To: Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen,
maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H . Peter Anvin,
Rafael J . Wysocki, Gautham R . Shenoy, Mario Limonciello,
Perry Yuan, Brijesh Singh, Peter Zijlstra, Li RongQing,
open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:ACPI,
open list:AMD PSTATE DRIVER, Pawan Gupta
Add a dump of the class and capabilities table to debugfs to assist
with debugging scheduler issues.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/platform/x86/amd/hfi/hfi.c | 36 ++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 0940950dd7adc..b6dc379bfd546 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -13,6 +13,7 @@
#include <linux/acpi.h>
#include <linux/cpu.h>
#include <linux/cpumask.h>
+#include <linux/debugfs.h>
#include <linux/gfp.h>
#include <linux/init.h>
#include <linux/io.h>
@@ -74,6 +75,8 @@ struct amd_hfi_data {
void __iomem *pcc_comm_addr;
struct acpi_subtable_header *pcct_entry;
struct amd_shmem_info *shmem;
+
+ struct dentry *dbgfs_dir;
};
/**
@@ -234,6 +237,13 @@ static int amd_hfi_alloc_class_data(struct platform_device *pdev)
return 0;
}
+static void amd_hfi_remove(struct platform_device *pdev)
+{
+ struct amd_hfi_data *dev = platform_get_drvdata(pdev);
+
+ debugfs_remove_recursive(dev->dbgfs_dir);
+}
+
static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
{
for (int i = 0; i < hfi_cpuinfo->nr_class; i++)
@@ -388,6 +398,27 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
return ret;
}
+static int class_capabilities_show(struct seq_file *s, void *unused)
+{
+ int cpu, idx;
+
+ seq_puts(s, "CPU #\tWLC\tPerf\tEff\n");
+ for_each_present_cpu(cpu) {
+ struct amd_hfi_cpuinfo *hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, cpu);
+
+ seq_printf(s, "%d", cpu);
+ for (idx = 0; idx < hfi_cpuinfo->nr_class; idx++) {
+ seq_printf(s, "\t%d\t%d\t%d\n",
+ idx,
+ hfi_cpuinfo->amd_hfi_classes[idx].perf,
+ hfi_cpuinfo->amd_hfi_classes[idx].eff);
+ }
+ }
+
+ return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(class_capabilities);
+
static int amd_hfi_pm_resume(struct device *dev)
{
int ret, cpu;
@@ -463,6 +494,10 @@ static int amd_hfi_probe(struct platform_device *pdev)
schedule_work(&sched_amd_hfi_itmt_work);
+ amd_hfi_data->dbgfs_dir = debugfs_create_dir("amd_hfi", arch_debugfs_dir);
+ debugfs_create_file("class_capabilities", 0644, amd_hfi_data->dbgfs_dir, pdev,
+ &class_capabilities_fops);
+
return 0;
}
@@ -474,6 +509,7 @@ static struct platform_driver amd_hfi_driver = {
.acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
},
.probe = amd_hfi_probe,
+ .remove = amd_hfi_remove,
};
static int __init amd_hfi_init(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 00/12] Add support for AMD hardware feedback interface
@ 2024-11-30 15:20 Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 01/12] Documentation: x86: Add AMD Hardware Feedback Interface documentation Mario Limonciello
` (11 more replies)
0 siblings, 12 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
The AMD Heterogeneous core design and Hardware Feedback Interface (HFI)
provide behavioral classification and a dynamically updated ranking table
for the scheduler to use when choosing cores for tasks.
Threads are classified during runtime into enumerated classes.
Currently, the driver supports 3 classes (0 through 2). These classes
represent thread performance/power characteristics that may benefit from
special scheduling behaviors. The real-time thread classification is
consumed by the operating system and is used to inform the scheduler of
where the thread should be placed for optimal performance or energy efficiency.
The thread classification helps to select CPU from a ranking table that describes
an efficiency and performance ranking for each classification from two dimensions.
The ranking data provided by the ranking table are numbers ranging from 0 to 255,
where a higher performance value indicates higher performance capability and a higher
efficiency value indicates greater efficiency. All the CPU cores are ranked into
different class IDs. Within each class ranking, the cores may have different ranking
values. Therefore, picking from each classification ID will later allow the scheduler
to select the best core while threads are classified into the specified workload class.
This series was originally submitted by Perry Yuan [1] but he is now doing a different
role and he asked me to take over.
Link: https://lore.kernel.org/all/cover.1724748733.git.perry.yuan@amd.com/
On applicable hardware this series has between a 2% and 5% improvement across various
benchmarks.
There is however a cost associated with clearing history on the process context switch.
On average it increases the delay by 119ns, and also has a wider range in delays
(the standard deviation is 25% greater).
---
Sorry for those of you that got this twice. I picked the wrong entry in my gitconfig
and it didn't use platform-x86.
Mario Limonciello (4):
MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver
cpufreq/amd-pstate: Disable preferred cores on designs with workload
classification
platform/x86/amd: hfi: Set ITMT priority from ranking data
platform/x86/amd: hfi: Add debugfs support
Perry Yuan (8):
Documentation: x86: Add AMD Hardware Feedback Interface documentation
x86/msr-index: define AMD heterogeneous CPU related MSR
platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver
platform/x86: hfi: parse CPU core ranking data from shared memory
platform/x86: hfi: init per-cpu scores for each class
platform/x86: hfi: add online and offline callback support
platform/x86: hfi: add power management callback
x86/process: Clear hardware feedback history for AMD processors
Documentation/arch/x86/amd-hfi.rst | 127 ++++++
Documentation/arch/x86/index.rst | 1 +
MAINTAINERS | 9 +
arch/x86/include/asm/msr-index.h | 5 +
arch/x86/kernel/process_32.c | 4 +
arch/x86/kernel/process_64.c | 4 +
drivers/cpufreq/amd-pstate.c | 6 +
drivers/platform/x86/amd/Kconfig | 1 +
drivers/platform/x86/amd/Makefile | 1 +
drivers/platform/x86/amd/hfi/Kconfig | 21 +
drivers/platform/x86/amd/hfi/Makefile | 7 +
drivers/platform/x86/amd/hfi/hfi.c | 546 ++++++++++++++++++++++++++
12 files changed, 732 insertions(+)
create mode 100644 Documentation/arch/x86/amd-hfi.rst
create mode 100644 drivers/platform/x86/amd/hfi/Kconfig
create mode 100644 drivers/platform/x86/amd/hfi/Makefile
create mode 100644 drivers/platform/x86/amd/hfi/hfi.c
--
2.43.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v7 01/12] Documentation: x86: Add AMD Hardware Feedback Interface documentation
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 02/12] MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver Mario Limonciello
` (10 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan, Bagas Sanjaya
From: Perry Yuan <Perry.Yuan@amd.com>
Introduce a new documentation file, `amd_hfi.rst`, which delves into the
implementation details of the AMD Hardware Feedback Interface and its
associated driver, `amd_hfi`. This documentation describes how the
driver provides hint to the OS scheduling which depends on the capability
of core performance and efficiency ranking data.
This documentation describes
* The design of the driver
* How the driver provides hints to the OS scheduling
* How the driver interfaces with the kernel for efficiency ranking data.
Reviewed-by: Bagas Sanjaya <bagasdotme@gmail.com>
Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
Documentation/arch/x86/amd-hfi.rst | 127 +++++++++++++++++++++++++++++
Documentation/arch/x86/index.rst | 1 +
2 files changed, 128 insertions(+)
create mode 100644 Documentation/arch/x86/amd-hfi.rst
diff --git a/Documentation/arch/x86/amd-hfi.rst b/Documentation/arch/x86/amd-hfi.rst
new file mode 100644
index 0000000000000..5d204688470e3
--- /dev/null
+++ b/Documentation/arch/x86/amd-hfi.rst
@@ -0,0 +1,127 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======================================================================
+Hardware Feedback Interface For Hetero Core Scheduling On AMD Platform
+======================================================================
+
+:Copyright: 2024 Advanced Micro Devices, Inc. All Rights Reserved.
+
+:Author: Perry Yuan <perry.yuan@amd.com>
+:Author: Mario Limonciello <mario.limonciello@amd.com>
+
+Overview
+--------
+
+AMD Heterogeneous Core implementations are comprised of more than one
+architectural class and CPUs are comprised of cores of various efficiency and
+power capabilities: performance-oriented *classic cores* and power-efficient
+*dense cores*. As such, power management strategies must be designed to
+accommodate the complexities introduced by incorporating different core types.
+Heterogeneous systems can also extend to more than two architectural classes as
+well. The purpose of the scheduling feedback mechanism is to provide
+information to the operating system scheduler in real time such that the
+scheduler can direct threads to the optimal core.
+
+The goal of AMD's heterogeneous architecture is to attain power benefit by sending
+background thread to the dense cores while sending high priority threads to the classic
+cores. From a performance perspective, sending background threads to dense cores can free
+up power headroom and allow the classic cores to optimally service demanding threads.
+Furthermore, the area optimized nature of the dense cores allows for an increasing
+number of physical cores. This improved core density will have positive multithreaded
+performance impact.
+
+AMD Heterogeneous Core Driver
+-----------------------------
+
+The ``amd_hfi`` driver delivers the operating system a performance and energy efficiency
+capability data for each CPU in the system. The scheduler can use the ranking data
+from the HFI driver to make task placement decisions.
+
+Thread Classification and Ranking Table Interaction
+----------------------------------------------------
+
+The thread classification is used to select into a ranking table that describes
+an efficiency and performance ranking for each classification.
+
+Threads are classified during runtime into enumerated classes. The classes represent
+thread performance/power characteristics that may benefit from special scheduling behaviors.
+The below table depicts an example of thread classification and a preference where a given thread
+should be scheduled based on its thread class. The real time thread classification is consumed
+by the operating system and is used to inform the scheduler of where the thread should be placed.
+
+Thread Classification Example Table
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
++----------+----------------+-------------------------------+---------------------+---------+
+| class ID | Classification | Preferred scheduling behavior | Preemption priority | Counter |
++----------+----------------+-------------------------------+---------------------+---------+
+| 0 | Default | Performant | Highest | |
++----------+----------------+-------------------------------+---------------------+---------+
+| 1 | Non-scalable | Efficient | Lowest | PMCx1A1 |
++----------+----------------+-------------------------------+---------------------+---------+
+| 2 | I/O bound | Efficient | Lowest | PMCx044 |
++----------+----------------+-------------------------------+---------------------+---------+
+
+Thread classification is performed by the hardware each time that the thread is switched out.
+Threads that don't meet any hardware specified criteria will be classified as "default".
+
+AMD Hardware Feedback Interface
+--------------------------------
+
+The Hardware Feedback Interface provides to the operating system information
+about the performance and energy efficiency of each CPU in the system. Each
+capability is given as a unit-less quantity in the range [0-255]. A higher
+performance value indicates higher performance capability, and a higher
+efficiency value indicates more efficiency. Energy efficiency and performance
+are reported in separate capabilities in the shared memory based ranking table.
+
+These capabilities may change at runtime as a result of changes in the
+operating conditions of the system or the action of external factors.
+Power Management FW is responsible for detecting events that would require
+a reordering of the performance and efficiency ranking. Table updates would
+happen relatively infrequently and occur on the time scale of seconds or more.
+
+The following events trigger a table update:
+ * Thermal Stress Events
+ * Silent Compute
+ * Extreme Low Battery Scenarios
+
+The kernel or a userspace policy daemon can use these capabilities to modify
+task placement decisions. For instance, if either the performance or energy
+capabilities of a given logical processor becomes zero, it is an indication that
+the hardware recommends to the operating system to not schedule any tasks on
+that processor for performance or energy efficiency reasons, respectively.
+
+Implementation details for Linux
+--------------------------------
+
+The implementation of threads scheduling consists of the following steps:
+
+1. A thread is spawned and scheduled to the ideal core using the default
+ heterogeneous scheduling policy.
+2. The processor profiles thread execution and assigns an enumerated classification ID.
+ This classification is communicated to the OS via logical processor scope MSR.
+3. During the thread context switch out the operating system consumes the workload(WL)
+ classification which resides in a logical processor scope MSR.
+4. The OS triggers the hardware to clear its history by writing to an MSR,
+ after consuming the WL classification and before switching in the new thread.
+5. If due to the classification, ranking table, and processor availability,
+ the thread is not on its ideal processor, the OS will then consider scheduling
+ the thread on its ideal processor (if available).
+
+Ranking Table
+-------------
+The ranking table is a shared memory region that is used to communicate the
+performance and energy efficiency capabilities of each CPU in the system.
+
+The ranking table design includes rankings for each APIC ID in the system and
+rankings both for performance and efficiency for each workload classification.
+
+.. kernel-doc:: drivers/platform/x86/amd/hfi/hfi.c
+ :doc: amd_shmem_info
+
+Ranking Table update
+---------------------------
+The power management firmware issues an platform interrupt after updating the ranking
+table and is ready for the operating system to consume it. CPUs receive such interrupt
+and read new ranking table from shared memory which PCCT table has provided, then
+``amd_hfi`` driver parse the new table to provide new consume data for scheduling decisions.
diff --git a/Documentation/arch/x86/index.rst b/Documentation/arch/x86/index.rst
index 8ac64d7de4dc9..56f2923f52597 100644
--- a/Documentation/arch/x86/index.rst
+++ b/Documentation/arch/x86/index.rst
@@ -43,3 +43,4 @@ x86-specific Documentation
features
elf_auxvec
xstate
+ amd-hfi
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 02/12] MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 01/12] Documentation: x86: Add AMD Hardware Feedback Interface documentation Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 03/12] x86/msr-index: define AMD heterogeneous CPU related MSR Mario Limonciello
` (9 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
Introduce the `amd_hfi` driver into the MAINTAINERS file.
The driver will support AMD Heterogeneous Core design which provides
hardware feedback to the OS scheduler.
Moving forward, Mario will be responsible for the maintenance
and Perry will assist on review of patches related to this driver.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
MAINTAINERS | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index c1fcc56bf2fba..62f384c41b36b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1085,6 +1085,15 @@ F: arch/x86/include/asm/amd_hsmp.h
F: arch/x86/include/uapi/asm/amd_hsmp.h
F: drivers/platform/x86/amd/hsmp/
+AMD HETERO CORE HARDWARE FEEDBACK DRIVER
+M: Mario Limonciello <mario.limonciello@amd.com>
+R: Perry Yuan <perry.yuan@amd.com>
+L: platform-driver-x86@vger.kernel.org
+S: Supported
+B: https://gitlab.freedesktop.org/drm/amd/-/issues
+F: Documentation/arch/x86/amd-hfi.rst
+F: drivers/platform/x86/amd/hfi/
+
AMD IOMMU (AMD-VI)
M: Joerg Roedel <joro@8bytes.org>
R: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 03/12] x86/msr-index: define AMD heterogeneous CPU related MSR
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 01/12] Documentation: x86: Add AMD Hardware Feedback Interface documentation Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 02/12] MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 04/12] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver Mario Limonciello
` (8 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
From: Perry Yuan <perry.yuan@amd.com>
Introduces new MSR registers for AMD hardware feedback support.
These registers enable the system to provide workload classification
and configuration capabilities.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
arch/x86/include/asm/msr-index.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 3ae84c3b8e6db..0cd5ffe50f4a4 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -712,6 +712,11 @@
#define MSR_AMD64_PERF_CNTR_GLOBAL_CTL 0xc0000301
#define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR 0xc0000302
+/* AMD Hardware Feedback Support MSRs */
+#define AMD_WORKLOAD_CLASS_CONFIG 0xc0000500
+#define AMD_WORKLOAD_CLASS_ID 0xc0000501
+#define AMD_WORKLOAD_HRST 0xc0000502
+
/* AMD Last Branch Record MSRs */
#define MSR_AMD64_LBR_SELECT 0xc000010e
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 04/12] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (2 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 03/12] x86/msr-index: define AMD heterogeneous CPU related MSR Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-12-19 14:39 ` Ilpo Järvinen
2024-11-30 15:20 ` [PATCH v7 05/12] platform/x86: hfi: parse CPU core ranking data from shared memory Mario Limonciello
` (7 subsequent siblings)
11 siblings, 1 reply; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan
From: Perry Yuan <Perry.Yuan@amd.com>
The AMD Heterogeneous core design and Hardware Feedback Interface (HFI)
provide behavioral classification and a dynamically updated ranking table
for the scheduler to use when choosing cores for tasks.
There are two CPU core types defined: `Classic Core` and `Dense Core`.
"Classic" cores are the standard performance cores, while "Dense" cores
are optimized for area and efficiency.
Heterogeneous compute refers to CPU implementations that are comprised
of more than one architectural class, each with two capabilities. This
means each CPU reports two separate capabilities: "perf" and "eff".
Each capability lists all core ranking numbers between 0 and 255, where
a higher number represents a higher capability.
Heterogeneous systems can also extend to more than two architectural
classes.
The purpose of the scheduling feedback mechanism is to provide information
to the operating system scheduler in real time, allowing the scheduler to
direct threads to the optimal core during task scheduling.
All core ranking data are provided by the PMFW via a shared memory ranking
table, which the driver reads and uses to update core capabilities to the
scheduler. When the hardware updates the table, it generates a platform
interrupt to notify the OS to read the new ranking table.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v7:
* Adjust Kconfig to 80 characters
---
drivers/platform/x86/amd/Kconfig | 1 +
drivers/platform/x86/amd/Makefile | 1 +
drivers/platform/x86/amd/hfi/Kconfig | 20 ++++
drivers/platform/x86/amd/hfi/Makefile | 7 ++
drivers/platform/x86/amd/hfi/hfi.c | 161 ++++++++++++++++++++++++++
5 files changed, 190 insertions(+)
create mode 100644 drivers/platform/x86/amd/hfi/Kconfig
create mode 100644 drivers/platform/x86/amd/hfi/Makefile
create mode 100644 drivers/platform/x86/amd/hfi/hfi.c
diff --git a/drivers/platform/x86/amd/Kconfig b/drivers/platform/x86/amd/Kconfig
index c3e086ea64fc6..589d61ebf726b 100644
--- a/drivers/platform/x86/amd/Kconfig
+++ b/drivers/platform/x86/amd/Kconfig
@@ -6,6 +6,7 @@
source "drivers/platform/x86/amd/hsmp/Kconfig"
source "drivers/platform/x86/amd/pmf/Kconfig"
source "drivers/platform/x86/amd/pmc/Kconfig"
+source "drivers/platform/x86/amd/hfi/Kconfig"
config AMD_3D_VCACHE
tristate "AMD 3D V-Cache Performance Optimizer Driver"
diff --git a/drivers/platform/x86/amd/Makefile b/drivers/platform/x86/amd/Makefile
index 56f62fc9c97b4..c50e93c3334cf 100644
--- a/drivers/platform/x86/amd/Makefile
+++ b/drivers/platform/x86/amd/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_AMD_PMC) += pmc/
obj-$(CONFIG_AMD_HSMP) += hsmp/
obj-$(CONFIG_AMD_PMF) += pmf/
obj-$(CONFIG_AMD_WBRF) += wbrf.o
+obj-$(CONFIG_AMD_HFI) += hfi/
diff --git a/drivers/platform/x86/amd/hfi/Kconfig b/drivers/platform/x86/amd/hfi/Kconfig
new file mode 100644
index 0000000000000..532939eb08a6a
--- /dev/null
+++ b/drivers/platform/x86/amd/hfi/Kconfig
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# AMD Hardware Feedback Interface Driver
+#
+
+config AMD_HFI
+ bool "AMD Hetero Core Hardware Feedback Driver"
+ depends on ACPI
+ depends on CPU_SUP_AMD
+ help
+ Select this option to enable the AMD Heterogeneous Core Hardware
+ Feedback Interface. If selected, hardware provides runtime thread
+ classification guidance to the operating system on the performance and
+ energy efficiency capabilities of each heterogeneous CPU core. These
+ capabilities may vary due to the inherent differences in the core types
+ and can also change as a result of variations in the operating
+ conditions of the system such as power and thermal limits. If selected,
+ the kernel relays updates in heterogeneous CPUs' capabilities to
+ userspace, allowing for more optimal task scheduling and resource
+ allocation, leveraging the diverse set of cores available.
diff --git a/drivers/platform/x86/amd/hfi/Makefile b/drivers/platform/x86/amd/hfi/Makefile
new file mode 100644
index 0000000000000..672c6ac106e95
--- /dev/null
+++ b/drivers/platform/x86/amd/hfi/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# AMD Hardware Feedback Interface Driver
+#
+
+obj-$(CONFIG_AMD_HFI) += amd_hfi.o
+amd_hfi-objs := hfi.o
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
new file mode 100644
index 0000000000000..2cd71d79a22c9
--- /dev/null
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * AMD Hardware Feedback Interface Driver
+ *
+ * Copyright (C) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
+ *
+ * Authors: Perry Yuan <Perry.Yuan@amd.com>
+ * Mario Limonciello <mario.limonciello@amd.com>
+ */
+
+#define pr_fmt(fmt) "amd-hfi: " fmt
+
+#include <linux/acpi.h>
+#include <linux/cpu.h>
+#include <linux/cpumask.h>
+#include <linux/gfp.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/smp.h>
+
+#define AMD_HFI_DRIVER "amd_hfi"
+#define AMD_HETERO_CPUID_27 0x80000027
+static struct platform_device *device;
+
+struct amd_hfi_data {
+ const char *name;
+ struct device *dev;
+ struct mutex lock;
+};
+
+struct amd_hfi_classes {
+ u32 perf;
+ u32 eff;
+};
+
+/**
+ * struct amd_hfi_cpuinfo - HFI workload class info per CPU
+ * @cpu: cpu index
+ * @cpus: mask of cpus associated with amd_hfi_cpuinfo
+ * @class_index: workload class ID index
+ * @nr_class: max number of workload class supported
+ * @amd_hfi_classes: current cpu workload class ranking data
+ *
+ * Parameters of a logical processor linked with hardware feedback class
+ */
+struct amd_hfi_cpuinfo {
+ int cpu;
+ cpumask_var_t cpus;
+ s16 class_index;
+ u8 nr_class;
+ struct amd_hfi_classes *amd_hfi_classes;
+};
+
+static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
+
+static int amd_hfi_alloc_class_data(struct platform_device *pdev)
+{
+ struct amd_hfi_cpuinfo *hfi_cpuinfo;
+ struct device *dev = &pdev->dev;
+ int idx;
+ int nr_class_id;
+
+ nr_class_id = cpuid_eax(AMD_HETERO_CPUID_27);
+ if (nr_class_id < 0 || nr_class_id > 255) {
+ dev_err(dev, "failed to get number of supported classes: %d\n",
+ nr_class_id);
+ return -EINVAL;
+ }
+
+ for_each_present_cpu(idx) {
+ struct amd_hfi_classes *classes;
+
+ classes = devm_kzalloc(dev,
+ nr_class_id * sizeof(struct amd_hfi_classes),
+ GFP_KERNEL);
+ if (!classes)
+ return -ENOMEM;
+ hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, idx);
+ hfi_cpuinfo->amd_hfi_classes = classes;
+ hfi_cpuinfo->nr_class = nr_class_id;
+ }
+
+ return 0;
+}
+
+static const struct acpi_device_id amd_hfi_platform_match[] = {
+ {"AMDI0104", 0},
+ { }
+};
+MODULE_DEVICE_TABLE(acpi, amd_hfi_platform_match);
+
+static int amd_hfi_probe(struct platform_device *pdev)
+{
+ struct amd_hfi_data *amd_hfi_data;
+ int ret;
+
+ if (!acpi_match_device(amd_hfi_platform_match, &pdev->dev))
+ return -ENODEV;
+
+ amd_hfi_data = devm_kzalloc(&pdev->dev, sizeof(*amd_hfi_data), GFP_KERNEL);
+ if (!amd_hfi_data)
+ return -ENOMEM;
+
+ amd_hfi_data->dev = &pdev->dev;
+ ret = devm_mutex_init(&pdev->dev, &amd_hfi_data->lock);
+ if (ret)
+ return ret;
+ platform_set_drvdata(pdev, amd_hfi_data);
+
+ ret = amd_hfi_alloc_class_data(pdev);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static struct platform_driver amd_hfi_driver = {
+ .driver = {
+ .name = AMD_HFI_DRIVER,
+ .owner = THIS_MODULE,
+ .acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
+ },
+ .probe = amd_hfi_probe,
+};
+
+static int __init amd_hfi_init(void)
+{
+ int ret;
+
+ if (acpi_disabled ||
+ !cpu_feature_enabled(X86_FEATURE_AMD_HETEROGENEOUS_CORES) ||
+ !cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
+ return -ENODEV;
+
+ device = platform_device_register_simple(AMD_HFI_DRIVER, -1, NULL, 0);
+ if (IS_ERR(device)) {
+ pr_err("unable to register HFI platform device\n");
+ return PTR_ERR(device);
+ }
+
+ ret = platform_driver_register(&amd_hfi_driver);
+ if (ret)
+ pr_err("failed to register HFI driver\n");
+
+ return ret;
+}
+
+static __exit void amd_hfi_exit(void)
+{
+ platform_device_unregister(device);
+ platform_driver_unregister(&amd_hfi_driver);
+}
+module_init(amd_hfi_init);
+module_exit(amd_hfi_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("AMD Hardware Feedback Interface Driver");
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 05/12] platform/x86: hfi: parse CPU core ranking data from shared memory
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (3 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 04/12] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-12-19 14:53 ` Ilpo Järvinen
2024-11-30 15:20 ` [PATCH v7 06/12] platform/x86: hfi: init per-cpu scores for each class Mario Limonciello
` (6 subsequent siblings)
11 siblings, 1 reply; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan
From: Perry Yuan <Perry.Yuan@amd.com>
When `amd_hfi` driver is loaded, it will use PCCT subspace type 4 table
to retrieve the shared memory address which contains the CPU core ranking
table. This table includes a header that specifies the number of ranking
data entries to be parsed and rank each CPU core with the Performance and
Energy Efficiency capability as implemented by the CPU power management
firmware.
Once the table has been parsed, each CPU is assigned a ranking score
within its class. Subsequently, when the scheduler selects cores, it
chooses from the ranking list based on the assigned scores in each class,
thereby ensuring the optimal selection of CPU cores according to their
predefined classifications and priorities.
Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
* Drop __packed
---
drivers/platform/x86/amd/hfi/hfi.c | 196 +++++++++++++++++++++++++++++
1 file changed, 196 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 2cd71d79a22c9..3c90e93fd192c 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -18,20 +18,72 @@
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/mailbox_client.h>
#include <linux/mutex.h>
+#include <linux/percpu-defs.h>
#include <linux/platform_device.h>
#include <linux/smp.h>
+#include <linux/topology.h>
+#include <linux/workqueue.h>
+
+#include <asm/cpu_device_id.h>
+
+#include <acpi/pcc.h>
+#include <acpi/cppc_acpi.h>
#define AMD_HFI_DRIVER "amd_hfi"
+#define AMD_HFI_MAILBOX_COUNT 1
+#define AMD_HETERO_RANKING_TABLE_VER 2
+
#define AMD_HETERO_CPUID_27 0x80000027
+
static struct platform_device *device;
+/**
+ * struct amd_shmem_info - Shared memory table for AMD HFI
+ *
+ * @header: The PCCT table header including signature, length flags and command.
+ * @version_number: Version number of the table
+ * @n_logical_processors: Number of logical processors
+ * @n_capabilities: Number of ranking dimensions (performance, efficiency, etc)
+ * @table_update_context: Command being sent over the subspace
+ * @n_bitmaps: Number of 32-bit bitmaps to enumerate all the APIC IDs
+ * This is based on the maximum APIC ID enumerated in the system
+ * @reserved: 24 bit spare
+ * @table_data: Bit Map(s) of enabled logical processors
+ * Followed by the ranking data for each logical processor
+ */
+struct amd_shmem_info {
+ struct acpi_pcct_ext_pcc_shared_memory header;
+ u32 version_number :8,
+ n_logical_processors :8,
+ n_capabilities :8,
+ table_update_context :8;
+ u32 n_bitmaps :8,
+ reserved :24;
+ u32 table_data[];
+};
+
struct amd_hfi_data {
const char *name;
struct device *dev;
struct mutex lock;
+
+ /* PCCT table related*/
+ struct pcc_mbox_chan *pcc_chan;
+ void __iomem *pcc_comm_addr;
+ struct acpi_subtable_header *pcct_entry;
+ struct amd_shmem_info *shmem;
};
+/**
+ * struct amd_hfi_classes - HFI class capabilities per CPU
+ * @perf: Performance capability
+ * @eff: Power efficiency capability
+ *
+ * Capabilities of a logical processor in the ranking table. These capabilities
+ * are unitless and specific to each HFI class.
+ */
struct amd_hfi_classes {
u32 perf;
u32 eff;
@@ -40,23 +92,105 @@ struct amd_hfi_classes {
/**
* struct amd_hfi_cpuinfo - HFI workload class info per CPU
* @cpu: cpu index
+ * @apic_id: apic id of the current cpu
* @cpus: mask of cpus associated with amd_hfi_cpuinfo
* @class_index: workload class ID index
* @nr_class: max number of workload class supported
+ * @ipcc_scores: ipcc scores for each class
* @amd_hfi_classes: current cpu workload class ranking data
*
* Parameters of a logical processor linked with hardware feedback class
*/
struct amd_hfi_cpuinfo {
int cpu;
+ u32 apic_id;
cpumask_var_t cpus;
s16 class_index;
u8 nr_class;
+ int *ipcc_scores;
struct amd_hfi_classes *amd_hfi_classes;
};
static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
+static int find_cpu_index_by_apicid(unsigned int target_apicid)
+{
+ int cpu_index;
+
+ for_each_present_cpu(cpu_index) {
+ struct cpuinfo_x86 *info = &cpu_data(cpu_index);
+
+ if (info->topo.apicid == target_apicid) {
+ pr_debug("match APIC id %d for CPU index: %d\n",
+ info->topo.apicid, cpu_index);
+ return cpu_index;
+ }
+ }
+
+ return -ENODEV;
+}
+
+static int amd_hfi_fill_metadata(struct amd_hfi_data *amd_hfi_data)
+{
+ struct acpi_pcct_ext_pcc_slave *pcct_ext =
+ (struct acpi_pcct_ext_pcc_slave *)amd_hfi_data->pcct_entry;
+ void __iomem *pcc_comm_addr;
+
+ pcc_comm_addr = acpi_os_ioremap(amd_hfi_data->pcc_chan->shmem_base_addr,
+ amd_hfi_data->pcc_chan->shmem_size);
+ if (!pcc_comm_addr) {
+ pr_err("failed to ioremap PCC common region mem\n");
+ return -ENOMEM;
+ }
+
+ memcpy_fromio(amd_hfi_data->shmem, pcc_comm_addr, pcct_ext->length);
+ iounmap(pcc_comm_addr);
+
+ if (amd_hfi_data->shmem->header.signature != PCC_SIGNATURE) {
+ pr_err("invalid signature in shared memory\n");
+ return -EINVAL;
+ }
+ if (amd_hfi_data->shmem->version_number != AMD_HETERO_RANKING_TABLE_VER) {
+ pr_err("invalid version %d\n", amd_hfi_data->shmem->version_number);
+ return -EINVAL;
+ }
+
+ for (unsigned int i = 0; i < amd_hfi_data->shmem->n_bitmaps; i++) {
+ u32 bitmap = amd_hfi_data->shmem->table_data[i];
+
+ for (unsigned int j = 0; j < BITS_PER_TYPE(u32); j++) {
+ struct amd_hfi_cpuinfo *info;
+ int apic_id = i * BITS_PER_TYPE(u32) + j;
+ int cpu_index;
+
+ if (!(bitmap & BIT(j)))
+ continue;
+
+ cpu_index = find_cpu_index_by_apicid(apic_id);
+ if (cpu_index < 0) {
+ pr_warn("APIC ID %d not found\n", apic_id);
+ continue;
+ }
+
+ info = per_cpu_ptr(&amd_hfi_cpuinfo, cpu_index);
+ info->apic_id = apic_id;
+
+ /* Fill the ranking data for each logical processor */
+ info = per_cpu_ptr(&amd_hfi_cpuinfo, cpu_index);
+ for (unsigned int k = 0; k < info->nr_class; k++) {
+ u32 *table = amd_hfi_data->shmem->table_data +
+ amd_hfi_data->shmem->n_bitmaps +
+ i * info->nr_class;
+
+ info->amd_hfi_classes[k].eff = table[apic_id + 2 * k];
+ info->amd_hfi_classes[k].perf = table[apic_id + 2 * k + 1];
+ }
+ }
+ }
+
+ return 0;
+}
+
static int amd_hfi_alloc_class_data(struct platform_device *pdev)
{
struct amd_hfi_cpuinfo *hfi_cpuinfo;
@@ -73,20 +207,78 @@ static int amd_hfi_alloc_class_data(struct platform_device *pdev)
for_each_present_cpu(idx) {
struct amd_hfi_classes *classes;
+ int *ipcc_scores;
classes = devm_kzalloc(dev,
nr_class_id * sizeof(struct amd_hfi_classes),
GFP_KERNEL);
if (!classes)
return -ENOMEM;
+ ipcc_scores = devm_kcalloc(dev, nr_class_id, sizeof(int), GFP_KERNEL);
+ if (!ipcc_scores)
+ return -ENOMEM;
hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, idx);
hfi_cpuinfo->amd_hfi_classes = classes;
+ hfi_cpuinfo->ipcc_scores = ipcc_scores;
hfi_cpuinfo->nr_class = nr_class_id;
}
return 0;
}
+static int amd_hfi_metadata_parser(struct platform_device *pdev,
+ struct amd_hfi_data *amd_hfi_data)
+{
+ struct acpi_pcct_ext_pcc_slave *pcct_ext;
+ struct acpi_subtable_header *pcct_entry;
+ struct mbox_chan *pcc_mbox_channels;
+ struct acpi_table_header *pcct_tbl;
+ struct pcc_mbox_chan *pcc_chan;
+ acpi_status status;
+ int ret;
+
+ pcc_mbox_channels = devm_kcalloc(&pdev->dev, AMD_HFI_MAILBOX_COUNT,
+ sizeof(*pcc_mbox_channels), GFP_KERNEL);
+ if (!pcc_mbox_channels)
+ return -ENOMEM;
+
+ pcc_chan = devm_kcalloc(&pdev->dev, AMD_HFI_MAILBOX_COUNT,
+ sizeof(*pcc_chan), GFP_KERNEL);
+ if (!pcc_chan)
+ return -ENOMEM;
+
+ status = acpi_get_table(ACPI_SIG_PCCT, 0, &pcct_tbl);
+ if (ACPI_FAILURE(status) || !pcct_tbl)
+ return -ENODEV;
+
+ /* get pointer to the first PCC subspace entry */
+ pcct_entry = (struct acpi_subtable_header *) (
+ (unsigned long)pcct_tbl + sizeof(struct acpi_table_pcct));
+
+ pcc_chan->mchan = &pcc_mbox_channels[0];
+
+ amd_hfi_data->pcc_chan = pcc_chan;
+ amd_hfi_data->pcct_entry = pcct_entry;
+ pcct_ext = (struct acpi_pcct_ext_pcc_slave *)pcct_entry;
+
+ if (pcct_ext->length <= 0)
+ return -EINVAL;
+
+ amd_hfi_data->shmem = devm_kzalloc(amd_hfi_data->dev, pcct_ext->length, GFP_KERNEL);
+ if (!amd_hfi_data->shmem)
+ return -ENOMEM;
+
+ pcc_chan->shmem_base_addr = pcct_ext->base_address;
+ pcc_chan->shmem_size = pcct_ext->length;
+
+ /* parse the shared memory info from the pcct table */
+ ret = amd_hfi_fill_metadata(amd_hfi_data);
+
+ acpi_put_table(pcct_tbl);
+
+ return ret;
+}
+
static const struct acpi_device_id amd_hfi_platform_match[] = {
{"AMDI0104", 0},
{ }
@@ -115,6 +307,10 @@ static int amd_hfi_probe(struct platform_device *pdev)
if (ret)
return ret;
+ ret = amd_hfi_metadata_parser(pdev, amd_hfi_data);
+ if (ret)
+ return ret;
+
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 06/12] platform/x86: hfi: init per-cpu scores for each class
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (4 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 05/12] platform/x86: hfi: parse CPU core ranking data from shared memory Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 07/12] platform/x86: hfi: add online and offline callback support Mario Limonciello
` (5 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan
From: Perry Yuan <Perry.Yuan@amd.com>
Initialize per cpu score `amd_hfi_ipcc_scores` which store energy score
and performance score data for each class.
`Classic core` and `Dense core` are ranked according to those values as
energy efficiency capability or performance capability.
OS scheduler will pick cores from the ranking list on each class ID for
the thread which provide the class id got from hardware feedback
interface.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v7:
* Drop mutex, move to proper patch
---
drivers/platform/x86/amd/hfi/hfi.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 3c90e93fd192c..9671f07c76390 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -226,6 +226,31 @@ static int amd_hfi_alloc_class_data(struct platform_device *pdev)
return 0;
}
+static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
+{
+ for (int i = 0; i < hfi_cpuinfo->nr_class; i++)
+ WRITE_ONCE(hfi_cpuinfo->ipcc_scores[i],
+ hfi_cpuinfo->amd_hfi_classes[i].perf);
+
+ return 0;
+}
+
+static int update_hfi_ipcc_scores(void)
+{
+ int cpu;
+ int ret;
+
+ for_each_present_cpu(cpu) {
+ struct amd_hfi_cpuinfo *hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, cpu);
+
+ ret = amd_set_hfi_ipcc_score(hfi_cpuinfo, cpu);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static int amd_hfi_metadata_parser(struct platform_device *pdev,
struct amd_hfi_data *amd_hfi_data)
{
@@ -311,6 +336,10 @@ static int amd_hfi_probe(struct platform_device *pdev)
if (ret)
return ret;
+ ret = update_hfi_ipcc_scores();
+ if (ret)
+ return ret;
+
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 07/12] platform/x86: hfi: add online and offline callback support
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (5 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 06/12] platform/x86: hfi: init per-cpu scores for each class Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 08/12] platform/x86: hfi: add power management callback Mario Limonciello
` (4 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan
From: Perry Yuan <Perry.Yuan@amd.com>
There are some firmware parameters that need to be configured
when a CPU core is brought online or offline.
when CPU is online, it will initialize the workload classification
parameters to CPU firmware which will trigger the workload class ID
updating function.
Once the CPU is going to offline, it will need to disable the workload
classification function and clear the history.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v7:
* move mutex to this patch
---
drivers/platform/x86/amd/hfi/hfi.c | 81 ++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 9671f07c76390..922a9ff0d447a 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -113,6 +113,8 @@ struct amd_hfi_cpuinfo {
static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
+static DEFINE_MUTEX(hfi_cpuinfo_lock);
+
static int find_cpu_index_by_apicid(unsigned int target_apicid)
{
int cpu_index;
@@ -235,6 +237,80 @@ static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
return 0;
}
+static int amd_hfi_set_state(unsigned int cpu, bool state)
+{
+ int ret;
+
+ ret = wrmsrl_on_cpu(cpu, AMD_WORKLOAD_CLASS_CONFIG, state);
+ if (ret)
+ return ret;
+
+ return wrmsrl_on_cpu(cpu, AMD_WORKLOAD_HRST, 0x1);
+}
+
+/**
+ * amd_hfi_online() - Enable workload classification on @cpu
+ * @cpu: CPU in which the workload classification will be enabled
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int amd_hfi_online(unsigned int cpu)
+{
+ struct amd_hfi_cpuinfo *hfi_info = per_cpu_ptr(&amd_hfi_cpuinfo, cpu);
+ struct amd_hfi_classes *hfi_classes;
+ int ret;
+
+ if (WARN_ON_ONCE(!hfi_info))
+ return -EINVAL;
+
+ /*
+ * Check if @cpu as an associated, initialized and ranking data must be filled
+ */
+ hfi_classes = hfi_info->amd_hfi_classes;
+ if (!hfi_classes)
+ return -EINVAL;
+
+ guard(mutex)(&hfi_cpuinfo_lock);
+
+ if (!zalloc_cpumask_var(&hfi_info->cpus, GFP_KERNEL))
+ return -ENOMEM;
+
+ cpumask_set_cpu(cpu, hfi_info->cpus);
+
+ ret = amd_hfi_set_state(cpu, true);
+ if (ret)
+ pr_err("WCT enable failed for CPU %d\n", cpu);
+
+ return ret;
+}
+
+/**
+ * amd_hfi_offline() - Disable workload classification on @cpu
+ * @cpu: CPU in which the workload classification will be disabled
+ *
+ * Remove @cpu from those covered by its HFI instance.
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int amd_hfi_offline(unsigned int cpu)
+{
+ struct amd_hfi_cpuinfo *hfi_info = &per_cpu(amd_hfi_cpuinfo, cpu);
+ int ret;
+
+ if (WARN_ON_ONCE(!hfi_info))
+ return -EINVAL;
+
+ guard(mutex)(&hfi_cpuinfo_lock);
+
+ ret = amd_hfi_set_state(cpu, false);
+ if (ret)
+ pr_err("WCT disable failed for CPU %d\n", cpu);
+
+ free_cpumask_var(hfi_info->cpus);
+
+ return ret;
+}
+
static int update_hfi_ipcc_scores(void)
{
int cpu;
@@ -340,6 +416,11 @@ static int amd_hfi_probe(struct platform_device *pdev)
if (ret)
return ret;
+ ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/amd_hfi:online",
+ amd_hfi_online, amd_hfi_offline);
+ if (ret < 0)
+ return ret;
+
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 08/12] platform/x86: hfi: add power management callback
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (6 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 07/12] platform/x86: hfi: add online and offline callback support Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 09/12] x86/process: Clear hardware feedback history for AMD processors Mario Limonciello
` (3 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan
From: Perry Yuan <Perry.Yuan@amd.com>
Introduces power management callbacks for the `amd_hfi` driver.
Specifically, the `suspend` and `resume` callbacks have been added
to handle the necessary operations during system low power states
and wake-up.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/platform/x86/amd/hfi/hfi.c | 33 ++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 922a9ff0d447a..80ccc50ee0914 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -380,6 +380,38 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
return ret;
}
+static int amd_hfi_pm_resume(struct device *dev)
+{
+ int ret, cpu;
+
+ for_each_online_cpu(cpu) {
+ ret = amd_hfi_set_state(cpu, true);
+ if (ret < 0) {
+ dev_err(dev, "failed to enable workload class config: %d\n", ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int amd_hfi_pm_suspend(struct device *dev)
+{
+ int ret, cpu;
+
+ for_each_online_cpu(cpu) {
+ ret = amd_hfi_set_state(cpu, false);
+ if (ret < 0) {
+ dev_err(dev, "failed to disable workload class config: %d\n", ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(amd_hfi_pm_ops, amd_hfi_pm_suspend, amd_hfi_pm_resume);
+
static const struct acpi_device_id amd_hfi_platform_match[] = {
{"AMDI0104", 0},
{ }
@@ -428,6 +460,7 @@ static struct platform_driver amd_hfi_driver = {
.driver = {
.name = AMD_HFI_DRIVER,
.owner = THIS_MODULE,
+ .pm = &amd_hfi_pm_ops,
.acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
},
.probe = amd_hfi_probe,
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 09/12] x86/process: Clear hardware feedback history for AMD processors
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (7 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 08/12] platform/x86: hfi: add power management callback Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 10/12] cpufreq/amd-pstate: Disable preferred cores on designs with workload classification Mario Limonciello
` (2 subsequent siblings)
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
From: Perry Yuan <perry.yuan@amd.com>
Incorporate a mechanism within the context switching code to reset
the hardware history for AMD processors. Specifically, when a task
is switched in, the class ID was read and reset the hardware workload
classification history of CPU firmware and then it start to trigger
workload classification for the next running thread.
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
arch/x86/kernel/process_32.c | 4 ++++
arch/x86/kernel/process_64.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 0917c7f25720b..0bb6391b9089b 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -213,6 +213,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
/* Load the Intel cache allocation PQR MSR. */
resctrl_sched_in(next_p);
+ /* Reset hw history on AMD CPUs */
+ if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
+ wrmsrl(AMD_WORKLOAD_HRST, 0x1);
+
return prev_p;
}
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 226472332a70d..371e0e8f987fa 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -709,6 +709,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
/* Load the Intel cache allocation PQR MSR. */
resctrl_sched_in(next_p);
+ /* Reset hw history on AMD CPUs */
+ if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
+ wrmsrl(AMD_WORKLOAD_HRST, 0x1);
+
return prev_p;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 10/12] cpufreq/amd-pstate: Disable preferred cores on designs with workload classification
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (8 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 09/12] x86/process: Clear hardware feedback history for AMD processors Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 11/12] platform/x86/amd: hfi: Set ITMT priority from ranking data Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support Mario Limonciello
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
On designs that have workload classification, it's preferred that
the amd-hfi driver is used to provide hints to the scheduler of
which cores to use instead of the amd-pstate driver.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Reviewed-by: Perry Yuan <perry.yuan@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/cpufreq/amd-pstate.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index d7630bab2516f..6039c719961d6 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -788,6 +788,12 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
/* user disabled or not detected */
if (!amd_pstate_prefcore)
return;
+ /* should use amd-hfi instead */
+ if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) &&
+ IS_ENABLED(CONFIG_AMD_HFI)) {
+ amd_pstate_prefcore = false;
+ return;
+ }
cpudata->hw_prefcore = true;
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 11/12] platform/x86/amd: hfi: Set ITMT priority from ranking data
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (9 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 10/12] cpufreq/amd-pstate: Disable preferred cores on designs with workload classification Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support Mario Limonciello
11 siblings, 0 replies; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
The static ranking data that is read at module load should be used
to set up the priorities for the cores relative to the performance
values.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/platform/x86/amd/hfi/Kconfig | 1 +
drivers/platform/x86/amd/hfi/hfi.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/Kconfig b/drivers/platform/x86/amd/hfi/Kconfig
index 532939eb08a6a..045f598f4866c 100644
--- a/drivers/platform/x86/amd/hfi/Kconfig
+++ b/drivers/platform/x86/amd/hfi/Kconfig
@@ -7,6 +7,7 @@ config AMD_HFI
bool "AMD Hetero Core Hardware Feedback Driver"
depends on ACPI
depends on CPU_SUP_AMD
+ depends on SCHED_MC_PRIO
help
Select this option to enable the AMD Heterogeneous Core Hardware
Feedback Interface. If selected, hardware provides runtime thread
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 80ccc50ee0914..0940950dd7adc 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -115,6 +115,12 @@ static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index =
static DEFINE_MUTEX(hfi_cpuinfo_lock);
+static void amd_hfi_sched_itmt_work(struct work_struct *work)
+{
+ sched_set_itmt_support();
+}
+static DECLARE_WORK(sched_amd_hfi_itmt_work, amd_hfi_sched_itmt_work);
+
static int find_cpu_index_by_apicid(unsigned int target_apicid)
{
int cpu_index;
@@ -234,6 +240,8 @@ static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
WRITE_ONCE(hfi_cpuinfo->ipcc_scores[i],
hfi_cpuinfo->amd_hfi_classes[i].perf);
+ sched_set_itmt_core_prio(hfi_cpuinfo->ipcc_scores[0], cpu);
+
return 0;
}
@@ -453,6 +461,8 @@ static int amd_hfi_probe(struct platform_device *pdev)
if (ret < 0)
return ret;
+ schedule_work(&sched_amd_hfi_itmt_work);
+
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
` (10 preceding siblings ...)
2024-11-30 15:20 ` [PATCH v7 11/12] platform/x86/amd: hfi: Set ITMT priority from ranking data Mario Limonciello
@ 2024-11-30 15:20 ` Mario Limonciello
2024-12-19 14:59 ` Ilpo Järvinen
11 siblings, 1 reply; 17+ messages in thread
From: Mario Limonciello @ 2024-11-30 15:20 UTC (permalink / raw)
To: Borislav Petkov, Hans de Goede, Ilpo Järvinen
Cc: x86, Gautham R . Shenoy, Mario Limonciello, Perry Yuan,
linux-kernel, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
Add a dump of the class and capabilities table to debugfs to assist
with debugging scheduler issues.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/platform/x86/amd/hfi/hfi.c | 36 ++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index 0940950dd7adc..b6dc379bfd546 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -13,6 +13,7 @@
#include <linux/acpi.h>
#include <linux/cpu.h>
#include <linux/cpumask.h>
+#include <linux/debugfs.h>
#include <linux/gfp.h>
#include <linux/init.h>
#include <linux/io.h>
@@ -74,6 +75,8 @@ struct amd_hfi_data {
void __iomem *pcc_comm_addr;
struct acpi_subtable_header *pcct_entry;
struct amd_shmem_info *shmem;
+
+ struct dentry *dbgfs_dir;
};
/**
@@ -234,6 +237,13 @@ static int amd_hfi_alloc_class_data(struct platform_device *pdev)
return 0;
}
+static void amd_hfi_remove(struct platform_device *pdev)
+{
+ struct amd_hfi_data *dev = platform_get_drvdata(pdev);
+
+ debugfs_remove_recursive(dev->dbgfs_dir);
+}
+
static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
{
for (int i = 0; i < hfi_cpuinfo->nr_class; i++)
@@ -388,6 +398,27 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
return ret;
}
+static int class_capabilities_show(struct seq_file *s, void *unused)
+{
+ int cpu, idx;
+
+ seq_puts(s, "CPU #\tWLC\tPerf\tEff\n");
+ for_each_present_cpu(cpu) {
+ struct amd_hfi_cpuinfo *hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, cpu);
+
+ seq_printf(s, "%d", cpu);
+ for (idx = 0; idx < hfi_cpuinfo->nr_class; idx++) {
+ seq_printf(s, "\t%d\t%d\t%d\n",
+ idx,
+ hfi_cpuinfo->amd_hfi_classes[idx].perf,
+ hfi_cpuinfo->amd_hfi_classes[idx].eff);
+ }
+ }
+
+ return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(class_capabilities);
+
static int amd_hfi_pm_resume(struct device *dev)
{
int ret, cpu;
@@ -463,6 +494,10 @@ static int amd_hfi_probe(struct platform_device *pdev)
schedule_work(&sched_amd_hfi_itmt_work);
+ amd_hfi_data->dbgfs_dir = debugfs_create_dir("amd_hfi", arch_debugfs_dir);
+ debugfs_create_file("class_capabilities", 0644, amd_hfi_data->dbgfs_dir, pdev,
+ &class_capabilities_fops);
+
return 0;
}
@@ -474,6 +509,7 @@ static struct platform_driver amd_hfi_driver = {
.acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
},
.probe = amd_hfi_probe,
+ .remove = amd_hfi_remove,
};
static int __init amd_hfi_init(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v7 04/12] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver
2024-11-30 15:20 ` [PATCH v7 04/12] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver Mario Limonciello
@ 2024-12-19 14:39 ` Ilpo Järvinen
0 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2024-12-19 14:39 UTC (permalink / raw)
To: Mario Limonciello
Cc: Borislav Petkov, Hans de Goede, x86, Gautham R . Shenoy,
Perry Yuan, LKML, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan
On Sat, 30 Nov 2024, Mario Limonciello wrote:
> From: Perry Yuan <Perry.Yuan@amd.com>
>
> The AMD Heterogeneous core design and Hardware Feedback Interface (HFI)
> provide behavioral classification and a dynamically updated ranking table
> for the scheduler to use when choosing cores for tasks.
>
> There are two CPU core types defined: `Classic Core` and `Dense Core`.
> "Classic" cores are the standard performance cores, while "Dense" cores
> are optimized for area and efficiency.
>
> Heterogeneous compute refers to CPU implementations that are comprised
> of more than one architectural class, each with two capabilities. This
> means each CPU reports two separate capabilities: "perf" and "eff".
>
> Each capability lists all core ranking numbers between 0 and 255, where
> a higher number represents a higher capability.
>
> Heterogeneous systems can also extend to more than two architectural
> classes.
>
> The purpose of the scheduling feedback mechanism is to provide information
> to the operating system scheduler in real time, allowing the scheduler to
> direct threads to the optimal core during task scheduling.
>
> All core ranking data are provided by the PMFW via a shared memory ranking
> table, which the driver reads and uses to update core capabilities to the
> scheduler. When the hardware updates the table, it generates a platform
> interrupt to notify the OS to read the new ranking table.
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Signed-off-by: Perry Yuan <perry.yuan@amd.com>
> Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
> Reviewed-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> v7:
> * Adjust Kconfig to 80 characters
> ---
> drivers/platform/x86/amd/Kconfig | 1 +
> drivers/platform/x86/amd/Makefile | 1 +
> drivers/platform/x86/amd/hfi/Kconfig | 20 ++++
> drivers/platform/x86/amd/hfi/Makefile | 7 ++
> drivers/platform/x86/amd/hfi/hfi.c | 161 ++++++++++++++++++++++++++
> 5 files changed, 190 insertions(+)
> create mode 100644 drivers/platform/x86/amd/hfi/Kconfig
> create mode 100644 drivers/platform/x86/amd/hfi/Makefile
> create mode 100644 drivers/platform/x86/amd/hfi/hfi.c
>
> diff --git a/drivers/platform/x86/amd/Kconfig b/drivers/platform/x86/amd/Kconfig
> index c3e086ea64fc6..589d61ebf726b 100644
> --- a/drivers/platform/x86/amd/Kconfig
> +++ b/drivers/platform/x86/amd/Kconfig
> @@ -6,6 +6,7 @@
> source "drivers/platform/x86/amd/hsmp/Kconfig"
> source "drivers/platform/x86/amd/pmf/Kconfig"
> source "drivers/platform/x86/amd/pmc/Kconfig"
> +source "drivers/platform/x86/amd/hfi/Kconfig"
>
> config AMD_3D_VCACHE
> tristate "AMD 3D V-Cache Performance Optimizer Driver"
> diff --git a/drivers/platform/x86/amd/Makefile b/drivers/platform/x86/amd/Makefile
> index 56f62fc9c97b4..c50e93c3334cf 100644
> --- a/drivers/platform/x86/amd/Makefile
> +++ b/drivers/platform/x86/amd/Makefile
> @@ -10,3 +10,4 @@ obj-$(CONFIG_AMD_PMC) += pmc/
> obj-$(CONFIG_AMD_HSMP) += hsmp/
> obj-$(CONFIG_AMD_PMF) += pmf/
> obj-$(CONFIG_AMD_WBRF) += wbrf.o
> +obj-$(CONFIG_AMD_HFI) += hfi/
> diff --git a/drivers/platform/x86/amd/hfi/Kconfig b/drivers/platform/x86/amd/hfi/Kconfig
> new file mode 100644
> index 0000000000000..532939eb08a6a
> --- /dev/null
> +++ b/drivers/platform/x86/amd/hfi/Kconfig
> @@ -0,0 +1,20 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +# AMD Hardware Feedback Interface Driver
> +#
> +
> +config AMD_HFI
> + bool "AMD Hetero Core Hardware Feedback Driver"
> + depends on ACPI
> + depends on CPU_SUP_AMD
> + help
> + Select this option to enable the AMD Heterogeneous Core Hardware
> + Feedback Interface. If selected, hardware provides runtime thread
> + classification guidance to the operating system on the performance and
> + energy efficiency capabilities of each heterogeneous CPU core. These
> + capabilities may vary due to the inherent differences in the core types
> + and can also change as a result of variations in the operating
> + conditions of the system such as power and thermal limits. If selected,
> + the kernel relays updates in heterogeneous CPUs' capabilities to
> + userspace, allowing for more optimal task scheduling and resource
> + allocation, leveraging the diverse set of cores available.
> diff --git a/drivers/platform/x86/amd/hfi/Makefile b/drivers/platform/x86/amd/hfi/Makefile
> new file mode 100644
> index 0000000000000..672c6ac106e95
> --- /dev/null
> +++ b/drivers/platform/x86/amd/hfi/Makefile
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# AMD Hardware Feedback Interface Driver
> +#
> +
> +obj-$(CONFIG_AMD_HFI) += amd_hfi.o
> +amd_hfi-objs := hfi.o
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> new file mode 100644
> index 0000000000000..2cd71d79a22c9
> --- /dev/null
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -0,0 +1,161 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * AMD Hardware Feedback Interface Driver
> + *
> + * Copyright (C) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
> + *
> + * Authors: Perry Yuan <Perry.Yuan@amd.com>
> + * Mario Limonciello <mario.limonciello@amd.com>
> + */
> +
> +#define pr_fmt(fmt) "amd-hfi: " fmt
> +
> +#include <linux/acpi.h>
> +#include <linux/cpu.h>
> +#include <linux/cpumask.h>
> +#include <linux/gfp.h>
> +#include <linux/init.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +#include <linux/smp.h>
> +
> +#define AMD_HFI_DRIVER "amd_hfi"
> +#define AMD_HETERO_CPUID_27 0x80000027
> +static struct platform_device *device;
> +
> +struct amd_hfi_data {
> + const char *name;
> + struct device *dev;
> + struct mutex lock;
> +};
> +
> +struct amd_hfi_classes {
> + u32 perf;
> + u32 eff;
> +};
> +
> +/**
> + * struct amd_hfi_cpuinfo - HFI workload class info per CPU
> + * @cpu: cpu index
> + * @cpus: mask of cpus associated with amd_hfi_cpuinfo
> + * @class_index: workload class ID index
> + * @nr_class: max number of workload class supported
> + * @amd_hfi_classes: current cpu workload class ranking data
> + *
> + * Parameters of a logical processor linked with hardware feedback class
> + */
> +struct amd_hfi_cpuinfo {
> + int cpu;
> + cpumask_var_t cpus;
> + s16 class_index;
> + u8 nr_class;
> + struct amd_hfi_classes *amd_hfi_classes;
> +};
> +
> +static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
> +
> +static int amd_hfi_alloc_class_data(struct platform_device *pdev)
> +{
> + struct amd_hfi_cpuinfo *hfi_cpuinfo;
> + struct device *dev = &pdev->dev;
> + int idx;
> + int nr_class_id;
> +
> + nr_class_id = cpuid_eax(AMD_HETERO_CPUID_27);
> + if (nr_class_id < 0 || nr_class_id > 255) {
> + dev_err(dev, "failed to get number of supported classes: %d\n",
> + nr_class_id);
> + return -EINVAL;
> + }
> +
> + for_each_present_cpu(idx) {
> + struct amd_hfi_classes *classes;
> +
> + classes = devm_kzalloc(dev,
> + nr_class_id * sizeof(struct amd_hfi_classes),
> + GFP_KERNEL);
devm_kcalloc()?
--
i.
> + if (!classes)
> + return -ENOMEM;
> + hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, idx);
> + hfi_cpuinfo->amd_hfi_classes = classes;
> + hfi_cpuinfo->nr_class = nr_class_id;
> + }
> +
> + return 0;
> +}
> +
> +static const struct acpi_device_id amd_hfi_platform_match[] = {
> + {"AMDI0104", 0},
> + { }
> +};
> +MODULE_DEVICE_TABLE(acpi, amd_hfi_platform_match);
> +
> +static int amd_hfi_probe(struct platform_device *pdev)
> +{
> + struct amd_hfi_data *amd_hfi_data;
> + int ret;
> +
> + if (!acpi_match_device(amd_hfi_platform_match, &pdev->dev))
> + return -ENODEV;
> +
> + amd_hfi_data = devm_kzalloc(&pdev->dev, sizeof(*amd_hfi_data), GFP_KERNEL);
> + if (!amd_hfi_data)
> + return -ENOMEM;
> +
> + amd_hfi_data->dev = &pdev->dev;
> + ret = devm_mutex_init(&pdev->dev, &amd_hfi_data->lock);
> + if (ret)
> + return ret;
> + platform_set_drvdata(pdev, amd_hfi_data);
> +
> + ret = amd_hfi_alloc_class_data(pdev);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> +
> +static struct platform_driver amd_hfi_driver = {
> + .driver = {
> + .name = AMD_HFI_DRIVER,
> + .owner = THIS_MODULE,
> + .acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
> + },
> + .probe = amd_hfi_probe,
> +};
> +
> +static int __init amd_hfi_init(void)
> +{
> + int ret;
> +
> + if (acpi_disabled ||
> + !cpu_feature_enabled(X86_FEATURE_AMD_HETEROGENEOUS_CORES) ||
> + !cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
> + return -ENODEV;
> +
> + device = platform_device_register_simple(AMD_HFI_DRIVER, -1, NULL, 0);
> + if (IS_ERR(device)) {
> + pr_err("unable to register HFI platform device\n");
> + return PTR_ERR(device);
> + }
> +
> + ret = platform_driver_register(&amd_hfi_driver);
> + if (ret)
> + pr_err("failed to register HFI driver\n");
> +
> + return ret;
> +}
> +
> +static __exit void amd_hfi_exit(void)
> +{
> + platform_device_unregister(device);
> + platform_driver_unregister(&amd_hfi_driver);
> +}
> +module_init(amd_hfi_init);
> +module_exit(amd_hfi_exit);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("AMD Hardware Feedback Interface Driver");
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v7 05/12] platform/x86: hfi: parse CPU core ranking data from shared memory
2024-11-30 15:20 ` [PATCH v7 05/12] platform/x86: hfi: parse CPU core ranking data from shared memory Mario Limonciello
@ 2024-12-19 14:53 ` Ilpo Järvinen
0 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2024-12-19 14:53 UTC (permalink / raw)
To: Mario Limonciello
Cc: Borislav Petkov, Hans de Goede, x86, Gautham R . Shenoy,
Perry Yuan, LKML, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K, Perry Yuan
[-- Attachment #1: Type: text/plain, Size: 10133 bytes --]
On Sat, 30 Nov 2024, Mario Limonciello wrote:
> From: Perry Yuan <Perry.Yuan@amd.com>
>
> When `amd_hfi` driver is loaded, it will use PCCT subspace type 4 table
> to retrieve the shared memory address which contains the CPU core ranking
> table. This table includes a header that specifies the number of ranking
> data entries to be parsed and rank each CPU core with the Performance and
> Energy Efficiency capability as implemented by the CPU power management
> firmware.
>
> Once the table has been parsed, each CPU is assigned a ranking score
> within its class. Subsequently, when the scheduler selects cores, it
> chooses from the ranking list based on the assigned scores in each class,
> thereby ensuring the optimal selection of CPU cores according to their
> predefined classifications and priorities.
>
> Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
> Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> * Drop __packed
> ---
> drivers/platform/x86/amd/hfi/hfi.c | 196 +++++++++++++++++++++++++++++
> 1 file changed, 196 insertions(+)
>
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index 2cd71d79a22c9..3c90e93fd192c 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -18,20 +18,72 @@
> #include <linux/io.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> +#include <linux/mailbox_client.h>
> #include <linux/mutex.h>
> +#include <linux/percpu-defs.h>
> #include <linux/platform_device.h>
> #include <linux/smp.h>
> +#include <linux/topology.h>
> +#include <linux/workqueue.h>
> +
> +#include <asm/cpu_device_id.h>
> +
> +#include <acpi/pcc.h>
> +#include <acpi/cppc_acpi.h>
>
> #define AMD_HFI_DRIVER "amd_hfi"
> +#define AMD_HFI_MAILBOX_COUNT 1
> +#define AMD_HETERO_RANKING_TABLE_VER 2
> +
> #define AMD_HETERO_CPUID_27 0x80000027
> +
> static struct platform_device *device;
Please add the empty lines already in the patch introducing
AMD_HETERO_CPUID_27 define.
>
> +/**
> + * struct amd_shmem_info - Shared memory table for AMD HFI
> + *
> + * @header: The PCCT table header including signature, length flags and command.
> + * @version_number: Version number of the table
> + * @n_logical_processors: Number of logical processors
> + * @n_capabilities: Number of ranking dimensions (performance, efficiency, etc)
> + * @table_update_context: Command being sent over the subspace
> + * @n_bitmaps: Number of 32-bit bitmaps to enumerate all the APIC IDs
> + * This is based on the maximum APIC ID enumerated in the system
> + * @reserved: 24 bit spare
> + * @table_data: Bit Map(s) of enabled logical processors
> + * Followed by the ranking data for each logical processor
> + */
> +struct amd_shmem_info {
> + struct acpi_pcct_ext_pcc_shared_memory header;
> + u32 version_number :8,
> + n_logical_processors :8,
> + n_capabilities :8,
> + table_update_context :8;
> + u32 n_bitmaps :8,
> + reserved :24;
> + u32 table_data[];
> +};
> +
> struct amd_hfi_data {
> const char *name;
> struct device *dev;
> struct mutex lock;
> +
> + /* PCCT table related*/
> + struct pcc_mbox_chan *pcc_chan;
> + void __iomem *pcc_comm_addr;
> + struct acpi_subtable_header *pcct_entry;
> + struct amd_shmem_info *shmem;
> };
>
> +/**
> + * struct amd_hfi_classes - HFI class capabilities per CPU
> + * @perf: Performance capability
> + * @eff: Power efficiency capability
> + *
> + * Capabilities of a logical processor in the ranking table. These capabilities
> + * are unitless and specific to each HFI class.
> + */
> struct amd_hfi_classes {
> u32 perf;
> u32 eff;
> @@ -40,23 +92,105 @@ struct amd_hfi_classes {
> /**
> * struct amd_hfi_cpuinfo - HFI workload class info per CPU
> * @cpu: cpu index
> + * @apic_id: apic id of the current cpu
> * @cpus: mask of cpus associated with amd_hfi_cpuinfo
> * @class_index: workload class ID index
> * @nr_class: max number of workload class supported
> + * @ipcc_scores: ipcc scores for each class
> * @amd_hfi_classes: current cpu workload class ranking data
> *
> * Parameters of a logical processor linked with hardware feedback class
> */
> struct amd_hfi_cpuinfo {
> int cpu;
> + u32 apic_id;
> cpumask_var_t cpus;
> s16 class_index;
> u8 nr_class;
> + int *ipcc_scores;
> struct amd_hfi_classes *amd_hfi_classes;
> };
>
> static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
>
> +static int find_cpu_index_by_apicid(unsigned int target_apicid)
> +{
> + int cpu_index;
> +
> + for_each_present_cpu(cpu_index) {
> + struct cpuinfo_x86 *info = &cpu_data(cpu_index);
> +
> + if (info->topo.apicid == target_apicid) {
> + pr_debug("match APIC id %d for CPU index: %d\n",
> + info->topo.apicid, cpu_index);
> + return cpu_index;
> + }
> + }
> +
> + return -ENODEV;
> +}
> +
> +static int amd_hfi_fill_metadata(struct amd_hfi_data *amd_hfi_data)
> +{
> + struct acpi_pcct_ext_pcc_slave *pcct_ext =
> + (struct acpi_pcct_ext_pcc_slave *)amd_hfi_data->pcct_entry;
> + void __iomem *pcc_comm_addr;
> +
> + pcc_comm_addr = acpi_os_ioremap(amd_hfi_data->pcc_chan->shmem_base_addr,
> + amd_hfi_data->pcc_chan->shmem_size);
> + if (!pcc_comm_addr) {
> + pr_err("failed to ioremap PCC common region mem\n");
> + return -ENOMEM;
> + }
> +
> + memcpy_fromio(amd_hfi_data->shmem, pcc_comm_addr, pcct_ext->length);
> + iounmap(pcc_comm_addr);
> +
> + if (amd_hfi_data->shmem->header.signature != PCC_SIGNATURE) {
> + pr_err("invalid signature in shared memory\n");
> + return -EINVAL;
> + }
> + if (amd_hfi_data->shmem->version_number != AMD_HETERO_RANKING_TABLE_VER) {
> + pr_err("invalid version %d\n", amd_hfi_data->shmem->version_number);
> + return -EINVAL;
> + }
> +
> + for (unsigned int i = 0; i < amd_hfi_data->shmem->n_bitmaps; i++) {
> + u32 bitmap = amd_hfi_data->shmem->table_data[i];
> +
> + for (unsigned int j = 0; j < BITS_PER_TYPE(u32); j++) {
> + struct amd_hfi_cpuinfo *info;
> + int apic_id = i * BITS_PER_TYPE(u32) + j;
> + int cpu_index;
Reverse xmas order.
--
i.
> +
> + if (!(bitmap & BIT(j)))
> + continue;
> +
> + cpu_index = find_cpu_index_by_apicid(apic_id);
> + if (cpu_index < 0) {
> + pr_warn("APIC ID %d not found\n", apic_id);
> + continue;
> + }
> +
> + info = per_cpu_ptr(&amd_hfi_cpuinfo, cpu_index);
> + info->apic_id = apic_id;
> +
> + /* Fill the ranking data for each logical processor */
> + info = per_cpu_ptr(&amd_hfi_cpuinfo, cpu_index);
> + for (unsigned int k = 0; k < info->nr_class; k++) {
> + u32 *table = amd_hfi_data->shmem->table_data +
> + amd_hfi_data->shmem->n_bitmaps +
> + i * info->nr_class;
> + info->amd_hfi_classes[k].eff = table[apic_id + 2 * k];
> + info->amd_hfi_classes[k].perf = table[apic_id + 2 * k + 1];
> + }
> + }
> + }
> +
> + return 0;
> +}
> +
> static int amd_hfi_alloc_class_data(struct platform_device *pdev)
> {
> struct amd_hfi_cpuinfo *hfi_cpuinfo;
> @@ -73,20 +207,78 @@ static int amd_hfi_alloc_class_data(struct platform_device *pdev)
>
> for_each_present_cpu(idx) {
> struct amd_hfi_classes *classes;
> + int *ipcc_scores;
>
> classes = devm_kzalloc(dev,
> nr_class_id * sizeof(struct amd_hfi_classes),
> GFP_KERNEL);
> if (!classes)
> return -ENOMEM;
> + ipcc_scores = devm_kcalloc(dev, nr_class_id, sizeof(int), GFP_KERNEL);
> + if (!ipcc_scores)
> + return -ENOMEM;
> hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, idx);
> hfi_cpuinfo->amd_hfi_classes = classes;
> + hfi_cpuinfo->ipcc_scores = ipcc_scores;
> hfi_cpuinfo->nr_class = nr_class_id;
> }
>
> return 0;
> }
>
> +static int amd_hfi_metadata_parser(struct platform_device *pdev,
> + struct amd_hfi_data *amd_hfi_data)
> +{
> + struct acpi_pcct_ext_pcc_slave *pcct_ext;
> + struct acpi_subtable_header *pcct_entry;
> + struct mbox_chan *pcc_mbox_channels;
> + struct acpi_table_header *pcct_tbl;
> + struct pcc_mbox_chan *pcc_chan;
> + acpi_status status;
> + int ret;
> +
> + pcc_mbox_channels = devm_kcalloc(&pdev->dev, AMD_HFI_MAILBOX_COUNT,
> + sizeof(*pcc_mbox_channels), GFP_KERNEL);
> + if (!pcc_mbox_channels)
> + return -ENOMEM;
> +
> + pcc_chan = devm_kcalloc(&pdev->dev, AMD_HFI_MAILBOX_COUNT,
> + sizeof(*pcc_chan), GFP_KERNEL);
> + if (!pcc_chan)
> + return -ENOMEM;
> +
> + status = acpi_get_table(ACPI_SIG_PCCT, 0, &pcct_tbl);
> + if (ACPI_FAILURE(status) || !pcct_tbl)
> + return -ENODEV;
> +
> + /* get pointer to the first PCC subspace entry */
> + pcct_entry = (struct acpi_subtable_header *) (
> + (unsigned long)pcct_tbl + sizeof(struct acpi_table_pcct));
> +
> + pcc_chan->mchan = &pcc_mbox_channels[0];
> +
> + amd_hfi_data->pcc_chan = pcc_chan;
> + amd_hfi_data->pcct_entry = pcct_entry;
> + pcct_ext = (struct acpi_pcct_ext_pcc_slave *)pcct_entry;
> +
> + if (pcct_ext->length <= 0)
> + return -EINVAL;
> +
> + amd_hfi_data->shmem = devm_kzalloc(amd_hfi_data->dev, pcct_ext->length, GFP_KERNEL);
> + if (!amd_hfi_data->shmem)
> + return -ENOMEM;
> +
> + pcc_chan->shmem_base_addr = pcct_ext->base_address;
> + pcc_chan->shmem_size = pcct_ext->length;
> +
> + /* parse the shared memory info from the pcct table */
> + ret = amd_hfi_fill_metadata(amd_hfi_data);
> +
> + acpi_put_table(pcct_tbl);
> +
> + return ret;
> +}
> +
> static const struct acpi_device_id amd_hfi_platform_match[] = {
> {"AMDI0104", 0},
> { }
> @@ -115,6 +307,10 @@ static int amd_hfi_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + ret = amd_hfi_metadata_parser(pdev, amd_hfi_data);
> + if (ret)
> + return ret;
> +
> return 0;
> }
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support
2024-11-30 15:20 ` [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support Mario Limonciello
@ 2024-12-19 14:59 ` Ilpo Järvinen
0 siblings, 0 replies; 17+ messages in thread
From: Ilpo Järvinen @ 2024-12-19 14:59 UTC (permalink / raw)
To: Mario Limonciello
Cc: Borislav Petkov, Hans de Goede, x86, Gautham R . Shenoy,
Perry Yuan, LKML, linux-doc, linux-pm, platform-driver-x86,
Shyam Sundar S K
On Sat, 30 Nov 2024, Mario Limonciello wrote:
> Add a dump of the class and capabilities table to debugfs to assist
> with debugging scheduler issues.
>
> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> drivers/platform/x86/amd/hfi/hfi.c | 36 ++++++++++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index 0940950dd7adc..b6dc379bfd546 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -13,6 +13,7 @@
> #include <linux/acpi.h>
> #include <linux/cpu.h>
> #include <linux/cpumask.h>
> +#include <linux/debugfs.h>
> #include <linux/gfp.h>
> #include <linux/init.h>
> #include <linux/io.h>
> @@ -74,6 +75,8 @@ struct amd_hfi_data {
> void __iomem *pcc_comm_addr;
> struct acpi_subtable_header *pcct_entry;
> struct amd_shmem_info *shmem;
> +
> + struct dentry *dbgfs_dir;
> };
>
> /**
> @@ -234,6 +237,13 @@ static int amd_hfi_alloc_class_data(struct platform_device *pdev)
> return 0;
> }
>
> +static void amd_hfi_remove(struct platform_device *pdev)
> +{
> + struct amd_hfi_data *dev = platform_get_drvdata(pdev);
> +
> + debugfs_remove_recursive(dev->dbgfs_dir);
> +}
> +
> static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
> {
> for (int i = 0; i < hfi_cpuinfo->nr_class; i++)
> @@ -388,6 +398,27 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
> return ret;
> }
>
> +static int class_capabilities_show(struct seq_file *s, void *unused)
> +{
> + int cpu, idx;
> +
> + seq_puts(s, "CPU #\tWLC\tPerf\tEff\n");
> + for_each_present_cpu(cpu) {
> + struct amd_hfi_cpuinfo *hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, cpu);
> +
> + seq_printf(s, "%d", cpu);
> + for (idx = 0; idx < hfi_cpuinfo->nr_class; idx++) {
> + seq_printf(s, "\t%d\t%d\t%d\n",
> + idx,
Put idx to the previous line.
> + hfi_cpuinfo->amd_hfi_classes[idx].perf,
> + hfi_cpuinfo->amd_hfi_classes[idx].eff);
> + }
> + }
> +
> + return 0;
> +}
> +DEFINE_SHOW_ATTRIBUTE(class_capabilities);
> +
> static int amd_hfi_pm_resume(struct device *dev)
> {
> int ret, cpu;
> @@ -463,6 +494,10 @@ static int amd_hfi_probe(struct platform_device *pdev)
>
> schedule_work(&sched_amd_hfi_itmt_work);
>
> + amd_hfi_data->dbgfs_dir = debugfs_create_dir("amd_hfi", arch_debugfs_dir);
> + debugfs_create_file("class_capabilities", 0644, amd_hfi_data->dbgfs_dir, pdev,
> + &class_capabilities_fops);
> +
> return 0;
> }
>
> @@ -474,6 +509,7 @@ static struct platform_driver amd_hfi_driver = {
> .acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
> },
> .probe = amd_hfi_probe,
> + .remove = amd_hfi_remove,
> };
>
> static int __init amd_hfi_init(void)
>
--
i.
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2024-12-19 14:59 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 15:20 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 01/12] Documentation: x86: Add AMD Hardware Feedback Interface documentation Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 02/12] MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 03/12] x86/msr-index: define AMD heterogeneous CPU related MSR Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 04/12] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver Mario Limonciello
2024-12-19 14:39 ` Ilpo Järvinen
2024-11-30 15:20 ` [PATCH v7 05/12] platform/x86: hfi: parse CPU core ranking data from shared memory Mario Limonciello
2024-12-19 14:53 ` Ilpo Järvinen
2024-11-30 15:20 ` [PATCH v7 06/12] platform/x86: hfi: init per-cpu scores for each class Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 07/12] platform/x86: hfi: add online and offline callback support Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 08/12] platform/x86: hfi: add power management callback Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 09/12] x86/process: Clear hardware feedback history for AMD processors Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 10/12] cpufreq/amd-pstate: Disable preferred cores on designs with workload classification Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 11/12] platform/x86/amd: hfi: Set ITMT priority from ranking data Mario Limonciello
2024-11-30 15:20 ` [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support Mario Limonciello
2024-12-19 14:59 ` Ilpo Järvinen
-- strict thread matches above, loose matches on Subject: below --
2024-11-30 14:06 [PATCH v7 00/12] Add support for AMD hardware feedback interface Mario Limonciello
2024-11-30 14:07 ` [PATCH v7 12/12] platform/x86/amd: hfi: Add debugfs support Mario Limonciello
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).