[Devel] [PATCH RH9 20/28] ve/cpu: handle sysfs attributes for CTs

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Oct 14 13:33:28 MSK 2021


From: Jan Dakinevich <jan.dakinevich at virtuozzo.com>

Add support for 'offline', 'online', 'possible' and 'present' attributes
under '/sys/devices/system/cpu' for CTs. All allowed CPUs are assumed
as posible and online, list of offline CPUs is empty.

This allows lscpu utility to correctly show an amount of CPUs in its
output, however topology information is still not provided.

https://jira.sw.ru/browse/PSBM-91808
Signed-off-by: Jan Dakinevich <jan.dakinevich at virtuozzo.com>

Acked-by: Konstantin Khorenko <khorenko at virtuozzo.com>

khorenko@: userspace patches are required for this feature as well:
1) to show /sys/devices/system/cpu/{online,possible,present,offline}
   entries inside Container
2) to show only limited number of /sys/devices/system/cpu/cpuX directories
   inside Containers depending on $CPUS CT settings.

(cherry picked from vz7 commit 11a5446266aa ("ve/cpu: handle sysfs attributes
for CTs"))

Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>

(cherry picked from vz8 commit 6e145f86fdedf28d7bc14706fe56b946f8f83d61)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/base/cpu.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 5ef14db..bbf7c6e 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -208,8 +208,20 @@ static ssize_t show_cpus_attr(struct device *dev,
 			      char *buf)
 {
 	struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr);
+	const struct cpumask *maskp;
+	struct cpumask mask;
 
-	return cpumap_print_to_pagebuf(true, buf, ca->map);
+	if (!ve_is_super(get_exec_env())) {
+		unsigned num = num_online_vcpus();
+
+		cpumask_clear(&mask);
+		while (num--)
+			cpumask_set_cpu(num, &mask);
+		maskp = &mask;
+	} else
+		maskp = ca->map;
+
+	return cpumap_print_to_pagebuf(true, buf, maskp);
 }
 
 #define _CPU_ATTR(name, map) \
@@ -241,6 +253,9 @@ static ssize_t print_cpus_offline(struct device *dev,
 	int len = 0;
 	cpumask_var_t offline;
 
+	if (!ve_is_super(get_exec_env()))
+		return snprintf(buf, len, "\n");
+
 	/* display offline cpus < nr_cpu_ids */
 	if (!alloc_cpumask_var(&offline, GFP_KERNEL))
 		return -ENOMEM;
-- 
1.8.3.1



More information about the Devel mailing list