Skip to content

Commit dbc58f7

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Generate default_ctrl instead of sharing it
The struct rdt_resource default_ctrl is used by both the architecture code for resetting the hardware controls, and sometimes by the filesystem code as the default value for the schema, unless the bandwidth software controller is in use. Having the default exposed by the architecture code causes unnecessary duplication for each architecture as the default value must be specified, but can be derived from other schema properties. Now that the maximum bandwidth is explicitly described, resctrl can derive the default value from the schema format and the other resource properties. 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: 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: Shanker Donthineni <sdonthineni@nvidia.com> # arm64 Tested-by: Babu Moger <babu.moger@amd.com> Link: https://lore.kernel.org/r/20250311183715.16445-9-james.morse@arm.com
1 parent 634ebb9 commit dbc58f7

4 files changed

Lines changed: 28 additions & 15 deletions

File tree

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ static inline void cache_alloc_hsw_probe(void)
155155
return;
156156

157157
hw_res->num_closid = 4;
158-
r->default_ctrl = max_cbm;
159158
r->cache.cbm_len = 20;
160159
r->cache.shareable_bits = 0xc0000;
161160
r->cache.min_cbm_bits = 2;
@@ -211,7 +210,6 @@ static __init bool __get_mem_config_intel(struct rdt_resource *r)
211210
cpuid_count(0x00000010, 3, &eax.full, &ebx, &ecx, &edx.full);
212211
hw_res->num_closid = edx.split.cos_max + 1;
213212
max_delay = eax.split.max_delay + 1;
214-
r->default_ctrl = MAX_MBA_BW;
215213
r->membw.max_bw = MAX_MBA_BW;
216214
r->membw.arch_needs_linear = true;
217215
if (ecx & MBA_IS_LINEAR) {
@@ -250,7 +248,6 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
250248

251249
cpuid_count(0x80000020, subleaf, &eax, &ebx, &ecx, &edx);
252250
hw_res->num_closid = edx + 1;
253-
r->default_ctrl = 1 << eax;
254251
r->membw.max_bw = 1 << eax;
255252

256253
/* AMD does not use delay */
@@ -276,13 +273,13 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
276273
union cpuid_0x10_1_eax eax;
277274
union cpuid_0x10_x_ecx ecx;
278275
union cpuid_0x10_x_edx edx;
279-
u32 ebx;
276+
u32 ebx, default_ctrl;
280277

281278
cpuid_count(0x00000010, idx, &eax.full, &ebx, &ecx.full, &edx.full);
282279
hw_res->num_closid = edx.split.cos_max + 1;
283280
r->cache.cbm_len = eax.split.cbm_len + 1;
284-
r->default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1;
285-
r->cache.shareable_bits = ebx & r->default_ctrl;
281+
default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1;
282+
r->cache.shareable_bits = ebx & default_ctrl;
286283
if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
287284
r->cache.arch_has_sparse_bitmasks = ecx.split.noncont;
288285
r->alloc_capable = true;
@@ -329,7 +326,7 @@ static u32 delay_bw_map(unsigned long bw, struct rdt_resource *r)
329326
return MAX_MBA_BW - bw;
330327

331328
pr_warn_once("Non Linear delay-bw map not supported but queried\n");
332-
return r->default_ctrl;
329+
return MAX_MBA_BW;
333330
}
334331

335332
static void mba_wrmsr_intel(struct msr_param *m)
@@ -438,7 +435,7 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
438435
* For Memory Allocation: Set b/w requested to 100%
439436
*/
440437
for (i = 0; i < hw_res->num_closid; i++, dc++)
441-
*dc = r->default_ctrl;
438+
*dc = resctrl_get_default_ctrl(r);
442439
}
443440

444441
static void ctrl_domain_free(struct rdt_hw_ctrl_domain *hw_dom)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ static int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
113113
*/
114114
static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
115115
{
116-
unsigned long first_bit, zero_bit, val;
116+
u32 supported_bits = BIT_MASK(r->cache.cbm_len) - 1;
117117
unsigned int cbm_len = r->cache.cbm_len;
118+
unsigned long first_bit, zero_bit, val;
118119
int ret;
119120

120121
ret = kstrtoul(buf, 16, &val);
@@ -123,7 +124,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
123124
return false;
124125
}
125126

126-
if ((r->cache.min_cbm_bits > 0 && val == 0) || val > r->default_ctrl) {
127+
if ((r->cache.min_cbm_bits > 0 && val == 0) || val > supported_bits) {
127128
rdt_last_cmd_puts("Mask out of range\n");
128129
return false;
129130
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ static int rdt_default_ctrl_show(struct kernfs_open_file *of,
978978
struct resctrl_schema *s = of->kn->parent->priv;
979979
struct rdt_resource *r = s->res;
980980

981-
seq_printf(seq, "%x\n", r->default_ctrl);
981+
seq_printf(seq, "%x\n", resctrl_get_default_ctrl(r));
982982
return 0;
983983
}
984984

@@ -2882,7 +2882,7 @@ static int reset_all_ctrls(struct rdt_resource *r)
28822882
hw_dom = resctrl_to_arch_ctrl_dom(d);
28832883

28842884
for (i = 0; i < hw_res->num_closid; i++)
2885-
hw_dom->ctrl_val[i] = r->default_ctrl;
2885+
hw_dom->ctrl_val[i] = resctrl_get_default_ctrl(r);
28862886
msr_param.dom = d;
28872887
smp_call_function_any(&d->hdr.cpu_mask, rdt_ctrl_update, &msr_param, 1);
28882888
}
@@ -3417,7 +3417,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid)
34173417
}
34183418

34193419
cfg = &d->staged_config[CDP_NONE];
3420-
cfg->new_ctrl = r->default_ctrl;
3420+
cfg->new_ctrl = resctrl_get_default_ctrl(r);
34213421
cfg->have_new_ctrl = true;
34223422
}
34233423
}

include/linux/resctrl.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ enum resctrl_schema_fmt {
216216
* @ctrl_domains: RCU list of all control domains for this resource
217217
* @mon_domains: RCU list of all monitor domains for this resource
218218
* @name: Name to use in "schemata" file.
219-
* @default_ctrl: Specifies default cache cbm or memory B/W percent.
220219
* @schema_fmt: Which format string and parser is used for this schema.
221220
* @evt_list: List of monitoring events
222221
* @cdp_capable: Is the CDP feature available on this resource
@@ -233,7 +232,6 @@ struct rdt_resource {
233232
struct list_head ctrl_domains;
234233
struct list_head mon_domains;
235234
char *name;
236-
u32 default_ctrl;
237235
enum resctrl_schema_fmt schema_fmt;
238236
struct list_head evt_list;
239237
bool cdp_capable;
@@ -268,6 +266,23 @@ struct resctrl_schema {
268266
u32 num_closid;
269267
};
270268

269+
/**
270+
* resctrl_get_default_ctrl() - Return the default control value for this
271+
* resource.
272+
* @r: The resource whose default control type is queried.
273+
*/
274+
static inline u32 resctrl_get_default_ctrl(struct rdt_resource *r)
275+
{
276+
switch (r->schema_fmt) {
277+
case RESCTRL_SCHEMA_BITMAP:
278+
return BIT_MASK(r->cache.cbm_len) - 1;
279+
case RESCTRL_SCHEMA_RANGE:
280+
return r->membw.max_bw;
281+
}
282+
283+
return WARN_ON_ONCE(1);
284+
}
285+
271286
/* The number of closid supported by this resource regardless of CDP */
272287
u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
273288
u32 resctrl_arch_system_num_rmid_idx(void);

0 commit comments

Comments
 (0)