All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Morse <james.morse@arm.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: Fenghua Yu <fenghua.yu@intel.com>,
	Reinette Chatre <reinette.chatre@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	H Peter Anvin <hpa@zytor.com>, Babu Moger <Babu.Moger@amd.com>,
	James Morse <james.morse@arm.com>,
	shameerali.kolothum.thodi@huawei.com,
	Jamie Iles <jamie@nuviainc.com>,
	D Scott Phillips OS <scott@os.amperecomputing.com>,
	lcherian@marvell.com, bobo.shaobowang@huawei.com,
	tan.shaopeng@fujitsu.com
Subject: [PATCH v2 17/23] x86/resctrl: Abstract __rmid_read()
Date: Fri,  1 Oct 2021 16:02:56 +0000	[thread overview]
Message-ID: <20211001160302.31189-18-james.morse@arm.com> (raw)
In-Reply-To: <20211001160302.31189-1-james.morse@arm.com>

__rmid_read() selects the specified eventid and returns the counter
value from the msr. The error handling is architecture specific, and
handled by the callers, rdtgroup_mondata_show() and __mon_event_count().

Error handling should be handled by architecture specific code, as
a different architecture may have different requirements. MPAM's
counters can report that they are 'not ready', requiring a second
read after a short delay. This should be hidden from resctrl.

Make __rmid_read() the architecture specific function for reading
a counter. Rename it resctrl_arch_rmid_read() and move the error
handling into it.

Signed-off-by: James Morse <james.morse@arm.com>
---
Changes since v1:
 * Return EINVAL from the impossible case in __mon_event_count() instead
   of an x86 hardware specific value.
---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  4 +--
 arch/x86/kernel/cpu/resctrl/internal.h    |  2 +-
 arch/x86/kernel/cpu/resctrl/monitor.c     | 42 +++++++++++++++--------
 include/linux/resctrl.h                   |  1 +
 4 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 25baacd331e0..c8ca7184c6d9 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -579,9 +579,9 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 
 	mon_event_read(&rr, r, d, rdtgrp, evtid, false);
 
-	if (rr.val & RMID_VAL_ERROR)
+	if (rr.err == -EIO)
 		seq_puts(m, "Error\n");
-	else if (rr.val & RMID_VAL_UNAVAIL)
+	else if (rr.err == -EINVAL)
 		seq_puts(m, "Unavailable\n");
 	else
 		seq_printf(m, "%llu\n", rr.val * hw_res->mon_scale);
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index f3f31315a907..eca7793d3342 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -40,7 +40,6 @@
  */
 #define MBM_CNTR_WIDTH_OFFSET_MAX (62 - MBM_CNTR_WIDTH_BASE)
 
-
 struct rdt_fs_context {
 	struct kernfs_fs_context	kfc;
 	bool				enable_cdpl2;
@@ -94,6 +93,7 @@ struct rmid_read {
 	struct rdt_domain	*d;
 	enum resctrl_event_id	evtid;
 	bool			first;
+	int			err;
 	u64			val;
 };
 
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index 35eef49954b0..cf35eaf01042 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -167,9 +167,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 		memset(am, 0, sizeof(*am));
 }
 
-static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
+int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
 {
-	u64 val;
+	u64 msr_val;
 
 	/*
 	 * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
@@ -180,14 +180,24 @@ static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
 	 * are error bits.
 	 */
 	wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid);
-	rdmsrl(MSR_IA32_QM_CTR, val);
+	rdmsrl(MSR_IA32_QM_CTR, msr_val);
 
-	return val;
+	if (msr_val & RMID_VAL_ERROR)
+		return -EIO;
+	if (msr_val & RMID_VAL_UNAVAIL)
+		return -EINVAL;
+
+	*val = msr_val;
+
+	return 0;
 }
 
 static bool rmid_dirty(struct rmid_entry *entry)
 {
-	u64 val = __rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID);
+	u64 val = 0;
+
+	if (resctrl_arch_rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID, &val))
+		return true;
 
 	return val >= resctrl_cqm_threshold;
 }
@@ -259,8 +269,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
 {
 	struct rdt_resource *r;
 	struct rdt_domain *d;
-	int cpu;
-	u64 val;
+	int cpu, err;
+	u64 val = 0;
 
 	r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
 
@@ -268,8 +278,10 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
 	cpu = get_cpu();
 	list_for_each_entry(d, &r->domains, list) {
 		if (cpumask_test_cpu(cpu, &d->cpu_mask)) {
-			val = __rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID);
-			if (val <= resctrl_cqm_threshold)
+			err = resctrl_arch_rmid_read(entry->rmid,
+						     QOS_L3_OCCUP_EVENT_ID,
+						     &val);
+			if (err || val <= resctrl_cqm_threshold)
 				continue;
 		}
 
@@ -319,15 +331,15 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m;
-	u64 chunks, tval;
+	u64 chunks, tval = 0;
 
 	if (rr->first)
 		resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
 
-	tval = __rmid_read(rmid, rr->evtid);
-	if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
-		return tval;
-	}
+	rr->err = resctrl_arch_rmid_read(rmid, rr->evtid, &tval);
+	if (rr->err)
+		return rr->err;
+
 	switch (rr->evtid) {
 	case QOS_L3_OCCUP_EVENT_ID:
 		rr->val += tval;
@@ -343,7 +355,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 		 * Code would never reach here because an invalid
 		 * event id would fail the __rmid_read.
 		 */
-		return RMID_VAL_ERROR;
+		return -EINVAL;
 	}
 
 	if (rr->first) {
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 04f30d80fc67..01bdd8be590b 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -218,6 +218,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type);
 int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
 void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
