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: Move primitive info to header for interface drivers

RAPL primitive information varies across different RAPL interfaces
(MSR, TPMI, MMIO). Keeping them in the common code adds no benefit, but
requires interface-specific handling logic and makes the common layer
unnecessarily complex.

Move the primitive info infrastructure to the shared header to allow
interface drivers to configure RAPL primitives. Specific changes:

1. Move struct rapl_primitive_info, enum unit_type, and
PRIMITIVE_INFO_INIT macro to intel_rapl.h.
2. Change the @rpi field in struct rapl_if_priv from void * to
struct rapl_primitive_info * to improve type safety and eliminate
unnecessary casts.

No functional changes. This is a preparatory refactoring to allow
interface drivers to supply their own RAPL primitive 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>
Link: https://patch.msgid.link/20260331211950.3329932-4-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
04bcbed4 3e6996c0

+32 -32
+2 -30
drivers/powercap/intel_rapl_common.c
··· 100 100 101 101 #define RAPL_EVENT_MASK GENMASK(7, 0) 102 102 103 - enum unit_type { 104 - ARBITRARY_UNIT, /* no translation */ 105 - POWER_UNIT, 106 - ENERGY_UNIT, 107 - TIME_UNIT, 108 - }; 109 - 110 103 static const char *pl_names[NR_POWER_LIMITS] = { 111 104 [POWER_LIMIT1] = "long_term", 112 105 [POWER_LIMIT2] = "short_term", ··· 200 207 { 201 208 return rp->priv->defaults; 202 209 } 203 - 204 - /* per domain data. used to describe individual knobs such that access function 205 - * can be consolidated into one instead of many inline functions. 206 - */ 207 - struct rapl_primitive_info { 208 - const char *name; 209 - u64 mask; 210 - int shift; 211 - enum rapl_domain_reg_id id; 212 - enum unit_type unit; 213 - u32 flag; 214 - }; 215 - 216 - #define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) { \ 217 - .name = #p, \ 218 - .mask = m, \ 219 - .shift = s, \ 220 - .id = i, \ 221 - .unit = u, \ 222 - .flag = f \ 223 - } 224 210 225 211 static void rapl_init_domains(struct rapl_package *rp); 226 212 static int rapl_read_data_raw(struct rapl_domain *rd, ··· 720 748 /* MMIO I/F shares the same register layout as MSR registers */ 721 749 case RAPL_IF_MMIO: 722 750 case RAPL_IF_MSR: 723 - rp->priv->rpi = (void *)rpi_msr; 751 + rp->priv->rpi = rpi_msr; 724 752 break; 725 753 case RAPL_IF_TPMI: 726 - rp->priv->rpi = (void *)rpi_tpmi; 754 + rp->priv->rpi = rpi_tpmi; 727 755 break; 728 756 default: 729 757 return -EINVAL;
+30 -2
include/linux/intel_rapl.h
··· 137 137 bool spr_psys_bits; 138 138 }; 139 139 140 + #define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) { \ 141 + .name = #p, \ 142 + .mask = m, \ 143 + .shift = s, \ 144 + .id = i, \ 145 + .unit = u, \ 146 + .flag = f \ 147 + } 148 + 149 + enum unit_type { 150 + ARBITRARY_UNIT, /* no translation */ 151 + POWER_UNIT, 152 + ENERGY_UNIT, 153 + TIME_UNIT, 154 + }; 155 + 156 + /* per domain data. used to describe individual knobs such that access function 157 + * can be consolidated into one instead of many inline functions. 158 + */ 159 + struct rapl_primitive_info { 160 + const char *name; 161 + u64 mask; 162 + int shift; 163 + enum rapl_domain_reg_id id; 164 + enum unit_type unit; 165 + u32 flag; 166 + }; 167 + 140 168 /** 141 169 * struct rapl_if_priv: private data for different RAPL interfaces 142 170 * @control_type: Each RAPL interface must have its own powercap ··· 180 152 * @write_raw: Callback for writing RAPL interface specific 181 153 * registers. 182 154 * @defaults: pointer to default settings 183 - * @rpi: internal pointer to interface primitive info 155 + * @rpi: pointer to interface primitive info 184 156 */ 185 157 struct rapl_if_priv { 186 158 enum rapl_if_type type; ··· 192 164 int (*read_raw)(int id, struct reg_action *ra, bool pmu_ctx); 193 165 int (*write_raw)(int id, struct reg_action *ra); 194 166 const struct rapl_defaults *defaults; 195 - void *rpi; 167 + struct rapl_primitive_info *rpi; 196 168 }; 197 169 198 170 #ifdef CONFIG_PERF_EVENTS