xen/sched: Re-position the domain_update_node_affinity() call during vcpu construction
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 6 Sep 2018 13:40:56 +0000 (14:40 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 11 Sep 2018 16:34:35 +0000 (17:34 +0100)
alloc_vcpu()'s call to domain_update_node_affinity() has existed for a decade,
but its effort is mostly wasted.

alloc_vcpu() is called in a loop for each vcpu, bringing them into existence.
The values of the affinity masks are still default, which is allcpus in
general, or a processor singleton for pinned domains.

Furthermore, domain_update_node_affinity() itself loops over all vcpus
accumulating the masks, making it quadratic with the number of vcpus.

Move it to be called once after all vcpus are constructed, which has the same
net effect, but with fewer intermediate memory allocations and less cpumask
arithmetic.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Dario Faggioli <dfaggioli@suse.com>
xen/arch/arm/domain_build.c
xen/arch/x86/hvm/dom0_build.c
xen/arch/x86/pv/dom0_build.c
xen/common/domain.c
xen/common/domctl.c

index d4dabc7beace2b45ffc38dabe42e278c8a8a4034..af941e19824cab0444b5f70b05582168a085f306 100644 (file)
@@ -2242,6 +2242,8 @@ int __init construct_dom0(struct domain *d)
             vcpu_switch_to_aarch64_mode(d->vcpu[i]);
     }
 
+    domain_update_node_affinity(d);
+
     v->is_initialised = 1;
     clear_bit(_VPF_down, &v->pause_flags);
 
index 90f70ec60aca2252c73179202321532d328345c5..5724883d8c705a3bf556065f617d20dad3b521bd 100644 (file)
@@ -600,6 +600,8 @@ static int __init pvh_setup_cpus(struct domain *d, paddr_t entry,
             cpu = p->processor;
     }
 
+    domain_update_node_affinity(d);
+
     rc = arch_set_info_hvm_guest(v, &cpu_ctx);
     if ( rc )
     {
index 976ba8d16b61ed2b0ef4f8cd77a62441cd95689f..21d262b62bfb88488f726f246a0e4dc263a2e390 100644 (file)
@@ -709,6 +709,7 @@ int __init dom0_construct_pv(struct domain *d,
             cpu = p->processor;
     }
 
+    domain_update_node_affinity(d);
     d->arch.paging.mode = 0;
 
     /* Set up CR3 value for write_ptbase */
index 9a541971dd8dbe5619dfeed724ca37c12c1557a4..a043812687a32e4cd56d02e52c476ff3d548fba1 100644 (file)
@@ -193,9 +193,6 @@ struct vcpu *alloc_vcpu(
     /* Must be called after making new vcpu visible to for_each_vcpu(). */
     vcpu_check_shutdown(v);
 
-    if ( !is_idle_domain(d) )
-        domain_update_node_affinity(d);
-
     return v;
 }
 
index ed047b7cd7093476914a5759d217e71dadb8567e..3df41ad833c48753d6a2e79547e1baa1b4e8b8fa 100644 (file)
@@ -575,6 +575,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
                 goto maxvcpu_out;
         }
 
+        domain_update_node_affinity(d);
         ret = 0;
 
     maxvcpu_out: