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

Konstantin Khorenko khorenko at virtuozzo.com
Thu Jun 17 18:18:02 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.44
------>
commit ed3a9a14b6025ae8d238e6077043cbed8ef13bd5
Author: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
Date:   Thu Jun 17 18:18:02 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>
---
 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 43e793ffef8d..d1362ef72ebf 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;


More information about the Devel mailing list