[Devel] [PATCH RHEL9 COMMIT] ve/cpu: handle sysfs attributes for CTs

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 20 11:40:45 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.12
------>
commit 543311688c66028f43ba97e6c928297364fdcb38
Author: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
Date:   Wed Oct 20 11:40:45 2021 +0300

    ve/cpu: handle sysfs attributes for CTs
    
    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 5ef14db97904..bbf7c6e4febc 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;


More information about the Devel mailing list