Skip to contentSkip to conversation

powerpc/booke: Eliminate rfi from exception entry path.

PATCH In review Scott Wood 3 participants 7 messages Jul 11, 2012 PowerPC

lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 1/1 powerpc/booke: Eliminate rfi from exception entry path.

Unlike classic, we don't really need the MSR change to be atomic with the branch. This eliminates a trap as a KVM guest (in the absence of hardware hypervisor extensions), where mtmsr is paravirtualized but rfi is not. For a virtualized guest without any paravirtualization, this eliminates an additional two traps (SRR0/1).

---
 arch/powerpc/kernel/entry_32.S |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
arch/powerpc/kernel/entry_32.S +16 -0
index ba3aeb4..6bb637c 100644
@@ -193,6 +193,9 @@ transfer_to_handler_cont:
 	lwz	r11,0(r9)		/* virtual address of handler */
 	lwz	r9,4(r9)		/* where to go when done */
 #ifdef CONFIG_TRACE_IRQFLAGS
+#ifdef CONFIG_BOOKE
+	mtmsr	r10
+#else
 	lis	r12,reenable_mmu@h
 	ori	r12,r12,reenable_mmu@l
 	mtspr	SPRN_SRR0,r12
@@ -201,6 +204,7 @@ transfer_to_handler_cont:
 	RFI
 reenable_mmu:				/* re-enable mmu so we can */
 	mfmsr	r10
+#endif /* !CONFIG_BOOKE */
 	lwz	r12,_MSR(r1)
 	xor	r10,r10,r12
 	andi.	r10,r10,MSR_EE		/* Did EE change? */
@@ -247,11 +251,23 @@ reenable_mmu:				/* re-enable mmu so we can */
 	mtlr	r9
 	bctr				/* jump to handler */
 #else /* CONFIG_TRACE_IRQFLAGS */
+#ifdef CONFIG_BOOKE
+	/*
+	 * We're not changing address space on Book E, and the extra rfi
+	 * can hurt when virtualized without hardware support -- whereas
+	 * mtmsr can be paravirtualized.
+	 */
+	mtmsr	r10
+	mtctr	r11
+	mtlr	r9
+	bctr
+#else
 	mtspr	SPRN_SRR0,r11
 	mtspr	SPRN_SRR1,r10
 	mtlr	r9
 	SYNC
 	RFI				/* jump to handler, enable MMU */
+#endif /* !CONFIG_BOOKE */
 #endif /* CONFIG_TRACE_IRQFLAGS */
 
 #if defined (CONFIG_6xx) || defined(CONFIG_E500)
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 5 lines · Scott Wood

Unlike classic, we don't really need the MSR change to be atomic with the branch. This eliminates a trap as a KVM guest (in the absence of hardware hypervisor extensions), where mtmsr is paravirtualized but rfi is not. For a virtualized guest without any paravirtualization, this eliminates an additional two traps (SRR0/1).

In fact, I wonder, what do we write into the MSR at this point that wasn't already in it in BookE ? RI ? I wonder if we could get away without the mtmsr alltogether...

Cheers,
Ben.

Quoted 51 lines
---
 arch/powerpc/kernel/entry_32.S |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
arch/powerpc/kernel/entry_32.S +16 -0
index ba3aeb4..6bb637c 100644
@@ -193,6 +193,9 @@ transfer_to_handler_cont:
 	lwz	r11,0(r9)		/* virtual address of handler */
 	lwz	r9,4(r9)		/* where to go when done */
 #ifdef CONFIG_TRACE_IRQFLAGS
+#ifdef CONFIG_BOOKE
+	mtmsr	r10
+#else
 	lis	r12,reenable_mmu@h
 	ori	r12,r12,reenable_mmu@l
 	mtspr	SPRN_SRR0,r12
@@ -201,6 +204,7 @@ transfer_to_handler_cont:
 	RFI
 reenable_mmu:				/* re-enable mmu so we can */
 	mfmsr	r10
+#endif /* !CONFIG_BOOKE */
 	lwz	r12,_MSR(r1)
 	xor	r10,r10,r12
 	andi.	r10,r10,MSR_EE		/* Did EE change? */
@@ -247,11 +251,23 @@ reenable_mmu:				/* re-enable mmu so we can */
 	mtlr	r9
 	bctr				/* jump to handler */
 #else /* CONFIG_TRACE_IRQFLAGS */
+#ifdef CONFIG_BOOKE
+	/*
+	 * We're not changing address space on Book E, and the extra rfi
+	 * can hurt when virtualized without hardware support -- whereas
+	 * mtmsr can be paravirtualized.
+	 */
+	mtmsr	r10
+	mtctr	r11
+	mtlr	r9
+	bctr
+#else
 	mtspr	SPRN_SRR0,r11
 	mtspr	SPRN_SRR1,r10
 	mtlr	r9
 	SYNC
 	RFI				/* jump to handler, enable MMU */
+#endif /* !CONFIG_BOOKE */
 #endif /* CONFIG_TRACE_IRQFLAGS */
 
 #if defined (CONFIG_6xx) || defined(CONFIG_E500)
author
#2 lore raw
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 5 lines · Scott Wood

Unlike classic, we don't really need the MSR change to be atomic with the branch. This eliminates a trap as a KVM guest (in the absence of hardware hypervisor extensions), where mtmsr is paravirtualized but rfi is not. For a virtualized guest without any paravirtualization, this eliminates an additional two traps (SRR0/1).

