Skip to content

Commit f62b4e4

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Move get_config_index() to a header
get_config_index() is used by the architecture specific code to map a CLOSID+type pair to an index in the configuration arrays. MPAM needs to do this too to preserve the ABI to user-space, there is no reason to do it differently. Move the helper to a header file to allow all architectures that either use or emulate CDP to use the same pattern of CLOSID values. Moving this to a header file means it must be marked inline, which matches the existing compiler choice for this static function. Co-developed-by: Dave Martin <Dave.Martin@arm.com> Signed-off-by: Dave Martin <Dave.Martin@arm.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Babu Moger <babu.moger@amd.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64 Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64 Tested-by: Babu Moger <babu.moger@amd.com> Link: https://lore.kernel.org/r/20250311183715.16445-30-james.morse@arm.com
1 parent 6c2282d commit f62b4e4

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

arch/x86/kernel/cpu/resctrl/ctrlmondata.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -287,25 +287,12 @@ static int parse_line(char *line, struct resctrl_schema *s,
287287
return -EINVAL;
288288
}
289289

290-
static u32 get_config_index(u32 closid, enum resctrl_conf_type type)
291-
{
292-
switch (type) {
293-
default:
294-
case CDP_NONE:
295-
return closid;
296-
case CDP_CODE:
297-
return closid * 2 + 1;
298-
case CDP_DATA:
299-
return closid * 2;
300-
}
301-
}
302-
303290
int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
304291
u32 closid, enum resctrl_conf_type t, u32 cfg_val)
305292
{
306293
struct rdt_hw_ctrl_domain *hw_dom = resctrl_to_arch_ctrl_dom(d);
307294
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
308-
u32 idx = get_config_index(closid, t);
295+
u32 idx = resctrl_get_config_index(closid, t);
309296
struct msr_param msr_param;
310297

311298
if (!cpumask_test_cpu(smp_processor_id(), &d->hdr.cpu_mask))
@@ -342,7 +329,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
342329
if (!cfg->have_new_ctrl)
343330
continue;
344331

345-
idx = get_config_index(closid, t);
332+
idx = resctrl_get_config_index(closid, t);
346333
if (cfg->new_ctrl == hw_dom->ctrl_val[idx])
347334
continue;
348335
hw_dom->ctrl_val[idx] = cfg->new_ctrl;
@@ -462,7 +449,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
462449
u32 closid, enum resctrl_conf_type type)
463450
{
464451
struct rdt_hw_ctrl_domain *hw_dom = resctrl_to_arch_ctrl_dom(d);
465-
u32 idx = get_config_index(closid, type);
452+
u32 idx = resctrl_get_config_index(closid, type);
466453

467454
return hw_dom->ctrl_val[idx];
468455
}

include/linux/resctrl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,21 @@ void resctrl_arch_mon_event_config_write(void *config_info);
384384
*/
385385
void resctrl_arch_mon_event_config_read(void *config_info);
386386

387+
/* For use by arch code to remap resctrl's smaller CDP CLOSID range */
388+
static inline u32 resctrl_get_config_index(u32 closid,
389+
enum resctrl_conf_type type)
390+
{
391+
switch (type) {
392+
default:
393+
case CDP_NONE:
394+
return closid;
395+
case CDP_CODE:
396+
return closid * 2 + 1;
397+
case CDP_DATA:
398+
return closid * 2;
399+
}
400+
}
401+
387402
/*
388403
* Update the ctrl_val and apply this config right now.
389404
* Must be called on one of the domain's CPUs.

0 commit comments

Comments
 (0)