Skip to content

Commit c091e90

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Add a helper to read/set the CDP configuration
Whether CDP is enabled for a hardware resource like the L3 cache can be found by inspecting the alloc_enabled flags of the L3CODE/L3DATA struct rdt_hw_resources, even if they aren't in use. Once these resources are merged, the flags can't be compared. Whether CDP is enabled needs tracking explicitly. If another architecture is emulating CDP the behaviour may not be per-resource. 'cdp_capable' needs to be visible to resctrl, even if its not in use, as this affects the padding of the schemata table visible to user-space. Add cdp_enabled to struct rdt_hw_resource and cdp_capable to struct rdt_resource. Add resctrl_arch_set_cdp_enabled() to let resctrl enable or disable CDP on a resource. resctrl_arch_get_cdp_enabled() lets it read the current state. 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-12-james.morse@arm.com
1 parent 32150ed commit c091e90

File tree

5 files changed

+62
-35
lines changed

5 files changed

+62
-35
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ static void rdt_get_cdp_config(int level, int type)
374374
* "cdp" during resctrl file system mount time.
375375
*/
376376
r->alloc_enabled = false;
377+
rdt_resources_all[level].cdp_enabled = false;
378+
rdt_resources_all[type].cdp_enabled = false;
379+
r_l->cdp_capable = true;
380+
r->cdp_capable = true;
377381
}
378382

379383
static void rdt_get_cdp_l3_config(void)

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ struct rdt_parse_data {
380380
* @msr_update: Function pointer to update QOS MSRs
381381
* @mon_scale: cqm counter * mon_scale = occupancy in bytes
382382
* @mbm_width: Monitor width, to detect and correct for overflow.
383+
* @cdp_enabled: CDP state of this resource
383384
*
384385
* Members of this structure are either private to the architecture
385386
* e.g. mbm_width, or accessed via helpers that provide abstraction. e.g.
@@ -394,6 +395,7 @@ struct rdt_hw_resource {
394395
struct rdt_resource *r);
395396
unsigned int mon_scale;
396397
unsigned int mbm_width;
398+
bool cdp_enabled;
397399
};
398400

399401
static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r)
@@ -414,7 +416,7 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
414416

415417
extern struct dentry *debugfs_resctrl;
416418

417-
enum {
419+
enum resctrl_res_level {
418420
RDT_RESOURCE_L3,
419421
RDT_RESOURCE_L3DATA,
420422
RDT_RESOURCE_L3CODE,
@@ -435,6 +437,13 @@ static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res)
435437
return &hw_res->r_resctrl;
436438
}
437439

440+
static inline bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l)
441+
{
442+
return rdt_resources_all[l].cdp_enabled;
443+
}
444+
445+
int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable);
446+
438447
/*
439448
* To return the common struct rdt_resource, which is contained in struct
440449
* rdt_hw_resource, walk the resctrl member of struct rdt_hw_resource.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp)
688688
* resource, the portion of cache used by it should be made
689689
* unavailable to all future allocations from both resources.
690690
*/
691-
if (rdt_resources_all[RDT_RESOURCE_L3DATA].r_resctrl.alloc_enabled ||
692-
rdt_resources_all[RDT_RESOURCE_L2DATA].r_resctrl.alloc_enabled) {
691+
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3) ||
692+
resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2)) {
693693
rdt_last_cmd_puts("CDP enabled\n");
694694
return -EINVAL;
695695
}

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

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,14 +1940,16 @@ static int set_cache_qos_cfg(int level, bool enable)
19401940
/* Restore the qos cfg state when a domain comes online */
19411941
void rdt_domain_reconfigure_cdp(struct rdt_resource *r)
19421942
{
1943-
if (!r->alloc_capable)
1943+
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
1944+
1945+
if (!r->cdp_capable)
19441946
return;
19451947

19461948
if (r == &rdt_resources_all[RDT_RESOURCE_L2DATA].r_resctrl)
1947-
l2_qos_cfg_update(&r->alloc_enabled);
1949+
l2_qos_cfg_update(&hw_res->cdp_enabled);
19481950

19491951
if (r == &rdt_resources_all[RDT_RESOURCE_L3DATA].r_resctrl)
1950-
l3_qos_cfg_update(&r->alloc_enabled);
1952+
l3_qos_cfg_update(&hw_res->cdp_enabled);
19511953
}
19521954

