Skip to content

Commit fea62d3

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Allow per-rmid arch private storage to be reset
To abstract the rmid counters into a helper that returns the number of bytes counted, architecture specific per-rmid state is needed. It needs to be possible to reset this hidden state, as the values may outlive the life of an rmid, or the mount time of the filesystem. mon_event_read() is called with first = true when an rmid is first allocated in mkdir_mondata_subdir(). Add resctrl_arch_reset_rmid() and call it from __mon_event_count()'s rr->first check. Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Jamie Iles <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Tested-by: Xin Hao <[email protected]> Tested-by: Shaopeng Tan <[email protected]> Tested-by: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 48dbe31 commit fea62d3

File tree

3 files changed

+62
-14
lines changed

3 files changed

+62
-14
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222

2323
#define L2_QOS_CDP_ENABLE 0x01ULL
2424

25-
/*
26-
* Event IDs are used to program IA32_QM_EVTSEL before reading event
27-
* counter from IA32_QM_CTR
28-
*/
29-
#define QOS_L3_OCCUP_EVENT_ID 0x01
30-
#define QOS_L3_MBM_TOTAL_EVENT_ID 0x02
31-
#define QOS_L3_MBM_LOCAL_EVENT_ID 0x03
32-
3325
#define CQM_LIMBOCHECK_INTERVAL 1000
3426

3527
#define MBM_CNTR_WIDTH_BASE 24
@@ -73,7 +65,7 @@ DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
7365
* @list: entry in &rdt_resource->evt_list
7466
*/
7567
struct mon_evt {
76-
u32 evtid;
68+
enum resctrl_event_id evtid;
7769
char *name;
7870
struct list_head list;
7971
};
@@ -90,17 +82,17 @@ struct mon_evt {
9082
union mon_data_bits {
9183
void *priv;
9284
struct {
93-
unsigned int rid : 10;
94-
unsigned int evtid : 8;
95-
unsigned int domid : 14;
85+
unsigned int rid : 10;
86+
enum resctrl_event_id evtid : 8;
87+
unsigned int domid : 14;
9688
} u;
9789
};
9890

9991
struct rmid_read {
10092
struct rdtgroup *rgrp;
10193
struct rdt_resource *r;
10294
struct rdt_domain *d;
103-
int evtid;
95+
enum resctrl_event_id evtid;
10496
bool first;
10597
u64 val;
10698
};

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,37 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)
137137
return entry;
138138
}
139139

140-
static u64 __rmid_read(u32 rmid, u32 eventid)
140+
static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,
141+
u32 rmid,
142+
enum resctrl_event_id eventid)
143+
{
144+
switch (eventid) {
145+
case QOS_L3_OCCUP_EVENT_ID:
146+
return NULL;
147+
case QOS_L3_MBM_TOTAL_EVENT_ID:
148+
return &hw_dom->arch_mbm_total[rmid];
149+
case QOS_L3_MBM_LOCAL_EVENT_ID:
150+
return &hw_dom->arch_mbm_local[rmid];
151+
}
152+
153+
/* Never expect to get here */
154+
WARN_ON_ONCE(1);
155+
156+
return NULL;
157+
}
158+
159+
void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
160+
u32 rmid, enum resctrl_event_id eventid)
161+
{
162+
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
163+
struct arch_mbm_state *am;
164+
165+
am = get_arch_mbm_state(hw_dom, rmid, eventid);
166+
if (am)
167+
memset(am, 0, sizeof(*am));
168+
}
169+
170+
static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
141171
{
142172
u64 val;
143173

@@ -291,6 +321,9 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
291321
struct mbm_state *m;
292322
u64 chunks, tval;
293323

324+
if (rr->first)
325+
resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
326+
294327
tval = __rmid_read(rmid, rr->evtid);
295328
if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
296329
return tval;

include/linux/resctrl.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ enum resctrl_conf_type {
3232

3333
#define CDP_NUM_TYPES (CDP_DATA + 1)
3434

35+
/*
36+
* Event IDs, the values match those used to program IA32_QM_EVTSEL before
37+
* reading IA32_QM_CTR on RDT systems.
38+
*/
39+
enum resctrl_event_id {
40+
QOS_L3_OCCUP_EVENT_ID = 0x01,
41+
QOS_L3_MBM_TOTAL_EVENT_ID = 0x02,
42+
QOS_L3_MBM_LOCAL_EVENT_ID = 0x03,
43+
};
44+
3545
/**
3646
* struct resctrl_staged_config - parsed configuration to be applied
3747
* @new_ctrl: new ctrl value to be loaded
@@ -210,4 +220,17 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
210220
int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
211221
void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
212222

223+
/**
224+
* resctrl_arch_reset_rmid() - Reset any private state associated with rmid
225+
* and eventid.
226+
* @r: The domain's resource.
227+
* @d: The rmid's domain.
228+
* @rmid: The rmid whose counter values should be reset.
229+
* @eventid: The eventid whose counter values should be reset.
230+
*
231+
* This can be called from any CPU.
232+
*/
233+
void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
234+
u32 rmid, enum resctrl_event_id eventid);
235+
213236
#endif /* _RESCTRL_H */

0 commit comments

Comments
 (0)