[Devel] [PATCH RH8 3/4] ve/cpu: handle sysfs attributes for CTs

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Wed Jun 16 17:42:34 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 commit 11a5446266aa63e43e53be9a6ebbf0a81b944d65)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 43e793f..d1362ef 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -211,8 +211,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) \
@@ -245,6 +257,9 @@ static ssize_t print_cpus_offline(struct device *dev,
 	int n = 0, len = PAGE_SIZE-2;
 	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