Skip to content

Commit 195b58a

Browse files
author
Russell King
committed
ARM: Avoid writing to control register on every exception
If we are not changing the control register value, avoid writing to it. Writes to the control register can be very expensive, taking around a hundred cycles or so. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 8b521cb commit 195b58a

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎arch/arm/kernel/entry-armv.S‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,18 @@ ENDPROC(__pabt_svc)
321321
ARM( stmib sp, {r1 - r12} )
322322
THUMB( stmia sp, {r0 - r12} )
323323

324+
ATRAP( mrc p15, 0, r7, c1, c0, 0)
325+
ATRAP( ldr r8, .LCcralign)
326+
324327
ldmia r0, {r3 - r5}
325328
add r0, sp, #S_PC @ here for interlock avoidance
326329
mov r6, #-1 @ "" "" "" ""
327330

328331
str r3, [sp] @ save the "real" r0 copied
329332
@ from the exception stack
330333

334+
ATRAP( ldr r8, [r8, #0])
335+
331336
@
332337
@ We are now ready to fill in the remaining blanks on the stack:
333338
@
@@ -341,10 +346,9 @@ ENDPROC(__pabt_svc)
341346
ARM( stmdb r0, {sp, lr}^ )
342347
THUMB( store_user_sp_lr r0, r1, S_SP - S_PC )
343348

344-
@
345349
@ Enable the alignment trap while in kernel mode
346-
@
347-
alignment_trap r0, .LCcralign
350+
ATRAP( teq r8, r7)
351+
ATRAP( mcrne p15, 0, r8, c1, c0, 0)
348352

349353
@
350354
@ Clear FP to mark the first stack frame

‎arch/arm/kernel/entry-common.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ ENTRY(vector_swi)
366366
str r0, [sp, #S_OLD_R0] @ Save OLD_R0
367367
#endif
368368
zero_fp
369-
alignment_trap ip, __cr_alignment
369+
alignment_trap r10, ip, __cr_alignment
370370
enable_irq
371371
ct_user_exit
372372
get_thread_info tsk

‎arch/arm/kernel/entry-header.S‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@
3737
#endif
3838
.endm
3939

40-
.macro alignment_trap, rtemp, label
4140
#ifdef CONFIG_ALIGNMENT_TRAP
42-
ldr \rtemp, \label
43-
ldr \rtemp, [\rtemp]
44-
mcr p15, 0, \rtemp, c1, c0
41+
#define ATRAP(x...) x
42+
#else
43+
#define ATRAP(x...)
44+
#endif
45+
46+
.macro alignment_trap, rtmp1, rtmp2, label
47+
#ifdef CONFIG_ALIGNMENT_TRAP
48+
mrc p15, 0, \rtmp2, c1, c0, 0
49+
ldr \rtmp1, \label
50+
ldr \rtmp1, [\rtmp1]
51+
teq \rtmp1, \rtmp2
52+
mcrne p15, 0, \rtmp1, c1, c0, 0
4553
#endif
4654
.endm
4755

0 commit comments

Comments
 (0)