Skip to content

Commit e8f7282

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Group staged configuration into a separate struct
When configuration changes are made, the new value is written to struct rdt_domain's new_ctrl field and the have_new_ctrl flag is set. Later new_ctrl is copied to hardware by a call to update_domains(). Once the CDP resources are merged, there will be one new_ctrl field in use by two struct resctrl_schema requiring a per-schema IPI to copy the value to hardware. Move new_ctrl and have_new_ctrl into a new struct resctrl_staged_config. Before the CDP resources can be merged, struct rdt_domain will need an array of these, one per type of configuration. Using the type as an index to the array will ensure that a schema configuration string can't specify the same domain twice. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Jamie Iles <jamie@nuviainc.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Tested-by: Babu Moger <babu.moger@amd.com> Link: https://lkml.kernel.org/r/20210728170637.25610-14-james.morse@arm.com
1 parent e198fde commit e8f7282

File tree

3 files changed

+54
-27
lines changed

3 files changed

+54
-27
lines changed

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
6262
{
6363
struct rdt_resource *r = s->res;
6464
unsigned long bw_val;
65+
struct resctrl_staged_config *cfg = &d->staged_config;
6566

66-
if (d->have_new_ctrl) {
67+
if (cfg->have_new_ctrl) {
6768
rdt_last_cmd_printf("Duplicate domain %d\n", d->id);
6869
return -EINVAL;
6970
}
7071

7172
if (!bw_validate(data->buf, &bw_val, r))
7273
return -EINVAL;
73-
d->new_ctrl = bw_val;
74-
d->have_new_ctrl = true;
74+
cfg->new_ctrl = bw_val;
75+
cfg->have_new_ctrl = true;
7576

7677
return 0;
7778
}
@@ -129,11 +130,12 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
129130
int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
130131
struct rdt_domain *d)
131132
{
133+
struct resctrl_staged_config *cfg = &d->staged_config;
132134
struct rdtgroup *rdtgrp = data->rdtgrp;
133135
struct rdt_resource *r = s->res;
134136
u32 cbm_val;
135137

136-
if (d->have_new_ctrl) {
138+
if (cfg->have_new_ctrl) {
137139
rdt_last_cmd_printf("Duplicate domain %d\n", d->id);
138140
return -EINVAL;
139141
}
@@ -175,8 +177,8 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
175177
}
176178
}
177179

178-
d->new_ctrl = cbm_val;
179-
d->have_new_ctrl = true;
180+
cfg->new_ctrl = cbm_val;
181+
cfg->have_new_ctrl = true;
180182

