Skip to content

Commit 52f1192

Browse files
committed
Merge branches 'pm-cpuidle' and 'pm-powercap'
Merge cpuidle updates and power capping updates for 6.12-rc1: - Add Granite Rapids Xeon support to intel_idle (Artem Bityutskiy). - Disable promotion to C1E on Jasper Lake and Elkhart Lake in intel_idle (Kai-Heng Feng). - Use scoped device node handling to fix missing of_node_put() and simplify walking OF children in the riscv-sbi cpuidle driver (Krzysztof Kozlowski). - Remove dead code from cpuidle_enter_state() (Dhruva Gole). - Change an error pointer to NULL to fix error handling in the intel_rapl power capping driver (Dan Carpenter). - Fix off by one in get_rpi() in the intel_rapl power capping driver (Dan Carpenter). - Add support for ArrowLake-U to the intel_rapl power capping driver (Sumeet Pawnikar). - Fix the energy-pkg event for AMD CPUs in the intel_rapl power capping driver (Dhananjay Ugwekar). - Add support for AMD family 1Ah processors to the intel_rapl power capping driver (Dhananjay Ugwekar). * pm-cpuidle: cpuidle: remove dead code from cpuidle_enter_state() cpuidle: riscv-sbi: Simplify with scoped for each OF child loop cpuidle: riscv-sbi: Use scoped device node handling to fix missing of_node_put intel_idle: Disable promotion to C1E on Jasper Lake and Elkhart Lake intel_idle: add Granite Rapids Xeon support * pm-powercap: powercap: intel_rapl: Change an error pointer to NULL powercap: intel_rapl: Fix off by one in get_rpi() powercap: intel_rapl: Add support for ArrowLake-U platform powercap/intel_rapl: Fix the energy-pkg event for AMD CPUs powercap/intel_rapl: Add support for AMD family 1Ah
3 parents 415dff1 + 6baacf9 + 6b08b4e commit 52f1192

File tree

4 files changed

+101
-30
lines changed

4 files changed

+101
-30
lines changed

drivers/cpuidle/cpuidle-riscv-sbi.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
1010

11+
#include <linux/cleanup.h>
1112
#include <linux/cpuhotplug.h>
1213
#include <linux/cpuidle.h>
1314
#include <linux/cpumask.h>
@@ -236,19 +237,16 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
236237
{
237238
struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu);
238239
struct device_node *state_node;
239-
struct device_node *cpu_node;
240240
u32 *states;
241241
int i, ret;
242242

243-
cpu_node = of_cpu_device_node_get(cpu);
243+
struct device_node *cpu_node __free(device_node) = of_cpu_device_node_get(cpu);
244244
if (!cpu_node)
245245
return -ENODEV;
246246

247247
states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL);
248-
if (!states) {
249-
ret = -ENOMEM;
250-
goto fail;
251-
}
248+
if (!states)
249+
return -ENOMEM;
252250

253251
/* Parse SBI specific details from state DT nodes */
254252
for (i = 1; i < state_count; i++) {
@@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
264262

265263
pr_debug("sbi-state %#x index %d\n", states[i], i);
266264
}
267-
if (i != state_count) {
268-
ret = -ENODEV;
269-
goto fail;
270-
}
265+
if (i != state_count)
266+
return -ENODEV;
271267

272268
/* Initialize optional data, used for the hierarchical topology. */
273269
ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu);
@@ -277,10 +273,7 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
277273
/* Store states in the per-cpu struct. */
278274
data->states = states;
279275

280-
fail:
281-
of_node_put(cpu_node);
282-
283-
return ret;
276+
return 0;
284277
}
285278

286279
static void sbi_cpuidle_deinit_cpu(int cpu)
@@ -455,7 +448,6 @@ static void sbi_pd_remove(void)
455448

456449
static int sbi_genpd_probe(struct device_node *np)
457450
{
458-
struct device_node *node;
459451
int ret = 0, pd_count = 0;
460452

461453
if (!np)
@@ -465,13 +457,13 @@ static int sbi_genpd_probe(struct device_node *np)
465457
* Parse child nodes for the "#power-domain-cells" property and
466458
* initialize a genpd/genpd-of-provider pair when it's found.
467459
*/
468-
for_each_child_of_node(np, node) {
460+
for_each_child_of_node_scoped(np, node) {
469461
if (!of_property_present(node, "#power-domain-cells"))
470462
continue;
471463

472464
ret = sbi_pd_init(node);
473465
if (ret)
474-
goto put_node;
466+
goto remove_pd;
475467

476468
pd_count++;
477469
}
@@ -487,8 +479,6 @@ static int sbi_genpd_probe(struct device_node *np)
487479

488480
return 0;
489481

490-
put_node:
491-
of_node_put(node);
492482
remove_pd:
493483
sbi_pd_remove();
494484
pr_err("failed to create CPU PM domains ret=%d\n", ret);

drivers/cpuidle/cpuidle.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
228228
if (broadcast && tick_broadcast_enter()) {
229229
index = find_deepest_state(drv, dev, target_state->exit_latency_ns,
230230
CPUIDLE_FLAG_TIMER_STOP, false);
231-
if (index < 0) {
232-
default_idle_call();
233-
return -EBUSY;
234-
}
231+
235232
target_state = &drv->states[index];
236233
broadcast = false;
237234
}

drivers/idle/intel_idle.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,45 @@ static struct cpuidle_state spr_cstates[] __initdata = {
10221022
.enter = NULL }
10231023
};
10241024

1025+
static struct cpuidle_state gnr_cstates[] __initdata = {
1026+
{
1027+
.name = "C1",
1028+
.desc = "MWAIT 0x00",
1029+
.flags = MWAIT2flg(0x00),
1030+
.exit_latency = 1,
1031+
.target_residency = 1,
1032+
.enter = &intel_idle,
1033+
.enter_s2idle = intel_idle_s2idle, },
1034+
{
1035+
.name = "C1E",
1036+
.desc = "MWAIT 0x01",
1037+
.flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1038+
.exit_latency = 4,
1039+
.target_residency = 4,
1040+
.enter = &intel_idle,
1041+
.enter_s2idle = intel_idle_s2idle, },
1042+
{
1043+
.name = "C6",
1044+
.desc = "MWAIT 0x20",
1045+
.flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
1046+
CPUIDLE_FLAG_INIT_XSTATE,
1047+
.exit_latency = 170,
1048+
.target_residency = 650,
1049+
.enter = &intel_idle,
1050+
.enter_s2idle = intel_idle_s2idle, },
1051+
{
1052+
.name = "C6P",
1053+
.desc = "MWAIT 0x21",
1054+
.flags = MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED |
1055+
CPUIDLE_FLAG_INIT_XSTATE,
1056+
.exit_latency = 210,
1057+
.target_residency = 1000,
1058+
.enter = &intel_idle,
1059+
.enter_s2idle = intel_idle_s2idle, },
1060+
{
1061+
.enter = NULL }
1062+
};
1063+
10251064
static struct cpuidle_state atom_cstates[] __initdata = {
10261065
{
10271066
.name = "C1E",
@@ -1453,6 +1492,12 @@ static const struct idle_cpu idle_cpu_spr __initconst = {
14531492
.use_acpi = true,
14541493
};
14551494

1495+
static const struct idle_cpu idle_cpu_gnr __initconst = {
1496+
.state_table = gnr_cstates,
1497+
.disable_promotion_to_c1e = true,
1498+
.use_acpi = true,
1499+
};
1500+
14561501
static const struct idle_cpu idle_cpu_avn __initconst = {
14571502
.state_table = avn_cstates,
14581503
.disable_promotion_to_c1e = true,
@@ -1475,6 +1520,10 @@ static const struct idle_cpu idle_cpu_dnv __initconst = {
14751520
.use_acpi = true,
14761521
};
14771522

1523+
static const struct idle_cpu idle_cpu_tmt __initconst = {
1524+
.disable_promotion_to_c1e = true,
1525+
};
1526+
14781527
static const struct idle_cpu idle_cpu_snr __initconst = {
14791528
.state_table = snr_cstates,
14801529
.disable_promotion_to_c1e = true,
@@ -1533,11 +1582,14 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
15331582
X86_MATCH_VFM(INTEL_ATOM_GRACEMONT, &idle_cpu_gmt),
15341583
X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X, &idle_cpu_spr),
15351584
X86_MATCH_VFM(INTEL_EMERALDRAPIDS_X, &idle_cpu_spr),
1585+
X86_MATCH_VFM(INTEL_GRANITERAPIDS_X, &idle_cpu_gnr),
15361586
X86_MATCH_VFM(INTEL_XEON_PHI_KNL, &idle_cpu_knl),
15371587
X86_MATCH_VFM(INTEL_XEON_PHI_KNM, &idle_cpu_knl),
15381588
X86_MATCH_VFM(INTEL_ATOM_GOLDMONT, &idle_cpu_bxt),
15391589
X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_PLUS, &idle_cpu_bxt),
15401590
X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_D, &idle_cpu_dnv),
1591+
X86_MATCH_VFM(INTEL_ATOM_TREMONT, &idle_cpu_tmt),
1592+
X86_MATCH_VFM(INTEL_ATOM_TREMONT_L, &idle_cpu_tmt),
15411593
X86_MATCH_VFM(INTEL_ATOM_TREMONT_D, &idle_cpu_snr),
15421594
X86_MATCH_VFM(INTEL_ATOM_CRESTMONT, &idle_cpu_grr),
15431595
X86_MATCH_VFM(INTEL_ATOM_CRESTMONT_X, &idle_cpu_srf),
@@ -2075,7 +2127,7 @@ static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
20752127

20762128
drv->state_count = 1;
20772129

2078-
if (icpu)
2130+
if (icpu && icpu->state_table)
20792131
intel_idle_init_cstates_icpu(drv);
20802132
else
20812133
intel_idle_init_cstates_acpi(drv);
@@ -2209,7 +2261,11 @@ static int __init intel_idle_init(void)
22092261

22102262
icpu = (const struct idle_cpu *)id->driver_data;
22112263
if (icpu) {
2212-
cpuidle_state_table = icpu->state_table;
2264+
if (icpu->state_table)
2265+
cpuidle_state_table = icpu->state_table;
2266+
else if (!intel_idle_acpi_cst_extract())
2267+
return -ENODEV;
2268+
22132269
auto_demotion_disable_flags = icpu->auto_demotion_disable_flags;
22142270
if (icpu->disable_promotion_to_c1e)
22152271
c1e_promotion = C1E_PROMOTION_DISABLE;

drivers/powercap/intel_rapl_common.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
740740
{
741741
struct rapl_primitive_info *rpi = rp->priv->rpi;
742742

743-
if (prim < 0 || prim > NR_RAPL_PRIMITIVES || !rpi)
743+
if (prim < 0 || prim >= NR_RAPL_PRIMITIVES || !rpi)
744744
return NULL;
745745

746746
return &rpi[prim];
@@ -1267,6 +1267,7 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {
12671267
X86_MATCH_VFM(INTEL_LUNARLAKE_M, &rapl_defaults_core),
12681268
X86_MATCH_VFM(INTEL_ARROWLAKE_H, &rapl_defaults_core),
12691269
X86_MATCH_VFM(INTEL_ARROWLAKE, &rapl_defaults_core),
1270+
X86_MATCH_VFM(INTEL_ARROWLAKE_U, &rapl_defaults_core),
12701271
X86_MATCH_VFM(INTEL_LAKEFIELD, &rapl_defaults_core),
12711272

12721273
X86_MATCH_VFM(INTEL_ATOM_SILVERMONT, &rapl_defaults_byt),
@@ -1285,6 +1286,7 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {
12851286

12861287
X86_MATCH_VENDOR_FAM(AMD, 0x17, &rapl_defaults_amd),
12871288
X86_MATCH_VENDOR_FAM(AMD, 0x19, &rapl_defaults_amd),
1289+
X86_MATCH_VENDOR_FAM(AMD, 0x1A, &rapl_defaults_amd),
12881290
X86_MATCH_VENDOR_FAM(HYGON, 0x18, &rapl_defaults_amd),
12891291
{}
12901292
};
@@ -2128,15 +2130,36 @@ void rapl_remove_package(struct rapl_package *rp)
21282130
}
21292131
EXPORT_SYMBOL_GPL(rapl_remove_package);
21302132

2133+
/*
2134+
* RAPL Package energy counter scope:
2135+
* 1. AMD/HYGON platforms use per-PKG package energy counter
2136+
* 2. For Intel platforms
2137+
* 2.1 CLX-AP platform has per-DIE package energy counter
2138+
* 2.2 Other platforms that uses MSR RAPL are single die systems so the
2139+
* package energy counter can be considered as per-PKG/per-DIE,
2140+
* here it is considered as per-DIE.
2141+
* 2.3 New platforms that use TPMI RAPL doesn't care about the
2142+
* scope because they are not MSR/CPU based.
2143+
*/
2144+
#define rapl_msrs_are_pkg_scope() \
2145+
(boot_cpu_data.x86_vendor == X86_VENDOR_AMD || \
2146+
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)
2147+
21312148
/* caller to ensure CPU hotplug lock is held */
21322149
struct rapl_package *rapl_find_package_domain_cpuslocked(int id, struct rapl_if_priv *priv,
21332150
bool id_is_cpu)
21342151
{
21352152
struct rapl_package *rp;
21362153
int uid;
21372154

2138-
if (id_is_cpu)
2139-
uid = topology_logical_die_id(id);
2155+
if (id_is_cpu) {
2156+
uid = rapl_msrs_are_pkg_scope() ?
2157+
topology_physical_package_id(id) : topology_logical_die_id(id);
2158+
if (uid < 0) {
2159+
pr_err("topology_logical_(package/die)_id() returned a negative value");
2160+
return NULL;
2161+
}
2162+
}
21402163
else
21412164
uid = id;
21422165

@@ -2168,9 +2191,14 @@ struct rapl_package *rapl_add_package_cpuslocked(int id, struct rapl_if_priv *pr
21682191
return ERR_PTR(-ENOMEM);
21692192

21702193
if (id_is_cpu) {
2171-
rp->id = topology_logical_die_id(id);
2194+
rp->id = rapl_msrs_are_pkg_scope() ?
2195+
topology_physical_package_id(id) : topology_logical_die_id(id);
2196+
if ((int)(rp->id) < 0) {
2197+
pr_err("topology_logical_(package/die)_id() returned a negative value");
2198+
return ERR_PTR(-EINVAL);
2199+
}
21722200
rp->lead_cpu = id;
2173-
if (topology_max_dies_per_package() > 1)
2201+
if (!rapl_msrs_are_pkg_scope() && topology_max_dies_per_package() > 1)
21742202
snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, "package-%d-die-%d",
21752203
topology_physical_package_id(id), topology_die_id(id));
21762204
else

0 commit comments

Comments
 (0)