mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Wang, Xiaoming" <xiaoming.wang@intel.com>
To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org
Cc: chuansheng.liu@intel.com
Subject: [PATCH] lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.
Date: Wed, 30 Apr 2014 13:04:31 -0400	[thread overview]
Message-ID: <1398877471.21870.6.camel@wxm-ubuntu> (raw)

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



             reply	other threads:[~2014-04-30  2:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-30 17:04 Wang, Xiaoming [this message]
2014-04-30  6:06 ` Peter Zijlstra
2014-04-30  6:17   ` Wang, Xiaoming
2014-04-30  7:43     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398877471.21870.6.camel@wxm-ubuntu \
    --to=xiaoming.wang@intel.com \
    --cc=chuansheng.liu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®