Skip to content

Commit 650680d

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Change mon_event_config_{read,write}() to be arch helpers
mon_event_config_{read,write}() are called via IPI and access model specific registers to do their work. To support another architecture, this needs abstracting. Rename mon_event_config_{read,write}() to have a "resctrl_arch_" prefix, and move their struct mon_config_info parameter into <linux/resctrl.h>. This allows another architecture to supply an implementation of these. As struct mon_config_info is now exposed globally, give it a 'resctrl_' prefix. MPAM systems need access to the domain to do this work, add the resource and domain to struct resctrl_mon_config_info. Co-developed-by: Dave Martin <[email protected]> Signed-off-by: Dave Martin <[email protected]> Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Reviewed-by: Tony Luck <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Reviewed-by: Babu Moger <[email protected]> Tested-by: Carl Worth <[email protected]> # arm64 Tested-by: Shaopeng Tan <[email protected]> Tested-by: Peter Newman <[email protected]> Tested-by: Amit Singh Tomar <[email protected]> # arm64 Tested-by: Shanker Donthineni <[email protected]> # arm64 Tested-by: Babu Moger <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d81826f commit 650680d

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,11 +1580,6 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
15801580
return ret;
15811581
}
15821582

1583-
struct mon_config_info {
1584-
u32 evtid;
1585-
u32 mon_config;
1586-
};
1587-
15881583
#define INVALID_CONFIG_INDEX UINT_MAX
15891584

15901585
/**
@@ -1609,31 +1604,32 @@ static inline unsigned int mon_event_config_index_get(u32 evtid)
16091604
}
16101605
}
16111606

1612-
static void mon_event_config_read(void *info)
1607+
void resctrl_arch_mon_event_config_read(void *_config_info)
16131608
{
1614-
struct mon_config_info *mon_info = info;
1609+
struct resctrl_mon_config_info *config_info = _config_info;
16151610
unsigned int index;
16161611
u64 msrval;
16171612

1618-
index = mon_event_config_index_get(mon_info->evtid);
1613+
index = mon_event_config_index_get(config_info->evtid);
16191614
if (index == INVALID_CONFIG_INDEX) {
1620-
pr_warn_once("Invalid event id %d\n", mon_info->evtid);
1615+
pr_warn_once("Invalid event id %d\n", config_info->evtid);
16211616
return;
16221617
}
16231618
rdmsrl(MSR_IA32_EVT_CFG_BASE + index, msrval);
16241619

16251620
/* Report only the valid event configuration bits */
1626-
mon_info->mon_config = msrval & MAX_EVT_CONFIG_BITS;
1621+
config_info->mon_config = msrval & MAX_EVT_CONFIG_BITS;
16271622
}
16281623

1629-
static void mondata_config_read(struct rdt_mon_domain *d, struct mon_config_info *mon_info)
1624+
static void mondata_config_read(struct resctrl_mon_config_info *mon_info)
16301625
{
1631-
smp_call_function_any(&d->hdr.cpu_mask, mon_event_config_read, mon_info, 1);
1626+
smp_call_function_any(&mon_info->d->hdr.cpu_mask,
1627+
resctrl_arch_mon_event_config_read, mon_info, 1);
16321628
}
16331629