181183
return 0;
182184
}
@@ -190,6 +192,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
190192
static int parse_line(char *line, struct resctrl_schema *s,
191193
struct rdtgroup *rdtgrp)
192194
{
195+
struct resctrl_staged_config *cfg;
193196
struct rdt_resource *r = s->res;
194197
struct rdt_parse_data data;
195198
char *dom = NULL, *id;
@@ -219,6 +222,7 @@ static int parse_line(char *line, struct resctrl_schema *s,
219222
if (r->parse_ctrlval(&data, s, d))
220223
return -EINVAL;
221224
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
225+
cfg = &d->staged_config;
222226
/*
223227
* In pseudo-locking setup mode and just
224228
* parsed a valid CBM that should be
@@ -229,7 +233,7 @@ static int parse_line(char *line, struct resctrl_schema *s,
229233
*/
230234
rdtgrp->plr->s = s;
231235
rdtgrp->plr->d = d;
232-
rdtgrp->plr->cbm = d->new_ctrl;
236+
rdtgrp->plr->cbm = cfg->new_ctrl;
233237
d->plr = rdtgrp->plr;
234238
return 0;
235239
}
@@ -239,14 +243,27 @@ static int parse_line(char *line, struct resctrl_schema *s,
239243
return -EINVAL;
240244
}
241245

246+
static void apply_config(struct rdt_hw_domain *hw_dom,
247+
struct resctrl_staged_config *cfg, int closid,
248+
cpumask_var_t cpu_mask, bool mba_sc)
249+
{
250+
struct rdt_domain *dom = &hw_dom->d_resctrl;
251+
u32 *dc = !mba_sc ? hw_dom->ctrl_val : hw_dom->mbps_val;
252+
253+
if (cfg->new_ctrl != dc[closid]) {
254+
cpumask_set_cpu(cpumask_any(&dom->cpu_mask), cpu_mask);
255+
dc[closid] = cfg->new_ctrl;
256+
}
257+
}
258+
242259
int update_domains(struct rdt_resource *r, int closid)
243260
{
261+
struct resctrl_staged_config *cfg;
244262
struct rdt_hw_domain *hw_dom;
245263
struct msr_param msr_param;
246264
cpumask_var_t cpu_mask;
247265
struct rdt_domain *d;
248266
bool mba_sc;
249-
u32 *dc;
250267
int cpu;
251268

252269
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
@@ -259,11 +276,9 @@ int update_domains(struct rdt_resource *r, int closid)
259276
mba_sc = is_mba_sc(r);
260277
list_for_each_entry(d, &r->domains, list) {
261278
hw_dom = resctrl_to_arch_dom(d);
262-
dc = !mba_sc ? hw_dom->ctrl_val : hw_dom->mbps_val;
263-
if (d->have_new_ctrl && d->new_ctrl != dc[closid]) {
264-
cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
265-
dc[closid] = d->new_ctrl;
266-
}
279+
cfg = &hw_dom->d_resctrl.staged_config;
280+
if (cfg->have_new_ctrl)
281+
apply_config(hw_dom, cfg, closid, cpu_mask, mba_sc);
267282
}
268283

269284
/*
@@ -335,7 +350,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
335350

336351
list_for_each_entry(s, &resctrl_schema_all, list) {
337352
list_for_each_entry(dom, &s->res->domains, list)
338-
dom->have_new_ctrl = false;
353+
memset(&dom->staged_config, 0, sizeof(dom->staged_config));
339354
}
340355

341356
while ((tok = strsep(&buf, "\n")) != NULL) {

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,7 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,
27522752
u32 closid)
27532753
{
27542754
struct rdt_resource *r_cdp = NULL;
2755+
struct resctrl_staged_config *cfg;
27552756
struct rdt_domain *d_cdp = NULL;
27562757
struct rdt_resource *r = s->res;
27572758
u32 used_b = 0, unused_b = 0;
@@ -2761,8 +2762,9 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,
27612762
int i;
27622763

27632764
rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp);
2764-
d->have_new_ctrl = false;
2765-
d->new_ctrl = r->cache.shareable_bits;
2765+
cfg = &d->staged_config;
2766+
cfg->have_new_ctrl = false;
2767+
cfg->new_ctrl = r->cache.shareable_bits;
27662768
used_b = r->cache.shareable_bits;
27672769
ctrl = resctrl_to_arch_dom(d)->ctrl_val;
27682770
for (i = 0; i < closids_supported(); i++, ctrl++) {
@@ -2786,29 +2788,29 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,
27862788
peer_ctl = 0;
27872789
used_b |= *ctrl | peer_ctl;
27882790
if (mode == RDT_MODE_SHAREABLE)
2789-
d->new_ctrl |= *ctrl | peer_ctl;
2791+
cfg->new_ctrl |= *ctrl | peer_ctl;
27902792
}
27912793
}
27922794
if (d->plr && d->plr->cbm > 0)
27932795
used_b |= d->plr->cbm;
27942796
unused_b = used_b ^ (BIT_MASK(r->cache.cbm_len) - 1);
27952797
unused_b &= BIT_MASK(r->cache.cbm_len) - 1;
2796-
d->new_ctrl |= unused_b;
2798+
cfg->new_ctrl |= unused_b;
27972799
/*
27982800
* Force the initial CBM to be valid, user can
27992801
* modify the CBM based on system availability.
28002802
*/
2801-
d->new_ctrl = cbm_ensure_valid(d->new_ctrl, r);
2803+
cfg->new_ctrl = cbm_ensure_valid(cfg->new_ctrl, r);
28022804
/*
28032805
* Assign the u32 CBM to an unsigned long to ensure that
28042806
* bitmap_weight() does not access out-of-bound memory.
28052807
*/
2806-
tmp_cbm = d->new_ctrl;
2808+
tmp_cbm = cfg->new_ctrl;
28072809
if (bitmap_weight(&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) {
28082810
rdt_last_cmd_printf("No space on %s:%d\n", s->name, d->id);
28092811
return -ENOSPC;
28102812
}
2811-
d->have_new_ctrl = true;
2813+
cfg->have_new_ctrl = true;
28122814

28132815
return 0;
28142816
}
@@ -2840,11 +2842,13 @@ static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid)
28402842
/* Initialize MBA resource with default values. */
28412843
static void rdtgroup_init_mba(struct rdt_resource *r)
28422844
{
2845+
struct resctrl_staged_config *cfg;
28432846
struct rdt_domain *d;
28442847

28452848
list_for_each_entry(d, &r->domains, list) {
2846-
d->new_ctrl = is_mba_sc(r) ? MBA_MAX_MBPS : r->default_ctrl;
2847-
d->have_new_ctrl = true;
2849+
cfg = &d->staged_config;
2850+
cfg->new_ctrl = is_mba_sc(r) ? MBA_MAX_MBPS : r->default_ctrl;
2851+
cfg->have_new_ctrl = true;
28482852
}
28492853
}
28502854

include/linux/resctrl.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@ enum resctrl_conf_type {
2727
CDP_DATA,
2828
};
2929

30+
/**
31+
* struct resctrl_staged_config - parsed configuration to be applied
32+
* @new_ctrl: new ctrl value to be loaded
33+
* @have_new_ctrl: whether the user provided new_ctrl is valid
34+
*/
35+
struct resctrl_staged_config {
36+
u32 new_ctrl;
37+
bool have_new_ctrl;
38+
};
39+
3040
/**
3141
* struct rdt_domain - group of CPUs sharing a resctrl resource
3242
* @list: all instances of this resource
3343
* @id: unique id for this instance
3444
* @cpu_mask: which CPUs share this resource
35-
* @new_ctrl: new ctrl value to be loaded
36-
* @have_new_ctrl: did user provide new_ctrl for this domain
3745
* @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold
3846
* @mbm_total: saved state for MBM total bandwidth
3947
* @mbm_local: saved state for MBM local bandwidth
@@ -42,13 +50,12 @@ enum resctrl_conf_type {
4250
* @mbm_work_cpu: worker CPU for MBM h/w counters
4351
* @cqm_work_cpu: worker CPU for CQM h/w counters
4452
* @plr: pseudo-locked region (if any) associated with domain
53+
* @staged_config: parsed configuration to be applied
4554
*/
4655
struct rdt_domain {
4756
struct list_head list;
4857
int id;
4958
struct cpumask cpu_mask;
50-
u32 new_ctrl;
51-
bool have_new_ctrl;
5259
unsigned long *rmid_busy_llc;
5360
struct mbm_state *mbm_total;
5461
struct mbm_state *mbm_local;
@@ -57,6 +64,7 @@ struct rdt_domain {
5764
int mbm_work_cpu;
5865
int cqm_work_cpu;
5966
struct pseudo_lock_region *plr;
67+
struct resctrl_staged_config staged_config;
6068
};
6169

6270
/**

0 commit comments

Comments
 (0)