All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] kvmppc: optimize kvm stat handling
@ 2008-10-10 10:59 ehrhardt
  2008-10-10 18:12 ` Hollis Blanchard
  2008-10-13 12:07 ` ehrhardt
  0 siblings, 2 replies; 3+ messages in thread
From: ehrhardt @ 2008-10-10 10:59 UTC (permalink / raw)
  To: kvm-ppc

From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>

Currently we use an unneicessary if&switch to detect some cases.
To be honest we don't need the ligh_exits counter anyway, because we can
calculate it out of others. Sum_exits can also be calculated, so we can
remove that too. 
MMIO, DCR  and INTR can be counted on other places without these
additional control structures (The INTR case was never hit anyway).

The handling of BOOKE_INTERRUPT_EXTERNAL/BOOKE_INTERRUPT_DECREMENTER is
similar, but we can avoid the additional if when copying 3 lines of code.
I thought about a goto there to prevent duplicate lines, but rewriting three
lines should be better style than a goto cross switch/case statements (its
also not enough code to justify a new inline function).

Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---

[diffstat]
 booke_guest.c |   40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)

[diff]

diff --git a/arch/powerpc/kvm/booke_guest.c b/arch/powerpc/kvm/booke_guest.c
--- a/arch/powerpc/kvm/booke_guest.c
+++ b/arch/powerpc/kvm/booke_guest.c
@@ -36,11 +36,9 @@
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
 
 struct kvm_stats_debugfs_item debugfs_entries[] = {
-	{ "exits",      VCPU_STAT(sum_exits) },
 	{ "mmio",       VCPU_STAT(mmio_exits) },
 	{ "dcr",        VCPU_STAT(dcr_exits) },
 	{ "sig",        VCPU_STAT(signal_exits) },
-	{ "light",      VCPU_STAT(light_exits) },
 	{ "itlb_r",     VCPU_STAT(itlb_real_miss_exits) },
 	{ "itlb_v",     VCPU_STAT(itlb_virt_miss_exits) },
 	{ "dtlb_r",     VCPU_STAT(dtlb_real_miss_exits) },
@@ -270,7 +268,16 @@
 		break;
 
 	case BOOKE_INTERRUPT_EXTERNAL:
+		vcpu->stat.ext_intr_exits++;
+		set_last_exit_type(EXT_INTR_EXITS);
+		if (need_resched())
+			cond_resched();
+		r = RESUME_GUEST;
+		break;
+
 	case BOOKE_INTERRUPT_DECREMENTER:
+		vcpu->stat.dec_exits++;
+		set_last_exit_type(DEC_EXITS);
 		/* Since we switched IVPR back to the host's value, the host
 		 * handled this interrupt the moment we enabled interrupts.
 		 * Now we just offer it a chance to reschedule the guest. */
@@ -281,13 +288,6 @@
 		 * misses before ceding control. */
 		if (need_resched())
 			cond_resched();
-		if (exit_nr = BOOKE_INTERRUPT_DECREMENTER) {
-			vcpu->stat.dec_exits++;
-			set_last_exit_type(DEC_EXITS);
-		} else {
-			vcpu->stat.ext_intr_exits++;
-			set_last_exit_type(EXT_INTR_EXITS);
-		}
 		r = RESUME_GUEST;
 		break;
 
@@ -313,6 +313,7 @@
 			break;
 		case EMULATE_DO_DCR:
 			run->exit_reason = KVM_EXIT_DCR;
+			vcpu->stat.dcr_exits++;
 			set_last_exit_type(DCR_EXITS);
 			r = RESUME_HOST;
 			break;
@@ -415,6 +416,7 @@
 			 * actually RAM. */
 			r = kvmppc_emulate_mmio(run, vcpu);
 			set_last_exit_type(MMIO_EXITS);
+			vcpu->stat.mmio_exits++;
 		}
 
 		break;
@@ -485,8 +487,6 @@
 
 	kvmppc_check_and_deliver_interrupts(vcpu);
 
