intel_rapl.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <[email protected]>
  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_domain;
  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. PSYS_POWER_LIMIT1,
  52. PSYS_POWER_LIMIT2,
  53. PSYS_PL1_ENABLE,
  54. PSYS_PL2_ENABLE,
  55. PSYS_TIME_WINDOW1,
  56. PSYS_TIME_WINDOW2,
  57. /* below are not raw primitive data */
  58. AVERAGE_POWER,
  59. NR_RAPL_PRIMITIVES,
  60. };
  61. struct rapl_domain_data {
  62. u64 primitives[NR_RAPL_PRIMITIVES];
  63. unsigned long timestamp;
  64. };
  65. #define NR_POWER_LIMITS (3)
  66. struct rapl_power_limit {
  67. struct powercap_zone_constraint *constraint;
  68. int prim_id; /* primitive ID used to enable */
  69. struct rapl_domain *domain;
  70. const char *name;
  71. u64 last_power_limit;
  72. };
  73. struct rapl_package;
  74. #define RAPL_DOMAIN_NAME_LENGTH 16
  75. struct rapl_domain {
  76. char name[RAPL_DOMAIN_NAME_LENGTH];
  77. enum rapl_domain_type id;
  78. u64 regs[RAPL_DOMAIN_REG_MAX];
  79. struct powercap_zone power_zone;
  80. struct rapl_domain_data rdd;
  81. struct rapl_power_limit rpl[NR_POWER_LIMITS];
  82. u64 attr_map; /* track capabilities */
  83. unsigned int state;
  84. unsigned int domain_energy_unit;
  85. struct rapl_package *rp;
  86. };
  87. struct reg_action {
  88. u64 reg;
  89. u64 mask;
  90. u64 value;
  91. int err;
  92. };
  93. /**
  94. * struct rapl_if_priv: private data for different RAPL interfaces
  95. * @control_type: Each RAPL interface must have its own powercap
  96. * control type.
  97. * @platform_rapl_domain: Optional. Some RAPL interface may have platform
  98. * level RAPL control.
  99. * @pcap_rapl_online: CPU hotplug state for each RAPL interface.
  100. * @reg_unit: Register for getting energy/power/time unit.
  101. * @regs: Register sets for different RAPL Domains.
  102. * @limits: Number of power limits supported by each domain.
  103. * @read_raw: Callback for reading RAPL interface specific
  104. * registers.
  105. * @write_raw: Callback for writing RAPL interface specific
  106. * registers.
  107. */
  108. struct rapl_if_priv {
  109. struct powercap_control_type *control_type;
  110. struct rapl_domain *platform_rapl_domain;
  111. enum cpuhp_state pcap_rapl_online;
  112. u64 reg_unit;
  113. u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
  114. int limits[RAPL_DOMAIN_MAX];
  115. int (*read_raw)(int cpu, struct reg_action *ra);
  116. int (*write_raw)(int cpu, struct reg_action *ra);
  117. };
  118. /* maximum rapl package domain name: package-%d-die-%d */
  119. #define PACKAGE_DOMAIN_NAME_LENGTH 30
  120. struct rapl_package {
  121. unsigned int id; /* logical die id, equals physical 1-die systems */
  122. unsigned int nr_domains;
  123. unsigned long domain_map; /* bit map of active domains */
  124. unsigned int power_unit;
  125. unsigned int energy_unit;
  126. unsigned int time_unit;
  127. struct rapl_domain *domains; /* array of domains, sized at runtime */
  128. struct powercap_zone *power_zone; /* keep track of parent zone */
  129. unsigned long power_limit_irq; /* keep track of package power limit
  130. * notify interrupt enable status.
  131. */
  132. struct list_head plist;
  133. int lead_cpu; /* one active cpu per package for access */
  134. /* Track active cpus */
  135. struct cpumask cpumask;
  136. char name[PACKAGE_DOMAIN_NAME_LENGTH];
  137. struct rapl_if_priv *priv;
  138. };
  139. struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv);
  140. struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv);
  141. void rapl_remove_package(struct rapl_package *rp);
  142. #endif /* __INTEL_RAPL_H__ */