Skip to content

Commit d089164

Browse files
aeglbp3tk0v
authored andcommitted
fs/resctrl: Move RMID initialization to first mount
L3 monitor features are enumerated during resctrl initialization and rmid_ptrs[] that tracks all RMIDs and depends on the number of supported RMIDs is allocated during this time. Telemetry monitor features are enumerated during first resctrl mount and may support a different number of RMIDs compared to L3 monitor features. Delay allocation and initialization of rmid_ptrs[] until first mount. Since the number of RMIDs cannot change on later mounts, keep the same set of rmid_ptrs[] until resctrl_exit(). This is required because the limbo handler keeps running after resctrl is unmounted and needs to access rmid_ptrs[] as it keeps tracking busy RMIDs after unmount. Rename routines to match what they now do: dom_data_init() -> setup_rmid_lru_list() dom_data_exit() -> free_rmid_lru_list() Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Link: https://lore.kernel.org/20251217172121.12030-1-tony.luck@intel.com
1 parent 0ecc988 commit d089164

3 files changed

Lines changed: 34 additions & 29 deletions

File tree

fs/resctrl/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ int closids_supported(void);
369369

370370
void closid_free(int closid);
371371

372+
int setup_rmid_lru_list(void);
373+
374+
void free_rmid_lru_list(void);
375+
372376
int alloc_rmid(u32 closid);
373377

374378
void free_rmid(u32 closid, u32 rmid);

fs/resctrl/monitor.c

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -903,20 +903,29 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long del
903903
schedule_delayed_work_on(cpu, &dom->mbm_over, delay);
904904
}
905905

906-
static int dom_data_init(struct rdt_resource *r)
906+
int setup_rmid_lru_list(void)
907907
{
908-
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
909908
struct rmid_entry *entry = NULL;
910-
int err = 0, i;
909+
u32 idx_limit;
911910
u32 idx;
911+
int i;
912912

913-
mutex_lock(&rdtgroup_mutex);
913+
if (!resctrl_arch_mon_capable())
914+
return 0;
914915

916+
/*
917+
* Called on every mount, but the number of RMIDs cannot change
918+
* after the first mount, so keep using the same set of rmid_ptrs[]
919+
* until resctrl_exit(). Note that the limbo handler continues to
920+
* access rmid_ptrs[] after resctrl is unmounted.
921+
*/
922+
if (rmid_ptrs)
923+
return 0;
924+
925+
idx_limit = resctrl_arch_system_num_rmid_idx();
915926
rmid_ptrs = kcalloc(idx_limit, sizeof(struct rmid_entry), GFP_KERNEL);
916-
if (!rmid_ptrs) {
917-
err = -ENOMEM;
918-
goto out_unlock;
919-
}
927+
if (!rmid_ptrs)
928+
return -ENOMEM;
920929

921930
for (i = 0; i < idx_limit; i++) {
922931
entry = &rmid_ptrs[i];
@@ -929,30 +938,24 @@ static int dom_data_init(struct rdt_resource *r)
929938
/*
930939
* RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID are special and
931940
* are always allocated. These are used for the rdtgroup_default
932-
* control group, which will be setup later in resctrl_init().
941+
* control group, which was setup earlier in rdtgroup_setup_default().
933942
*/
934943
idx = resctrl_arch_rmid_idx_encode(RESCTRL_RESERVED_CLOSID,
935944
RESCTRL_RESERVED_RMID);
936945
entry = __rmid_entry(idx);
937946
list_del(&entry->list);
938947

939-
out_unlock:
940-
mutex_unlock(&rdtgroup_mutex);
941-
942-
return err;
948+
return 0;
943949
}
944950

945-
static void dom_data_exit(struct rdt_resource *r)
951+
void free_rmid_lru_list(void)
946952
{
947-
mutex_lock(&rdtgroup_mutex);
948-
949-
if (!r->mon_capable)
950-
goto out_unlock;
953+
if (!resctrl_arch_mon_capable())
954+
return;
951955

956+
mutex_lock(&rdtgroup_mutex);
952957
kfree(rmid_ptrs);
953958
rmid_ptrs = NULL;
954-
955-
out_unlock:
956959
mutex_unlock(&rdtgroup_mutex);
957960
}
958961

@@ -1830,7 +1833,8 @@ static void closid_num_dirty_rmid_free(void)
18301833
* resctrl_l3_mon_resource_init() - Initialise global monitoring structures.
18311834
*
18321835
* Allocate and initialise global monitor resources that do not belong to a
1833-
* specific domain. i.e. the rmid_ptrs[] used for the limbo and free lists.
1836+
* specific domain. i.e. the closid_num_dirty_rmid[] used to find the CLOSID
1837+
* with the cleanest set of RMIDs.
18341838
* Called once during boot after the struct rdt_resource's have been configured
18351839
* but before the filesystem is mounted.
18361840
* Resctrl's cpuhp callbacks may be called before this point to bring a domain
@@ -1850,12 +1854,6 @@ int resctrl_l3_mon_resource_init(void)
18501854
if (ret)
18511855
return ret;
18521856

1853-
ret = dom_data_init(r);
1854-
if (ret) {
1855-
closid_num_dirty_rmid_free();
1856-
return ret;
1857-
}
1858-
18591857
if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) {
18601858
mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable = true;
18611859
resctrl_file_fflags_init("mbm_total_bytes_config",
@@ -1902,6 +1900,4 @@ void resctrl_l3_mon_resource_exit(void)
19021900
return;
19031901

19041902
closid_num_dirty_rmid_free();
1905-
1906-
dom_data_exit(r);
19071903
}

fs/resctrl/rdtgroup.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,10 @@ static int rdt_get_tree(struct fs_context *fc)
28002800
goto out;
28012801
}
28022802

2803+
ret = setup_rmid_lru_list();
2804+
if (ret)
2805+
goto out;
2806+
28032807
ret = rdtgroup_setup_root(ctx);
28042808
if (ret)
28052809
goto out;
@@ -4655,4 +4659,5 @@ void resctrl_exit(void)
46554659
*/
46564660

46574661
resctrl_l3_mon_resource_exit();
4662+
free_rmid_lru_list();
46584663
}

0 commit comments

Comments
 (0)