From patchwork Tue Jun 17 09:02:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihai Caraman X-Patchwork-Id: 360399 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 28812140098 for ; Tue, 17 Jun 2014 19:03:12 +1000 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 0D1841A02E7 for ; Tue, 17 Jun 2014 19:03:12 +1000 (EST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from na01-bn1-obe.outbound.protection.outlook.com (dns-bn1lp0143.outbound.protection.outlook.com [207.46.163.143]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id AFC001A02B4 for ; Tue, 17 Jun 2014 19:02:34 +1000 (EST) Received: from BY2PR03CA030.namprd03.prod.outlook.com (10.242.234.151) by BY2PR03MB507.namprd03.prod.outlook.com (10.141.143.21) with Microsoft SMTP Server (TLS) id 15.0.954.9; Tue, 17 Jun 2014 09:02:25 +0000 Received: from BY2FFO11FD006.protection.gbl (2a01:111:f400:7c0c::104) by BY2PR03CA030.outlook.office365.com (2a01:111:e400:2c2c::23) with Microsoft SMTP Server (TLS) id 15.0.959.24 via Frontend Transport; Tue, 17 Jun 2014 09:02:24 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD006.mail.protection.outlook.com (10.1.14.127) with Microsoft SMTP Server (TLS) id 15.0.959.15 via Frontend Transport; Tue, 17 Jun 2014 09:02:24 +0000 Received: from fsr-fed1764-012.ea.freescale.net (fsr-fed1764-012-010171073213.ea.freescale.net [10.171.73.213]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s5H92M4U023057; Tue, 17 Jun 2014 02:02:22 -0700 From: Mihai Caraman To: Subject: [PATCH v2] KVM: PPC: e500mc: Enhance tlb invalidation condition on vcpu schedule Date: Tue, 17 Jun 2014 12:02:19 +0300 Message-ID: <1402995739-23756-1-git-send-email-mihai.caraman@freescale.com> X-Mailer: git-send-email 1.7.11.7 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(6009001)(199002)(189002)(89996001)(46102001)(76482001)(50986999)(26826002)(79102001)(19580395003)(88136002)(62966002)(81342001)(85852003)(81542001)(68736004)(83072002)(77156001)(74662001)(93916002)(47776003)(104016002)(95666004)(104166001)(21056001)(64706001)(92726001)(44976005)(20776003)(84676001)(87286001)(33646001)(92566001)(86362001)(74502001)(31966008)(83322001)(97736001)(77982001)(48376002)(4396001)(80022001)(6806004)(102836001)(50466002)(36756003)(50226001)(81156003)(85306003)(87936001)(19580405001)(69596002)(99396002); DIR:OUT; SFP:; SCL:1; SRVR:BY2PR03MB507; H:az84smr01.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: BL:0; ACTION:Default; RISK:Low; SCL:0; SPMLVL:NotSpam; PCL:0; RULEID: X-Forefront-PRVS: 0245702D7B Received-SPF: Fail (: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=mihai.caraman@freescale.com; X-OriginatorOrg: freescale.com Cc: Scott Wood , Mihai Caraman , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" On vcpu schedule, the condition checked for tlb pollution is too loose. The tlb entries of a vcpu become polluted (vs stale) only when a different vcpu within the same logical partition runs in-between. Optimize the tlb invalidation condition taking into account the logical partition id. With the new invalidation condition, a guest shows 4% performance improvement on P5020DS while running a memory stress application with the cpu oversubscribed, the other guest running a cpu intensive workload. Guest - old invalidation condition real 3.89 user 3.87 sys 0.01 Guest - enhanced invalidation condition real 3.75 user 3.73 sys 0.01 Host real 3.70 user 1.85 sys 0.00 The memory stress application accesses 4KB pages backed by 75% of available TLB0 entries: char foo[ENTRIES][4096] __attribute__ ((aligned (4096))); int main() { char bar; int i, j; for (i = 0; i < ITERATIONS; i++) for (j = 0; j < ENTRIES; j++) bar = foo[j][0]; return 0; } Signed-off-by: Mihai Caraman Cc: Scott Wood --- v2: - improve patch name and description - add performance results arch/powerpc/kvm/e500mc.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c index 17e4562..d3b814b0 100644 --- a/arch/powerpc/kvm/e500mc.c +++ b/arch/powerpc/kvm/e500mc.c @@ -111,10 +111,12 @@ void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr) } static DEFINE_PER_CPU(struct kvm_vcpu *, last_vcpu_on_cpu); +static DEFINE_PER_CPU(int, last_lpid_on_cpu); static void kvmppc_core_vcpu_load_e500mc(struct kvm_vcpu *vcpu, int cpu) { struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); + bool update_last = false, inval_tlb = false; kvmppc_booke_vcpu_load(vcpu, cpu); @@ -140,12 +142,24 @@ static void kvmppc_core_vcpu_load_e500mc(struct kvm_vcpu *vcpu, int cpu) mtspr(SPRN_GDEAR, vcpu->arch.shared->dar); mtspr(SPRN_GESR, vcpu->arch.shared->esr); - if (vcpu->arch.oldpir != mfspr(SPRN_PIR) || - __get_cpu_var(last_vcpu_on_cpu) != vcpu) { - kvmppc_e500_tlbil_all(vcpu_e500); + if (vcpu->arch.oldpir != mfspr(SPRN_PIR)) { + /* stale tlb entries */ + inval_tlb = update_last = true; + } else if (__get_cpu_var(last_vcpu_on_cpu) != vcpu) { + update_last = true; + /* polluted tlb entries */ + inval_tlb = __get_cpu_var(last_lpid_on_cpu) == + vcpu->kvm->arch.lpid; + } + + if (update_last) { __get_cpu_var(last_vcpu_on_cpu) = vcpu; + __get_cpu_var(last_lpid_on_cpu) = vcpu->kvm->arch.lpid; } + if (inval_tlb) + kvmppc_e500_tlbil_all(vcpu_e500); + kvmppc_load_guest_fp(vcpu); }