Skip to contentSkip to conversation

ARM: change definition of cpu_relax() for ARM11MPCore

PATCH New Will Deacon 2 participants 4 messages May 27, 2010 – May 28, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore

The cpu_relax() macro is often used in the body of busy-wait loops to ensure that the variable being spun on is re-loaded for each iteration. On the ARM11MPCore processor [where loads are prioritised over stores], spinning in such a loop will prevent the write buffer from draining. If a write contained in the write buffer indirectly affects the variable being spun on, there is a potential for deadlock. This deadlock is experienced when executing the KGDB testsuite on an SMP ARM11MPCore configuration.

This patch changes the definition of cpu_relax() to smp_mb() for ARMv6 cores, forcing a flushing of the write buffer on SMP systems before the next load takes place. If the Kernel is not compiled for SMP support, this will expand to a barrier() as before.

---

Russell - the discussion on this last month seemed to draw to a close. Can I submit this to the patch system please, or are there any outstanding issues?

 arch/arm/include/asm/processor.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
arch/arm/include/asm/processor.h +4 -0
index 6a89567..7bed3da 100644
@@ -91,7 +91,11 @@ extern void release_thread(struct task_struct *);
 
 unsigned long get_wchan(struct task_struct *p);
 
+#if __LINUX_ARM_ARCH__ == 6
+#define cpu_relax()			smp_mb()
+#else
 #define cpu_relax()			barrier()
+#endif
 
 /*
  * Create a new kernel thread
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore

Will,

Quoted 16 lines

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm-kernel- bounces at lists.infradead.org] On Behalf Of Will Deacon
Sent: Thursday, May 27, 2010 8:42 PM
To: linux-arm-kernel at lists.infradead.org
Cc: Russell King - ARM Linux; Will Deacon
Subject: [PATCH] ARM: change definition of cpu_relax() for ARM11MPCore

The cpu_relax() macro is often used in the body of busy-wait loops to ensure that the variable being spun on is re-loaded for each iteration. On the ARM11MPCore processor [where loads are prioritised over stores], spinning in such a loop will prevent the write buffer from draining. If a write contained in the write buffer indirectly affects the variable being spun on, there is a potential for deadlock. This deadlock is experienced when executing the KGDB testsuite on an SMP ARM11MPCore configuration.

Quoted 5 lines

This patch changes the definition of cpu_relax() to smp_mb() for ARMv6 cores, forcing a flushing of the write buffer on SMP systems before the next load takes place. If the Kernel is not compiled for SMP support, this will expand to a barrier() as before.

I have missed this thread. Is this not applicable for ARMv7 MP Cores as well??

Quoted 29 lines

---

Russell - the discussion on this last month seemed to draw to a close. Can I submit this to the patch system please, or are there any outstanding issues?

 arch/arm/include/asm/processor.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
arch/arm/include/asm/processor.h +4 -1
index 6a89567..7bed3da 100644
@@ -91,7 +91,11 @@ extern void release_thread(struct task_struct *);
 
 unsigned long get_wchan(struct task_struct *p);
 
+#if __LINUX_ARM_ARCH__ == 6
+#define cpu_relax()			smp_mb()
+#else
 #define cpu_relax()			barrier()
+#endif
 
 /*
  * Create a new kernel thread
--
Quoted 1 line

1.6.3.3

Regards,
Santosh

#2 lore raw

PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore

Hi Santosh,

Quoted 6 lines
Quoted 5 lines

This patch changes the definition of cpu_relax() to smp_mb() for ARMv6 cores, forcing a flushing of the write buffer on SMP systems before the next load takes place. If the Kernel is not compiled for SMP support, this will expand to a barrier() as before.

I have missed this thread. Is this not applicable for ARMv7 MP Cores as well??

You can pick up on some of the old thread here:

http://lists.infradead.org/pipermail/linux-arm-kernel/2010-April/012874.html

Actually, the ChangeLog I wrote for that patch is better, so I'll update my current one.

To answer your question; this problem only occurs on ARM11MPCore. For ARMv7MP, stores are guaranteed to become visible eventually [i.e. they can't be held up indefinitely by a sequence of aggresive loads].

An addition to the ARM ARM [Section A3.8.2] says:

* For an implementation that does not include the Multiprocessing Extensions, it is IMPLEMENTATION DEFINED whether all writes become globally observed in their shareability domain in a finite period of time, or whether in some cases, software must execute a DSB to ensure the visibility of some writes.

* For an implementation that includes the Multiprocessing Extensions, all writes become globally observed in their shareability domain in a finite period of time.

Will

#3 lore raw

PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore

Quoted 29 lines

-----Original Message-----
From: Will Deacon [mailto:will.deacon at arm.com]
Sent: Thursday, May 27, 2010 10:24 PM
To: Shilimkar, Santosh; linux-arm-kernel at lists.infradead.org
Cc: Russell King - ARM Linux
Subject: RE: [PATCH] ARM: change definition of cpu_relax() for ARM11MPCore

Hi Santosh,

Quoted 6 lines
Quoted 5 lines

This patch changes the definition of cpu_relax() to smp_mb() for ARMv6 cores, forcing a flushing of the write buffer on SMP systems before the next load takes place. If the Kernel is not compiled for SMP support, this will expand to a barrier() as before.

I have missed this thread. Is this not applicable for ARMv7 MP Cores as well??

You can pick up on some of the old thread here:

http://lists.infradead.org/pipermail/linux-arm-kernel/2010-April/012874.html

Actually, the ChangeLog I wrote for that patch is better, so I'll update my current one.

To answer your question; this problem only occurs on ARM11MPCore. For ARMv7MP, stores are guaranteed to become visible eventually [i.e. they can't be held up indefinitely by a sequence of aggresive loads].

An addition to the ARM ARM [Section A3.8.2] says:

Quoted 8 lines

* For an implementation that does not include the Multiprocessing Extensions, it is IMPLEMENTATION DEFINED whether all writes become globally observed in their shareability domain in a finite period of time, or whether in some cases, software must execute a DSB to ensure the visibility of some writes.

* For an implementation that includes the Multiprocessing Extensions, all writes become globally observed in their shareability domain in a finite period of time.

Thanks. It's clear to me now.

Regards,
Santosh