2019-07-10 21:44:24 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Data types and headers for RAPL support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Author: Zhang Rui <rui.zhang@intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __INTEL_RAPL_H__
|
|
|
|
#define __INTEL_RAPL_H__
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/powercap.h>
|
2019-07-15 07:56:30 +08:00
|
|
|
#include <linux/cpuhotplug.h>
|
2019-07-10 21:44:24 +08:00
|
|
|
|
2023-04-19 10:44:17 +08:00
|
|
|
enum rapl_if_type {
|
|
|
|
RAPL_IF_MSR, /* RAPL I/F using MSR registers */
|
|
|
|
RAPL_IF_MMIO, /* RAPL I/F using MMIO registers */
|
2023-04-19 10:44:18 +08:00
|
|
|
RAPL_IF_TPMI, /* RAPL I/F using TPMI registers */
|
2023-04-19 10:44:17 +08:00
|
|
|
};
|
|
|
|
|
2019-07-10 21:44:24 +08:00
|
|
|
enum rapl_domain_type {
|
|
|
|
RAPL_DOMAIN_PACKAGE, /* entire package/socket */
|
|
|
|
RAPL_DOMAIN_PP0, /* core power plane */
|
|
|
|
RAPL_DOMAIN_PP1, /* graphics uncore */
|
|
|
|
RAPL_DOMAIN_DRAM, /* DRAM control_type */
|
|
|
|
RAPL_DOMAIN_PLATFORM, /* PSys control_type */
|
|
|
|
RAPL_DOMAIN_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum rapl_domain_reg_id {
|
|
|
|
RAPL_DOMAIN_REG_LIMIT,
|
|
|
|
RAPL_DOMAIN_REG_STATUS,
|
|
|
|
RAPL_DOMAIN_REG_PERF,
|
|
|
|
RAPL_DOMAIN_REG_POLICY,
|
|
|
|
RAPL_DOMAIN_REG_INFO,
|
2020-07-17 01:44:55 +08:00
|
|
|
RAPL_DOMAIN_REG_PL4,
|
2023-04-19 10:44:09 +08:00
|
|
|
RAPL_DOMAIN_REG_UNIT,
|
2023-04-19 10:44:18 +08:00
|
|
|
RAPL_DOMAIN_REG_PL2,
|
2019-07-10 21:44:24 +08:00
|
|
|
RAPL_DOMAIN_REG_MAX,
|
|
|
|
};
|
|
|
|
|
2021-03-30 14:39:23 +08:00
|
|
|
struct rapl_domain;
|
2019-07-10 21:44:24 +08:00
|
|
|
|
|
|
|
enum rapl_primitives {
|
|
|
|
POWER_LIMIT1,
|
|
|
|
POWER_LIMIT2,
|
2020-07-17 01:44:55 +08:00
|
|
|
POWER_LIMIT4,
|
2023-04-19 10:44:11 +08:00
|
|
|
ENERGY_COUNTER,
|
2019-07-10 21:44:24 +08:00
|
|
|
FW_LOCK,
|
2023-04-19 10:44:14 +08:00
|
|
|
FW_HIGH_LOCK,
|
2023-04-19 10:44:18 +08:00
|
|
|
PL1_LOCK,
|
|
|
|
PL2_LOCK,
|
|
|
|
PL4_LOCK,
|
2019-07-10 21:44:24 +08:00
|
|
|
|
|
|
|
PL1_ENABLE, /* power limit 1, aka long term */
|
|
|
|
PL1_CLAMP, /* allow frequency to go below OS request */
|
|
|
|
PL2_ENABLE, /* power limit 2, aka short term, instantaneous */
|
|
|
|
PL2_CLAMP,
|
2020-07-17 01:44:55 +08:00
|
|
|
PL4_ENABLE, /* power limit 4, aka max peak power */
|
2019-07-10 21:44:24 +08:00
|
|
|
|
|
|
|
TIME_WINDOW1, /* long term */
|
|
|
|
TIME_WINDOW2, /* short term */
|
|
|
|
THERMAL_SPEC_POWER,
|
|
|
|
MAX_POWER,
|
|
|
|
|
|
|
|
MIN_POWER,
|
|
|
|
MAX_TIME_WINDOW,
|
|
|
|
THROTTLED_TIME,
|
|
|
|
PRIORITY_LEVEL,
|
|
|
|
|
2021-12-07 21:17:34 +08:00
|
|
|
PSYS_POWER_LIMIT1,
|
|
|
|
PSYS_POWER_LIMIT2,
|
|
|
|
PSYS_PL1_ENABLE,
|
|
|
|
PSYS_PL2_ENABLE,
|
|
|
|
PSYS_TIME_WINDOW1,
|
|
|
|
PSYS_TIME_WINDOW2,
|
2019-07-10 21:44:24 +08:00
|
|
|
/* below are not raw primitive data */
|
|
|
|
AVERAGE_POWER,
|
|
|
|
NR_RAPL_PRIMITIVES,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rapl_domain_data {
|
|
|
|
u64 primitives[NR_RAPL_PRIMITIVES];
|
|
|
|
unsigned long timestamp;
|
|
|
|
};
|
|
|
|
|
2023-04-19 10:44:11 +08:00
|
|
|
#define NR_POWER_LIMITS (POWER_LIMIT4 + 1)
|
|
|
|
|
2019-07-10 21:44:24 +08:00
|
|
|
struct rapl_power_limit {
|
|
|
|
struct powercap_zone_constraint *constraint;
|
|
|
|
struct rapl_domain *domain;
|
|
|
|
const char *name;
|
2023-04-19 10:44:14 +08:00
|
|
|
bool locked;
|
2019-07-10 21:44:24 +08:00
|
|
|
u64 last_power_limit;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rapl_package;
|
|
|
|
|
2020-10-13 15:42:41 +08:00
|
|
|
#define RAPL_DOMAIN_NAME_LENGTH 16
|
|
|
|
|
2019-07-10 21:44:24 +08:00
|
|
|
struct rapl_domain {
|
2020-10-13 15:42:41 +08:00
|
|
|
char name[RAPL_DOMAIN_NAME_LENGTH];
|
2019-07-10 21:44:24 +08:00
|
|
|
enum rapl_domain_type id;
|
2019-07-10 21:44:31 +08:00
|
|
|
u64 regs[RAPL_DOMAIN_REG_MAX];
|
2019-07-10 21:44:24 +08:00
|
|
|
struct powercap_zone power_zone;
|
|
|
|
struct rapl_domain_data rdd;
|
|
|
|
struct rapl_power_limit rpl[NR_POWER_LIMITS];
|
|
|
|
u64 attr_map; /* track capabilities */
|
|
|
|
unsigned int state;
|
2023-04-19 10:44:09 +08:00
|
|
|
unsigned int power_unit;
|
|
|
|
unsigned int energy_unit;
|
|
|
|
unsigned int time_unit;
|
2019-07-10 21:44:24 +08:00
|
|
|
struct rapl_package *rp;
|
|
|
|
};
|
|
|
|
|
2019-07-10 21:44:27 +08:00
|
|
|
struct reg_action {
|
2019-07-10 21:44:31 +08:00
|
|
|
u64 reg;
|
2019-07-10 21:44:27 +08:00
|
|
|
u64 mask;
|
|
|
|
u64 value;
|
|
|
|
int err;
|
|
|
|
};
|
|
|
|
|
2019-07-10 21:44:25 +08:00
|
|
|
/**
|
|
|
|
* struct rapl_if_priv: private data for different RAPL interfaces
|
|
|
|
* @control_type: Each RAPL interface must have its own powercap
|
|
|
|
* control type.
|
|
|
|
* @platform_rapl_domain: Optional. Some RAPL interface may have platform
|
|
|
|
* level RAPL control.
|
|
|
|
* @pcap_rapl_online: CPU hotplug state for each RAPL interface.
|
2019-07-10 21:44:26 +08:00
|
|
|
* @reg_unit: Register for getting energy/power/time unit.
|
|
|
|
* @regs: Register sets for different RAPL Domains.
|
2019-07-10 21:44:32 +08:00
|
|
|
* @limits: Number of power limits supported by each domain.
|
2019-07-10 21:44:27 +08:00
|
|
|
* @read_raw: Callback for reading RAPL interface specific
|
|
|
|
* registers.
|
|
|
|
* @write_raw: Callback for writing RAPL interface specific
|
|
|
|
* registers.
|
2023-04-19 10:44:07 +08:00
|
|
|
* @defaults: internal pointer to interface default settings
|
2023-04-19 10:44:08 +08:00
|
|
|
* @rpi: internal pointer to interface primitive info
|
2019-07-10 21:44:25 +08:00
|
|
|
*/
|
|
|
|
struct rapl_if_priv {
|
2023-04-19 10:44:17 +08:00
|
|
|
enum rapl_if_type type;
|
2019-07-10 21:44:25 +08:00
|
|
|
struct powercap_control_type *control_type;
|
|
|
|
enum cpuhp_state pcap_rapl_online;
|
2019-07-10 21:44:31 +08:00
|
|
|
u64 reg_unit;
|
|
|
|
u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
|
2019-07-10 21:44:32 +08:00
|
|
|
int limits[RAPL_DOMAIN_MAX];
|
powercap: intel_rapl: Make cpu optional for rapl_package
MSR RAPL Interface always removes a rapl_package when all the CPUs in
that rapl_package are offlined. This is because it relies on an online
CPU to access the MSR.
But for RAPL Interface using MMIO registers, when all the cpus within
the rapl_package are offlined,
1. the register can still be accessed
2. monitoring and setting the Power Pimits for the rapl_package is still
meaningful because of uncore power.
This means that, a valid rapl_package doesn't rely on one or more cpus
being onlined.
For this sense, make cpu optional for rapl_package. A rapl_package can
be registered either using a CPU id to represent the physical
package/die, or using the physical package id directly.
Note that, the thermal throttling interrupt is not disabled via
MSR_IA32_PACKAGE_THERM_INTERRUPT for such rapl_package at the moment.
If it is still needed in the future, this can be achieved by selecting
an onlined CPU using the physical package id.
Note that, processor_thermal_rapl, the current MMIO RAPL Interface
driver, can also be converted to register using a package id instead.
But this is not done right now because processor_thermal_rapl driver
works on single-package systems only, and offlining the only package
will not happen. So keep the previous logic.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested-by: Wang Wendy <wendy.wang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-19 10:44:16 +08:00
|
|
|
int (*read_raw)(int id, struct reg_action *ra);
|
|
|
|
int (*write_raw)(int id, struct reg_action *ra);
|
2023-04-19 10:44:07 +08:00
|
|
|
void *defaults;
|
2023-04-19 10:44:08 +08:00
|
|
|
void *rpi;
|
2019-07-10 21:44:25 +08:00
|
|
|
};
|
|
|
|
|
2019-07-10 21:44:24 +08:00
|
|
|
/* maximum rapl package domain name: package-%d-die-%d */
|
|
|
|
#define PACKAGE_DOMAIN_NAME_LENGTH 30
|
|
|
|
|
|
|
|
struct rapl_package {
|
|
|
|
unsigned int id; /* logical die id, equals physical 1-die systems */
|
|
|
|
unsigned int nr_domains;
|
|
|
|
unsigned long domain_map; /* bit map of active domains */
|
|
|
|
struct rapl_domain *domains; /* array of domains, sized at runtime */
|
|
|
|
struct powercap_zone *power_zone; /* keep track of parent zone */
|
|
|
|
unsigned long power_limit_irq; /* keep track of package power limit
|
|
|
|
* notify interrupt enable status.
|
|
|
|
*/
|
|
|
|
struct list_head plist;
|
|
|
|
int lead_cpu; /* one active cpu per package for access */
|
|
|
|
/* Track active cpus */
|
|
|
|
struct cpumask cpumask;
|
|
|
|
char name[PACKAGE_DOMAIN_NAME_LENGTH];
|
2019-07-10 21:44:25 +08:00
|
|
|
struct rapl_if_priv *priv;
|
2019-07-10 21:44:24 +08:00
|
|
|
};
|
|
|
|
|
powercap: intel_rapl: Make cpu optional for rapl_package
MSR RAPL Interface always removes a rapl_package when all the CPUs in
that rapl_package are offlined. This is because it relies on an online
CPU to access the MSR.
But for RAPL Interface using MMIO registers, when all the cpus within
the rapl_package are offlined,
1. the register can still be accessed
2. monitoring and setting the Power Pimits for the rapl_package is still
meaningful because of uncore power.
This means that, a valid rapl_package doesn't rely on one or more cpus
being onlined.
For this sense, make cpu optional for rapl_package. A rapl_package can
be registered either using a CPU id to represent the physical
package/die, or using the physical package id directly.
Note that, the thermal throttling interrupt is not disabled via
MSR_IA32_PACKAGE_THERM_INTERRUPT for such rapl_package at the moment.
If it is still needed in the future, this can be achieved by selecting
an onlined CPU using the physical package id.
Note that, processor_thermal_rapl, the current MMIO RAPL Interface
driver, can also be converted to register using a package id instead.
But this is not done right now because processor_thermal_rapl driver
works on single-package systems only, and offlining the only package
will not happen. So keep the previous logic.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested-by: Wang Wendy <wendy.wang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-19 10:44:16 +08:00
|
|
|
struct rapl_package *rapl_find_package_domain(int id, struct rapl_if_priv *priv, bool id_is_cpu);
|
|
|
|
struct rapl_package *rapl_add_package(int id, struct rapl_if_priv *priv, bool id_is_cpu);
|
2019-07-10 21:44:30 +08:00
|
|
|
void rapl_remove_package(struct rapl_package *rp);
|
|
|
|
|
2019-07-10 21:44:24 +08:00
|
|
|
#endif /* __INTEL_RAPL_H__ */
|