Skip to content

Commit d89b737

Browse files
Vikas ShivappaKAGA-KOKO
authored andcommitted
x86/intel_rdt/cqm: Add mon_data
Add a mon_data directory for the root rdtgroup and all other rdtgroups. The directory holds all of the monitored data for all domains and events of all resources being monitored. The mon_data itself has a list of directories in the format mon_<domain_name>_<domain_id>. Each of these subdirectories contain one file per event in the mode "0444". Reading the file displays a snapshot of the monitored data for the event the file represents. For ex, on a 2 socket Broadwell with llc_occupancy being monitored the mon_data contents look as below: $ ls /sys/fs/resctrl/p1/mon_data/ mon_L3_00 mon_L3_01 Each domain directory has one file per event: $ ls /sys/fs/resctrl/p1/mon_data/mon_L3_00/ llc_occupancy To read current llc_occupancy of ctrl_mon group p1 $ cat /sys/fs/resctrl/p1/mon_data/mon_L3_00/llc_occupancy 33789096 [This patch idea is based on Tony's sample patches to organise data in a per domain directory and have one file per event (and use the fp->priv to store mon data bits)] Signed-off-by: Vikas Shivappa <vikas.shivappa@linux.intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: ravi.v.shankar@intel.com Cc: tony.luck@intel.com Cc: fenghua.yu@intel.com Cc: peterz@infradead.org Cc: eranian@google.com Cc: vikas.shivappa@intel.com Cc: ak@linux.intel.com Cc: davidcc@google.com Cc: reinette.chatre@intel.com Link: http://lkml.kernel.org/r/1501017287-28083-20-git-send-email-vikas.shivappa@linux.intel.com
1 parent 90c403e commit d89b737

File tree

5 files changed

+284
-3
lines changed

5 files changed

+284
-3
lines changed

arch/x86/kernel/cpu/intel_rdt.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ cat_wrmsr(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r);
7171
struct rdt_resource rdt_resources_all[] = {
7272
[RDT_RESOURCE_L3] =
7373
{
74+
.rid = RDT_RESOURCE_L3,
7475
.name = "L3",
7576
.domains = domain_init(RDT_RESOURCE_L3),
7677
.msr_base = IA32_L3_CBM_BASE,
@@ -87,6 +88,7 @@ struct rdt_resource rdt_resources_all[] = {
8788
},
8889
[RDT_RESOURCE_L3DATA] =
8990
{
91+
.rid = RDT_RESOURCE_L3DATA,
9092
.name = "L3DATA",
9193
.domains = domain_init(RDT_RESOURCE_L3DATA),
9294
.msr_base = IA32_L3_CBM_BASE,
@@ -103,6 +105,7 @@ struct rdt_resource rdt_resources_all[] = {
103105
},
104106
[RDT_RESOURCE_L3CODE] =
105107
{
108+
.rid = RDT_RESOURCE_L3CODE,
106109
.name = "L3CODE",
107110
.domains = domain_init(RDT_RESOURCE_L3CODE),
108111
.msr_base = IA32_L3_CBM_BASE,
@@ -119,6 +122,7 @@ struct rdt_resource rdt_resources_all[] = {
119122
},
120123
[RDT_RESOURCE_L2] =
121124
{
125+
.rid = RDT_RESOURCE_L2,
122126
.name = "L2",
123127
.domains = domain_init(RDT_RESOURCE_L2),
124128
.msr_base = IA32_L2_CBM_BASE,
@@ -135,6 +139,7 @@ struct rdt_resource rdt_resources_all[] = {
135139
},
136140
[RDT_RESOURCE_MBA] =
137141
{
142+
.rid = RDT_RESOURCE_MBA,
138143
.name = "MB",
139144
.domains = domain_init(RDT_RESOURCE_MBA),
140145
.msr_base = IA32_MBA_THRTL_BASE,
@@ -362,8 +367,8 @@ void rdt_ctrl_update(void *arg)
362367
* caller, return the first domain whose id is bigger than the input id.
363368
* The domain list is sorted by id in ascending order.
364369
*/
365-
static struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
366-
struct list_head **pos)
370+
struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
371+
struct list_head **pos)
367372
{
368373
struct rdt_domain *d;
369374
struct list_head *l;

arch/x86/kernel/cpu/intel_rdt.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ struct mon_evt {
3333
struct list_head list;
3434
};
3535

36+
/**
37+
* struct mon_data_bits - Monitoring details for each event file
38+
* @rid: Resource id associated with the event file.
39+
* @evtid: Event id associated with the event file
40+
* @domid: The domain to which the event file belongs
41+
*/
42+
union mon_data_bits {
43+
void *priv;
44+
struct {
45+
unsigned int rid : 10;
46+
unsigned int evtid : 8;
47+
unsigned int domid : 14;
48+
} u;
49+
};
50+
51+
struct rmid_read {
52+
struct rdtgroup *rgrp;
53+
int evtid;
54+
u64 val;
55+
};
56+
3657
extern unsigned int intel_cqm_threshold;
3758
extern bool rdt_alloc_capable;
3859
extern bool rdt_mon_capable;
@@ -46,11 +67,13 @@ enum rdt_group_type {
4667

4768
/**
4869
* struct mongroup - store mon group's data in resctrl fs.
70+
* @mon_data_kn kernlfs node for the mon_data directory
4971
* @parent: parent rdtgrp
5072
* @crdtgrp_list: child rdtgroup node list
5173
* @rmid: rmid for this rdtgroup
5274
*/
5375
struct mongroup {
76+
struct kernfs_node *mon_data_kn;
5477
struct rdtgroup *parent;
5578
struct list_head crdtgrp_list;
5679
u32 rmid;
@@ -209,6 +232,7 @@ static inline bool is_llc_occupancy_enabled(void)
209232

210233
/**
211234
* struct rdt_resource - attributes of an RDT resource
235+
* @rid: The index of the resource
212236
* @alloc_enabled: Is allocation enabled on this machine
213237
* @mon_enabled: Is monitoring enabled for this feature
214238
* @alloc_capable: Is allocation available on this machine
@@ -230,6 +254,7 @@ static inline bool is_llc_occupancy_enabled(void)
230254
* @fflags: flags to choose base and info files
231255
*/
232256
struct rdt_resource {
257+
int rid;
233258
bool alloc_enabled;
234259
bool mon_enabled;
235260
bool alloc_capable;
@@ -323,6 +348,8 @@ union cpuid_0x10_x_edx {
323348
void rdt_ctrl_update(void *arg);
324349
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
325350
void rdtgroup_kn_unlock(struct kernfs_node *kn);
351+
struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
352+
struct list_head **pos);
326353
ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
327354
char *buf, size_t nbytes, loff_t off);
328355
int rdtgroup_schemata_show(struct kernfs_open_file *of,
@@ -331,5 +358,7 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r);
331358
int alloc_rmid(void);
332359
void free_rmid(u32 rmid);
333360
int rdt_get_mon_l3_config(struct rdt_resource *r);
361+
void mon_event_count(void *info);
362+
int rdtgroup_mondata_show(struct seq_file *m, void *arg);
334363

335364
#endif /* _ASM_X86_INTEL_RDT_H */

arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
269269
{
270270
struct rdtgroup *rdtgrp;
271271
struct rdt_resource *r;
272-
int closid, ret = 0;
272+
int ret = 0;
273+
u32 closid;
273274

274275
rdtgrp = rdtgroup_kn_lock_live(of->kn);
275276
if (rdtgrp) {
@@ -284,3 +285,55 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
284285
rdtgroup_kn_unlock(of->kn);
285286
return ret;
286287
}
288+
289+
void mon_event_read(struct rmid_read *rr, struct rdt_domain *d,
290+
struct rdtgroup *rdtgrp, int evtid)
291+
{
292+
/*
293+
* setup the parameters to send to the IPI to read the data.
294+
*/
295+
rr->rgrp = rdtgrp;
296+
rr->evtid = evtid;
297+
rr->val = 0;
298+
299+
smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1);
300+
}
301+
302+
int rdtgroup_mondata_show(struct seq_file *m, void *arg)
303+
{
304+
struct kernfs_open_file *of = m->private;
305+
u32 resid, evtid, domid;
306+
struct rdtgroup *rdtgrp;
307+
struct rdt_resource *r;
308+
union mon_data_bits md;
309+
struct rdt_domain *d;
310+
struct rmid_read rr;
311+
int ret = 0;
312+
313+
rdtgrp = rdtgroup_kn_lock_live(of->kn);
314+
315+
md.priv = of->kn->priv;
316+
resid = md.u.rid;
317+
domid = md.u.domid;
318+
evtid = md.u.evtid;
319+
320+
r = &rdt_resources_all[resid];
321+
d = rdt_find_domain(r, domid, NULL);
322+
if (!d) {
323+
ret = -ENOENT;
324+
goto out;
325+
}
326+
327+
mon_event_read(&rr, d, rdtgrp, evtid);
328+
329+
if (rr.val & RMID_VAL_ERROR)
330+
seq_puts(m, "Error\n");
331+
else if (rr.val & RMID_VAL_UNAVAIL)
332+
seq_puts(m, "Unavailable\n");
333+
else
334+
seq_printf(m, "%llu\n", rr.val * r->mon_scale);
335+
336+
out:
337+
rdtgroup_kn_unlock(of->kn);
338+
return ret;
339+
}

arch/x86/kernel/cpu/intel_rdt_monitor.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,55 @@ void free_rmid(u32 rmid)
294294
list_add_tail(&entry->list, &rmid_free_lru);
295295
}
296296

297+
static int __mon_event_count(u32 rmid, struct rmid_read *rr)
298+
{
299+
u64 tval;
300+
301+
tval = __rmid_read(rmid, rr->evtid);
302+
if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
303+
rr->val = tval;
304+
return -EINVAL;
305+
}
306+
switch (rr->evtid) {
307+
case QOS_L3_OCCUP_EVENT_ID:
308+
rr->val += tval;
309+
return 0;
310+
default:
311+
/*
312+
* Code would never reach here because
313+
* an invalid event id would fail the __rmid_read.
314+
*/
315+
return -EINVAL;
316+
}
317+
}
318+
319+
/*
320+
* This is called via IPI to read the CQM/MBM counters
321+
* on a domain.
322+
*/
323+
void mon_event_count(void *info)
324+
{
325+
struct rdtgroup *rdtgrp, *entry;
326+
struct rmid_read *rr = info;
327+
struct list_head *head;
328+
329+
rdtgrp = rr->rgrp;
330+
331+
if (__mon_event_count(rdtgrp->mon.rmid, rr))
332+
return;
333+
334+
/*
335+
* For Ctrl groups read data from child monitor groups.
336+
*/
337+
head = &rdtgrp->mon.crdtgrp_list;
338+
339+
if (rdtgrp->type == RDTCTRL_GROUP) {
340+
list_for_each_entry(entry, head, mon.crdtgrp_list) {
341+
if (__mon_event_count(entry->mon.rmid, rr))
342+
return;
343+
}
344+
}
345+
}
297346
static int dom_data_init(struct rdt_resource *r)
298347
{
299348
struct rmid_entry *entry = NULL;

0 commit comments

Comments
 (0)