linux/include/linux/intel_rapl.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 *  Data types and headers for RAPL support
   4 *
   5 *  Copyright (C) 2019  Intel Corporation.
   6 *
   7 *  Author: Zhang Rui <rui.zhang@intel.com>
   8 */
   9
  10#ifndef __INTEL_RAPL_H__
  11#define __INTEL_RAPL_H__
  12
  13#include <linux/types.h>
  14#include <linux/powercap.h>
  15#include <linux/cpuhotplug.h>
  16
  17enum rapl_domain_type {
  18        RAPL_DOMAIN_PACKAGE,    /* entire package/socket */
  19        RAPL_DOMAIN_PP0,        /* core power plane */
  20        RAPL_DOMAIN_PP1,        /* graphics uncore */
  21        RAPL_DOMAIN_DRAM,       /* DRAM control_type */
  22        RAPL_DOMAIN_PLATFORM,   /* PSys control_type */
  23        RAPL_DOMAIN_MAX,
  24};
  25
  26enum rapl_domain_reg_id {
  27        RAPL_DOMAIN_REG_LIMIT,
  28        RAPL_DOMAIN_REG_STATUS,
  29        RAPL_DOMAIN_REG_PERF,
  30        RAPL_DOMAIN_REG_POLICY,
  31        RAPL_DOMAIN_REG_INFO,
  32        RAPL_DOMAIN_REG_MAX,
  33};
  34
  35struct rapl_package;
  36
  37enum rapl_primitives {
  38        ENERGY_COUNTER,
  39        POWER_LIMIT1,
  40        POWER_LIMIT2,
  41        FW_LOCK,
  42
  43        PL1_ENABLE,             /* power limit 1, aka long term */
  44        PL1_CLAMP,              /* allow frequency to go below OS request */
  45        PL2_ENABLE,             /* power limit 2, aka short term, instantaneous */
  46        PL2_CLAMP,
  47
  48        TIME_WINDOW1,           /* long term */
  49        TIME_WINDOW2,           /* short term */
  50        THERMAL_SPEC_POWER,
  51        MAX_POWER,
  52
  53        MIN_POWER,
  54        MAX_TIME_WINDOW,
  55        THROTTLED_TIME,
  56        PRIORITY_LEVEL,
  57
  58        /* below are not raw primitive data */
  59        AVERAGE_POWER,
  60        NR_RAPL_PRIMITIVES,
  61};
  62
  63struct rapl_domain_data {
  64        u64 primitives[NR_RAPL_PRIMITIVES];
  65        unsigned long timestamp;
  66};
  67
  68#define NR_POWER_LIMITS (2)
  69struct rapl_power_limit {
  70        struct powercap_zone_constraint *constraint;
  71        int prim_id;            /* primitive ID used to enable */
  72        struct rapl_domain *domain;
  73        const char *name;
  74        u64 last_power_limit;
  75};
  76
  77struct rapl_package;
  78
  79#define RAPL_DOMAIN_NAME_LENGTH 16
  80
  81struct rapl_domain {
  82        char name[RAPL_DOMAIN_NAME_LENGTH];
  83        enum rapl_domain_type id;
  84        u64 regs[RAPL_DOMAIN_REG_MAX];
  85        struct powercap_zone power_zone;
  86        struct rapl_domain_data rdd;
  87        struct rapl_power_limit rpl[NR_POWER_LIMITS];
  88        u64 attr_map;           /* track capabilities */
  89        unsigned int state;
  90        unsigned int domain_energy_unit;
  91        struct rapl_package *rp;
  92};
  93
  94struct reg_action {
  95        u64 reg;
  96        u64 mask;
  97        u64 value;
  98        int err;
  99};
 100
 101/**
 102 * struct rapl_if_priv: private data for different RAPL interfaces
 103 * @control_type:               Each RAPL interface must have its own powercap
 104 *                              control type.
 105 * @platform_rapl_domain:       Optional. Some RAPL interface may have platform
 106 *                              level RAPL control.
 107 * @pcap_rapl_online:           CPU hotplug state for each RAPL interface.
 108 * @reg_unit:                   Register for getting energy/power/time unit.
 109 * @regs:                       Register sets for different RAPL Domains.
 110 * @limits:                     Number of power limits supported by each domain.
 111 * @read_raw:                   Callback for reading RAPL interface specific
 112 *                              registers.
 113 * @write_raw:                  Callback for writing RAPL interface specific
 114 *                              registers.
 115 */
 116struct rapl_if_priv {
 117        struct powercap_control_type *control_type;
 118        struct rapl_domain *platform_rapl_domain;
 119        enum cpuhp_state pcap_rapl_online;
 120        u64 reg_unit;
 121        u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
 122        int limits[RAPL_DOMAIN_MAX];
 123        int (*read_raw)(int cpu, struct reg_action *ra);
 124        int (*write_raw)(int cpu, struct reg_action *ra);
 125};
 126
 127/* maximum rapl package domain name: package-%d-die-%d */
 128#define PACKAGE_DOMAIN_NAME_LENGTH 30
 129
 130struct rapl_package {
 131        unsigned int id;        /* logical die id, equals physical 1-die systems */
 132        unsigned int nr_domains;
 133        unsigned long domain_map;       /* bit map of active domains */
 134        unsigned int power_unit;
 135        unsigned int energy_unit;
 136        unsigned int time_unit;
 137        struct rapl_domain *domains;    /* array of domains, sized at runtime */
 138        struct powercap_zone *power_zone;       /* keep track of parent zone */
 139        unsigned long power_limit_irq;  /* keep track of package power limit
 140                                         * notify interrupt enable status.
 141                                         */
 142        struct list_head plist;
 143        int lead_cpu;           /* one active cpu per package for access */
 144        /* Track active cpus */
 145        struct cpumask cpumask;
 146        char name[PACKAGE_DOMAIN_NAME_LENGTH];
 147        struct rapl_if_priv *priv;
 148};
 149
 150struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv);
 151struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv);
 152void rapl_remove_package(struct rapl_package *rp);
 153
 154#endif /* __INTEL_RAPL_H__ */
 155