AMD Hardware provides a set of ABMC counters when the feature is supported. These hardware counters are used for assigning the RMIDs to the group. Introduce the bitmap assignable_counter_free_map to allocate and free counters. Signed-off-by: Babu Moger <babu.moger@xxxxxxx> --- v2: Changed the bitmap name to assignable_counter_free_map from abmc_counter_free_map. --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 7cae6ac13954..19b0ebf4f435 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -164,6 +164,22 @@ static bool closid_allocated(unsigned int closid) return (closid_free_map & (1 << closid)) == 0; } +static u64 assignable_counter_free_map; +static u32 assignable_counter_free_map_len; + +static void assignable_counters_init(void) +{ + struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3]; + + if (hw_res->mbm_assignable_counters > 64) { + hw_res->mbm_assignable_counters = 64; + WARN(1, "Cannot support more than 64 Assignable counters\n"); + } + + assignable_counter_free_map = BIT_MASK(hw_res->mbm_assignable_counters) - 1; + assignable_counter_free_map_len = hw_res->mbm_assignable_counters; +} + /** * rdtgroup_mode_by_closid - Return mode of resource group with closid * @closid: closid if the resource group @@ -2777,6 +2793,10 @@ static int rdt_get_tree(struct fs_context *fc) closid_init(); + r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + if (r->mbm_assign_capable) + assignable_counters_init(); + if (rdt_mon_capable) flags |= RFTYPE_MON; @@ -2821,7 +2841,6 @@ static int rdt_get_tree(struct fs_context *fc) static_branch_enable_cpuslocked(&rdt_enable_key); if (is_mbm_enabled()) { - r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; list_for_each_entry(dom, &r->domains, list) mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL); } -- 2.34.1