mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Horgan <ben.horgan@arm.com>
To: reinette.chatre@intel.com
Cc: Dave.Martin@arm.com, babu.moger@amd.com, ben.horgan@arm.com,
	bp@alien8.de, dave.hansen@linux.intel.com, fenghuay@nvidia.com,
	fustini@kernel.org, james.morse@arm.com,
	linux-kernel@vger.kernel.org, peternewman@google.com,
	tglx@linutronix.de, tony.luck@intel.com, x86@kernel.org,
	yu.c.chen@intel.com
Subject: [RFC PATCH 3/3] fs/resctrl: display size for scalar cache controls
Date: Mon, 21 Sep 2026 14:57:02 +0100	[thread overview]
Message-ID: <20260921135702.2874931-4-ben.horgan@arm.com> (raw)
In-Reply-To: <20260921135702.2874931-1-ben.horgan@arm.com>

resctrl allows controls specifying a minimum or maximum cache allocation
but does not display their sizes in the 'size' file.

Calculate the size of any scalar cache controls and add them to the 'size' file.

Signed-off-by: Ben Horgan <ben.horgan@arm.com>
---
 fs/resctrl/internal.h    |  4 ++--
 fs/resctrl/pseudo_lock.c |  2 +-
 fs/resctrl/rdtgroup.c    | 41 +++++++++++++++++++++++++++-------------
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index 4bd09b1541c7..119f702a4f1f 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -362,8 +362,8 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource_final *f, struct rdt_ctrl_domain
 			   unsigned long cbm, int closid, bool exclusive,
 			   struct resctrl_ctrl *ctrl);
 
-unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct resctrl_ctrl *ctrl,
-				  struct rdt_ctrl_domain *d, unsigned long cbm);
+unsigned int rdtgroup_cache_ctrl_to_size(struct rdt_resource *r, struct resctrl_ctrl *ctrl,
+					 struct rdt_ctrl_domain *d, unsigned long ctrl_val);
 
 enum rdtgrp_mode rdtgroup_mode_by_closid(int closid);
 
diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
index 17b99a075eaf..36881491d074 100644
--- a/fs/resctrl/pseudo_lock.c
+++ b/fs/resctrl/pseudo_lock.c
@@ -255,7 +255,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)
 	ci = get_cpu_cacheinfo_level(plr->cpu, scope);
 	if (ci) {
 		plr->line_size = ci->coherency_line_size;
-		plr->size = rdtgroup_cbm_to_size(plr->f->res, ctrl, plr->d, plr->cbm);
+		plr->size = rdtgroup_cache_ctrl_to_size(plr->f->res, ctrl, plr->d, plr->cbm);
 		return 0;
 	}
 
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index deb47edb2e87..ab0d8d0454f6 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1751,20 +1751,27 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
  *
  * Return: Size (in bytes) of cache portion represented by CBM, 0 on failure.
  */
-unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct resctrl_ctrl *ctrl,
-				  struct rdt_ctrl_domain *d, unsigned long cbm)
+unsigned int rdtgroup_cache_ctrl_to_size(struct rdt_resource *r, struct resctrl_ctrl *ctrl,
+					 struct rdt_ctrl_domain *d, unsigned long ctrl_val)
 {
 	unsigned int size = 0;
 	struct cacheinfo *ci;
-	int num_b;
 
 	if (WARN_ON_ONCE(r->ctrl_scope != RESCTRL_L2_CACHE && r->ctrl_scope != RESCTRL_L3_CACHE))
 		return size;
 
-	num_b = bitmap_weight(&cbm, ctrl->bitmap.cbm_len);
 	ci = get_cpu_cacheinfo_level(cpumask_any(&d->hdr.cpu_mask), r->ctrl_scope);
-	if (ci)
+	if (!ci)
+		return size;
+
+	if (ctrl->type == RESCTRL_CTRL_BITMAP) {
+		int num_b;
+
+		num_b = bitmap_weight(&ctrl_val, ctrl->bitmap.cbm_len);
 		size = ci->size / ctrl->bitmap.cbm_len * num_b;
+	} else {
+		size = ci->size / ctrl->scalar.resolution * ctrl->scalar.scale * ctrl_val;
+	}
 
 	return size;
 }
@@ -1834,10 +1841,10 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 			}
 			seq_printf(s, "%*s:", max_name_width,
 				   rdtgrp->plr->f->name);
-			size = rdtgroup_cbm_to_size(rdtgrp->plr->f->res,
-						    ctrl,
-						    rdtgrp->plr->d,
-						    rdtgrp->plr->cbm);
+			size = rdtgroup_cache_ctrl_to_size(rdtgrp->plr->f->res,
+							   ctrl,
+							   rdtgrp->plr->d,
+							   rdtgrp->plr->cbm);
 			seq_printf(s, "%d=%u\n", rdtgrp->plr->d->hdr.id, size);
 		}
 		goto out;
