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

Konstantin Khorenko khorenko at virtuozzo.com
Thu Oct 3 14:19:40 MSK 2019


The commit is pushed to "branch-rh7-3.10.0-957.27.2.vz7.107.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.27.2.vz7.107.13
------>
commit 4799dc5604a24468737964f7c180228ddd438e2f
Author: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
Date:   Thu Oct 3 14:19:38 2019 +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.
---
 drivers/base/cpu.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 3aa0bee19466..f59eb23c5be2 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -183,7 +183,22 @@ static ssize_t show_cpus_attr(struct device *dev,
 			      char *buf)
 {
 	struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr);
-	int n = cpulist_scnprintf(buf, PAGE_SIZE-2, *(ca->map));
+	const struct cpumask *maskp;
+	struct cpumask mask;
+	int n;
+
+	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;
+
+
+	n = cpulist_scnprintf(buf, PAGE_SIZE-2, maskp);
 
 	buf[n++] = '\n';
 	buf[n] = '\0';
@@ -220,6 +235,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