Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs/resctrl: Add the functionality to unassign MBM events

The "mbm_event" counter assignment mode offers "num_mbm_cntrs" number of
counters that can be assigned to RMID, event pairs and monitor bandwidth usage
as long as it is assigned. If all the counters are in use, the kernel logs the
error message "Failed to allocate counter for <event> in domain <id>" in
/sys/fs/resctrl/info/last_cmd_status when a new assignment is requested.

To make space for a new assignment, users must unassign an already assigned
counter and retry the assignment again.

Add the functionality to unassign and free the counters in the domain. Also,
add the helper rdtgroup_unassign_cntrs() to unassign counters in the group.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/cover.1757108044.git.babu.moger@amd.com

authored by

Babu Moger and committed by
Borislav Petkov (AMD)
aab2c508 bd85310e

+68
+2
fs/resctrl/internal.h
··· 398 398 399 399 void rdtgroup_assign_cntrs(struct rdtgroup *rdtgrp); 400 400 401 + void rdtgroup_unassign_cntrs(struct rdtgroup *rdtgrp); 402 + 401 403 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK 402 404 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); 403 405
+66
fs/resctrl/monitor.c
··· 405 405 return -ENOSPC; 406 406 } 407 407 408 + /* 409 + * mbm_cntr_free() - Clear the counter ID configuration details in the domain @d. 410 + */ 411 + static void mbm_cntr_free(struct rdt_mon_domain *d, int cntr_id) 412 + { 413 + memset(&d->cntr_cfg[cntr_id], 0, sizeof(*d->cntr_cfg)); 414 + } 415 + 408 416 static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) 409 417 { 410 418 int cpu = smp_processor_id(); ··· 1049 1041 if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) 1050 1042 rdtgroup_assign_cntr_event(NULL, rdtgrp, 1051 1043 &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]); 1044 + } 1045 + 1046 + /* 1047 + * rdtgroup_free_unassign_cntr() - Unassign and reset the counter ID configuration 1048 + * for the event pointed to by @mevt within the domain @d and resctrl group @rdtgrp. 1049 + */ 1050 + static void rdtgroup_free_unassign_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, 1051 + struct rdtgroup *rdtgrp, struct mon_evt *mevt) 1052 + { 1053 + int cntr_id; 1054 + 1055 + cntr_id = mbm_cntr_get(r, d, rdtgrp, mevt->evtid); 1056 + 1057 + /* If there is no cntr_id assigned, nothing to do */ 1058 + if (cntr_id < 0) 1059 + return; 1060 + 1061 + rdtgroup_assign_cntr(r, d, mevt->evtid, rdtgrp->mon.rmid, rdtgrp->closid, cntr_id, false); 1062 + 1063 + mbm_cntr_free(d, cntr_id); 1064 + } 1065 + 1066 + /* 1067 + * rdtgroup_unassign_cntr_event() - Unassign a hardware counter associated with 1068 + * the event structure @mevt from the domain @d and the group @rdtgrp. Unassign 1069 + * the counters from all the domains if @d is NULL else unassign from @d. 1070 + */ 1071 + static void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, 1072 + struct mon_evt *mevt) 1073 + { 1074 + struct rdt_resource *r = resctrl_arch_get_resource(mevt->rid); 1075 + 1076 + if (!d) { 1077 + list_for_each_entry(d, &r->mon_domains, hdr.list) 1078 + rdtgroup_free_unassign_cntr(r, d, rdtgrp, mevt); 1079 + } else { 1080 + rdtgroup_free_unassign_cntr(r, d, rdtgrp, mevt); 1081 + } 1082 + } 1083 + 1084 + /* 1085 + * rdtgroup_unassign_cntrs() - Unassign the counters associated with MBM events. 1086 + * Called when a group is deleted. 1087 + */ 1088 + void rdtgroup_unassign_cntrs(struct rdtgroup *rdtgrp) 1089 + { 1090 + struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3); 1091 + 1092 + if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r)) 1093 + return; 1094 + 1095 + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) 1096 + rdtgroup_unassign_cntr_event(NULL, rdtgrp, 1097 + &mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID]); 1098 + 1099 + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) 1100 + rdtgroup_unassign_cntr_event(NULL, rdtgrp, 1101 + &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]); 1052 1102 } 1053 1103 1054 1104 int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,