Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

powercap: intel_rapl: Allow interface drivers to configure rapl_defaults

RAPL default settings vary across different RAPL interfaces (MSR, TPMI,
MMIO). Currently, these defaults are stored in the common RAPL driver,
which requires interface-specific handling logic and makes the common
layer unnecessarily complex. There is no strong reason for the common
code to own these defaults, since they are inherently
interface-specific.

To prepare for moving default configuration into the individual
interface drivers,

1. Move struct rapl_defaults into a shared header so that interface
drivers can directly populate their own default settings.

2. Change the @defaults field in struct rapl_if_priv from void * to
const struct rapl_defaults * to improve type safety and readability
and update the common driver to use the typed defaults structure.

3. Update all internal getter functions and local pointers to use
const struct rapl_defaults * to maintain const-correctness.

4. Rename and export the common helper functions (check_unit,
set_floor_freq, compute_time_window) so interface drivers may
reuse or override them as appropriate.

No functional changes. This is a preparatory refactoring to allow
interface drivers to supply their own RAPL default settings.

Co-developed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://patch.msgid.link/20260212233044.329790-9-sathyanarayanan.kuppuswamy@linux.intel.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Kuppuswamy Sathyanarayanan and committed by
Rafael J. Wysocki
d7ca7d14 90503f9f

