Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  Data types and headers for RAPL support
0004  *
0005  *  Copyright (C) 2019  Intel Corporation.
0006  *
0007  *  Author: Zhang Rui <rui.zhang@intel.com>
0008  */
0009 
0010 #ifndef __INTEL_RAPL_H__
0011 #define __INTEL_RAPL_H__
0012 
0013 #include <linux/types.h>
0014 #include <linux/powercap.h>
0015 #include <linux/cpuhotplug.h>
0016 
0017 enum rapl_domain_type {
0018     RAPL_DOMAIN_PACKAGE,    /* entire package/socket */
0019     RAPL_DOMAIN_PP0,    /* core power plane */
0020     RAPL_DOMAIN_PP1,    /* graphics uncore */
0021     RAPL_DOMAIN_DRAM,   /* DRAM control_type */
0022     RAPL_DOMAIN_PLATFORM,   /* PSys control_type */
0023     RAPL_DOMAIN_MAX,
0024 };
0025 
0026 enum rapl_domain_reg_id {
0027     RAPL_DOMAIN_REG_LIMIT,
0028     RAPL_DOMAIN_REG_STATUS,
0029     RAPL_DOMAIN_REG_PERF,
0030     RAPL_DOMAIN_REG_POLICY,
0031     RAPL_DOMAIN_REG_INFO,
0032     RAPL_DOMAIN_REG_PL4,
0033     RAPL_DOMAIN_REG_MAX,
0034 };
0035 
0036 struct rapl_domain;
0037 
0038 enum rapl_primitives {
0039     ENERGY_COUNTER,
0040     POWER_LIMIT1,
0041     POWER_LIMIT2,
0042     POWER_LIMIT4,
0043     FW_LOCK,
0044 
0045     PL1_ENABLE,     /* power limit 1, aka long term */
0046     PL1_CLAMP,      /* allow frequency to go below OS request */
0047     PL2_ENABLE,     /* power limit 2, aka short term, instantaneous */
0048     PL2_CLAMP,
0049     PL4_ENABLE,     /* power limit 4, aka max peak power */
0050 
0051     TIME_WINDOW1,       /* long term */
0052     TIME_WINDOW2,       /* short term */
0053     THERMAL_SPEC_POWER,
0054     MAX_POWER,
0055 
0056     MIN_POWER,
0057     MAX_TIME_WINDOW,
0058     THROTTLED_TIME,
0059     PRIORITY_LEVEL,
0060 
0061     PSYS_POWER_LIMIT1,
0062     PSYS_POWER_LIMIT2,
0063     PSYS_PL1_ENABLE,
0064     PSYS_PL2_ENABLE,
0065     PSYS_TIME_WINDOW1,
0066     PSYS_TIME_WINDOW2,
0067     /* below are not raw primitive data */
0068     AVERAGE_POWER,
0069     NR_RAPL_PRIMITIVES,
0070 };
0071 
0072 struct rapl_domain_data {
0073     u64 primitives[NR_RAPL_PRIMITIVES];
0074     unsigned long timestamp;
0075 };
0076 
0077 #define NR_POWER_LIMITS (3)
0078 struct rapl_power_limit {
0079     struct powercap_zone_constraint *constraint;
0080     int prim_id;        /* primitive ID used to enable */
0081     struct rapl_domain *domain;
0082     const char *name;
0083     u64 last_power_limit;
0084 };
0085 
0086 struct rapl_package;
0087 
0088 #define RAPL_DOMAIN_NAME_LENGTH 16
0089 
0090 struct rapl_domain {
0091     char name[RAPL_DOMAIN_NAME_LENGTH];
0092     enum rapl_domain_type id;
0093     u64 regs[RAPL_DOMAIN_REG_MAX];
0094     struct powercap_zone power_zone;
0095     struct rapl_domain_data rdd;
0096     struct rapl_power_limit rpl[NR_POWER_LIMITS];
0097     u64 attr_map;       /* track capabilities */
0098     unsigned int state;
0099     unsigned int domain_energy_unit;
0100     struct rapl_package *rp;
0101 };
0102 
0103 struct reg_action {
0104     u64 reg;
0105     u64 mask;
0106     u64 value;
0107     int err;
0108 };
0109 
0110 /**
0111  * struct rapl_if_priv: private data for different RAPL interfaces
0112  * @control_type:       Each RAPL interface must have its own powercap
0113  *              control type.
0114  * @platform_rapl_domain:   Optional. Some RAPL interface may have platform
0115  *              level RAPL control.
0116  * @pcap_rapl_online:       CPU hotplug state for each RAPL interface.
0117  * @reg_unit:           Register for getting energy/power/time unit.
0118  * @regs:           Register sets for different RAPL Domains.
0119  * @limits:         Number of power limits supported by each domain.
0120  * @read_raw:           Callback for reading RAPL interface specific
0121  *              registers.
0122  * @write_raw:          Callback for writing RAPL interface specific
0123  *              registers.
0124  */
0125 struct rapl_if_priv {
0126     struct powercap_control_type *control_type;
0127     struct rapl_domain *platform_rapl_domain;
0128     enum cpuhp_state pcap_rapl_online;
0129     u64 reg_unit;
0130     u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
0131     int limits[RAPL_DOMAIN_MAX];
0132     int (*read_raw)(int cpu, struct reg_action *ra);
0133     int (*write_raw)(int cpu, struct reg_action *ra);
0134 };
0135 
0136 /* maximum rapl package domain name: package-%d-die-%d */
0137 #define PACKAGE_DOMAIN_NAME_LENGTH 30
0138 
0139 struct rapl_package {
0140     unsigned int id;    /* logical die id, equals physical 1-die systems */
0141     unsigned int nr_domains;
0142     unsigned long domain_map;   /* bit map of active domains */
0143     unsigned int power_unit;
0144     unsigned int energy_unit;
0145     unsigned int time_unit;
0146     struct rapl_domain *domains;    /* array of domains, sized at runtime */
0147     struct powercap_zone *power_zone;   /* keep track of parent zone */
0148     unsigned long power_limit_irq;  /* keep track of package power limit
0149                      * notify interrupt enable status.
0150                      */
0151     struct list_head plist;
0152     int lead_cpu;       /* one active cpu per package for access */
0153     /* Track active cpus */
0154     struct cpumask cpumask;
0155     char name[PACKAGE_DOMAIN_NAME_LENGTH];
0156     struct rapl_if_priv *priv;
0157 };
0158 
0159 struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv);
0160 struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv);
0161 void rapl_remove_package(struct rapl_package *rp);
0162 
0163 #endif /* __INTEL_RAPL_H__ */