16341630
static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid)
16351631
{
1636-
struct mon_config_info mon_info;
1632+
struct resctrl_mon_config_info mon_info;
16371633
struct rdt_mon_domain *dom;
16381634
bool sep = false;
16391635

@@ -1644,9 +1640,11 @@ static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid
16441640
if (sep)
16451641
seq_puts(s, ";");
16461642

1647-
memset(&mon_info, 0, sizeof(struct mon_config_info));
1643+
memset(&mon_info, 0, sizeof(struct resctrl_mon_config_info));
1644+
mon_info.r = r;
1645+
mon_info.d = dom;
16481646
mon_info.evtid = evtid;
1649-
mondata_config_read(dom, &mon_info);
1647+
mondata_config_read(&mon_info);
16501648

16511649
seq_printf(s, "%d=0x%02x", dom->hdr.id, mon_info.mon_config);
16521650
sep = true;
@@ -1679,30 +1677,32 @@ static int mbm_local_bytes_config_show(struct kernfs_open_file *of,
16791677
return 0;
16801678
}
16811679

1682-
static void mon_event_config_write(void *info)
1680+
void resctrl_arch_mon_event_config_write(void *_config_info)
16831681
{
1684-
struct mon_config_info *mon_info = info;
1682+
struct resctrl_mon_config_info *config_info = _config_info;
16851683
unsigned int index;
16861684

1687-
index = mon_event_config_index_get(mon_info->evtid);
1685+
index = mon_event_config_index_get(config_info->evtid);
16881686
if (index == INVALID_CONFIG_INDEX) {
1689-
pr_warn_once("Invalid event id %d\n", mon_info->evtid);
1687+
pr_warn_once("Invalid event id %d\n", config_info->evtid);
16901688
return;
16911689
}
1692-
wrmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, 0);
1690+
wrmsr(MSR_IA32_EVT_CFG_BASE + index, config_info->mon_config, 0);
16931691
}
16941692

16951693
static void mbm_config_write_domain(struct rdt_resource *r,
16961694
struct rdt_mon_domain *d, u32 evtid, u32 val)
16971695
{
1698-
struct mon_config_info mon_info = {0};
1696+
struct resctrl_mon_config_info mon_info = {0};
16991697

17001698
/*
17011699
* Read the current config value first. If both are the same then
17021700
* no need to write it again.
17031701
*/
1702+
mon_info.r = r;
1703+
mon_info.d = d;
17041704
mon_info.evtid = evtid;
1705-
mondata_config_read(d, &mon_info);
1705+
mondata_config_read(&mon_info);
17061706
if (mon_info.mon_config == val)
17071707
return;
17081708

@@ -1714,7 +1714,7 @@ static void mbm_config_write_domain(struct rdt_resource *r,
17141714
* are scoped at the domain level. Writing any of these MSRs
17151715
* on one CPU is observed by all the CPUs in the domain.
17161716
*/
1717-
smp_call_function_any(&d->hdr.cpu_mask, mon_event_config_write,
1717+
smp_call_function_any(&d->hdr.cpu_mask, resctrl_arch_mon_event_config_write,
17181718
&mon_info, 1);
17191719

17201720
/*

include/linux/resctrl.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ struct resctrl_cpu_defaults {
270270
u32 rmid;
271271
};
272272

273+
struct resctrl_mon_config_info {
274+
struct rdt_resource *r;
275+
struct rdt_mon_domain *d;
276+
u32 evtid;
277+
u32 mon_config;
278+
};
279+
273280
/**
274281
* resctrl_arch_sync_cpu_closid_rmid() - Refresh this CPU's CLOSID and RMID.
275282
* Call via IPI.
@@ -311,6 +318,30 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
311318

312319
__init bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
313320

321+
/**
322+
* resctrl_arch_mon_event_config_write() - Write the config for an event.
323+
* @config_info: struct resctrl_mon_config_info describing the resource, domain
324+
* and event.
325+
*
326+
* Reads resource, domain and eventid from @config_info and writes the
327+
* event config_info->mon_config into hardware.
328+
*
329+
* Called via IPI to reach a CPU that is a member of the specified domain.
330+
*/
331+
void resctrl_arch_mon_event_config_write(void *config_info);
332+
333+
/**
334+
* resctrl_arch_mon_event_config_read() - Read the config for an event.
335+
* @config_info: struct resctrl_mon_config_info describing the resource, domain
336+
* and event.
337+
*
338+
* Reads resource, domain and eventid from @config_info and reads the
339+
* hardware config value into config_info->mon_config.
340+
*
341+
* Called via IPI to reach a CPU that is a member of the specified domain.
342+
*/
343+
void resctrl_arch_mon_event_config_read(void *config_info);
344+
314345
/*
315346
* Update the ctrl_val and apply this config right now.
316347
* Must be called on one of the domain's CPUs.

0 commit comments

Comments
 (0)