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: Provide interface to update the event configurations

When "mbm_event" counter assignment mode is enabled, users can modify the
event configuration by writing to the 'event_filter' resctrl file. The event
configurations for mbm_event mode are located in
/sys/fs/resctrl/info/L3_MON/event_configs/.

Update the assignments of all CTRL_MON and MON resource groups when the event
configuration is modified.

Example:
$ mount -t resctrl resctrl /sys/fs/resctrl

$ cd /sys/fs/resctrl/

$ cat info/L3_MON/event_configs/mbm_local_bytes/event_filter
local_reads,local_non_temporal_writes,local_reads_slow_memory

$ echo "local_reads,local_non_temporal_writes" >
info/L3_MON/event_configs/mbm_total_bytes/event_filter

$ cat info/L3_MON/event_configs/mbm_total_bytes/event_filter
local_reads,local_non_temporal_writes

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)
f9ae5913 ea274cbe

+131 -1
+12
Documentation/filesystems/resctrl.rst
··· 343 343 # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter 344 344 local_reads,local_non_temporal_writes,local_reads_slow_memory 345 345 346 + Modify the event configuration by writing to the "event_filter" file within 347 + the "event_configs" directory. The read/write "event_filter" file contains the 348 + configuration of the event that reflects which memory transactions are counted by it. 349 + 350 + For example:: 351 + 352 + # echo "local_reads, local_non_temporal_writes" > 353 + /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter 354 + 355 + # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter 356 + local_reads,local_non_temporal_writes 357 + 346 358 "max_threshold_occupancy": 347 359 Read/write file provides the largest value (in 348 360 bytes) at which a previously used LLC_occupancy
+3
fs/resctrl/internal.h
··· 407 407 408 408 int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v); 409 409 410 + ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes, 411 + loff_t off); 412 + 410 413 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK 411 414 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); 412 415
+114
fs/resctrl/monitor.c
··· 1192 1192 &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]); 1193 1193 } 1194 1194 1195 + static int resctrl_parse_mem_transactions(char *tok, u32 *val) 1196 + { 1197 + u32 temp_val = 0; 1198 + char *evt_str; 1199 + bool found; 1200 + int i; 1201 + 1202 + next_config: 1203 + if (!tok || tok[0] == '\0') { 1204 + *val = temp_val; 1205 + return 0; 1206 + } 1207 + 1208 + /* Start processing the strings for each memory transaction type */ 1209 + evt_str = strim(strsep(&tok, ",")); 1210 + found = false; 1211 + for (i = 0; i < NUM_MBM_TRANSACTIONS; i++) { 1212 + if (!strcmp(mbm_transactions[i].name, evt_str)) { 1213 + temp_val |= mbm_transactions[i].val; 1214 + found = true; 1215 + break; 1216 + } 1217 + } 1218 + 1219 + if (!found) { 1220 + rdt_last_cmd_printf("Invalid memory transaction type %s\n", evt_str); 1221 + return -EINVAL; 1222 + } 1223 + 1224 + goto next_config; 1225 + } 1226 + 1227 + /* 1228 + * rdtgroup_update_cntr_event - Update the counter assignments for the event 1229 + * in a group. 1230 + * @r: Resource to which update needs to be done. 1231 + * @rdtgrp: Resctrl group. 1232 + * @evtid: MBM monitor event. 1233 + */ 1234 + static void rdtgroup_update_cntr_event(struct rdt_resource *r, struct rdtgroup *rdtgrp, 1235 + enum resctrl_event_id evtid) 1236 + { 1237 + struct rdt_mon_domain *d; 1238 + int cntr_id; 1239 + 1240 + list_for_each_entry(d, &r->mon_domains, hdr.list) { 1241 + cntr_id = mbm_cntr_get(r, d, rdtgrp, evtid); 1242 + if (cntr_id >= 0) 1243 + rdtgroup_assign_cntr(r, d, evtid, rdtgrp->mon.rmid, 1244 + rdtgrp->closid, cntr_id, true); 1245 + } 1246 + } 1247 + 1248 + /* 1249 + * resctrl_update_cntr_allrdtgrp - Update the counter assignments for the event 1250 + * for all the groups. 1251 + * @mevt MBM Monitor event. 1252 + */ 1253 + static void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt) 1254 + { 1255 + struct rdt_resource *r = resctrl_arch_get_resource(mevt->rid); 1256 + struct rdtgroup *prgrp, *crgrp; 1257 + 1258 + /* 1259 + * Find all the groups where the event is assigned and update the 1260 + * configuration of existing assignments. 1261 + */ 1262 + list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { 1263 + rdtgroup_update_cntr_event(r, prgrp, mevt->evtid); 1264 + 1265 + list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list) 1266 + rdtgroup_update_cntr_event(r, crgrp, mevt->evtid); 1267 + } 1268 + } 1269 + 1270 + ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes, 1271 + loff_t off) 1272 + { 1273 + struct mon_evt *mevt = rdt_kn_parent_priv(of->kn); 1274 + struct rdt_resource *r; 1275 + u32 evt_cfg = 0; 1276 + int ret = 0; 1277 + 1278 + /* Valid input requires a trailing newline */ 1279 + if (nbytes == 0 || buf[nbytes - 1] != '\n') 1280 + return -EINVAL; 1281 + 1282 + buf[nbytes - 1] = '\0'; 1283 + 1284 + cpus_read_lock(); 1285 + mutex_lock(&rdtgroup_mutex); 1286 + 1287 + rdt_last_cmd_clear(); 1288 + 1289 + r = resctrl_arch_get_resource(mevt->rid); 1290 + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { 1291 + rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n"); 1292 + ret = -EINVAL; 1293 + goto out_unlock; 1294 + } 1295 + 1296 + ret = resctrl_parse_mem_transactions(buf, &evt_cfg); 1297 + if (!ret && mevt->evt_cfg != evt_cfg) { 1298 + mevt->evt_cfg = evt_cfg; 1299 + resctrl_update_cntr_allrdtgrp(mevt); 1300 + } 1301 + 1302 + out_unlock: 1303 + mutex_unlock(&rdtgroup_mutex); 1304 + cpus_read_unlock(); 1305 + 1306 + return ret ?: nbytes; 1307 + } 1308 + 1195 1309 int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, 1196 1310 struct seq_file *s, void *v) 1197 1311 {
+2 -1
fs/resctrl/rdtgroup.c
··· 1925 1925 }, 1926 1926 { 1927 1927 .name = "event_filter", 1928 - .mode = 0444, 1928 + .mode = 0644, 1929 1929 .kf_ops = &rdtgroup_kf_single_ops, 1930 1930 .seq_show = event_filter_show, 1931 + .write = event_filter_write, 1931 1932 }, 1932 1933 { 1933 1934 .name = "mbm_assign_mode",