# HG changeset patch # User Keir Fraser # Date 1204118269 0 # Node ID b58180cf8ab8c69def4129f7152f136daf5e1596 # Parent 2b940e46857c0ddf5ef1e255e201a42caf310df6 xend: Set default vcpu affinity for better performance in NUMA systems. Signed-off-by: Duan Ronghui Index: xen-3.2.1-testing/tools/python/xen/xend/XendDomainInfo.py =================================================================== --- xen-3.2.1-testing.orig/tools/python/xen/xend/XendDomainInfo.py +++ xen-3.2.1-testing/tools/python/xen/xend/XendDomainInfo.py @@ -1754,6 +1754,39 @@ class XendDomainInfo: if self.info['cpus'] is not None and len(self.info['cpus']) > 0: for v in range(0, self.info['VCPUs_max']): xc.vcpu_setaffinity(self.domid, v, self.info['cpus']) + else: + info = xc.physinfo() + if info['nr_nodes'] > 1: + node_memory_list = info['node_to_memory'] + needmem = self.image.getRequiredAvailableMemory(self.info['memory_dynamic_max']) / 1024 + candidate_node_list = [] + for i in range(0, info['nr_nodes']): + if node_memory_list[i] >= needmem: + candidate_node_list.append(i) + if candidate_node_list is None or len(candidate_node_list) == 1: + index = node_memory_list.index( max(node_memory_list) ) + cpumask = info['node_to_cpu'][index] + else: + nodeload = [0] + nodeload = nodeload * info['nr_nodes'] + from xen.xend import XendDomain + doms = XendDomain.instance().list('all') + for dom in doms: + cpuinfo = dom.getVCPUInfo() + for vcpu in sxp.children(cpuinfo, 'vcpu'): + def vinfo(n, t): + return t(sxp.child_value(vcpu, n)) + cpumap = vinfo('cpumap', list) + for i in candidate_node_list: + node_cpumask = info['node_to_cpu'][i] + for j in node_cpumask: + if j in cpumap: + nodeload[i] += 1 + break + index = nodeload.index( min(nodeload) ) + cpumask = info['node_to_cpu'][index] + for v in range(0, self.info['VCPUs_max']): + xc.vcpu_setaffinity(self.domid, v, cpumask) # Use architecture- and image-specific calculations to determine # the various headrooms necessary, given the raw configured