19531955
/*
@@ -1991,51 +1993,62 @@ static int cdp_enable(int level, int data_type, int code_type)
19911993
r_l->alloc_enabled = false;
19921994
r_ldata->alloc_enabled = true;
19931995
r_lcode->alloc_enabled = true;
1996+
rdt_resources_all[level].cdp_enabled = true;
1997+
rdt_resources_all[data_type].cdp_enabled = true;
1998+
rdt_resources_all[code_type].cdp_enabled = true;
19941999
}
19952000
return ret;
19962001
}
19972002

1998-
static int cdpl3_enable(void)
1999-
{
2000-
return cdp_enable(RDT_RESOURCE_L3, RDT_RESOURCE_L3DATA,
2001-
RDT_RESOURCE_L3CODE);
2002-
}
2003-
2004-
static int cdpl2_enable(void)
2005-
{
2006-
return cdp_enable(RDT_RESOURCE_L2, RDT_RESOURCE_L2DATA,
2007-
RDT_RESOURCE_L2CODE);
2008-
}
2009-
20102003
static void cdp_disable(int level, int data_type, int code_type)
20112004
{
2012-
struct rdt_resource *r = &rdt_resources_all[level].r_resctrl;
2005+
struct rdt_hw_resource *r_hw = &rdt_resources_all[level];
2006+
struct rdt_resource *r = &r_hw->r_resctrl;
20132007

20142008
r->alloc_enabled = r->alloc_capable;
20152009

2016-
if (rdt_resources_all[data_type].r_resctrl.alloc_enabled) {
2010+
if (r_hw->cdp_enabled) {
20172011
rdt_resources_all[data_type].r_resctrl.alloc_enabled = false;
20182012
rdt_resources_all[code_type].r_resctrl.alloc_enabled = false;
20192013
set_cache_qos_cfg(level, false);
2014+
r_hw->cdp_enabled = false;
2015+
rdt_resources_all[data_type].cdp_enabled = false;
2016+
rdt_resources_all[code_type].cdp_enabled = false;
20202017
}
20212018
}
20222019

2023-
static void cdpl3_disable(void)
2020+
int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable)
20242021
{
2025-
cdp_disable(RDT_RESOURCE_L3, RDT_RESOURCE_L3DATA, RDT_RESOURCE_L3CODE);
2026-
}
2022+
struct rdt_hw_resource *hw_res = &rdt_resources_all[l];
2023+
enum resctrl_res_level code_type, data_type;
20272024

2028-
static void cdpl2_disable(void)
2029-
{
2030-
cdp_disable(RDT_RESOURCE_L2, RDT_RESOURCE_L2DATA, RDT_RESOURCE_L2CODE);
2025+
if (!hw_res->r_resctrl.cdp_capable)
2026+
return -EINVAL;
2027+
2028+
if (l == RDT_RESOURCE_L3) {
2029+
code_type = RDT_RESOURCE_L3CODE;
2030+
data_type = RDT_RESOURCE_L3DATA;
2031+
} else if (l == RDT_RESOURCE_L2) {
2032+
code_type = RDT_RESOURCE_L2CODE;
2033+
data_type = RDT_RESOURCE_L2DATA;
2034+
} else {
2035+
return -EINVAL;
2036+
}
2037+
2038+
if (enable)
2039+
return cdp_enable(l, data_type, code_type);
2040+
2041+
cdp_disable(l, data_type, code_type);
2042+
2043+
return 0;
20312044
}
20322045

20332046
static void cdp_disable_all(void)
20342047
{
2035-
if (rdt_resources_all[RDT_RESOURCE_L3DATA].r_resctrl.alloc_enabled)
2036-
cdpl3_disable();
2037-
if (rdt_resources_all[RDT_RESOURCE_L2DATA].r_resctrl.alloc_enabled)
2038-
cdpl2_disable();
2048+
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
2049+
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
2050+
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
2051+
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
20392052
}
20402053

20412054
/*
@@ -2113,10 +2126,10 @@ static int rdt_enable_ctx(struct rdt_fs_context *ctx)
21132126
int ret = 0;
21142127

21152128
if (ctx->enable_cdpl2)
2116-
ret = cdpl2_enable();
2129+
ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, true);
21172130

21182131
if (!ret && ctx->enable_cdpl3)
2119-
ret = cdpl3_enable();
2132+
ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, true);
21202133

21212134
if (!ret && ctx->enable_mba_mbps)
21222135
ret = set_mba_sc(true);
@@ -3199,10 +3212,10 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
31993212

32003213
static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
32013214
{
3202-
if (rdt_resources_all[RDT_RESOURCE_L3DATA].r_resctrl.alloc_enabled)
3215+
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
32033216
seq_puts(seq, ",cdp");
32043217

3205-
if (rdt_resources_all[RDT_RESOURCE_L2DATA].r_resctrl.alloc_enabled)
3218+
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
32063219
seq_puts(seq, ",cdpl2");
32073220

32083221
if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))

include/linux/resctrl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct resctrl_schema;
142142
* @parse_ctrlval: Per resource function pointer to parse control values
143143
* @evt_list: List of monitoring events
144144
* @fflags: flags to choose base and info files
145+
* @cdp_capable: Is the CDP feature available on this resource
145146
*/
146147
struct rdt_resource {
147148
int rid;
@@ -163,7 +164,7 @@ struct rdt_resource {
163164
struct rdt_domain *d);
164165
struct list_head evt_list;
165166
unsigned long fflags;
166-
167+
bool cdp_capable;
167168
};
168169

169170
/**

0 commit comments

Comments
 (0)