Skip to content

Commit 04bcbed

Browse files
Kuppuswamy Sathyanarayananrafaeljw
authored andcommitted
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>
1 parent 3e6996c commit 04bcbed

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

drivers/powercap/intel_rapl_common.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@
100100

101101
#define RAPL_EVENT_MASK GENMASK(7, 0)
102102

103-
enum unit_type {
104-
ARBITRARY_UNIT, /* no translation */
105-
POWER_UNIT,
106-
ENERGY_UNIT,
107-
TIME_UNIT,
108-
};
109-
110103
static const char *pl_names[NR_POWER_LIMITS] = {
111104
[POWER_LIMIT1] = "long_term",
112105
[POWER_LIMIT2] = "short_term",
@@ -208,27 +201,6 @@ static const struct rapl_defaults *get_defaults(struct rapl_package *rp)
208201
return rp->priv->defaults;
209202
}
210203

211-
/* per domain data. used to describe individual knobs such that access function
212-
* can be consolidated into one instead of many inline functions.
213-
*/
214-
struct rapl_primitive_info {
215-
const char *name;
216-
u64 mask;
217-
int shift;
218-
enum rapl_domain_reg_id id;
219-
enum unit_type unit;
220-
u32 flag;
221-
};
222-
223-
#define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) { \
224-
.name = #p, \
225-
.mask = m, \
226-
.shift = s, \
227-
.id = i, \
228-
.unit = u, \
229-
.flag = f \
230-
}
231-
232204
static void rapl_init_domains(struct rapl_package *rp);
233205
static int rapl_read_data_raw(struct rapl_domain *rd,
234206
enum rapl_primitives prim,
@@ -748,10 +720,10 @@ static int rapl_config(struct rapl_package *rp)
748720
/* MMIO I/F shares the same register layout as MSR registers */
749721
case RAPL_IF_MMIO:
750722
case RAPL_IF_MSR:
751-
rp->priv->rpi = (void *)rpi_msr;
723+
rp->priv->rpi = rpi_msr;
752724
break;
753725
case RAPL_IF_TPMI:
754-
rp->priv->rpi = (void *)rpi_tpmi;
726+
rp->priv->rpi = rpi_tpmi;
755727
break;
756728
default:
757729
return -EINVAL;

include/linux/intel_rapl.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,34 @@ struct rapl_defaults {
137137
bool spr_psys_bits;
138138
};
139139

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+
140168
/**
141169
* struct rapl_if_priv: private data for different RAPL interfaces
142170
* @control_type: Each RAPL interface must have its own powercap
@@ -152,7 +180,7 @@ struct rapl_defaults {
152180
* @write_raw: Callback for writing RAPL interface specific
153181
* registers.
154182
* @defaults: pointer to default settings
155-
* @rpi: internal pointer to interface primitive info
183+
* @rpi: pointer to interface primitive info
156184
*/
157185
struct rapl_if_priv {
158186
enum rapl_if_type type;
@@ -164,7 +192,7 @@ struct rapl_if_priv {
164192
int (*read_raw)(int id, struct reg_action *ra, bool pmu_ctx);
165193
int (*write_raw)(int id, struct reg_action *ra);
166194
const struct rapl_defaults *defaults;
167-
void *rpi;
195+
struct rapl_primitive_info *rpi;
168196
};
169197

170198
#ifdef CONFIG_PERF_EVENTS

0 commit comments

Comments
 (0)