From nobody Sat May 4 21:28:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563801853; cv=none; d=zoho.com; s=zohoarc; b=gt7mZXWzhCjEjFzyCv6aPSowrb8iBymqaNTRP8jrmSx1hJmRKFizDuWJPGO4C+OM8XLYeMKkdAqSNj7t2OZB7rxd30iwZG5/vMQzSNRD12ZOmndur5Vjn2s/tfH/wV6oK9hC+7fHPInpYWeu0CpIbYbqX7kbwIMjNisx8PeZ9Kc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563801853; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=CkzGl7ZDKK3AJ6QMCUJ2HEOcs81+FoguBYtKBMJ541A=; b=IlfMTMEmxLf8atEWqJRylQ3sBZsxZp4AaVJ414DPMmoiYs5T7qx4hwUmV8G/suvzt1D5o5IwTf2gvb8SvrHEfEhK4WNDrCpgXWV83QYlL4so0iCwytrNsiOWSbATNbOrhtJlnS7Hvi0XQ/AsEeoDDNKXBMZ+HiWK2bxZ21OFM/o= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563801852943675.8145276007233; Mon, 22 Jul 2019 06:24:12 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hpYHC-00086v-BG; Mon, 22 Jul 2019 13:22:50 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hpYHB-00086q-8Q for xen-devel@lists.xenproject.org; Mon, 22 Jul 2019 13:22:49 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id cb7c9b06-ac83-11e9-8980-bc764e045a96; Mon, 22 Jul 2019 13:22:47 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 317B7B123; Mon, 22 Jul 2019 13:22:46 +0000 (UTC) X-Inumbo-ID: cb7c9b06-ac83-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 22 Jul 2019 15:22:44 +0200 Message-Id: <20190722132244.893-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Subject: [Xen-devel] [PATCH] x86: optimize loading of GDT at context switch X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 Reviewed-by: Jan Beulich --- This patch was originally part of my core scheduling series, but it neither depends on any patch of that series, nor does any patch of the series depend on this one, so I'm sending it on its own. I have removed latching the need_full_gdt(nd) value in a local variable as it has shown to impact performance very slightly in a bad way. --- xen/arch/x86/cpu/common.c | 3 +++ xen/arch/x86/domain.c | 14 ++++++++------ xen/include/asm-x86/desc.h | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 1db96d959c..b0bb9292fd 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -49,6 +49,8 @@ unsigned int vaddr_bits __read_mostly =3D VADDR_BITS; static unsigned int cleared_caps[NCAPINTS]; static unsigned int forced_caps[NCAPINTS]; =20 +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); =20 + per_cpu(full_gdt_loaded, cpu) =3D false; lgdt(&gdtr); lidt(&idtr); ltr(TSS_ENTRY << 3); diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index ea55160887..353a6e24fb 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -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)); } =20 -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 =3D { .limit =3D LAST_RESERVED_GDT_BYTE, @@ -1678,6 +1678,8 @@ static void load_full_gdt(const struct vcpu *v) }; =20 lgdt(&gdt_desc); + + per_cpu(full_gdt_loaded, cpu) =3D true; } =20 static void load_default_gdt(unsigned int cpu) @@ -1689,6 +1691,8 @@ static void load_default_gdt(unsigned int cpu) }; =20 lgdt(&gdt_desc); + + per_cpu(full_gdt_loaded, cpu) =3D false; } =20 static void __context_switch(void) @@ -1739,8 +1743,7 @@ static void __context_switch(void) =20 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 !=3D n->vcpu_id) || !need_full_gdt(nd)) ) load_default_gdt(cpu); =20 @@ -1753,9 +1756,8 @@ static void __context_switch(void) svm_load_segs(0, 0, 0, 0, 0, 0, 0); #endif =20 - if ( need_full_gdt(nd) && - ((p->vcpu_id !=3D 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); =20 if ( pd !=3D nd ) cpumask_clear_cpu(cpu, pd->dirty_cpumask); diff --git a/xen/include/asm-x86/desc.h b/xen/include/asm-x86/desc.h index e565727dc0..c011c03ae2 100644 --- a/xen/include/asm-x86/desc.h +++ b/xen/include/asm-x86/desc.h @@ -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); =20 extern void load_TR(void); =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel