Skip to content

Commit 5d902ee

Browse files
Perry Yuanbp3tk0v
authored andcommitted
platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver
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 and Dense. 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. Signed-off-by: Perry Yuan <[email protected]> Co-developed-by: Mario Limonciello <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Gautham R. Shenoy <[email protected]> Reviewed-by: Shyam Sundar S K <[email protected]> Acked-by: Ilpo Järvinen <[email protected]> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Link: https://lore.kernel.org/[email protected]
1 parent a3c4f33 commit 5d902ee

File tree

5 files changed

+184
-0
lines changed

5 files changed

+184
-0
lines changed

drivers/platform/x86/amd/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
source "drivers/platform/x86/amd/hsmp/Kconfig"
77
source "drivers/platform/x86/amd/pmf/Kconfig"
88
source "drivers/platform/x86/amd/pmc/Kconfig"
9+
source "drivers/platform/x86/amd/hfi/Kconfig"
910

1011
config AMD_3D_VCACHE
1112
tristate "AMD 3D V-Cache Performance Optimizer Driver"

drivers/platform/x86/amd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ obj-$(CONFIG_AMD_HSMP) += hsmp/
1111
obj-$(CONFIG_AMD_PMF) += pmf/
1212
obj-$(CONFIG_AMD_WBRF) += wbrf.o
1313
obj-$(CONFIG_AMD_ISP_PLATFORM) += amd_isp4.o
14+
obj-$(CONFIG_AMD_HFI) += hfi/

drivers/platform/x86/amd/hfi/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# AMD Hardware Feedback Interface Driver
4+
#
5+
6+
config AMD_HFI
7+
bool "AMD Hetero Core Hardware Feedback Driver"
8+
depends on ACPI
9+
depends on CPU_SUP_AMD
10+
help
11+
Select this option to enable the AMD Heterogeneous Core Hardware
12+
Feedback Interface. If selected, hardware provides runtime thread
13+
classification guidance to the operating system on the performance and
14+
energy efficiency capabilities of each heterogeneous CPU core. These
15+
capabilities may vary due to the inherent differences in the core types
16+
and can also change as a result of variations in the operating
17+
conditions of the system such as power and thermal limits.

drivers/platform/x86/amd/hfi/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# AMD Hardware Feedback Interface Driver
4+
#
5+
6+
obj-$(CONFIG_AMD_HFI) += amd_hfi.o
7+
amd_hfi-objs := hfi.o

drivers/platform/x86/amd/hfi/hfi.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* AMD Hardware Feedback Interface Driver
4+
*
5+
* Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved.
6+
*
7+
* Authors: Perry Yuan <[email protected]>
8+
* Mario Limonciello <[email protected]>
9+
*/
10+
11+
#define pr_fmt(fmt) "amd-hfi: " fmt
12+
13+
#include <linux/acpi.h>
14+
#include <linux/cpu.h>
15+
#include <linux/cpumask.h>
16+
#include <linux/gfp.h>
17+
#include <linux/init.h>
18+
#include <linux/io.h>
19+
#include <linux/kernel.h>
20+
#include <linux/module.h>
21+
#include <linux/mutex.h>
22+
#include <linux/platform_device.h>
23+
#include <linux/smp.h>
24+
25+
#define AMD_HFI_DRIVER "amd_hfi"
26+
27+
#define AMD_HETERO_CPUID_27 0x80000027
28+
29+
static struct platform_device *device;
30+
31+
struct amd_hfi_data {
32+
const char *name;
33+
struct device *dev;
34+
};
35+
36+
struct amd_hfi_classes {
37+
u32 perf;
38+
u32 eff;
39+
};
40+
41+
/**
42+
* struct amd_hfi_cpuinfo - HFI workload class info per CPU
43+
* @cpu: CPU index
44+
* @class_index: workload class ID index
45+
* @nr_class: max number of workload class supported
46+
* @amd_hfi_classes: current CPU workload class ranking data
47+
*
48+
* Parameters of a logical processor linked with hardware feedback class.
49+
*/
50+
struct amd_hfi_cpuinfo {
51+
int cpu;
52+
s16 class_index;
53+
u8 nr_class;
54+
struct amd_hfi_classes *amd_hfi_classes;
55+
};
56+
57+
static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
58+
59+
static int amd_hfi_alloc_class_data(struct platform_device *pdev)
60+
{
61+
struct amd_hfi_cpuinfo *hfi_cpuinfo;
62+
struct device *dev = &pdev->dev;
63+
u32 nr_class_id;
64+
int idx;
65+
66+
nr_class_id = cpuid_eax(AMD_HETERO_CPUID_27);
67+
if (nr_class_id > 255) {
68+
dev_err(dev, "number of supported classes too large: %d\n",
69+
nr_class_id);
70+
return -EINVAL;
71+
}
72+
73+
for_each_possible_cpu(idx) {
74+
struct amd_hfi_classes *classes;
75+
76+
classes = devm_kcalloc(dev,
77+
nr_class_id,
78+
sizeof(struct amd_hfi_classes),
79+
GFP_KERNEL);
80+
if (!classes)
81+
return -ENOMEM;
82+
hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, idx);
83+
hfi_cpuinfo->amd_hfi_classes = classes;
84+
hfi_cpuinfo->nr_class = nr_class_id;
85+
}
86+
87+
return 0;
88+
}
89+
90+
static const struct acpi_device_id amd_hfi_platform_match[] = {
91+
{"AMDI0104", 0},
92+
{ }
93+
};
94+
MODULE_DEVICE_TABLE(acpi, amd_hfi_platform_match);
95+
96+
static int amd_hfi_probe(struct platform_device *pdev)
97+
{
98+
struct amd_hfi_data *amd_hfi_data;
99+
int ret;
100+
101+
if (!acpi_match_device(amd_hfi_platform_match, &pdev->dev))
102+
return -ENODEV;
103+
104+
amd_hfi_data = devm_kzalloc(&pdev->dev, sizeof(*amd_hfi_data), GFP_KERNEL);
105+
if (!amd_hfi_data)
106+
return -ENOMEM;
107+
108+
amd_hfi_data->dev = &pdev->dev;
109+
platform_set_drvdata(pdev, amd_hfi_data);
110+
111+
ret = amd_hfi_alloc_class_data(pdev);
112+
if (ret)
113+
return ret;
114+
115+
return 0;
116+
}
117+
118+
static struct platform_driver amd_hfi_driver = {
119+
.driver = {
120+
.name = AMD_HFI_DRIVER,
121+
.owner = THIS_MODULE,
122+
.acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
123+
},
124+
.probe = amd_hfi_probe,
125+
};
126+
127+
static int __init amd_hfi_init(void)
128+
{
129+
int ret;
130+
131+
if (acpi_disabled ||
132+
!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES) ||
133+
!cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
134+
return -ENODEV;
135+
136+
device = platform_device_register_simple(AMD_HFI_DRIVER, -1, NULL, 0);
137+
if (IS_ERR(device)) {
138+
pr_err("unable to register HFI platform device\n");
139+
return PTR_ERR(device);
140+
}
141+
142+
ret = platform_driver_register(&amd_hfi_driver);
143+
if (ret)
144+
pr_err("failed to register HFI driver\n");
145+
146+
return ret;
147+
}
148+
149+
static __exit void amd_hfi_exit(void)
150+
{
151+
platform_driver_unregister(&amd_hfi_driver);
152+
platform_device_unregister(device);
153+
}
154+
module_init(amd_hfi_init);
155+
module_exit(amd_hfi_exit);
156+
157+
MODULE_LICENSE("GPL");
158+
MODULE_DESCRIPTION("AMD Hardware Feedback Interface Driver");

0 commit comments

Comments
 (0)