-	/* Do some exit accounting. */
-	vcpu->stat.sum_exits++;
 	if (!(r & RESUME_HOST)) {
 		/* To avoid clobbering exit_reason, only check for signals if
 		 * we aren't already exiting to userspace for some other
@@ -494,24 +494,8 @@
 		if (signal_pending(current)) {
 			run->exit_reason = KVM_EXIT_INTR;
 			r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
-
+			set_last_exit_type(SIGNAL_EXITS);
 			vcpu->stat.signal_exits++;
-			set_last_exit_type(SIGNAL_EXITS);
-		} else {
-			vcpu->stat.light_exits++;
-		}
-	} else {
-		switch (run->exit_reason) {
-		case KVM_EXIT_MMIO:
-			vcpu->stat.mmio_exits++;
-			break;
-		case KVM_EXIT_DCR:
-			vcpu->stat.dcr_exits++;
-			break;
-		case KVM_EXIT_INTR:
-			vcpu->stat.signal_exits++;
-			set_last_exit_type(SIGNAL_EXITS);
-			break;
 		}
 	}
 

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

* Re: [PATCH 2/3] kvmppc: optimize kvm stat handling
  2008-10-10 10:59 [PATCH 2/3] kvmppc: optimize kvm stat handling ehrhardt
@ 2008-10-10 18:12 ` Hollis Blanchard
  2008-10-13 12:07 ` ehrhardt
  1 sibling, 0 replies; 3+ messages in thread
From: Hollis Blanchard @ 2008-10-10 18:12 UTC (permalink / raw)
  To: kvm-ppc

On Fri, 2008-10-10 at 12:59 +0200, ehrhardt@linux.vnet.ibm.com wrote:
> From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
> 
> Currently we use an unneicessary if&switch to detect some cases.
> To be honest we don't need the ligh_exits counter anyway, because we can
> calculate it out of others. Sum_exits can also be calculated, so we can
> remove that too. 
> MMIO, DCR  and INTR can be counted on other places without these
> additional control structures (The INTR case was never hit anyway).
> 
> The handling of BOOKE_INTERRUPT_EXTERNAL/BOOKE_INTERRUPT_DECREMENTER is
> similar, but we can avoid the additional if when copying 3 lines of code.
> I thought about a goto there to prevent duplicate lines, but rewriting three
> lines should be better style than a goto cross switch/case statements (its
> also not enough code to justify a new inline function).
> 
> Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>

Looks fine, but depends on your kvmppc-exit-timing.diff, which I didn't
know you wanted applied already.

-- 
Hollis Blanchard
IBM Linux Technology Center


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

* [PATCH 2/3] kvmppc: optimize kvm stat handling
  2008-10-10 10:59 [PATCH 2/3] kvmppc: optimize kvm stat handling ehrhardt
  2008-10-10 18:12 ` Hollis Blanchard
@ 2008-10-13 12:07 ` ehrhardt
  1 sibling, 0 replies; 3+ messages in thread
From: ehrhardt @ 2008-10-13 12:07 UTC (permalink / raw)
  To: kvm-ppc

From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>

Currently we use an unneicessary if&switch to detect some cases.
To be honest we don't need the ligh_exits counter anyway, because we can
calculate it out of others. Sum_exits can also be calculated, so we can
remove that too.
MMIO, DCR  and INTR can be counted on other places without these
additional control structures (The INTR case was never hit anyway).

The handling of BOOKE_INTERRUPT_EXTERNAL/BOOKE_INTERRUPT_DECREMENTER is
similar, but we can avoid the additional if when copying 3 lines of code.
I thought about a goto there to prevent duplicate lines, but rewriting three
lines should be better style than a goto cross switch/case statements (its
also not enough code to justify a new inline function).

Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---

[diffstat]
 booke_guest.c |   32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

[diff]

diff --git a/arch/powerpc/kvm/booke_guest.c b/arch/powerpc/kvm/booke_guest.c
--- a/arch/powerpc/kvm/booke_guest.c
+++ b/arch/powerpc/kvm/booke_guest.c
@@ -34,11 +34,9 @@
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
 
 struct kvm_stats_debugfs_item debugfs_entries[] = {
-	{ "exits",      VCPU_STAT(sum_exits) },
 	{ "mmio",       VCPU_STAT(mmio_exits) },
 	{ "dcr",        VCPU_STAT(dcr_exits) },
 	{ "sig",        VCPU_STAT(signal_exits) },
-	{ "light",      VCPU_STAT(light_exits) },
 	{ "itlb_r",     VCPU_STAT(itlb_real_miss_exits) },
 	{ "itlb_v",     VCPU_STAT(itlb_virt_miss_exits) },
 	{ "dtlb_r",     VCPU_STAT(dtlb_real_miss_exits) },
@@ -220,6 +218,12 @@
 		break;
 
 	case BOOKE_INTERRUPT_EXTERNAL:
+		vcpu->stat.ext_intr_exits++;
+		if (need_resched())
+			cond_resched();
+		r = RESUME_GUEST;
+		break;
+
 	case BOOKE_INTERRUPT_DECREMENTER:
 		/* Since we switched IVPR back to the host's value, the host
 		 * handled this interrupt the moment we enabled interrupts.
@@ -229,12 +233,9 @@
 		 * we do reschedule the host will fault over it. Perhaps we
 		 * should politely restore the host's entries to minimize
 		 * misses before ceding control. */
+		vcpu->stat.dec_exits++;
 		if (need_resched())
 			cond_resched();
-		if (exit_nr = BOOKE_INTERRUPT_DECREMENTER)
-			vcpu->stat.dec_exits++;
-		else
-			vcpu->stat.ext_intr_exits++;
 		r = RESUME_GUEST;
 		break;
 
@@ -258,6 +259,7 @@
 			break;
 		case EMULATE_DO_DCR:
 			run->exit_reason = KVM_EXIT_DCR;
+			vcpu->stat.dcr_exits++;
 			r = RESUME_HOST;
 			break;
 		case EMULATE_FAIL:
@@ -336,6 +338,7 @@
 			/* Guest has mapped and accessed a page which is not
 			 * actually RAM. */
 			r = kvmppc_emulate_mmio(run, vcpu);
+			vcpu->stat.mmio_exits++;
 		}
 
 		break;
@@ -403,8 +406,6 @@
 
 	kvmppc_check_and_deliver_interrupts(vcpu);
 
-	/* Do some exit accounting. */
-	vcpu->stat.sum_exits++;
 	if (!(r & RESUME_HOST)) {
 		/* To avoid clobbering exit_reason, only check for signals if
 		 * we aren't already exiting to userspace for some other
@@ -412,22 +413,7 @@
 		if (signal_pending(current)) {
 			run->exit_reason = KVM_EXIT_INTR;
 			r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
-
 			vcpu->stat.signal_exits++;
-		} else {
-			vcpu->stat.light_exits++;
-		}
-	} else {
-		switch (run->exit_reason) {
-		case KVM_EXIT_MMIO:
-			vcpu->stat.mmio_exits++;
-			break;
-		case KVM_EXIT_DCR:
-			vcpu->stat.dcr_exits++;
-			break;
-		case KVM_EXIT_INTR:
-			vcpu->stat.signal_exits++;
-			break;
 		}
 	}
 

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

end of thread, other threads:[~2008-10-13 12:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-10 10:59 [PATCH 2/3] kvmppc: optimize kvm stat handling ehrhardt
2008-10-10 18:12 ` Hollis Blanchard
2008-10-13 12:07 ` ehrhardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.