Skip to contentSkip to conversation

ARM: mm: update CONTEXTIDR register to contain PID of current process

PATCH New Will Deacon 2 participants 2 messages Nov 8, 2011 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: mm: update CONTEXTIDR register to contain PID of current process

This patch introduces a new Kconfig option which, when enabled, causes the kernel to write the PID of the current task into the PROCID field of the CONTEXTIDR on context switch. This is useful when analysing hardware trace, since writes to this register can be configured to emit an event into the trace stream.

The thread notifier for writing the PID is deliberately kept separate from the ASID code, so that we can easily support newer processors (A15 onwards) which store the ASID in TTBR0. As such, the switch_mm code is updated to perform a read-modify-write sequence to ensure that we don't clobber the PID on older CPUs.

---
 arch/arm/Kconfig.debug |    9 ++++++
 arch/arm/mm/context.c  |   67 +++++++++++++++++++++++++++++++++++++++++++++---
 arch/arm/mm/proc-v6.S  |    6 ++++
 arch/arm/mm/proc-v7.S  |    6 ++++
 4 files changed, 84 insertions(+), 4 deletions(-)
arch/arm/Kconfig.debug +9 -0
index c5213e7..5b9eca2 100644
@@ -271,4 +271,13 @@ config ARM_KPROBES_TEST
 	help
 	  Perform tests of kprobes API and instruction set simulation.
 
+config PID_IN_CONTEXTIDR
+	bool "Write the current PID to the CONTEXTIDR register"
+	depends on CPU_COPY_V6
+	help
+	  Enabling this option causes the kernel to write the current PID to
+	  the PROCID field of the CONTEXTIDR register, at the expense of some
+	  additional instructions during context switch. Say Y here only if you
+	  are planning to use hardware trace tools with this kernel.
+
 endmenu
arch/arm/mm/context.c +63 -4

91 lines not on this page · raw message

arch/arm/mm/proc-v6.S +6 -0
index d061d2f..8614eb3 100644
@@ -104,6 +104,12 @@ ENTRY(cpu_v6_switch_mm)
 	mcr	p15, 0, r2, c7, c5, 6		@ flush BTAC/BTB
 	mcr	p15, 0, r2, c7, c10, 4		@ drain write buffer
 	mcr	p15, 0, r0, c2, c0, 0		@ set TTB 0
+#ifdef CONFIG_PID_IN_CONTEXTIDR
+	mrc	p15, 0, r2, c13, c0, 1		@ read current context ID
+	bic	r2, r2, #0xff			@ extract the PID
+	and	r1, r1, #0xff
+	orr	r1, r1, r2			@ insert the PID into r1
+#endif
 	mcr	p15, 0, r1, c13, c0, 1		@ set context ID
 #endif
 	mov	pc, lr
arch/arm/mm/proc-v7.S +6 -0
index 2c559ac..fe1075d 100644
@@ -119,6 +119,12 @@ ENTRY(cpu_v7_switch_mm)
 #ifdef CONFIG_ARM_ERRATA_754322
 	dsb
 #endif
+#ifdef CONFIG_PID_IN_CONTEXTIDR
+	mrc	p15, 0, r2, c13, c0, 1		@ read current context ID
+	bic	r2, r2, #0xff			@ extract the PID
+	and	r1, r1, #0xff
+	orr	r1, r1, r2			@ insert the PID into r1
+#endif
 	mcr	p15, 0, r2, c13, c0, 1		@ set reserved context ID
 	isb
 1:	mcr	p15, 0, r0, c2, c0, 0		@ set TTB 0
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/1 ARM: mm: update CONTEXTIDR register to contain PID of current process

Quoted 6 lines · Will Deacon

This patch introduces a new Kconfig option which, when enabled, causes the kernel to write the PID of the current task into the PROCID field of the CONTEXTIDR on context switch. This is useful when analysing hardware trace, since writes to this register can be configured to emit an event into the trace stream.

Quoted 8 lines

The thread notifier for writing the PID is deliberately kept separate from the ASID code, so that we can easily support newer processors (A15 onwards) which store the ASID in TTBR0. As such, the switch_mm code is updated to perform a read-modify-write sequence to ensure that we don't clobber the PID on older CPUs.

Looks fine to me.