LKML Archive on
help / color / mirror / Atom feed
From: Babu Moger <>
Subject: [PATCH v2] x86/resctrl: Fix default monitoring groups reporting
Date: Mon, 02 Aug 2021 14:38:58 -0500	[thread overview]
Message-ID: <162793309296.9224.15871659871696482080.stgit@bmoger-ubuntu> (raw)

From: Babu Moger <>

Creating a new sub monitoring group in the root /sys/fs/resctrl leads to
getting the "Unavailable" value for mbm_total_bytes and mbm_local_bytes
on the entire filesystem.

Steps to reproduce.
1. #mount -t resctrl resctrl /sys/fs/resctrl/

2. #cd /sys/fs/resctrl/

3. #cat mon_data/mon_L3_00/mbm_total_bytes

4. #mkdir mon_groups/test1 (create sub monitor group)

5. #cat mon_data/mon_L3_00/mbm_total_bytes

When a new monitoring group is created, a new RMID is assigned to the new
group. But the RMID is not active yet. When the events are read on the new
RMID, it is expected to report the status as "Unavailable".

When the user reads the events on the default monitoring group with
multiple subgroups, the events on all sub groups are consolidated together.
Currently, if any of the RMID reads report as "Unavailable", then
everything will be reported as "Unavailable".

Fix the issue by discarding the "Unavailable" reads and reporting all the
successful RMID reads. This is not a problem on Intel systems as Intel
reports 0 on Inactive RMIDs.

Fixes: d89b7379015f ("x86/intel_rdt/cqm: Add mon_data")
Reported-by: Paweł Szulik <>
Signed-off-by: Babu Moger <>
Acked-by: Reinette Chatre <>
  Taken care of Reinette's comments. Added Fixes line and Added Cc to stable.


 arch/x86/kernel/cpu/resctrl/monitor.c |   27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index f07c10b87a87..57e4bb695ff9 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -285,15 +285,14 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
 	return chunks >>= shift;
-static int __mon_event_count(u32 rmid, struct rmid_read *rr)
+static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 	struct mbm_state *m;
 	u64 chunks, tval;
 	tval = __rmid_read(rmid, rr->evtid);
-		rr->val = tval;
-		return -EINVAL;
+		return tval;
 	switch (rr->evtid) {
@@ -305,12 +304,6 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr)
 		m = &rr->d->mbm_local[rmid];
-	default:
-		/*
-		 * Code would never reach here because
-		 * an invalid event id would fail the __rmid_read.
-		 */
-		return -EINVAL;
 	if (rr->first) {
@@ -361,23 +354,29 @@ void mon_event_count(void *info)
 	struct rdtgroup *rdtgrp, *entry;
 	struct rmid_read *rr = info;
 	struct list_head *head;
+	u64 ret_val;
 	rdtgrp = rr->rgrp;
-	if (__mon_event_count(rdtgrp->mon.rmid, rr))
-		return;
+	ret_val = __mon_event_count(rdtgrp->mon.rmid, rr);
-	 * For Ctrl groups read data from child monitor groups.
+	 * For Ctrl groups read data from child monitor groups and
+	 * add them together. Count events which are read successfully.
+	 * Discard the rmid_read's reporting errors.
 	head = &rdtgrp->mon.crdtgrp_list;
 	if (rdtgrp->type == RDTCTRL_GROUP) {
 		list_for_each_entry(entry, head, mon.crdtgrp_list) {
-			if (__mon_event_count(entry->mon.rmid, rr))
-				return;
+			if (__mon_event_count(entry->mon.rmid, rr) == 0)
+				ret_val = 0;
+	/* Report error if none of rmid_reads are successful */
+	if (ret_val)
+		rr->val = ret_val;

             reply	other threads:[~2021-08-02 19:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02 19:38 Babu Moger [this message]
2021-08-12 18:20 ` [tip: x86/urgent] " tip-bot2 for 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:

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

  git send-email \
    --in-reply-to=162793309296.9224.15871659871696482080.stgit@bmoger-ubuntu \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH v2] x86/resctrl: Fix default monitoring groups reporting' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).