Skip to content

Commit 4b6bdbf

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Move monitor init work to a resctrl init call
rdt_get_mon_l3_config() is called from the arch's resctrl_arch_late_init(), and initialises both architecture specific fields, such as hw_res->mon_scale and resctrl filesystem fields by calling dom_data_init(). To separate the filesystem and architecture parts of resctrl, this function needs splitting up. Add resctrl_mon_resource_init() to do the filesystem specific work, and call it from resctrl_init(). This runs later, but is still before the filesystem is mounted and the rmid_ptrs[] array can be used. [ bp: Massage commit message. ] Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Reviewed-by: Tony Luck <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Reviewed-by: Babu Moger <[email protected]> Tested-by: Carl Worth <[email protected]> # arm64 Tested-by: Shaopeng Tan <[email protected]> Tested-by: Peter Newman <[email protected]> Tested-by: Amit Singh Tomar <[email protected]> # arm64 Tested-by: Shanker Donthineni <[email protected]> # arm64 Tested-by: Babu Moger <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0118427 commit 4b6bdbf

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,14 @@ void closid_free(int closid);
586586
int alloc_rmid(u32 closid);
587587
void free_rmid(u32 closid, u32 rmid);
588588
int rdt_get_mon_l3_config(struct rdt_resource *r);
589-
void __exit resctrl_mon_resource_exit(void);
589+
void resctrl_mon_resource_exit(void);
590590
bool __init rdt_cpu_has(int flag);
591591
void mon_event_count(void *info);
592592
int rdtgroup_mondata_show(struct seq_file *m, void *arg);
593593
void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
594594
struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
595595
cpumask_t *cpumask, int evtid, int first);
596+
int __init resctrl_mon_resource_init(void);
596597
void mbm_setup_overflow_handler(struct rdt_mon_domain *dom,
597598
unsigned long delay_ms,
598599
int exclude_cpu);

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ static int dom_data_init(struct rdt_resource *r)
10401040
return err;
10411041
}
10421042

1043-
static void __exit dom_data_exit(struct rdt_resource *r)
1043+
static void dom_data_exit(struct rdt_resource *r)
10441044
{
10451045
mutex_lock(&rdtgroup_mutex);
10461046

@@ -1176,12 +1176,40 @@ static __init int snc_get_config(void)
11761176
return ret;
11771177
}
11781178

1179+
/**
1180+
* resctrl_mon_resource_init() - Initialise global monitoring structures.
1181+
*
1182+
* Allocate and initialise global monitor resources that do not belong to a
1183+
* specific domain. i.e. the rmid_ptrs[] used for the limbo and free lists.
1184+
* Called once during boot after the struct rdt_resource's have been configured
1185+
* but before the filesystem is mounted.
1186+
* Resctrl's cpuhp callbacks may be called before this point to bring a domain
1187+
* online.
1188+
*
1189+
* Returns 0 for success, or -ENOMEM.
1190+
*/
1191+
int __init resctrl_mon_resource_init(void)
1192+
{
1193+
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
1194+
int ret;
1195+
1196+
if (!r->mon_capable)
1197+
return 0;
1198+
1199+
ret = dom_data_init(r);
1200+
if (ret)
1201+
return ret;
1202+
1203+
l3_mon_evt_init(r);
1204+
1205+
return 0;
1206+
}
1207+
11791208
int __init rdt_get_mon_l3_config(struct rdt_resource *r)
11801209
{
11811210
unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
11821211
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
11831212
unsigned int threshold;
1184-
int ret;
11851213

11861214
snc_nodes_per_l3_cache = snc_get_config();
11871215

@@ -1211,10 +1239,6 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
12111239
*/
12121240
resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
12131241

1214-
ret = dom_data_init(r);
1215-
if (ret)
1216-
return ret;
1217-
12181242
if (rdt_cpu_has(X86_FEATURE_BMEC)) {
12191243
u32 eax, ebx, ecx, edx;
12201244

@@ -1234,14 +1258,12 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
12341258
}
12351259
}
12361260

1237-
l3_mon_evt_init(r);
1238-
12391261
r->mon_capable = true;
12401262

12411263
return 0;
12421264
}
12431265

1244-
void __exit resctrl_mon_resource_exit(void)
1266+
void resctrl_mon_resource_exit(void)
12451267
{
12461268
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
12471269

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4102,6 +4102,19 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d
41024102
mutex_unlock(&rdtgroup_mutex);
41034103
}
41044104

4105+
/**
4106+
* domain_setup_mon_state() - Initialise domain monitoring structures.
4107+
* @r: The resource for the newly online domain.
4108+
* @d: The newly online domain.
4109+
*
4110+
* Allocate monitor resources that belong to this domain.
4111+
* Called when the first CPU of a domain comes online, regardless of whether
4112+
* the filesystem is mounted.
4113+
* During boot this may be called before global allocations have been made by
4114+
* resctrl_mon_resource_init().
4115+
*
4116+
* Returns 0 for success, or -ENOMEM.
4117+
*/
41054118
static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domain *d)
41064119
{
41074120
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
@@ -4252,10 +4265,16 @@ int __init resctrl_init(void)
42524265

42534266
rdtgroup_setup_default();
42544267

4255-
ret = sysfs_create_mount_point(fs_kobj, "resctrl");
4268+
ret = resctrl_mon_resource_init();
42564269
if (ret)
42574270
return ret;
42584271

4272+
ret = sysfs_create_mount_point(fs_kobj, "resctrl");
4273+
if (ret) {
4274+
resctrl_mon_resource_exit();
4275+
return ret;
4276+
}
4277+
42594278
ret = register_filesystem(&rdt_fs_type);
42604279
if (ret)
42614280
goto cleanup_mountpoint;
@@ -4287,6 +4306,7 @@ int __init resctrl_init(void)
42874306

42884307
cleanup_mountpoint:
42894308
sysfs_remove_mount_point(fs_kobj, "resctrl");
4309+
resctrl_mon_resource_exit();
42904310

42914311
return ret;
42924312
}

0 commit comments

Comments
 (0)