mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/3] x86/resctrl: Display the number of available CLOSIDs
@ 2024-01-23  9:20 Haifeng Xu
  2024-01-24 22:23 ` Reinette Chatre
  0 siblings, 1 reply; 4+ messages in thread
From: Haifeng Xu @ 2024-01-23  9:20 UTC (permalink / raw)
  To: reinette.chatre
  Cc: fenghua.yu, babu.moger, peternewman, x86, linux-kernel, Haifeng Xu

We can know the number of CLOSIDs for each rdt resource, for example:

cat /sys/fs/resctrl/info/L3/num_closids
cat /sys/fs/resctrl/info/MB/num_closids
...

The number of available CLOSIDs is the minimal value of them. When users
try to create new control groups, to avoid running out of CLOSIDs, they
have to traverse /sys/fs/resctrl/ and count the number of directories.

To make things more easier, add a RFTYPE_TOP_INFO file 'free_closids'
that tells users how many free closids are left.

Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 69a1de92384a..577d870ac45f 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -113,6 +113,7 @@ void rdt_staged_configs_clear(void)
  */
 static int closid_free_map;
 static int closid_free_map_len;
+static int free_closids;
 
 int closids_supported(void)
 {
@@ -133,6 +134,7 @@ static void closid_init(void)
 	/* CLOSID 0 is always reserved for the default group */
 	closid_free_map &= ~1;
 	closid_free_map_len = rdt_min_closid;
+	free_closids = rdt_min_closid - 1;
 }
 
 static int closid_alloc(void)
@@ -143,6 +145,7 @@ static int closid_alloc(void)
 		return -ENOSPC;
 	closid--;
 	closid_free_map &= ~(1 << closid);
+	free_closids--;
 
 	return closid;
 }
@@ -150,6 +153,7 @@ static int closid_alloc(void)
 void closid_free(int closid)
 {
 	closid_free_map |= 1 << closid;
+	free_closids++;
 }
 
 /**
@@ -912,6 +916,15 @@ static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static int rdt_free_closids_show(struct kernfs_open_file *of,
+				 struct seq_file *seq, void *v)
+{
+	mutex_lock(&rdtgroup_mutex);
+	seq_printf(seq, "%d\n", free_closids);
+	mutex_unlock(&rdtgroup_mutex);
+	return 0;
+}
+
 static int rdt_num_closids_show(struct kernfs_open_file *of,
 				struct seq_file *seq, void *v)
 {
@@ -1755,6 +1768,13 @@ static struct rftype res_common_files[] = {
 		.seq_show	= rdt_last_cmd_status_show,
 		.fflags		= RFTYPE_TOP_INFO,
 	},
+	{
+		.name           = "free_closids",
+		.mode           = 0444,
+		.kf_ops         = &rdtgroup_kf_single_ops,
+		.seq_show       = rdt_free_closids_show,
+		.fflags         = RFTYPE_TOP_INFO,
+	},
 	{
 		.name		= "num_closids",
 		.mode		= 0444,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-25 16:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-23  9:20 [PATCH 1/3] x86/resctrl: Display the number of available CLOSIDs Haifeng Xu
2024-01-24 22:23 ` Reinette Chatre
2024-01-25  7:44   ` Haifeng Xu
2024-01-25 16:57     ` Reinette Chatre

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®