intel_rapl.h 4.1 KB

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