Skip to content

Commit 49d09bf

Browse files
npigginmpe
authored andcommitted
powerpc/64s: Optimise MSR handling in exception handling
mtmsrd with L=1 only affects MSR_EE and MSR_RI bits, and we always know what state those bits are, so the kernel MSR does not need to be loaded when modifying them. mtmsrd is often in the critical execution path, so avoiding dependency on even L1 load is noticable. On a POWER8 this saves about 3 cycles from the syscall path, and possibly a few from other exception returns (not measured). Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 18e3f56 commit 49d09bf

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

arch/powerpc/kernel/entry_64.S

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
139139
#ifdef CONFIG_PPC_BOOK3E
140140
wrteei 1
141141
#else
142-
ld r11,PACAKMSR(r13)
142+
li r11,MSR_RI
143143
ori r11,r11,MSR_EE
144144
mtmsrd r11,1
145145
#endif /* CONFIG_PPC_BOOK3E */
@@ -195,16 +195,14 @@ system_call: /* label this so stack traces look sane */
195195
#ifdef CONFIG_PPC_BOOK3E
196196
wrteei 0
197197
#else
198-
ld r10,PACAKMSR(r13)
199198
/*
200199
* For performance reasons we clear RI the same time that we
201200
* clear EE. We only need to clear RI just before we restore r13
202201
* below, but batching it with EE saves us one expensive mtmsrd call.
203202
* We have to be careful to restore RI if we branch anywhere from
204203
* here (eg syscall_exit_work).
205204
*/
206-
li r9,MSR_RI
207-
andc r11,r10,r9
205+
li r11,0
208206
mtmsrd r11,1
209207
#endif /* CONFIG_PPC_BOOK3E */
210208

@@ -221,13 +219,12 @@ system_call: /* label this so stack traces look sane */
221219
#endif
222220
2: addi r3,r1,STACK_FRAME_OVERHEAD
223221
#ifdef CONFIG_PPC_BOOK3S
222+
li r10,MSR_RI
224223
mtmsrd r10,1 /* Restore RI */
225224
#endif
226225
bl restore_math
227226
#ifdef CONFIG_PPC_BOOK3S
228-
ld r10,PACAKMSR(r13)
229-
li r9,MSR_RI
230-
andc r11,r10,r9 /* Re-clear RI */
227+
li r11,0
231228
mtmsrd r11,1
232229
#endif
233230
ld r8,_MSR(r1)
@@ -308,6 +305,7 @@ syscall_enosys:
308305

309306
syscall_exit_work:
310307
#ifdef CONFIG_PPC_BOOK3S
308+
li r10,MSR_RI
311309
mtmsrd r10,1 /* Restore RI */
312310
#endif
313311
/* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr.
@@ -354,7 +352,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
354352
#ifdef CONFIG_PPC_BOOK3E
355353
wrteei 1
356354
#else
357-
ld r10,PACAKMSR(r13)
355+
li r10,MSR_RI
358356
ori r10,r10,MSR_EE
359357
mtmsrd r10,1
360358
#endif /* CONFIG_PPC_BOOK3E */
@@ -619,7 +617,7 @@ _GLOBAL(ret_from_except_lite)
619617
#ifdef CONFIG_PPC_BOOK3E
620618
wrteei 0
621619
#else
622-
ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
620+
li r10,MSR_RI
623621
mtmsrd r10,1 /* Update machine state */
624622
#endif /* CONFIG_PPC_BOOK3E */
625623

@@ -751,7 +749,7 @@ resume_kernel:
751749
#ifdef CONFIG_PPC_BOOK3E
752750
wrteei 0
753751
#else
754-
ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
752+
li r10,MSR_RI
755753
mtmsrd r10,1 /* Update machine state */
756754
#endif /* CONFIG_PPC_BOOK3E */
757755
#endif /* CONFIG_PREEMPT */
@@ -841,8 +839,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
841839
* userspace and we take an exception after restoring r13,
842840
* we end up corrupting the userspace r13 value.
843841
*/
844-
ld r4,PACAKMSR(r13) /* Get kernel MSR without EE */
845-
andc r4,r4,r0 /* r0 contains MSR_RI here */
842+
li r4,0
846843
mtmsrd r4,1
847844

848845
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM

0 commit comments

Comments
 (0)