[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240123092024.1271882-1-haifeng.xu@shopee.com>
Date: Tue, 23 Jan 2024 09:20:22 +0000
From: Haifeng Xu <haifeng.xu@...pee.com>
To: reinette.chatre@...el.com
Cc: fenghua.yu@...el.com,
babu.moger@....com,
peternewman@...gle.com,
x86@...nel.org,
linux-kernel@...r.kernel.org,
Haifeng Xu <haifeng.xu@...pee.com>
Subject: [PATCH 1/3] x86/resctrl: Display the number of available CLOSIDs
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@...pee.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
Powered by blists - more mailing lists