@@ -1863,11 +1870,19 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 						ctrl_val = resctrl_arch_get_config(r, ctrl, d,
 										   closid,
 										   type);
-					if (r->rid == RDT_RESOURCE_MBA ||
-					    r->rid == RDT_RESOURCE_SMBA)
+					switch (r->rid) {
+					case RDT_RESOURCE_L3:
+					case RDT_RESOURCE_L2:
+						size = rdtgroup_cache_ctrl_to_size(r, ctrl, d,
+										   ctrl_val);
+						break;
+					case RDT_RESOURCE_MBA:
+					case RDT_RESOURCE_SMBA:
 						size = ctrl_val;
-					else
-						size = rdtgroup_cbm_to_size(r, ctrl, d, ctrl_val);
+						break;
+					case RDT_RESOURCE_PERF_PKG:
+						size = 0;
+					}
 				}
 				seq_printf(s, "%d=%u", d->hdr.id, size);
 				sep = true;
-- 
2.43.0


  parent reply	other threads:[~2026-09-21 13:57 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  5:26 [RFC v2] arm,x86,fs/resctrl: Generic schema description Proof of Concept Reinette Chatre
2026-08-05 16:59 ` Ben Horgan
2026-08-05 23:57   ` Reinette Chatre
2026-08-06 17:04     ` Luck, Tony
2026-08-06 17:11       ` Reinette Chatre
2026-08-07 14:14         ` Moger, Babu
2026-08-07 15:35           ` Reinette Chatre
2026-08-07 18:33             ` Moger, Babu
2026-08-07 22:53               ` Reinette Chatre
2026-08-10 18:52                 ` Babu Moger
2026-08-11  4:06                   ` Reinette Chatre
2026-08-11 14:59                     ` Babu Moger
2026-08-11 15:30                       ` Reinette Chatre
2026-08-11 16:09                         ` Babu Moger
2026-08-24 14:40                 ` Ben Horgan
2026-08-24 18:07                   ` Reinette Chatre
2026-08-25 15:20                     ` Ben Horgan
2026-08-07 15:35           ` Chen, Yu C
2026-08-07 17:57             ` Moger, Babu
2026-08-10  2:05 ` Chen, Yu C
2026-08-10 15:53   ` Reinette Chatre
2026-08-10 17:23     ` Chen, Yu C
2026-08-10 18:09       ` Reinette Chatre
2026-08-11  3:49         ` Chen, Yu C
2026-08-13 13:59           ` Chen Yu
2026-08-13 15:19             ` Reinette Chatre
2026-08-18 16:02               ` Chen Yu
2026-08-18 17:10                 ` Reinette Chatre
2026-09-14  2:49         ` Chen Yu
2026-09-18 23:11           ` Reinette Chatre
2026-09-21  5:13             ` Chen, Yu C
2026-09-21 15:01               ` Reinette Chatre
2026-09-22  3:19                 ` Chen, Yu C
2026-09-21 16:21               ` Luck, Tony
2026-08-10  2:55 ` Fenghua Yu
2026-08-10  3:02   ` Chen, Yu C
2026-08-10  3:25     ` Fenghua Yu
2026-08-10  5:24       ` Chen, Yu C
2026-08-10 15:53   ` Reinette Chatre
2026-08-17 15:09     ` Reinette Chatre
2026-09-11 10:09     ` Ben Horgan
2026-09-18 22:47       ` Reinette Chatre
2026-09-21 10:22         ` Ben Horgan
2026-09-21 16:06           ` Reinette Chatre
2026-09-21 16:53             ` Ben Horgan
2026-09-23 15:28               ` Reinette Chatre
2026-09-24 14:38                 ` Ben Horgan
2026-09-21 13:56 ` [RFC PATCH 0/3] Suggestions for cache scalar controls Ben Horgan
2026-09-21 13:57   ` [RFC PATCH 1/3] fs/resctrl: Add schema_name to struct resctrl_ctrl Ben Horgan
2026-09-22 20:15     ` Drew Fustini
2026-09-23  9:05       ` Ben Horgan
2026-09-21 13:57   ` [RFC PATCH 2/3] fs/resctrl: Use correct schema name in bw_validate() last_cmd_status messages Ben Horgan
2026-09-21 13:57   ` Ben Horgan [this message]
2026-09-21 14:08   ` [RFC PATCH 0/3] Suggestions for cache scalar controls Ben Horgan
2026-09-22 20:26   ` Drew Fustini

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=20260921135702.2874931-4-ben.horgan@arm.com \
    --to=ben.horgan@arm.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghuay@nvidia.com \
    --cc=fustini@kernel.org \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peternewman@google.com \
    --cc=reinette.chatre@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=yu.c.chen@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®