Skip to content

Commit dc2a3e8

Browse files
babumogerbp3tk0v
authored andcommitted
x86/resctrl: Add interface to read mbm_total_bytes_config
The event configuration can be viewed by the user by reading the configuration file /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config. The event configuration settings are domain specific and will affect all the CPUs in the domain. Following are the types of events supported: ==== =========================================================== Bits Description ==== =========================================================== 6 Dirty Victims from the QOS domain to all types of memory 5 Reads to slow memory in the non-local NUMA domain 4 Reads to slow memory in the local NUMA domain 3 Non-temporal writes to non-local NUMA domain 2 Non-temporal writes to local NUMA domain 1 Reads to memory in the non-local NUMA domain 0 Reads to memory in the local NUMA domain ==== =========================================================== By default, the mbm_total_bytes_config is set to 0x7f to count all the event types. For example: $cat /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config 0=0x7f;1=0x7f;2=0x7f;3=0x7f In this case, the event mbm_total_bytes is configured with 0x7f on domains 0 to 3. Signed-off-by: Babu Moger <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d507f83 commit dc2a3e8

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@
10621062
/* - AMD: */
10631063
#define MSR_IA32_MBA_BW_BASE 0xc0000200
10641064
#define MSR_IA32_SMBA_BW_BASE 0xc0000280
1065+
#define MSR_IA32_EVT_CFG_BASE 0xc0000400
10651066

10661067
/* MSR_IA32_VMX_MISC bits */
10671068
#define MSR_IA32_VMX_MISC_INTEL_PT (1ULL << 14)

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@
3030
*/
3131
#define MBM_CNTR_WIDTH_OFFSET_MAX (62 - MBM_CNTR_WIDTH_BASE)
3232

33+
/* Reads to Local DRAM Memory */
34+
#define READS_TO_LOCAL_MEM BIT(0)
35+
36+
/* Reads to Remote DRAM Memory */
37+
#define READS_TO_REMOTE_MEM BIT(1)
38+
39+
/* Non-Temporal Writes to Local Memory */
40+
#define NON_TEMP_WRITE_TO_LOCAL_MEM BIT(2)
41+
42+
/* Non-Temporal Writes to Remote Memory */
43+
#define NON_TEMP_WRITE_TO_REMOTE_MEM BIT(3)
44+
45+
/* Reads to Local Memory the system identifies as "Slow Memory" */
46+
#define READS_TO_LOCAL_S_MEM BIT(4)
47+
48+
/* Reads to Remote Memory the system identifies as "Slow Memory" */
49+
#define READS_TO_REMOTE_S_MEM BIT(5)
50+
51+
/* Dirty Victims to All Types of Memory */
52+
#define DIRTY_VICTIMS_TO_ALL_MEM BIT(6)
53+
54+
/* Max event bits supported */
55+
#define MAX_EVT_CONFIG_BITS GENMASK(6, 0)
3356

3457
struct rdt_fs_context {
3558
struct kernfs_fs_context kfc;
@@ -531,5 +554,6 @@ bool has_busy_rmid(struct rdt_resource *r, struct rdt_domain *d);
531554
void __check_limbo(struct rdt_domain *d, bool force_free);
532555
void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
533556
void __init thread_throttle_mode_init(void);
557+
void __init mbm_config_rftype_init(const char *config);
534558

535559
#endif /* _ASM_X86_RESCTRL_INTERNAL_H */

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,10 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
801801
return ret;
802802

803803
if (rdt_cpu_has(X86_FEATURE_BMEC)) {
804-
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL))
804+
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
805805
mbm_total_event.configurable = true;
806+
mbm_config_rftype_init("mbm_total_bytes_config");
807+
}
806808
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL))
807809
mbm_local_event.configurable = true;
808810
}

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,93 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
14201420
return ret;
14211421
}
14221422