+int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *res);
 
 /**
  * resctrl_arch_reset_rmid() - Reset any private state associated with rmid
-- 
2.30.2


  parent reply	other threads:[~2021-10-01 16:04 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 16:02 [PATCH v2 00/23] x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes James Morse
2021-10-01 16:02 ` [PATCH v2 01/23] x86/resctrl: Free the ctrlval arrays when domain_setup_mon_state() fails James Morse
2021-10-01 16:02 ` [PATCH v2 02/23] x86/resctrl: Fix kfree() of the wrong type in domain_add_cpu() James Morse
2021-10-01 16:02 ` [PATCH v2 03/23] x86/resctrl: Kill off alloc_enabled James Morse
2021-10-15 22:19   ` Reinette Chatre
2021-10-01 16:02 ` [PATCH v2 04/23] x86/resctrl: Merge mon_capable and mon_enabled James Morse
2021-10-19 23:18   ` Babu Moger
2021-10-22 18:30     ` James Morse
2021-10-01 16:02 ` [PATCH v2 05/23] x86/resctrl: Add domain online callback for resctrl work James Morse
2021-10-15 22:19   ` Reinette Chatre
2021-10-22 18:30     ` James Morse
2021-10-19 23:19   ` Babu Moger
2021-10-22 18:30     ` James Morse
2021-10-01 16:02 ` [PATCH v2 06/23] x86/resctrl: Group struct rdt_hw_domain cleanup James Morse
2021-10-01 16:02 ` [PATCH v2 07/23] x86/resctrl: Add domain offline callback for resctrl work James Morse
2021-10-19 23:19   ` Babu Moger
2021-10-22 18:30     ` James Morse
2021-10-01 16:02 ` [PATCH v2 08/23] x86/resctrl: Create mba_sc configuration in the rdt_domain James Morse
2021-10-15 22:26   ` Reinette Chatre
2021-10-22 18:30     ` James Morse
2021-10-01 16:02 ` [PATCH v2 09/23] x86/resctrl: Switch over to the resctrl mbps_val list James Morse
2021-10-15 22:26   ` Reinette Chatre
2021-10-27 16:49     ` James Morse
2021-10-01 16:02 ` [PATCH v2 10/23] x86/resctrl: Remove architecture copy of mbps_val James Morse
2021-10-15 22:27   ` Reinette Chatre
2021-10-27 16:49     ` James Morse
2021-10-01 16:02 ` [PATCH v2 11/23] x86/resctrl: Remove set_mba_sc()s control array re-initialisation James Morse
2021-10-01 16:02 ` [PATCH v2 12/23] x86/resctrl: Abstract and use supports_mba_mbps() James Morse
2021-10-07  6:13   ` tan.shaopeng
2021-10-27 16:50     ` James Morse
2021-10-15 22:28   ` Reinette Chatre
2021-10-01 16:02 ` [PATCH v2 13/23] x86/resctrl: Allow update_mba_bw() to update controls directly James Morse
2021-10-15 22:28   ` Reinette Chatre
2021-10-27 16:49     ` James Morse
2021-10-01 16:02 ` [PATCH v2 14/23] x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks James Morse
2021-10-15 22:28   ` Reinette Chatre
2021-10-27 16:50     ` James Morse
2021-10-27 20:41       ` Reinette Chatre
2021-10-29 15:50         ` James Morse
2021-10-29 22:22           ` Reinette Chatre
2021-10-01 16:02 ` [PATCH v2 15/23] x86/recstrl: Add per-rmid arch private storage for overflow and chunks James Morse
2021-10-15 22:29   ` Reinette Chatre
2021-10-01 16:02 ` [PATCH v2 16/23] x86/recstrl: Allow per-rmid arch private storage to be reset James Morse
2021-10-07  6:16   ` tan.shaopeng
2021-10-01 16:02 ` James Morse [this message]
2021-10-15 22:29   ` [PATCH v2 17/23] x86/resctrl: Abstract __rmid_read() Reinette Chatre
2021-10-19 23:20   ` Babu Moger
2021-10-20 18:15     ` Reinette Chatre
2021-10-20 19:22       ` Babu Moger
2021-10-20 20:28         ` Reinette Chatre
2021-10-27 16:50           ` James Morse
2021-10-27 18:59             ` Babu Moger
2021-10-01 16:02 ` [PATCH v2 18/23] x86/resctrl: Pass the required parameters into resctrl_arch_rmid_read() James Morse
2021-10-15 22:30   ` Reinette Chatre
2021-10-01 16:02 ` [PATCH v2 19/23] x86/resctrl: Move mbm_overflow_count() " James Morse
2021-10-01 16:02 ` [PATCH v2 20/23] x86/resctrl: Move get_corrected_mbm_count() " James Morse
2021-10-01 16:03 ` [PATCH v2 21/23] x86/resctrl: Rename and change the units of resctrl_cqm_threshold James Morse
2021-10-01 16:03 ` [PATCH v2 22/23] x86/resctrl: Add resctrl_rmid_realloc_limit to abstract x86's boot_cpu_data James Morse
2021-10-01 16:03 ` [PATCH v2 23/23] x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes James Morse
2021-10-13  2:09 ` [PATCH v2 00/23] " tan.shaopeng
2021-10-19 23:17 ` Babu Moger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211001160302.31189-18-james.morse@arm.com \
    --to=james.morse@arm.com \
    --cc=Babu.Moger@amd.com \
    --cc=bobo.shaobowang@huawei.com \
    --cc=bp@alien8.de \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=jamie@nuviainc.com \
    --cc=lcherian@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=reinette.chatre@intel.com \
    --cc=scott@os.amperecomputing.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=tan.shaopeng@fujitsu.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.