Add human readable nodes for cpus_assigned and cpus_failed and let jailhouse-cell-list use those nodes.
Signed-off-by: Ralf Ramsauer <[email protected]> --- driver/sysfs.c | 22 ++++++++++++++++++++++ tools/jailhouse-cell-list | 41 +++++------------------------------------ 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/driver/sysfs.c b/driver/sysfs.c index b6bf545..ce4dba7 100644 --- a/driver/sysfs.c +++ b/driver/sysfs.c @@ -218,6 +218,14 @@ static ssize_t cpus_assigned_show(struct kobject *kobj, return print_cpumask(buf, PAGE_SIZE, &cell->cpus_assigned, false); } +static ssize_t cpus_assigned_list_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct cell *cell = container_of(kobj, struct cell, kobj); + + return print_cpumask(buf, PAGE_SIZE, &cell->cpus_assigned, true); +} + static ssize_t cpus_failed_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -226,17 +234,31 @@ static ssize_t cpus_failed_show(struct kobject *kobj, return print_failed_cpus(buf, PAGE_SIZE, cell, false); } +static ssize_t cpus_failed_list_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct cell *cell = container_of(kobj, struct cell, kobj); + + return print_failed_cpus(buf, PAGE_SIZE, cell, true); +} + static struct kobj_attribute cell_name_attr = __ATTR_RO(name); static struct kobj_attribute cell_state_attr = __ATTR_RO(state); static struct kobj_attribute cell_cpus_assigned_attr = __ATTR_RO(cpus_assigned); +static struct kobj_attribute cell_cpus_assigned_list_attr = + __ATTR_RO(cpus_assigned_list); static struct kobj_attribute cell_cpus_failed_attr = __ATTR_RO(cpus_failed); +static struct kobj_attribute cell_cpus_failed_list_attr = + __ATTR_RO(cpus_failed_list); static struct attribute *cell_attrs[] = { &cell_name_attr.attr, &cell_state_attr.attr, &cell_cpus_assigned_attr.attr, + &cell_cpus_assigned_list_attr.attr, &cell_cpus_failed_attr.attr, + &cell_cpus_failed_list_attr.attr, NULL, }; diff --git a/tools/jailhouse-cell-list b/tools/jailhouse-cell-list index d4123f6..d5a535b 100755 --- a/tools/jailhouse-cell-list +++ b/tools/jailhouse-cell-list @@ -15,38 +15,6 @@ import os import sys -def read_cpus(path): - return int(open(path).readline().strip().replace(",", ""), 16) - - -def finish_cpu_list(last_cpu, cpu): - if last_cpu is not None: - if cpu-last_cpu > 1: - return "%s%d," % ("-" if cpu-last_cpu > 2 else ",", cpu-1) - else: - return "," - else: - return "" - - -def print_cpus(mask): - last_cpu = None - cpu = 0 - output = "" - while mask > 0: - if mask & 1: - if last_cpu is None: - last_cpu = cpu - output += str(cpu) - else: - output += finish_cpu_list(last_cpu, cpu) - last_cpu = None - mask >>= 1 - cpu += 1 - output += finish_cpu_list(last_cpu, cpu) - return output.strip(",") - - if len(sys.argv) > 1: print("usage: %s" % os.path.basename(sys.argv[0]).replace("-", " ")) exit(0 if sys.argv[1] in ("--help", "-h") else 1) @@ -57,8 +25,10 @@ for cell_path in glob.glob('/sys/devices/jailhouse/cells/*'): 'id': os.path.basename(cell_path), 'name': open(cell_path + "/name").readline().strip(), 'state': open(cell_path + "/state").readline().strip(), - 'cpus_assigned': read_cpus(cell_path + "/cpus_assigned"), - 'cpus_failed': read_cpus(cell_path + "/cpus_failed") + 'cpus_assigned_list': + open(cell_path + "/cpus_assigned_list").readline().strip(), + 'cpus_failed_list': + open(cell_path + "/cpus_failed_list").readline().strip() }) line_format = "%-8s%-24s%-16s%-24s%-24s" @@ -67,5 +37,4 @@ if not cells == []: "Assigned CPUs", "Failed CPUs")) for cell in sorted(cells, key=lambda cell: cell['id']): print(line_format % (cell['id'], cell['name'], cell['state'], - print_cpus(cell['cpus_assigned']), - print_cpus(cell['cpus_failed']))) + cell['cpus_assigned_list'], cell['cpus_failed_list'])) -- 2.9.3 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
