Skip to contentSkip to conversation

ARM: kernel: irq: Simplify allocation of stack frame

RFC In review Joel Fernandes 2 participants 4 messages Oct 6, 2013 – Oct 7, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

RFC 1/1 ARM: kernel: irq: Simplify allocation of stack frame

On receiving IRQ exception in SVC mode, all the SVC mode registers are saved onto the stack very early on.

The stack frame allocation code for IRQ entry during SVC mode (svc_entry) is hard to read as 4-less is allocated initially only to be allocated later implicity using the mov r3, [sp, #-4]! instruction. We make code easier to read by allocating the 4 bytes on the stack frame in the beginning itself and remove all instances where 4 bytes is adjusted.

Cc Russell King <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Santosh Shilimkar <[email protected]>
---
 arch/arm/kernel/entry-armv.S | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm/kernel/entry-armv.S +5 -5
index 9cbe70c..fc5ac2a 100644
@@ -149,7 +149,7 @@ ENDPROC(__und_invalid)
 	.macro	svc_entry, stack_hole=0
  UNWIND(.fnstart		)
  UNWIND(.save {r0 - pc}		)
-	sub	sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
+	sub	sp, sp, #(S_FRAME_SIZE + \stack_hole)
 #ifdef CONFIG_THUMB2_KERNEL
  SPFIX(	str	r0, [sp]	)	@ temporarily saved
  SPFIX(	mov	r0, sp		)
@@ -159,14 +159,14 @@ ENDPROC(__und_invalid)
  SPFIX(	tst	sp, #4		)
 #endif
  SPFIX(	subeq	sp, sp, #4	)
-	stmia	sp, {r1 - r12}
+	stmia	sp, {r0 - r12}
 
 	ldmia	r0, {r3 - r5}
-	add	r7, sp, #S_SP - 4	@ here for interlock avoidance
+	add	r7, sp, #S_SP		@ here for interlock avoidance
 	mov	r6, #-1			@  ""  ""      ""       ""
-	add	r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
+	add	r2, sp, #(S_FRAME_SIZE + \stack_hole)
  SPFIX(	addeq	r2, r2, #4	)
-	str	r3, [sp, #-4]!		@ save the "real" r0 copied
+	str	r3, [sp]		@ save the "real" r0 copied
 					@ from the exception stack
 
 	mov	r3, lr
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 8 lines · Joel Fernandes

On receiving IRQ exception in SVC mode, all the SVC mode registers are saved onto the stack very early on.

The stack frame allocation code for IRQ entry during SVC mode (svc_entry) is hard to read as 4-less is allocated initially only to be allocated later implicity using the mov r3, [sp, #-4]! instruction. We make code easier to read by allocating the 4 bytes on the stack frame in the beginning itself and remove all instances where 4 bytes is adjusted.

You omit to say that this results in saving one additional register unnecessarily in the stmia. We could use a stmib there instead which would avoid that issue while keeping the rest of the change.

#2 lore raw
Quoted 11 lines · Russell King - ARM Linux
Quoted 8 lines · Joel Fernandes

On receiving IRQ exception in SVC mode, all the SVC mode registers are saved onto the stack very early on.

The stack frame allocation code for IRQ entry during SVC mode (svc_entry) is hard to read as 4-less is allocated initially only to be allocated later implicity using the mov r3, [sp, #-4]! instruction. We make code easier to read by allocating the 4 bytes on the stack frame in the beginning itself and remove all instances where 4 bytes is adjusted.

You omit to say that this results in saving one additional register

Ok, I will add this detail to the commit message.

Quoted 2 lines

unnecessarily in the stmia. We could use a stmib there instead which would avoid that issue while keeping the rest of the change.

But stmib is not available in THUMB mode, so this will break the THUMB builds.

usr_entry does something similar:

 ARM(   stmib   sp, {r1 - r12}  )
 THUMB( stmia   sp, {r0 - r12}  )

Let me know your suggestions about using ARM/THUMB macros or stmia for both cases. Thanks.

Regards,

-Joel

#3 lore raw
In reply to Russell King - ARM Linux
Quoted 10 lines · Russell King - ARM Linux
Quoted 8 lines · Joel Fernandes

On receiving IRQ exception in SVC mode, all the SVC mode registers are saved onto the stack very early on.

The stack frame allocation code for IRQ entry during SVC mode (svc_entry) is hard to read as 4-less is allocated initially only to be allocated later implicity using the mov r3, [sp, #-4]! instruction. We make code easier to read by allocating the 4 bytes on the stack frame in the beginning itself and remove all instances where 4 bytes is adjusted.

Quoted 4 lines

You omit to say that this results in saving one additional register unnecessarily in the stmia. We could use a stmib there instead which would avoid that issue while keeping the rest of the change.

Hi Russel,

BTW I used ETM to check the number of cycles used to store the extra register with and without this patch and with both cases it takes 7 cycles.

My platform uses Cortex-A8 (AM335x SoC).

Thanks,

-Joel