122 lines
2.9 KiB
C
Raw Normal View History

2026-01-21 18:59:54 +08:00
// SPDX-License-Identifier: GPL-2.0-only
/*
* Resource Director Technology(RDT)
* - Cache Allocation code.
*
* Copyright (C) 2016 Intel Corporation
*
* Authors:
* Fenghua Yu <fenghua.yu@intel.com>
* Tony Luck <tony.luck@intel.com>
*
* More information about RDT be found in the Intel (R) x86 Architecture
* Software Developer Manual June 2016, volume 3, section 17.17.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/cpu.h>
#include <linux/kernfs.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
2026-01-29 22:25:33 +08:00
#include <linux/tick.h>
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
#include "internal.h"
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
static bool apply_config(struct rdt_hw_domain *hw_dom,
struct resctrl_staged_config *cfg, u32 idx,
cpumask_var_t cpu_mask)
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
struct rdt_domain *dom = &hw_dom->d_resctrl;
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) {
cpumask_set_cpu(cpumask_any(&dom->cpu_mask), cpu_mask);
hw_dom->ctrl_val[idx] = cfg->new_ctrl;
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
return true;
2026-01-21 18:59:54 +08:00
}
2026-01-29 22:25:33 +08:00
return false;
2026-01-21 18:59:54 +08:00
}
2026-01-29 22:25:33 +08:00
int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,
u32 closid, enum resctrl_conf_type t, u32 cfg_val)
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
u32 idx = resctrl_get_config_index(closid, t);
struct msr_param msr_param;
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
2026-01-21 18:59:54 +08:00
return -EINVAL;
2026-01-29 22:25:33 +08:00
hw_dom->ctrl_val[idx] = cfg_val;
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
msr_param.res = r;
msr_param.low = idx;
msr_param.high = idx + 1;
hw_res->msr_update(d, &msr_param, r);
2026-01-21 18:59:54 +08:00
return 0;
}
2026-01-29 22:25:33 +08:00
int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
struct resctrl_staged_config *cfg;
struct rdt_hw_domain *hw_dom;
2026-01-21 18:59:54 +08:00
struct msr_param msr_param;
2026-01-29 22:25:33 +08:00
enum resctrl_conf_type t;
2026-01-21 18:59:54 +08:00
cpumask_var_t cpu_mask;
struct rdt_domain *d;
2026-01-29 22:25:33 +08:00
u32 idx;
/* Walking r->domains, ensure it can't race with cpuhp */
lockdep_assert_cpus_held();
2026-01-21 18:59:54 +08:00
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
return -ENOMEM;
2026-01-29 22:25:33 +08:00
msr_param.res = NULL;
2026-01-21 18:59:54 +08:00
list_for_each_entry(d, &r->domains, list) {
2026-01-29 22:25:33 +08:00
hw_dom = resctrl_to_arch_dom(d);
for (t = 0; t < CDP_NUM_TYPES; t++) {
cfg = &hw_dom->d_resctrl.staged_config[t];
if (!cfg->have_new_ctrl)
continue;
idx = resctrl_get_config_index(closid, t);
if (!apply_config(hw_dom, cfg, idx, cpu_mask))
continue;
if (!msr_param.res) {
msr_param.low = idx;
msr_param.high = msr_param.low + 1;
msr_param.res = r;
} else {
msr_param.low = min(msr_param.low, idx);
msr_param.high = max(msr_param.high, idx + 1);
}
2026-01-21 18:59:54 +08:00
}
}
2026-01-29 22:25:33 +08:00
if (cpumask_empty(cpu_mask))
2026-01-21 18:59:54 +08:00
goto done;
2026-01-29 22:25:33 +08:00
/* Update resource control msr on all the CPUs. */
on_each_cpu_mask(cpu_mask, rdt_ctrl_update, &msr_param, 1);
2026-01-21 18:59:54 +08:00
done:
free_cpumask_var(cpu_mask);
return 0;
}
2026-01-29 22:25:33 +08:00
u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
u32 closid, enum resctrl_conf_type type)
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
u32 idx = resctrl_get_config_index(closid, type);
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
return hw_dom->ctrl_val[idx];
2026-01-21 18:59:54 +08:00
}