+43 -38
+28 -36
drivers/powercap/intel_rapl_common.c
··· 221 221 #define power_zone_to_rapl_domain(_zone) \ 222 222 container_of(_zone, struct rapl_domain, power_zone) 223 223 224 - struct rapl_defaults { 225 - u8 floor_freq_reg_addr; 226 - int (*check_unit)(struct rapl_domain *rd); 227 - void (*set_floor_freq)(struct rapl_domain *rd, bool mode); 228 - u64 (*compute_time_window)(struct rapl_domain *rd, u64 val, 229 - bool to_raw); 230 - unsigned int dram_domain_energy_unit; 231 - unsigned int psys_domain_energy_unit; 232 - bool spr_psys_bits; 233 - }; 234 - static struct rapl_defaults *defaults_msr; 224 + static const struct rapl_defaults *defaults_msr; 235 225 static const struct rapl_defaults defaults_tpmi; 236 226 237 - static struct rapl_defaults *get_defaults(struct rapl_package *rp) 227 + static const struct rapl_defaults *get_defaults(struct rapl_package *rp) 238 228 { 239 229 return rp->priv->defaults; 240 230 } ··· 341 351 static int set_domain_enable(struct powercap_zone *power_zone, bool mode) 342 352 { 343 353 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone); 344 - struct rapl_defaults *defaults = get_defaults(rd->rp); 354 + const struct rapl_defaults *defaults = get_defaults(rd->rp); 345 355 u64 val; 346 356 int ret; 347 357 ··· 630 640 u64 value, int to_raw) 631 641 { 632 642 u64 units = 1; 633 - struct rapl_defaults *defaults = get_defaults(rd->rp); 643 + const struct rapl_defaults *defaults = get_defaults(rd->rp); 634 644 u64 scale = 1; 635 645 636 646 switch (type) { ··· 775 785 /* MMIO I/F shares the same register layout as MSR registers */ 776 786 case RAPL_IF_MMIO: 777 787 case RAPL_IF_MSR: 778 - rp->priv->defaults = (void *)defaults_msr; 788 + rp->priv->defaults = defaults_msr; 779 789 rp->priv->rpi = (void *)rpi_msr; 780 790 break; 781 791 case RAPL_IF_TPMI: 782 - rp->priv->defaults = (void *)&defaults_tpmi; 792 + rp->priv->defaults = &defaults_tpmi; 783 793 rp->priv->rpi = (void *)rpi_tpmi; 784 794 break; 785 795 default: ··· 796 806 static enum rapl_primitives 797 807 prim_fixups(struct rapl_domain *rd, enum rapl_primitives prim) 798 808 { 799 - struct rapl_defaults *defaults = get_defaults(rd->rp); 809 + const struct rapl_defaults *defaults = get_defaults(rd->rp); 800 810 801 811 if (!defaults->spr_psys_bits) 802 812 return prim; ··· 941 951 * power unit : microWatts : Represented in milliWatts by default 942 952 * time unit : microseconds: Represented in seconds by default 943 953 */ 944 - static int rapl_check_unit_core(struct rapl_domain *rd) 954 + int rapl_default_check_unit(struct rapl_domain *rd) 945 955 { 946 956 struct reg_action ra; 947 957 u32 value; ··· 968 978 969 979 return 0; 970 980 } 981 + EXPORT_SYMBOL_NS_GPL(rapl_default_check_unit, "INTEL_RAPL"); 971 982 972 983 static int rapl_check_unit_atom(struct rapl_domain *rd) 973 984 { ··· 1062 1071 wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h); 1063 1072 } 1064 1073 1065 - static void set_floor_freq_default(struct rapl_domain *rd, bool mode) 1074 + void rapl_default_set_floor_freq(struct rapl_domain *rd, bool mode) 1066 1075 { 1067 1076 int i; 1068 1077 ··· 1076 1085 rapl_write_pl_data(rd, i, PL_CLAMP, mode); 1077 1086 } 1078 1087 } 1088 + EXPORT_SYMBOL_NS_GPL(rapl_default_set_floor_freq, "INTEL_RAPL"); 1079 1089 1080 1090 static void set_floor_freq_atom(struct rapl_domain *rd, bool enable) 1081 1091 { 1082 1092 static u32 power_ctrl_orig_val; 1083 - struct rapl_defaults *defaults = get_defaults(rd->rp); 1093 + const struct rapl_defaults *defaults = get_defaults(rd->rp); 1084 1094 u32 mdata; 1085 1095 1086 1096 if (!defaults->floor_freq_reg_addr) { ··· 1102 1110 defaults->floor_freq_reg_addr, mdata); 1103 1111 } 1104 1112 1105 - static u64 rapl_compute_time_window_core(struct rapl_domain *rd, u64 value, 1106 - bool to_raw) 1113 + u64 rapl_default_compute_time_window(struct rapl_domain *rd, u64 value, bool to_raw) 1107 1114 { 1108 1115 u64 f, y; /* fraction and exp. used for time unit */ 1109 1116 ··· 1133 1142 } 1134 1143 return value; 1135 1144 } 1145 + EXPORT_SYMBOL_NS_GPL(rapl_default_compute_time_window, "INTEL_RAPL"); 1136 1146 1137 1147 static u64 rapl_compute_time_window_atom(struct rapl_domain *rd, u64 value, 1138 1148 bool to_raw) ··· 1179 1187 static const struct rapl_defaults defaults_tpmi = { 1180 1188 .check_unit = rapl_check_unit_tpmi, 1181 1189 /* Reuse existing logic, ignore the PL_CLAMP failures and enable all Power Limits */ 1182 - .set_floor_freq = set_floor_freq_default, 1183 - .compute_time_window = rapl_compute_time_window_core, 1190 + .set_floor_freq = rapl_default_set_floor_freq, 1191 + .compute_time_window = rapl_default_compute_time_window, 1184 1192 }; 1185 1193 1186 1194 static const struct rapl_defaults rapl_defaults_core = { 1187 1195 .floor_freq_reg_addr = 0, 1188 - .check_unit = rapl_check_unit_core, 1189 - .set_floor_freq = set_floor_freq_default, 1190 - .compute_time_window = rapl_compute_time_window_core, 1196 + .check_unit = rapl_default_check_unit, 1197 + .set_floor_freq = rapl_default_set_floor_freq, 1198 + .compute_time_window = rapl_default_compute_time_window, 1191 1199 }; 1192 1200 1193 1201 static const struct rapl_defaults rapl_defaults_hsw_server = { 1194 - .check_unit = rapl_check_unit_core, 1195 - .set_floor_freq = set_floor_freq_default, 1196 - .compute_time_window = rapl_compute_time_window_core, 1202 + .check_unit = rapl_default_check_unit, 1203 + .set_floor_freq = rapl_default_set_floor_freq, 1204 + .compute_time_window = rapl_default_compute_time_window, 1197 1205 .dram_domain_energy_unit = 15300, 1198 1206 }; 1199 1207 1200 1208 static const struct rapl_defaults rapl_defaults_spr_server = { 1201 - .check_unit = rapl_check_unit_core, 1202 - .set_floor_freq = set_floor_freq_default, 1203 - .compute_time_window = rapl_compute_time_window_core, 1209 + .check_unit = rapl_default_check_unit, 1210 + .set_floor_freq = rapl_default_set_floor_freq, 1211 + .compute_time_window = rapl_default_compute_time_window, 1204 1212 .psys_domain_energy_unit = NANOJOULE_PER_JOULE, 1205 1213 .spr_psys_bits = true, 1206 1214 }; ··· 1234 1242 }; 1235 1243 1236 1244 static const struct rapl_defaults rapl_defaults_amd = { 1237 - .check_unit = rapl_check_unit_core, 1245 + .check_unit = rapl_default_check_unit, 1238 1246 }; 1239 1247 1240 1248 static const struct x86_cpu_id rapl_ids[] __initconst = { ··· 1440 1448 */ 1441 1449 static int rapl_get_domain_unit(struct rapl_domain *rd) 1442 1450 { 1443 - struct rapl_defaults *defaults = get_defaults(rd->rp); 1451 + const struct rapl_defaults *defaults = get_defaults(rd->rp); 1444 1452 int ret; 1445 1453 1446 1454 if (!rd->regs[RAPL_DOMAIN_REG_UNIT].val) { ··· 2333 2341 2334 2342 id = x86_match_cpu(rapl_ids); 2335 2343 if (id) { 2336 - defaults_msr = (struct rapl_defaults *)id->driver_data; 2344 + defaults_msr = (const struct rapl_defaults *)id->driver_data; 2337 2345 2338 2346 rapl_msr_platdev = platform_device_alloc("intel_rapl_msr", 0); 2339 2347 if (!rapl_msr_platdev)
+15 -2
include/linux/intel_rapl.h
··· 128 128 int err; 129 129 }; 130 130 131 + struct rapl_defaults { 132 + u8 floor_freq_reg_addr; 133 + int (*check_unit)(struct rapl_domain *rd); 134 + void (*set_floor_freq)(struct rapl_domain *rd, bool mode); 135 + u64 (*compute_time_window)(struct rapl_domain *rd, u64 val, bool to_raw); 136 + unsigned int dram_domain_energy_unit; 137 + unsigned int psys_domain_energy_unit; 138 + bool spr_psys_bits; 139 + }; 140 + 131 141 /** 132 142 * struct rapl_if_priv: private data for different RAPL interfaces 133 143 * @control_type: Each RAPL interface must have its own powercap ··· 152 142 * registers. 153 143 * @write_raw: Callback for writing RAPL interface specific 154 144 * registers. 155 - * @defaults: internal pointer to interface default settings 145 + * @defaults: pointer to default settings 156 146 * @rpi: internal pointer to interface primitive info 157 147 */ 158 148 struct rapl_if_priv { ··· 164 154 int limits[RAPL_DOMAIN_MAX]; 165 155 int (*read_raw)(int id, struct reg_action *ra, bool pmu_ctx); 166 156 int (*write_raw)(int id, struct reg_action *ra); 167 - void *defaults; 157 + const struct rapl_defaults *defaults; 168 158 void *rpi; 169 159 }; 170 160 ··· 221 211 struct rapl_package *rapl_find_package_domain(int id, struct rapl_if_priv *priv, bool id_is_cpu); 222 212 struct rapl_package *rapl_add_package(int id, struct rapl_if_priv *priv, bool id_is_cpu); 223 213 void rapl_remove_package(struct rapl_package *rp); 214 + int rapl_default_check_unit(struct rapl_domain *rd); 215 + void rapl_default_set_floor_freq(struct rapl_domain *rd, bool mode); 216 + u64 rapl_default_compute_time_window(struct rapl_domain *rd, u64 value, bool to_raw); 224 217 225 218 #ifdef CONFIG_PERF_EVENTS 226 219 int rapl_package_add_pmu(struct rapl_package *rp);