]> xenbits.xensource.com Git - people/dwmw2/xen.git/commitdiff
x86: optimize loading of GDT at context switch
authorJuergen Gross <jgross@suse.com>
Fri, 26 Jul 2019 08:43:42 +0000 (10:43 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 26 Jul 2019 08:43:42 +0000 (10:43 +0200)
Instead of dynamically decide whether the previous vcpu was using full
or default GDT just add a percpu variable for that purpose. This at
once removes the need for testing vcpu_ids to differ twice.

This change improves performance by 0.5% - 1% on my test machine when
doing parallel compilation.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/common.c
xen/arch/x86/domain.c
xen/include/asm-x86/desc.h

index 1db96d959c7aba901c2f3ae6fd093d85ce58e38c..7478e21177bdf22ac4954d90d9fb41336fe0c258 100644 (file)
@@ -49,6 +49,8 @@ unsigned int vaddr_bits __read_mostly = VADDR_BITS;
 static unsigned int cleared_caps[NCAPINTS];
 static unsigned int forced_caps[NCAPINTS];
 
+DEFINE_PER_CPU(bool, full_gdt_loaded);
+
 void __init setup_clear_cpu_cap(unsigned int cap)
 {
        const uint32_t *dfs;
@@ -756,6 +758,7 @@ void load_system_tables(void)
                offsetof(struct tss_struct, __cacheline_filler) - 1,
                SYS_DESC_tss_busy);
 
+       per_cpu(full_gdt_loaded, cpu) = false;
        lgdt(&gdtr);
        lidt(&idtr);
        ltr(TSS_ENTRY << 3);
index ea551608877b98faa41965d51e3eb0a85da238e7..5933b3f51b007ac2188c327481f0e083e6409ea1 100644 (file)
@@ -1670,7 +1670,7 @@ static void update_xen_slot_in_full_gdt(const struct vcpu *v, unsigned int cpu)
                                    : per_cpu(compat_gdt_table_l1e, cpu));
 }
 
-static void load_full_gdt(const struct vcpu *v)
+static void load_full_gdt(const struct vcpu *v, unsigned int cpu)
 {
     struct desc_ptr gdt_desc = {
         .limit = LAST_RESERVED_GDT_BYTE,
@@ -1678,6 +1678,8 @@ static void load_full_gdt(const struct vcpu *v)
     };
 
     lgdt(&gdt_desc);
+
+    per_cpu(full_gdt_loaded, cpu) = true;
 }
 
 static void load_default_gdt(unsigned int cpu)
@@ -1689,6 +1691,8 @@ static void load_default_gdt(unsigned int cpu)
     };
 
     lgdt(&gdt_desc);
+
+    per_cpu(full_gdt_loaded, cpu) = false;
 }
 
 static void __context_switch(void)
@@ -1740,7 +1744,7 @@ static void __context_switch(void)
     if ( need_full_gdt(nd) )
         update_xen_slot_in_full_gdt(n, cpu);
 
-    if ( need_full_gdt(pd) &&
+    if ( per_cpu(full_gdt_loaded, cpu) &&
          ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(nd)) )
         load_default_gdt(cpu);
 
@@ -1753,9 +1757,8 @@ static void __context_switch(void)
         svm_load_segs(0, 0, 0, 0, 0, 0, 0);
 #endif
 
-    if ( need_full_gdt(nd) &&
-         ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(pd)) )
-        load_full_gdt(n);
+    if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
+        load_full_gdt(n, cpu);
 
     if ( pd != nd )
         cpumask_clear_cpu(cpu, pd->dirty_cpumask);
index e565727dc09ccf14580d6e0aa0053ff509748087..c011c03ae2fb7cf8b68372ede9b29f03e326b0a1 100644 (file)
@@ -210,6 +210,7 @@ DECLARE_PER_CPU(l1_pgentry_t, gdt_table_l1e);
 extern seg_desc_t boot_cpu_compat_gdt_table[];
 DECLARE_PER_CPU(seg_desc_t *, compat_gdt_table);
 DECLARE_PER_CPU(l1_pgentry_t, compat_gdt_table_l1e);
+DECLARE_PER_CPU(bool, full_gdt_loaded);
 
 extern void load_TR(void);