From b195c30cf4f76667bcac28cf2c4ddd61475c2851 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 15 Nov 2005 17:28:05 +0100 Subject: [PATCH 1/3] This patch fixes a number of vcpu related issues. 1. xm vcpu-list now shows info for all vcpus by using info['max_vcpu_id']+1 as end of the range to query vcpu_info. 2. Add new vcpu fields, online_vcpus, max_vcpu_id to XendDomainInfo.sxpr() 3. Remove filter_cpump() which isn't needed now that the per vcpu cpumap field is correct. 4. Update xm/main.py to use online_vcpus as the number vcpus to display in list. Signed-off-by: Ryan Harper --- tools/python/xen/xend/XendDomainInfo.py | 13 ++++++------- tools/python/xen/xm/main.py | 14 +++++++------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 886d5c4f0f..c634cb8623 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -438,8 +438,10 @@ class XendDomainInfo: defaultInfo('cpu', lambda: None) defaultInfo('cpu_weight', lambda: 1.0) defaultInfo('vcpus', lambda: int(1)) + defaultInfo('online_vcpus', lambda: self.info['vcpus']) self.info['vcpus'] = int(self.info['vcpus']) + defaultInfo('max_vcpu_id', lambda: self.info['vcpus']-1) defaultInfo('vcpu_avail', lambda: (1 << self.info['vcpus']) - 1) @@ -927,6 +929,7 @@ class XendDomainInfo: if self.infoIsSet('cpu_time'): sxpr.append(['cpu_time', self.info['cpu_time']/1e9]) sxpr.append(['vcpus', self.info['vcpus']]) + sxpr.append(['online_vcpus', self.info['online_vcpus']]) if self.infoIsSet('start_time'): up_time = time.time() - self.info['start_time'] @@ -943,16 +946,13 @@ class XendDomainInfo: def getVCPUInfo(self): try: - def filter_cpumap(map, max): - return filter(lambda x: x >= 0, map[0:max]) - # We include the domain name and ID, to help xm. sxpr = ['domain', ['domid', self.domid], ['name', self.info['name']], - ['vcpu_count', self.info['vcpus']]] + ['vcpu_count', self.info['online_vcpus']]] - for i in range(0, self.info['vcpus']): + for i in range(0, self.info['max_vcpu_id']+1): info = xc.vcpu_getinfo(self.domid, i) sxpr.append(['vcpu', @@ -962,8 +962,7 @@ class XendDomainInfo: ['running', info['running']], ['cpu_time', info['cpu_time'] / 1e9], ['cpu', info['cpu']], - ['cpumap', filter_cpumap(info['cpumap'], - self.info['vcpus'])]]) + ['cpumap', info['cpumap']]]) return sxpr diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index ec4bf16d3a..fc0521fe3f 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -260,13 +260,13 @@ def parse_doms_info(info): return t(sxp.child_value(info, n, d)) return { - 'dom' : get_info('domid', int, -1), - 'name' : get_info('name', str, '??'), - 'mem' : get_info('memory', int, 0), - 'vcpus' : get_info('vcpus', int, 0), - 'state' : get_info('state', str, '??'), - 'cpu_time' : get_info('cpu_time', float, 0), - 'ssidref' : get_info('ssidref', int, 0), + 'dom' : get_info('domid', int, -1), + 'name' : get_info('name', str, '??'), + 'mem' : get_info('memory', int, 0), + 'vcpus' : get_info('online_vcpus', int, 0), + 'state' : get_info('state', str, '??'), + 'cpu_time' : get_info('cpu_time', float, 0), + 'ssidref' : get_info('ssidref', int, 0), } From 56be995b8a60ebe8a30e349674cc8abae5e1a559 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 15 Nov 2005 17:30:55 +0100 Subject: [PATCH 2/3] This patch fixes dom0 SMP vcpu hotplug. Currently, domains without config files (e.g. dom0) don't set info['vcpus'] correctly resulting in incorrect cpu availablity values in the store. This prevents hotplug from functioning. Signed-off-by: Ryan Harper --- tools/python/xen/xend/XendDomainInfo.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index c634cb8623..3b50fc9be6 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -437,12 +437,18 @@ class XendDomainInfo: defaultInfo('on_crash', lambda: "restart") defaultInfo('cpu', lambda: None) defaultInfo('cpu_weight', lambda: 1.0) - defaultInfo('vcpus', lambda: int(1)) + + # some domains don't have a config file (e.g. dom0 ) + # to set number of vcpus so we derive available cpus + # from max_vcpu_id which is present for running domains. + if not self.infoIsSet('vcpus') and self.infoIsSet('max_vcpu_id'): + avail = int(self.info['max_vcpu_id'])+1 + else: + avail = int(1) + + defaultInfo('vcpus', lambda: avail) defaultInfo('online_vcpus', lambda: self.info['vcpus']) - - self.info['vcpus'] = int(self.info['vcpus']) defaultInfo('max_vcpu_id', lambda: self.info['vcpus']-1) - defaultInfo('vcpu_avail', lambda: (1 << self.info['vcpus']) - 1) defaultInfo('memory', lambda: 0) From fcde973e26c585ade21bb16dd13df5205a4f0998 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Tue, 15 Nov 2005 18:43:28 +0100 Subject: [PATCH 3/3] Ensure we initialise the cpu_present_map before topology_init() is called. In latest Linux kernels it iterates over cpu_present_map rather than cpu_possible_map. Also, save/restore should really iterate over possible cpus, not present ones (not that it really matters, but it's a small cleanup). Signed-off-by: Keir Fraser --- linux-2.6-xen-sparse/arch/xen/kernel/reboot.c | 2 +- linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c index 89c2005450..81f0f10c21 100644 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c @@ -188,7 +188,7 @@ static int __do_suspend(void *ignore) xenbus_resume(); #ifdef CONFIG_SMP - for_each_present_cpu(i) + for_each_cpu(i) vcpu_prepare(i); out_reenable_cpus: diff --git a/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c b/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c index 31ea6473f1..66bb891ec6 100644 --- a/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c +++ b/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c @@ -277,6 +277,18 @@ void __devinit smp_prepare_boot_cpu(void) #ifdef CONFIG_HOTPLUG_CPU +/* + * Initialize cpu_present_map late to skip SMP boot code in init/main.c. + * But do it early enough to catch critical for_each_present_cpu() loops + * in i386-specific code. + */ +static int __init initialize_cpu_present_map(void) +{ + cpu_present_map = cpu_possible_map; + return 0; +} +core_initcall(initialize_cpu_present_map); + static void vcpu_hotplug(unsigned int cpu) { int err; @@ -293,7 +305,6 @@ static void vcpu_hotplug(unsigned int cpu) } if (strcmp(state, "online") == 0) { - cpu_set(cpu, cpu_present_map); (void)cpu_up(cpu); } else if (strcmp(state, "offline") == 0) { (void)cpu_down(cpu);