ARM: change definition of cpu_relax() for ARM11MPCore
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. If the Kernel is not compiled for SMP support, this will expand to a barrier() as before.
--- arch/arm/include/asm/processor.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/arm/include/asm/processor.h +4 -0
@@ -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
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Quoted 2 lines · Will Deacon
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.
No, cpu_relax() exists to avoid x86 CPUs overheating - if you spin like so:
for(;;);
the CPU will overheat, so it's conventional to write:
for(;;) cpu_relax();
so that architectures can prevent those kinds of problems occuring.
cpu_relax() is also defined to be a compiler barrier so that the compiler reloads the variable on every iteration.
Quoted 3 lines
This patch changes the definition of
cpu_relax()tosmp_mb()for ARMv6 cores, forcing a flushing of the write buffer on SMP systems. If the Kernel is not compiled for SMP support, this will expand to abarrier()as before.
I don't think this is correct. You're making a macro do something on ARM which no other platform, apart from blackfin (which I believe is wrong) makes it do.
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Hi Russell,
Quoted 7 lines · Will Deacon
Quoted 2 lines
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.No,
cpu_relax()exists to avoid x86 CPUs overheating - if you spin like so:
Quoted 8 lines
for(;;);the CPU will overheat, so it's conventional to write:
for(;;) cpu_relax();so that architectures can prevent those kinds of problems occuring.
Ok. I was going by the comments in Documentation/volatile-considered-harmful.txt where cpu_relax() is also used as a memory barrier.
Quoted 10 lines
cpu_relax()is also defined to be a compiler barrier so that the compiler reloads the variable on every iteration.Quoted 3 lines
This patch changes the definition of
cpu_relax()tosmp_mb()for ARMv6 cores, forcing a flushing of the write buffer on SMP systems. If the Kernel is not compiled for SMP support, this will expand to abarrier()as before.I don't think this is correct. You're making a macro do something on ARM which no other platform, apart from blackfin (which I believe is wrong) makes it do.
In the KGDB case [where this cropped up], if cpu_relax() is left as it is, then an smp_mb() is required in the architecture independent code. This also seems wrong because it's only needed for the ARM11MPCore. There may also potentially be other situations in the Kernel which are prone to deadlock because it is assumed that the write buffer will always drain.
Since both solutions to this problem are nasty, it would be good to get some clarification on the definition of cpu_relax() across the Kernel. If the KGDB guys don't mind adding an extra memory barrier, we can solve the problem that way instead and hope that it doesn't occur elsewhere.
Thoughts?
Cheers,
Will
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Quoted 13 lines · Will Deacon
Hi Russell,
Quoted 11 lines · Will Deacon
Quoted 2 lines
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.No,
cpu_relax()exists to avoid x86 CPUs overheating - if you spin like so:for(;;);the CPU will overheat, so it's conventional to write:
Quoted 7 lines
Quoted 4 lines
for(;;) cpu_relax();so that architectures can prevent those kinds of problems occuring.
Ok. I was going by the comments in
Documentation/volatile-considered-harmful.txtwherecpu_relax()is also used as a memory barrier.
I thought you might; I've just submitted a patch for that to akpm, lkml and linux-arch.
Quoted 5 lines
In the KGDB case [where this cropped up], if
cpu_relax()is left as it is, then ansmp_mb()is required in the architecture independent code. This also seems wrong because it's only needed for the ARM11MPCore. There may also potentially be other situations in the Kernel which are prone to deadlock because it is assumed that the write buffer will always drain.
Why is KGDB being special about this? Ah yes, it's being brain dead:
static atomic_t passive_cpu_wait[NR_CPUS];
static atomic_t cpu_in_kgdb[NR_CPUS];
while (atomic_read(&passive_cpu_wait[cpu]))
cpu_relax();
for (i = 0; i < NR_CPUS; i++)
atomic_set(&passive_cpu_wait[i], 1);
for (i = NR_CPUS-1; i >= 0; i--)
atomic_set(&passive_cpu_wait[i], 0);
atomic_set(&cpu_in_kgdb[cpu], 1);
atomic_set(&cpu_in_kgdb[cpu], 0);
atomic_set(&cpu_in_kgdb[ks->cpu], 1);
for_each_online_cpu(i) {
while (!atomic_read(&cpu_in_kgdb[i]))
cpu_relax();
}
atomic_set(&cpu_in_kgdb[ks->cpu], 0);
for_each_online_cpu(i) {
while (atomic_read(&cpu_in_kgdb[i]))
cpu_relax();
}
if (!atomic_read(&cpu_in_kgdb[cpu]) &&
atomic_read(&kgdb_active) != cpu &&
atomic_read(&cpu_in_kgdb[atomic_read(&kgdb_active)])) {None of the above is atomic in any way, and I suspect that all these places in kernel/kgdb.c are buggy. As I've said in the past, just because something is called 'atomic' does not make it so:
On atomic_set():
The setting is atomic in that the return values of the atomic operations by all threads are guaranteed to be correct reflecting either the value that has been set with this operation or set with another operation. A proper implicit or explicit memory barrier is needed before the value set with the operation is guaranteed to be readable with atomic_read from another thread.
On atomic_read():
The read is atomic in that the return value is guaranteed to be one of the values initialized or modified with the interface operations if a proper implicit or explicit memory barrier is used after possible runtime initialization by any other thread and the value is modified only with the interface operations. atomic_read does not guarantee that the runtime initialization by any other thread is visible yet, so the user of the interface must take care of that with a proper implicit or explicit memory barrier.
Clearly, kgdb is using atomic_set()/atomic_read() in a way which does not match this documentation - it's certainly missing the barriers as required by the above quoted paragraphs.
Let me repeat: atomic_set() and atomic_read() are NOT atomic. There's nothing atomic about them. All they do is provide a pair of accessors to the underlying value in the atomic type. They are no different to declaring a volatile int and reading/writing it directly.
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Quoted 5 lines
Quoted 2 lines
Ok. I was going by the comments in
Documentation/volatile-considered-harmful.txtwherecpu_relax()is also used as a memory barrier.I thought you might; I've just submitted a patch for that to akpm, lkml and linux-arch.
Cheers, I'll take a read.
Quoted 7 lines
Quoted 5 lines
In the KGDB case [where this cropped up], if
cpu_relax()is left as it is, then ansmp_mb()is required in the architecture independent code. This also seems wrong because it's only needed for the ARM11MPCore. There may also potentially be other situations in the Kernel which are prone to deadlock because it is assumed that the write buffer will always drain.Why is KGDB being special about this? Ah yes, it's being brain dead:
<snip>
Quoted 8 lines
Clearly, kgdb is using atomic_set()/atomic_read() in a way which does not match this documentation - it's certainly missing the barriers as required by the above quoted paragraphs.
Let me repeat:
atomic_set()andatomic_read()are NOT atomic. There's nothing atomic about them. All they do is provide a pair of accessors to the underlying value in the atomic type. They are no different to declaring a volatile int and reading/writing it directly.
Indeed. I'm not familiar enough with KGDB internals to dive in and look at all the potential barrier conflicts, so I'll submit a patch that addresses the one that's bitten me so far. Maybe it will motivate somebody else to take a closer look!
Cheers,
Will
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Quoted 8 lines · Will Deacon
Quoted 8 lines
Clearly, kgdb is using atomic_set()/atomic_read() in a way which does not match this documentation - it's certainly missing the barriers as required by the above quoted paragraphs.
Let me repeat:
atomic_set()andatomic_read()are NOT atomic. There's nothing atomic about them. All they do is provide a pair of accessors to the underlying value in the atomic type. They are no different to declaring a volatile int and reading/writing it directly.
Clearly the docs state this.
Quoted 5 lines
Indeed. I'm not familiar enough with KGDB internals to dive in and look at all the potential barrier conflicts, so I'll submit a patch that addresses the one that's bitten me so far. Maybe it will motivate somebody else to take a closer look!
Do you think you can try the patch below?
It seems we might not need to change to using the atomic_add_return(0,...) because using the atomic_inc() and atomic_dec() will end up using the memory barriers.
I would certainly rather fix kgdb vs mucking with the internals of cpu_relax().
Jason.
kernel/kgdb.c +9 -10
@@ -580,14 +580,13 @@ static void kgdb_wait(struct pt_regs *re* Make sure the above info reaches the primary CPU before * our cpu_in_kgdb[] flag setting does: */ -smp_wmb (); -atomic_set (&cpu_in_kgdb[cpu],1 ); +atomic_inc (&cpu_in_kgdb[cpu]);/* Disable any cpu specific hw breakpoints */ kgdb_disable_hw_debug (regs);/* Wait till primary CPU is done with debugging */ -while (atomic_read (&passive_cpu_wait[cpu])) +while (atomic_add_return (0 , &passive_cpu_wait[cpu]))cpu_relax (); kgdb_info[cpu].debuggerinfo =NULL ;
@@ -598,7 +597,7 @@ static void kgdb_wait(struct pt_regs *re arch_kgdb_ops.correct_hw_break ();/* Signal the primary CPU that we are done: */ -atomic_set (&cpu_in_kgdb[cpu],0 ); +atomic_dec (&cpu_in_kgdb[cpu]);touch_softlockup_watchdog_sync ();clocksource_touch_watchdog ();local_irq_restore (flags);
@@ -1493,7 +1492,7 @@ acquirelock:* spin_lock code is good enough as a barrier so we don't * need one here: */ -atomic_set (&cpu_in_kgdb[ks->cpu],1 ); +atomic_inc (&cpu_in_kgdb[ks->cpu]);#ifdef CONFIG_SMP /* Signal the other CPUs to enter kgdb_wait() */
@@ -1505,7 +1504,7 @@ acquirelock:* Wait for the other CPUs to be notified and be waiting for us: */ for_each_online_cpu (i) { -while (!atomic_read (&cpu_in_kgdb[i])) +while (!atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); }
@@ -1528,7 +1527,7 @@ acquirelock: kgdb_info[ks->cpu].debuggerinfo =NULL ; kgdb_info[ks->cpu].task =NULL ; -atomic_set (&cpu_in_kgdb[ks->cpu],0 ); +atomic_dec (&cpu_in_kgdb[ks->cpu]);if (!kgdb_single_step) {for (i =NR_CPUS -1 ; i >=0 ; i--)
@@ -1538,7 +1537,7 @@ acquirelock:* from the debugger. */ for_each_online_cpu (i) { -while (atomic_read (&cpu_in_kgdb[i])) +while (atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); } }
@@ -1742,11 +1741,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod*/ void kgdb_breakpoint (void ) { -atomic_set (&kgdb_setting_breakpoint,1 ); +atomic_inc (&kgdb_setting_breakpoint);wmb ();/* Sync point before breakpoint */ arch_kgdb_breakpoint ();wmb ();/* Sync point after breakpoint */ -atomic_set (&kgdb_setting_breakpoint,0 ); +atomic_dec (&kgdb_setting_breakpoint); }EXPORT_SYMBOL_GPL (kgdb_breakpoint);
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Quoted 20 lines · Jason Wessel
Quoted 8 lines · Will Deacon
Quoted 8 lines
Clearly, kgdb is using atomic_set()/atomic_read() in a way which does not match this documentation - it's certainly missing the barriers as required by the above quoted paragraphs.
Let me repeat:
atomic_set()andatomic_read()are NOT atomic. There's nothing atomic about them. All they do is provide a pair of accessors to the underlying value in the atomic type. They are no different to declaring a volatile int and reading/writing it directly.Clearly the docs state this.
Quoted 4 lines
Indeed. I'm not familiar enough with KGDB internals to dive in and look at all the potential barrier conflicts, so I'll submit a patch that addresses the one that's bitten me so far. Maybe it will motivate somebody else to take a closer look!
Quoted 4 lines
Do you think you can try the patch below?
It seems we might not need to change to using the
atomic_add_return(0,...)because using theatomic_inc()andatomic_dec()will end up using the memory barriers.
Hi Jason,
Maybe we should initial the atomic_t variable before we using such as atomic_inc/dec() directly.
Dongdong.
kernel/kgdb.c +0 -0
@@ -227,6 +227,17 @@ kgdb_post_primary_code(struct pt_regs *regs, int
e_vector, int err_code)
return;
}
+static void kgdb_initial_atomic_var()
+{
+ int i;
+ for (i = NR_CPUS-1; i >= 0; i--) {
+ atomic_set(&passive_cpu_wait[i], 0);
+ atomic_set(&cpu_in_kgdb[i], 0);
+ }
+
+ atomic_set(&kgdb_setting_breakpoint, 0);
+}
+
/**
* kgdb_disable_hw_debug - Disable hardware debugging while we in
kgdb.
* @regs: Current &struct pt_regs.
@@ -1619,6 +1630,7 @@ static void kgdb_register_callbacks(void)
{
if (!kgdb_io_module_registered) {
kgdb_io_module_registered = 1;
+ kgdb_initial_atomic_var();
kgdb_arch_init();
#ifdef CONFIG_MAGIC_SYSRQ
register_sysrq_key('g', &sysrq_gdb_op);Quoted 95 lines
I would certainly rather fix kgdb vs mucking with the internals of
cpu_relax().Jason.
kernel/kgdb.c +9
-11@@ -580,14 +580,13 @@ static void kgdb_wait(struct pt_regs *re* Make sure the above info reaches the primary CPU before * our cpu_in_kgdb[] flag setting does: */ -smp_wmb (); -atomic_set (&cpu_in_kgdb[cpu],1 ); +atomic_inc (&cpu_in_kgdb[cpu]);/* Disable any cpu specific hw breakpoints */ kgdb_disable_hw_debug (regs);/* Wait till primary CPU is done with debugging */ -while (atomic_read (&passive_cpu_wait[cpu])) +while (atomic_add_return (0 , &passive_cpu_wait[cpu]))cpu_relax (); kgdb_info[cpu].debuggerinfo =NULL ;@@ -598,7 +597,7 @@ static void kgdb_wait(struct pt_regs *re arch_kgdb_ops.correct_hw_break ();/* Signal the primary CPU that we are done: */ -atomic_set (&cpu_in_kgdb[cpu],0 ); +atomic_dec (&cpu_in_kgdb[cpu]);touch_softlockup_watchdog_sync ();clocksource_touch_watchdog ();local_irq_restore (flags);@@ -1493,7 +1492,7 @@ acquirelock:* spin_lock code is good enough as a barrier so we don't * need one here: */ -atomic_set (&cpu_in_kgdb[ks->cpu],1 ); +atomic_inc (&cpu_in_kgdb[ks->cpu]);#ifdef CONFIG_SMP /* Signal the other CPUs to enter kgdb_wait() */ @@ -1505,7 +1504,7 @@ acquirelock:* Wait for the other CPUs to be notified and be waiting for us: */ for_each_online_cpu (i) { -while (!atomic_read (&cpu_in_kgdb[i])) +while (!atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); }@@ -1528,7 +1527,7 @@ acquirelock: kgdb_info[ks->cpu].debuggerinfo =NULL ; kgdb_info[ks->cpu].task =NULL ; -atomic_set (&cpu_in_kgdb[ks->cpu],0 ); +atomic_dec (&cpu_in_kgdb[ks->cpu]);if (!kgdb_single_step) {for (i =NR_CPUS -1 ; i >=0 ; i--)@@ -1538,7 +1537,7 @@ acquirelock:* from the debugger. */ for_each_online_cpu (i) { -while (atomic_read (&cpu_in_kgdb[i])) +while (atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); } }@@ -1742,11 +1741,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod*/ void kgdb_breakpoint (void ) { -atomic_set (&kgdb_setting_breakpoint,1 ); +atomic_inc (&kgdb_setting_breakpoint);wmb ();/* Sync point before breakpoint */ arch_kgdb_breakpoint ();wmb ();/* Sync point after breakpoint */ -atomic_set (&kgdb_setting_breakpoint,0 ); +atomic_dec (&kgdb_setting_breakpoint); }EXPORT_SYMBOL_GPL (kgdb_breakpoint); ------------------------------------------------------------------------------Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Kgdb-bugreport mailing list
Kgdb-bugreport at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kgdb-bugreport
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Quoted 14 lines
Maybe we should initial the
atomic_tvariable before we using such as atomic_inc/dec() directly.Dongdong.
kernel/kgdb.c +1
-0@@ -227,6 +227,17 @@ kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)return ; } +static void kgdb_initial_atomic_var ()
kernel/kgdb.c kgdb_post_primary_code(struct pt_regs *regs, int · line 241
Quoted 10 lines
kernel/kgdb.c +10
-0+{ +int i; +for (i =NR_CPUS -1 ; i >=0 ; i--) { +atomic_set (&passive_cpu_wait[i],0 ); +atomic_set (&cpu_in_kgdb[i],0 ); + } + +atomic_set (&kgdb_setting_breakpoint,0 ); +} +
Given that passive_cpu_wait and cpu_in_kgdb are static, I think those guys are alright as-is. kgdb_setting_breakpoint should probably be reset though.
Will
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
In reply to Jason WesselHello Jason,
Quoted 1 line
Do you think you can try the patch below?
Sure - I'll give it a go this afternoon.
Quoted 2 lines
It seems we might not need to change to using the
atomic_add_return(0,...)because using theatomic_inc()andatomic_dec()will end up using the memory barriers.
The fix I posted to the LKML here:
http://lkml.org/lkml/2010/3/9/260
fixed the issue for me, but your patch seems more general [although maybe overkill?].
Quoted 1 line
I would certainly rather fix kgdb vs mucking with the internals of
cpu_relax().
I think that's the general consensus. I was worried about changing the general KGDB code to fix an ARM specific problem, but it turns out that the problem is an issue of semantics.
I'll let you know whether your patch fixes the problems for me.
Will
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
In reply to Jason WesselQuoted 1 line
Do you think you can try the patch below?
<snip>
Quoted 67 lines
kernel/kgdb.c +7
-8@@ -580,14 +580,13 @@ static void kgdb_wait(struct pt_regs *re* Make sure the above info reaches the primary CPU before * our cpu_in_kgdb[] flag setting does: */ -smp_wmb (); -atomic_set (&cpu_in_kgdb[cpu],1 ); +atomic_inc (&cpu_in_kgdb[cpu]);/* Disable any cpu specific hw breakpoints */ kgdb_disable_hw_debug (regs);/* Wait till primary CPU is done with debugging */ -while (atomic_read (&passive_cpu_wait[cpu])) +while (atomic_add_return (0 , &passive_cpu_wait[cpu]))cpu_relax (); kgdb_info[cpu].debuggerinfo =NULL ;@@ -598,7 +597,7 @@ static void kgdb_wait(struct pt_regs *re arch_kgdb_ops.correct_hw_break ();/* Signal the primary CPU that we are done: */ -atomic_set (&cpu_in_kgdb[cpu],0 ); +atomic_dec (&cpu_in_kgdb[cpu]);touch_softlockup_watchdog_sync ();clocksource_touch_watchdog ();local_irq_restore (flags);@@ -1493,7 +1492,7 @@ acquirelock:* spin_lock code is good enough as a barrier so we don't * need one here: */ -atomic_set (&cpu_in_kgdb[ks->cpu],1 ); +atomic_inc (&cpu_in_kgdb[ks->cpu]);#ifdef CONFIG_SMP /* Signal the other CPUs to enter kgdb_wait() */ @@ -1505,7 +1504,7 @@ acquirelock:* Wait for the other CPUs to be notified and be waiting for us: */ for_each_online_cpu (i) { -while (!atomic_read (&cpu_in_kgdb[i])) +while (!atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); }@@ -1528,7 +1527,7 @@ acquirelock: kgdb_info[ks->cpu].debuggerinfo =NULL ; kgdb_info[ks->cpu].task =NULL ; -atomic_set (&cpu_in_kgdb[ks->cpu],0 ); +atomic_dec (&cpu_in_kgdb[ks->cpu]);if (!kgdb_single_step) {for (i =NR_CPUS -1 ; i >=0 ; i--)@@ -1538,7 +1537,7 @@ acquirelock:* from the debugger. */ for_each_online_cpu (i) { -while (atomic_read (&cpu_in_kgdb[i])) +while (atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); } }@@ -1742,11 +1741,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod*/ void kgdb_breakpoint (void )
kernel/kgdb.c EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod · line 1750
Quoted 10 lines
kernel/kgdb.c +2
-2{ -atomic_set (&kgdb_setting_breakpoint,1 ); +atomic_inc (&kgdb_setting_breakpoint);wmb ();/* Sync point before breakpoint */ arch_kgdb_breakpoint ();wmb ();/* Sync point after breakpoint */ -atomic_set (&kgdb_setting_breakpoint,0 ); +atomic_dec (&kgdb_setting_breakpoint); }EXPORT_SYMBOL_GPL (kgdb_breakpoint);
Appears to work, but it's hard to be 100% with these sorts of things. I ran the basic testsuite, the fork tests and the breakpoint tests as mentioned in drivers/misc/kgdbts.c. The patch might introduce more barriers than we really need, but this isn't performance-critical code and without it, KGDB is broken, so:
Cheers,
Will
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
In reply to Jason WesselHi Jason,
Quoted 78 lines
Do you think you can try the patch below?
It seems we might not need to change to using the
atomic_add_return(0,...)because using theatomic_inc()andatomic_dec()will end up using the memory barriers.I would certainly rather fix kgdb vs mucking with the internals of
cpu_relax().Jason.
kernel/kgdb.c +7
-8@@ -580,14 +580,13 @@ static void kgdb_wait(struct pt_regs *re* Make sure the above info reaches the primary CPU before * our cpu_in_kgdb[] flag setting does: */ -smp_wmb (); -atomic_set (&cpu_in_kgdb[cpu],1 ); +atomic_inc (&cpu_in_kgdb[cpu]);/* Disable any cpu specific hw breakpoints */ kgdb_disable_hw_debug (regs);/* Wait till primary CPU is done with debugging */ -while (atomic_read (&passive_cpu_wait[cpu])) +while (atomic_add_return (0 , &passive_cpu_wait[cpu]))cpu_relax (); kgdb_info[cpu].debuggerinfo =NULL ;@@ -598,7 +597,7 @@ static void kgdb_wait(struct pt_regs *re arch_kgdb_ops.correct_hw_break ();/* Signal the primary CPU that we are done: */ -atomic_set (&cpu_in_kgdb[cpu],0 ); +atomic_dec (&cpu_in_kgdb[cpu]);touch_softlockup_watchdog_sync ();clocksource_touch_watchdog ();local_irq_restore (flags);@@ -1493,7 +1492,7 @@ acquirelock:* spin_lock code is good enough as a barrier so we don't * need one here: */ -atomic_set (&cpu_in_kgdb[ks->cpu],1 ); +atomic_inc (&cpu_in_kgdb[ks->cpu]);#ifdef CONFIG_SMP /* Signal the other CPUs to enter kgdb_wait() */ @@ -1505,7 +1504,7 @@ acquirelock:* Wait for the other CPUs to be notified and be waiting for us: */ for_each_online_cpu (i) { -while (!atomic_read (&cpu_in_kgdb[i])) +while (!atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); }@@ -1528,7 +1527,7 @@ acquirelock: kgdb_info[ks->cpu].debuggerinfo =NULL ; kgdb_info[ks->cpu].task =NULL ; -atomic_set (&cpu_in_kgdb[ks->cpu],0 ); +atomic_dec (&cpu_in_kgdb[ks->cpu]);if (!kgdb_single_step) {for (i =NR_CPUS -1 ; i >=0 ; i--)@@ -1538,7 +1537,7 @@ acquirelock:* from the debugger. */ for_each_online_cpu (i) { -while (atomic_read (&cpu_in_kgdb[i])) +while (atomic_add_return (0 , &cpu_in_kgdb[i]))cpu_relax (); } }@@ -1742,11 +1741,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod*/ void kgdb_breakpoint (void ) {
kernel/kgdb.c EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod · line 1751
Quoted 10 lines
kernel/kgdb.c +2
-2-atomic_set (&kgdb_setting_breakpoint,1 ); +atomic_inc (&kgdb_setting_breakpoint);wmb ();/* Sync point before breakpoint */ arch_kgdb_breakpoint ();wmb ();/* Sync point after breakpoint */ -atomic_set (&kgdb_setting_breakpoint,0 ); +atomic_dec (&kgdb_setting_breakpoint); }EXPORT_SYMBOL_GPL (kgdb_breakpoint);
What's the status on this patch? Russell has applied the ARM SMP code to his tree now, so it would be good to get this patch into KGDB to avoid the deadlock on ARM11MPCore.
I only ask because I can't see it in -next [although I see kgdb.c has moved!].
Cheers,
Will
PATCH 1/1 ARM: change definition of cpu_relax() for ARM11MPCore
Quoted 8 lines · Will Deacon
Hi Jason,
What's the status on this patch? Russell has applied the ARM SMP code to his tree now, so it would be good to get this patch into KGDB to avoid the deadlock on ARM11MPCore.
Linux-next presently reflects the state of the outstanding pull request I have to Linus. I have yet to hear back any word as to what happened with my pull request.
Quoted 2 lines
I only ask because I can't see it in -next [although I see
kgdb.chas moved!].
It lives in kernel/debug/debug_core.c, assuming the code in linux-next gets pulled into Linus's tree. I already have an updated version of the patch for the new structure, but not pushed to linux-next while my pull request is in limbo.
Jason.