mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.
  2014-04-30 17:04 [PATCH] lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time Wang, Xiaoming
@ 2014-04-30  6:06 ` Peter Zijlstra
  2014-04-30  6:17   ` Wang, Xiaoming
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2014-04-30  6:06 UTC (permalink / raw)
  To: Wang, Xiaoming; +Cc: mingo, linux-kernel, chuansheng.liu

On Wed, Apr 30, 2014 at 01:04:31PM -0400, Wang, Xiaoming wrote:
> loops_per_jiffy is larger than expectation that possible
> causes one thread can not obtain the spin lock for a long time.
> So use cpu_clock() to reach timeout in one second which can
> avoid HARD LOCKUP.

This is just not making sense.. one thing is broken so then you tape on
another? Fix the first already.

Also, why do you care?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.
  2014-04-30  6:06 ` Peter Zijlstra
@ 2014-04-30  6:17   ` Wang, Xiaoming
  2014-04-30  7:43     ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Wang, Xiaoming @ 2014-04-30  6:17 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, linux-kernel, Liu, Chuansheng

Dear Peter
	If we wait the end of loop as loops_per_jiffy. 
It may last more than 130s and local IRQ disabled at interval 
which may cause Hard LOCKUP. We break out in 1 second and
dump the stack for debug.

> -----Original Message-----
> From: Peter Zijlstra [mailto:peterz@infradead.org]
> Sent: Wednesday, April 30, 2014 2:06 PM
> To: Wang, Xiaoming
> Cc: mingo@redhat.com; linux-kernel@vger.kernel.org; Liu, Chuansheng
> Subject: Re: [PATCH] lib/spinlock_debug: avoid one thread can not obtain
> the spinlock for a long time.
> 
> On Wed, Apr 30, 2014 at 01:04:31PM -0400, Wang, Xiaoming wrote:
> > loops_per_jiffy is larger than expectation that possible causes one
> > thread can not obtain the spin lock for a long time.
> > So use cpu_clock() to reach timeout in one second which can avoid
> HARD
> > LOCKUP.
> 
> This is just not making sense.. one thing is broken so then you tape on
> another? Fix the first already.
> 
> Also, why do you care?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.
  2014-04-30  6:17   ` Wang, Xiaoming
@ 2014-04-30  7:43     ` Peter Zijlstra
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2014-04-30  7:43 UTC (permalink / raw)
  To: Wang, Xiaoming; +Cc: mingo, linux-kernel, Liu, Chuansheng

On Wed, Apr 30, 2014 at 06:17:48AM +0000, Wang, Xiaoming wrote:
> Dear Peter
> 	If we wait the end of loop as loops_per_jiffy. 
> It may last more than 130s and local IRQ disabled at interval 
> which may cause Hard LOCKUP. We break out in 1 second and
> dump the stack for debug.

Yeah, so? That makes shoddy engineering alright then?

So either fix the loops_per_jiffy thing, it is supposed to wait for 1
second after all, or explain why its broken and entirely replace it.

What you do not do is make a loop with 2 differently broken timeouts and
hope one works.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.
@ 2014-04-30 17:04 Wang, Xiaoming
  2014-04-30  6:06 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Wang, Xiaoming @ 2014-04-30 17:04 UTC (permalink / raw)
  To: peterz, mingo, linux-kernel; +Cc: chuansheng.liu

loops_per_jiffy is larger than expectation that possible
causes one thread can not obtain the spin lock for a long time.
So use cpu_clock() to reach timeout in one second which can
avoid HARD LOCKUP.

Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
Signed-off-by: xiaoming wang <xiaoming.wang@intel.com>
---
 kernel/locking/spinlock_debug.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c
index 0374a59..5d3c4f3 100644
--- a/kernel/locking/spinlock_debug.c
+++ b/kernel/locking/spinlock_debug.c
@@ -105,13 +105,19 @@ static inline void debug_spin_unlock(raw_spinlock_t *lock)
 
 static void __spin_lock_debug(raw_spinlock_t *lock)
 {
-	u64 i;
+	u64 i, t;
 	u64 loops = loops_per_jiffy * HZ;
+	u64 one_second = 1000000000;
+	u32 this_cpu = raw_smp_processor_id();
+
+	t = cpu_clock(this_cpu);
 
 	for (i = 0; i < loops; i++) {
 		if (arch_spin_trylock(&lock->raw_lock))
 			return;
 		__delay(1);
+		if (cpu_clock(this_cpu) - t > one_second)
+			break;
 	}
 	/* lockup suspected: */
 	spin_dump(lock, "lockup suspected");
-- 
1.7.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-30  7:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-30 17:04 [PATCH] lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time Wang, Xiaoming
2014-04-30  6:06 ` Peter Zijlstra
2014-04-30  6:17   ` Wang, Xiaoming
2014-04-30  7:43     ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®