1423+
struct mon_config_info {
1424+
u32 evtid;
1425+
u32 mon_config;
1426+
};
1427+
1428+
#define INVALID_CONFIG_INDEX UINT_MAX
1429+
1430+
/**
1431+
* mon_event_config_index_get - get the hardware index for the
1432+
* configurable event
1433+
* @evtid: event id.
1434+
*
1435+
* Return: 0 for evtid == QOS_L3_MBM_TOTAL_EVENT_ID
1436+
* 1 for evtid == QOS_L3_MBM_LOCAL_EVENT_ID
1437+
* INVALID_CONFIG_INDEX for invalid evtid
1438+
*/
1439+
static inline unsigned int mon_event_config_index_get(u32 evtid)
1440+
{
1441+
switch (evtid) {
1442+
case QOS_L3_MBM_TOTAL_EVENT_ID:
1443+
return 0;
1444+
case QOS_L3_MBM_LOCAL_EVENT_ID:
1445+
return 1;
1446+
default:
1447+
/* Should never reach here */
1448+
return INVALID_CONFIG_INDEX;
1449+
}
1450+
}
1451+
1452+
static void mon_event_config_read(void *info)
1453+
{
1454+
struct mon_config_info *mon_info = info;
1455+
unsigned int index;
1456+
u32 h;
1457+
1458+
index = mon_event_config_index_get(mon_info->evtid);
1459+
if (index == INVALID_CONFIG_INDEX) {
1460+
pr_warn_once("Invalid event id %d\n", mon_info->evtid);
1461+
return;
1462+
}
1463+
rdmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, h);
1464+
1465+
/* Report only the valid event configuration bits */
1466+
mon_info->mon_config &= MAX_EVT_CONFIG_BITS;
1467+
}
1468+
1469+
static void mondata_config_read(struct rdt_domain *d, struct mon_config_info *mon_info)
1470+
{
1471+
smp_call_function_any(&d->cpu_mask, mon_event_config_read, mon_info, 1);
1472+
}
1473+
1474+
static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid)
1475+
{
1476+
struct mon_config_info mon_info = {0};
1477+
struct rdt_domain *dom;
1478+
bool sep = false;
1479+
1480+
mutex_lock(&rdtgroup_mutex);
1481+
1482+
list_for_each_entry(dom, &r->domains, list) {
1483+
if (sep)
1484+
seq_puts(s, ";");
1485+
1486+
memset(&mon_info, 0, sizeof(struct mon_config_info));
1487+
mon_info.evtid = evtid;
1488+
mondata_config_read(dom, &mon_info);
1489+
1490+
seq_printf(s, "%d=0x%02x", dom->id, mon_info.mon_config);
1491+
sep = true;
1492+
}
1493+
seq_puts(s, "\n");
1494+
1495+
mutex_unlock(&rdtgroup_mutex);
1496+
1497+
return 0;
1498+
}
1499+
1500+
static int mbm_total_bytes_config_show(struct kernfs_open_file *of,
1501+
struct seq_file *seq, void *v)
1502+
{
1503+
struct rdt_resource *r = of->kn->parent->priv;
1504+
1505+
mbm_config_show(seq, r, QOS_L3_MBM_TOTAL_EVENT_ID);
1506+
1507+
return 0;
1508+
}
1509+
14231510
/* rdtgroup information files for one cache resource. */
14241511
static struct rftype res_common_files[] = {
14251512
{
@@ -1518,6 +1605,12 @@ static struct rftype res_common_files[] = {
15181605
.seq_show = max_threshold_occ_show,
15191606
.fflags = RF_MON_INFO | RFTYPE_RES_CACHE,
15201607
},
1608+
{
1609+
.name = "mbm_total_bytes_config",
1610+
.mode = 0444,
1611+
.kf_ops = &rdtgroup_kf_single_ops,
1612+
.seq_show = mbm_total_bytes_config_show,
1613+
},
15211614
{
15221615
.name = "cpus",
15231616
.mode = 0644,
@@ -1624,6 +1717,15 @@ void __init thread_throttle_mode_init(void)
16241717
rft->fflags = RF_CTRL_INFO | RFTYPE_RES_MB;
16251718
}
16261719

1720+
void __init mbm_config_rftype_init(const char *config)
1721+
{
1722+
struct rftype *rft;
1723+
1724+
rft = rdtgroup_get_rftype_by_name(config);
1725+
if (rft)
1726+
rft->fflags = RF_MON_INFO | RFTYPE_RES_CACHE;
1727+
}
1728+
16271729
/**
16281730
* rdtgroup_kn_mode_restrict - Restrict user access to named resctrl file
16291731
* @r: The resource group with which the file is associated.

0 commit comments

Comments
 (0)