In fact, I wonder, what do we write into the MSR at this point that wasn't already in it in BookE ? RI ? I wonder if we could get away without the mtmsr alltogether...

Doesn't EE get set there for some exceptions?

-Scott

#3 lore raw
Quoted 8 lines · Scott Wood
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines · Scott Wood

Unlike classic, we don't really need the MSR change to be atomic with the branch. This eliminates a trap as a KVM guest (in the absence of hardware hypervisor extensions), where mtmsr is paravirtualized but rfi is not. For a virtualized guest without any paravirtualization, this eliminates an additional two traps (SRR0/1).

Quoted 5 lines
Quoted 3 lines

In fact, I wonder, what do we write into the MSR at this point that wasn't already in it in BookE ? RI ? I wonder if we could get away without the mtmsr alltogether...

Doesn't EE get set there for some exceptions?

It does, tho arguably it shouldn't in most cases :-) I'm happy to turn a bunch of these into explicit local_irq_enable() in the C code though which will turn into a wrteei which is more efficient on BookE.

Cheers,
Ben.

#4 lore raw
In reply to Scott Wood
Quoted 1 line · Scott Wood

Unlike classic, we don't really need the MSR change to be atomic with =

the

Quoted 2 lines

branch. This eliminates a trap as a KVM guest (in the absence of hardware hypervisor extensions), where mtmsr is paravirtualized but =

rfi

=

Quoted 9 lines

is not. For a virtualized guest without any paravirtualization, this eliminates an additional two traps (SRR0/1).
=20

---
arch/powerpc/kernel/entry_32.S | 16 ++++++++++++++++

1 files changed, 16 insertions(+), 0 deletions(-)

=20

= renamed from arch/powerpc/kernel/entry_32.S +0 -0

b/arch/powerpc/kernel/entry_32.S

arch/powerpc/kernel/entry_32.S reenable_mmu: /* =

Quoted 22 lines

index ba3aeb4..6bb637c 100644

arch/powerpc/kernel/entry_32.S +3 -0
@@ -193,6 +193,9 @@ transfer_to_handler_cont:
 	lwz	r11,0(r9)		/* virtual address of handler */
 	lwz	r9,4(r9)		/* where to go when done */
 #ifdef CONFIG_TRACE_IRQFLAGS
+#ifdef CONFIG_BOOKE
+	mtmsr	r10
+#else
 	lis	r12,reenable_mmu@h
 	ori	r12,r12,reenable_mmu@l
 	mtspr	SPRN_SRR0,r12
@@ -201,6 +204,7 @@ transfer_to_handler_cont:
 	RFI

reenable_mmu: /* re-enable mmu so we can */

	mfmsr	r10
+#endif /* !CONFIG_BOOKE */
	lwz	r12,_MSR(r1)
	xor	r10,r10,r12
	andi.	r10,r10,MSR_EE		/* Did EE change? */
arch/powerpc/kernel/entry_32.S +0 -0
@@ -247,11 +251,23 @@ reenable_mmu:				/* =

re-enable mmu so we can */

arch/powerpc/kernel/entry_32.S reenable_mmu: /* re-enable mmu so we can */ · line 258

Quoted 8 lines
arch/powerpc/kernel/entry_32.S +5 -0
 	mtlr	r9
 	bctr				/* jump to handler */
 #else /* CONFIG_TRACE_IRQFLAGS */
+#ifdef CONFIG_BOOKE
+	/*
+	 * We're not changing address space on Book E, and the extra rfi
+	 * can hurt when virtualized without hardware support -- whereas
+	 * mtmsr can be paravirtualized.

We can always paravirtualize RFI as well if it makes sense.

Alex

author
#5 lore raw
Quoted 9 lines · Alexander Graf

arch/powerpc/kernel/entry_32.S reenable_mmu: /* re-enable mmu so we can */ · line 258

Quoted 5 lines · Scott Wood
arch/powerpc/kernel/entry_32.S +5 -0
+#ifdef CONFIG_BOOKE
+	/*
+	 * We're not changing address space on Book E, and the extra rfi
+	 * can hurt when virtualized without hardware support -- whereas
+	 * mtmsr can be paravirtualized.

We can always paravirtualize RFI as well if it makes sense.

I'm not sure that's possible. We thought about it a while back, but IIRC the difficulty was not leaving a register clobbered.

-Scott

#6 lore raw
Quoted 11 lines · Scott Wood
Quoted 9 lines · Alexander Graf

arch/powerpc/kernel/entry_32.S reenable_mmu: /* re-enable mmu so we can */ · line 258

Quoted 5 lines · Scott Wood
arch/powerpc/kernel/entry_32.S +5 -0
+#ifdef CONFIG_BOOKE
+	/*
+	 * We're not changing address space on Book E, and the extra rfi
+	 * can hurt when virtualized without hardware support -- whereas
+	 * mtmsr can be paravirtualized.

We can always paravirtualize RFI as well if it makes sense.

Quoted 2 lines

I'm not sure that's possible. We thought about it a while back, but IIRC the difficulty was not leaving a register clobbered.

Besides mtmsr is slow on real HW as well. Also paravirt as done today for complex instructions like mtmsr is racy :-) (I already had a chat about that with Alex a while back, we might want to re-consider what kind of fix can be done at some point).

Cheers,
Ben.