[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1498503368-20173-21-git-send-email-vikas.shivappa@linux.intel.com>
Date: Mon, 26 Jun 2017 11:56:07 -0700
From: Vikas Shivappa <vikas.shivappa@...ux.intel.com>
To: x86@...nel.org, linux-kernel@...r.kernel.org, tglx@...utronix.de
Cc: hpa@...or.com, peterz@...radead.org, ravi.v.shankar@...el.com,
vikas.shivappa@...el.com, tony.luck@...el.com,
fenghua.yu@...el.com, andi.kleen@...el.com
Subject: [PATCH 20/21] x86/intel_rdt/mbm: Add mbm counter initialization
MBM counters are monotonically increasing counts representing the total
memory bytes at a particular time. In order to calculate total_bytes for
an rdtgroup, we store the value of the counter when we create an
rdtgroup or when a new domain comes online.
When the total_bytes(all memory controller bytes) or local_bytes(local
memory controller bytes) file in "mon_data" is read it shows the total
bytes for that rdtgroup since its creation. User can snapshot this at
different time intervals to obtain bytes/second.
Signed-off-by: Vikas Shivappa <vikas.shivappa@...ux.intel.com>
---
arch/x86/kernel/cpu/intel_rdt.c | 2 +-
arch/x86/kernel/cpu/intel_rdt.h | 11 +++++++++-
arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c | 25 +++++++++++++--------
arch/x86/kernel/cpu/intel_rdt_monitor.c | 7 ++++++
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 34 ++++++++++++++++++-----------
5 files changed, 55 insertions(+), 24 deletions(-)
diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c
index a17f323..7762e32 100644
--- a/arch/x86/kernel/cpu/intel_rdt.c
+++ b/arch/x86/kernel/cpu/intel_rdt.c
@@ -469,7 +469,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
* per domain monitor data directories.
*/
if (static_branch_unlikely(&rdt_mon_enable_key))
- mkdir_mondata_subdir_allrdtgrp(r, d->id);
+ mkdir_mondata_subdir_allrdtgrp(r, d);
}
static void domain_remove_cpu(int cpu, struct rdt_resource *r)
diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
index ab010fb..f0896ac 100644
--- a/arch/x86/kernel/cpu/intel_rdt.h
+++ b/arch/x86/kernel/cpu/intel_rdt.h
@@ -57,6 +57,7 @@ struct rmid_read {
struct rdtgroup *rgrp;
struct rdt_domain *d;
int evtid;
+ bool first;
u64 val;
};
@@ -253,6 +254,12 @@ static inline bool is_mbm_enabled(void)
return (is_mbm_total_enabled() || is_mbm_local_enabled());
}
+static inline bool is_mbm_event(int e)
+{
+ return (e >= QOS_L3_MBM_TOTAL_EVENT_ID &&
+ e <= QOS_L3_MBM_LOCAL_EVENT_ID);
+}
+
/**
* struct rdt_resource - attributes of an RDT resource
* @alloc_enabled: Is allocation enabled on this machine
@@ -390,6 +397,8 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
unsigned int dom_id);
void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
- unsigned int dom_id);
+ struct rdt_domain *d);
+void mon_event_read(struct rmid_read *rr, struct rdt_domain *d,
+ struct rdtgroup *rdtgrp, int evtid, int first);
#endif /* _ASM_X86_INTEL_RDT_H */
diff --git a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
index 926d889..e9391e3 100644
--- a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
+++ b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
@@ -285,6 +285,21 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
return ret;
}
+void mon_event_read(struct rmid_read *rr, struct rdt_domain *d,
+ struct rdtgroup *rdtgrp, int evtid, int first)
+{
+ /*
+ * setup the parameters to send to the IPI to read the data.
+ */
+ rr->rgrp = rdtgrp;
+ rr->evtid = evtid;
+ rr->d = d;
+ rr->val = 0;
+ rr->first = first;
+
+ smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1);
+}
+
int rdtgroup_mondata_show(struct seq_file *m, void *arg)
{
struct kernfs_open_file *of = m->private;
@@ -310,15 +325,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
goto out;
}
- /*
- * setup the parameters to send to the IPI to read the data.
- */
- rr.rgrp = rdtgrp;
- rr.evtid = evtid;
- rr.d = d;
- rr.val = 0;
-
- smp_call_function_any(&d->cpu_mask, mon_event_count, &rr, 1);
+ mon_event_read(&rr, d, rdtgrp, evtid, false);
if (rr.val & RMID_VAL_ERROR)
seq_puts(m, "Error\n");
diff --git a/arch/x86/kernel/cpu/intel_rdt_monitor.c b/arch/x86/kernel/cpu/intel_rdt_monitor.c
index 2c5768c..a196f4d 100644
--- a/arch/x86/kernel/cpu/intel_rdt_monitor.c
+++ b/arch/x86/kernel/cpu/intel_rdt_monitor.c
@@ -230,6 +230,13 @@ static bool __mon_event_count(u32 rmid, struct rmid_read *rr)
default:
return false;
}
+
+ if (rr->first) {
+ m->prev_msr = tval;
+ m->chunks = 0;
+ return true;
+ }
+
shift = 64 - MBM_CNTR_WIDTH;
chunks = (tval << shift) - (m->prev_msr << shift);
chunks >>= shift;
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index 8e1581a..1b84485 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -1379,12 +1379,14 @@ static int get_rdt_resourceid(struct rdt_resource *r)
return ((r - rdt_resources_all) / sizeof(struct rdt_resource));
}
-static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, int domid,
+static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
+ struct rdt_domain *d,
struct rdt_resource *r, struct rdtgroup *pr)
{
union mon_data_bits priv;
struct kernfs_node *kn;
struct mon_evt *mevt;
+ struct rmid_read rr;
char name[32];
int ret, rid;
@@ -1392,7 +1394,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, int domid,
if (rid < 0)
return -EINVAL;
- sprintf(name, "mon_%s_%02d", r->name, domid);
+ sprintf(name, "mon_%s_%02d", r->name, d->id);
/* create the directory */
kn = kernfs_create_dir(parent_kn, name, parent_kn->mode, pr);
if (IS_ERR(kn))
@@ -1413,12 +1415,15 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, int domid,
}
priv.u.rid = rid;
- priv.u.domid = domid;
+ priv.u.domid = d->id;
list_for_each_entry(mevt, &r->evt_list, list) {
priv.u.evtid = mevt->evtid;
ret = mon_addfile(kn, mevt->name, priv.priv);
if (ret)
goto out_destroy;
+
+ if (is_mbm_event(mevt->evtid))
+ mon_event_read(&rr, d, pr, mevt->evtid, true);
}
kernfs_activate(kn);
return 0;
@@ -1432,7 +1437,8 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, int domid,
* Add all subdirectories of mon_data for "ctrl_mon" groups
* and "monitor" groups with given domain id.
*/
-void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, unsigned int domid)
+void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
+ struct rdt_domain *d)
{
struct kernfs_node *parent_kn;
struct rdtgroup *pr, *cr;
@@ -1442,11 +1448,11 @@ void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, unsigned int domid)
list_for_each_entry(pr, &rdt_all_groups, rdtgroup_list) {
parent_kn = pr->mon_data_kn;
- mkdir_mondata_subdir(parent_kn, domid, r, pr);
+ mkdir_mondata_subdir(parent_kn, d, r, pr);
list_for_each_entry(cr, &pr->crdtgrp_list, crdtgrp_list) {
parent_kn = cr->mon_data_kn;
- mkdir_mondata_subdir(parent_kn, domid, r, cr);
+ mkdir_mondata_subdir(parent_kn, d, r, cr);
}
}
}
@@ -1459,7 +1465,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,
int ret;
list_for_each_entry(dom, &r->domains, list) {
- ret = mkdir_mondata_subdir(parent_kn, dom->id, r, pr);
+ ret = mkdir_mondata_subdir(parent_kn, dom, r, pr);
if (ret)
return ret;
}
@@ -1575,20 +1581,22 @@ static int mkdir_rdt_common(struct kernfs_node *pkn, struct kernfs_node *prkn,
goto out_destroy;
if (rdt_mon_features) {
- ret = mkdir_mondata_all(kn, rdtgrp, &rdtgrp->mon_data_kn);
- if (ret)
- goto out_destroy;
-
ret = alloc_rmid();
if (ret < 0)
- return ret;
-
+ goto out_destroy;
rdtgrp->rmid = ret;
+
+ ret = mkdir_mondata_all(kn, rdtgrp, &rdtgrp->mon_data_kn);
+ if (ret)
+ goto out_idfree;
}
kernfs_activate(kn);
return 0;
+out_idfree:
+ if (rdtgrp->rmid)
+ free_rmid(rdtgrp->rmid);
out_destroy:
kernfs_remove(rdtgrp->kn);
out_cancel_ref:
--
1.9.1
Powered by blists - more mailing lists