Skip to content

Commit 8ccb1f8

Browse files
aeglbp3tk0v
authored andcommitted
x86,fs/resctrl: Add architectural event pointer
The resctrl file system layer passes the domain, RMID, and event id to the architecture to fetch an event counter. Fetching a telemetry event counter requires additional information that is private to the architecture, for example, the offset into MMIO space from where the counter should be read. Add mon_evt::arch_priv that architecture can use for any private data related to the event. The resctrl filesystem initializes mon_evt::arch_priv when the architecture enables the event and passes it back to architecture when needing to fetch an event counter. Suggested-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Link: https://lore.kernel.org/20251217172121.12030-1-tony.luck@intel.com
1 parent 8f6b6ad commit 8ccb1f8

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,15 +918,15 @@ static __init bool get_rdt_mon_resources(void)
918918
bool ret = false;
919919

920920
if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) {
921-
resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID, false, 0);
921+
resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID, false, 0, NULL);
922922
ret = true;
923923
}
924924
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
925-
resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false, 0);
925+
resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false, 0, NULL);
926926
ret = true;
927927
}
928928
if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) {
929-
resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false, 0);
929+
resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false, 0, NULL);
930930
ret = true;
931931
}
932932
if (rdt_cpu_has(X86_FEATURE_ABMC))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static u64 get_corrected_val(struct rdt_resource *r, struct rdt_l3_mon_domain *d
240240

241241
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
242242
u32 unused, u32 rmid, enum resctrl_event_id eventid,
243-
u64 *val, void *ignored)
243+
void *arch_priv, u64 *val, void *ignored)
244244
{
245245
struct rdt_hw_l3_mon_domain *hw_dom;
246246
struct rdt_l3_mon_domain *d;

fs/resctrl/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
6666
* @binary_bits: number of fixed-point binary bits from architecture,
6767
* only valid if @is_floating_point is true
6868
* @enabled: true if the event is enabled
69+
* @arch_priv: Architecture private data for this event.
70+
* The @arch_priv provided by the architecture via
71+
* resctrl_enable_mon_event().
6972
*/
7073
struct mon_evt {
7174
enum resctrl_event_id evtid;
@@ -77,6 +80,7 @@ struct mon_evt {
7780
bool is_floating_point;
7881
unsigned int binary_bits;
7982
bool enabled;
83+
void *arch_priv;
8084
};
8185

8286
extern struct mon_evt mon_event_all[QOS_NUM_EVENTS];

fs/resctrl/monitor.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
137137
struct rmid_entry *entry;
138138
u32 idx, cur_idx = 1;
139139
void *arch_mon_ctx;
140+
void *arch_priv;
140141
bool rmid_dirty;
141142
u64 val = 0;
142143

144+
arch_priv = mon_event_all[QOS_L3_OCCUP_EVENT_ID].arch_priv;
143145
arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, QOS_L3_OCCUP_EVENT_ID);
144146
if (IS_ERR(arch_mon_ctx)) {
145147
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
@@ -160,7 +162,7 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
160162

161163
entry = __rmid_entry(idx);
162164
if (resctrl_arch_rmid_read(r, &d->hdr, entry->closid, entry->rmid,
163-
QOS_L3_OCCUP_EVENT_ID, &val,
165+
QOS_L3_OCCUP_EVENT_ID, arch_priv, &val,
164166
arch_mon_ctx)) {
165167
rmid_dirty = true;
166168
} else {
@@ -456,7 +458,8 @@ static int __l3_mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
456458
rr->evt->evtid, &tval);
457459
else
458460
rr->err = resctrl_arch_rmid_read(rr->r, rr->hdr, closid, rmid,
459-
rr->evt->evtid, &tval, rr->arch_mon_ctx);
461+
rr->evt->evtid, rr->evt->arch_priv,
462+
&tval, rr->arch_mon_ctx);
460463
if (rr->err)
461464
return rr->err;
462465

@@ -501,7 +504,8 @@ static int __l3_mon_event_count_sum(struct rdtgroup *rdtgrp, struct rmid_read *r
501504
if (d->ci_id != rr->ci->id)
502505
continue;
503506
err = resctrl_arch_rmid_read(rr->r, &d->hdr, closid, rmid,
504-
rr->evt->evtid, &tval, rr->arch_mon_ctx);
507+
rr->evt->evtid, rr->evt->arch_priv,
508+
&tval, rr->arch_mon_ctx);
505509
if (!err) {
506510
rr->val += tval;
507511
ret = 0;
@@ -993,7 +997,8 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] = {
993997
MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", RDT_RESOURCE_PERF_PKG, false),
994998
};
995999

996-
void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, unsigned int binary_bits)
1000+
void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,
1001+
unsigned int binary_bits, void *arch_priv)
9971002
{
9981003
if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >= QOS_NUM_EVENTS ||
9991004
binary_bits > MAX_BINARY_BITS))
@@ -1009,6 +1014,7 @@ void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, unsig
10091014

10101015
mon_event_all[eventid].any_cpu = any_cpu;
10111016
mon_event_all[eventid].binary_bits = binary_bits;
1017+
mon_event_all[eventid].arch_priv = arch_priv;
10121018
mon_event_all[eventid].enabled = true;
10131019
}
10141020

include/linux/resctrl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ u32 resctrl_arch_system_num_rmid_idx(void);
415415
int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
416416

417417
void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,
418-
unsigned int binary_bits);
418+
unsigned int binary_bits, void *arch_priv);
419419

420420
bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid);
421421

@@ -532,6 +532,9 @@ void resctrl_arch_pre_mount(void);
532532
* only.
533533
* @rmid: rmid of the counter to read.
534534
* @eventid: eventid to read, e.g. L3 occupancy.
535+
* @arch_priv: Architecture private data for this event.
536+
* The @arch_priv provided by the architecture via
537+
* resctrl_enable_mon_event().
535538
* @val: result of the counter read in bytes.
536539
* @arch_mon_ctx: An architecture specific value from
537540
* resctrl_arch_mon_ctx_alloc(), for MPAM this identifies
@@ -549,7 +552,7 @@ void resctrl_arch_pre_mount(void);
549552
*/
550553
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
551554
u32 closid, u32 rmid, enum resctrl_event_id eventid,
552-
u64 *val, void *arch_mon_ctx);
555+
void *arch_priv, u64 *val, void *arch_mon_ctx);
553556

554557
/**
555558
* resctrl_arch_rmid_read_context_check() - warn about invalid contexts

0 commit comments

Comments
 (0)