linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] KVM: PPC: e500mc: Enhance tlb invalidation condition on vcpu schedule
@ 2014-06-17  9:02 Mihai Caraman
  2014-06-17 15:35 ` Scott Wood
  0 siblings, 1 reply; 4+ messages in thread
From: Mihai Caraman @ 2014-06-17  9:02 UTC (permalink / raw)
  To: kvm-ppc; +Cc: Scott Wood, Mihai Caraman, linuxppc-dev, kvm

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 <mihai.caraman@freescale.com>
Cc: Scott Wood <scottwood@freescale.com>
---
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);
 }
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] KVM: PPC: e500mc: Enhance tlb invalidation condition on vcpu schedule
  2014-06-17  9:02 [PATCH v2] KVM: PPC: e500mc: Enhance tlb invalidation condition on vcpu schedule Mihai Caraman
@ 2014-06-17 15:35 ` Scott Wood
  2014-06-17 19:04   ` mihai.caraman
  0 siblings, 1 reply; 4+ messages in thread
From: Scott Wood @ 2014-06-17 15:35 UTC (permalink / raw)
  To: Mihai Caraman; +Cc: linuxppc-dev, kvm, kvm-ppc

On Tue, 2014-06-17 at 12:02 +0300, Mihai Caraman wrote:
> 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.

See
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118547.html

-Scott

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v2] KVM: PPC: e500mc: Enhance tlb invalidation condition on vcpu schedule
  2014-06-17 15:35 ` Scott Wood
@ 2014-06-17 19:04   ` mihai.caraman
  2014-06-17 19:05     ` Scott Wood
  0 siblings, 1 reply; 4+ messages in thread
From: mihai.caraman @ 2014-06-17 19:04 UTC (permalink / raw)
  To: Scott Wood
  Cc: linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org,
	kvm-ppc@vger.kernel.org

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBXb29kIFNjb3R0LUIwNzQyMQ0K
PiBTZW50OiBUdWVzZGF5LCBKdW5lIDE3LCAyMDE0IDY6MzYgUE0NCj4gVG86IENhcmFtYW4gTWlo
YWkgQ2xhdWRpdS1CMDIwMDgNCj4gQ2M6IGt2bS1wcGNAdmdlci5rZXJuZWwub3JnOyBrdm1Admdl
ci5rZXJuZWwub3JnOyBsaW51eHBwYy0NCj4gZGV2QGxpc3RzLm96bGFicy5vcmcNCj4gU3ViamVj
dDogUmU6IFtQQVRDSCB2Ml0gS1ZNOiBQUEM6IGU1MDBtYzogRW5oYW5jZSB0bGIgaW52YWxpZGF0
aW9uDQo+IGNvbmRpdGlvbiBvbiB2Y3B1IHNjaGVkdWxlDQo+IA0KPiBPbiBUdWUsIDIwMTQtMDYt
MTcgYXQgMTI6MDIgKzAzMDAsIE1paGFpIENhcmFtYW4gd3JvdGU6DQo+ID4gT24gdmNwdSBzY2hl
ZHVsZSwgdGhl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condition on vcpu schedule
  2014-06-17 19:04   ` mihai.caraman
@ 2014-06-17 19:05     ` Scott Wood
  0 siblings, 0 replies; 4+ messages in thread
From: Scott Wood @ 2014-06-17 19:05 UTC (permalink / raw)
  To: Caraman Mihai Claudiu-B02008
  Cc: linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org,
	kvm-ppc@vger.kernel.org

On Tue, 2014-06-17 at 14:04 -0500, Caraman Mihai Claudiu-B02008 wrote:
> > -----Original Message-----
> > From: Wood Scott-B07421
> > Sent: Tuesday, June 17, 2014 6:36 PM
> > To: Caraman Mihai Claudiu-B02008
> > Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; linuxppc-
> > dev@lists.ozlabs.org
> > Subject: Re: [PATCH v2] KVM: PPC: e500mc: Enhance tlb invalidation
> > condition on vcpu schedule
> > 
> > On Tue, 2014-06-17 at 12:02 +0300, Mihai Caraman wrote:
> > > 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.
> > 
> > See
> > https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118547.html
> 
> Thanks. The original code needs just a simple adjustment to benefit from
> this optimization, please review v3.

Where is v3?  Or is it forthcoming?

-Scott

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-17 19:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17  9:02 [PATCH v2] KVM: PPC: e500mc: Enhance tlb invalidation condition on vcpu schedule Mihai Caraman
2014-06-17 15:35 ` Scott Wood
2014-06-17 19:04   ` mihai.caraman
2014-06-17 19:05     ` Scott Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).