All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	"Ted Ts'o" <tytso@mit.edu>, Greg KH <greg@kroah.com>,
	Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
	akpm@linux-foundation.org
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [RFC][PATCH 5/7] semaphore: Pull wakeup out from under sem->lock
Date: Wed, 21 Dec 2011 11:57:44 +0100	[thread overview]
Message-ID: <20111221111143.568920970@chello.nl> (raw)
In-Reply-To: 20111221105739.798864333@chello.nl

[-- Attachment #1: sem-vs-printk.patch --]
[-- Type: text/plain, Size: 2677 bytes --]

Rather horrid patch this, surely there's a better way..

rcuc/1/13 is trying to acquire lock:
 ((console_sem).lock){-.-...}, at:
but task is already holding lock:
 (&rt_rq->rt_runtime_lock){-.....}, at:
which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

 -> #3 (&rt_rq->rt_runtime_lock){-.....}:
 -> #2 (&rq->lock){-.-.-.}:
 -> #1 (&p->pi_lock){-.-.-.}:
 -> #0 ((console_sem).lock){-.-...}:

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 kernel/semaphore.c |   46 +++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)
--- a/kernel/semaphore.c
+++ b/kernel/semaphore.c
@@ -168,6 +168,14 @@ int down_timeout(struct semaphore *sem, 
 }
 EXPORT_SYMBOL(down_timeout);
 
+/* Functions for the contended case */
+
+struct semaphore_waiter {
+	struct list_head list;
+	struct task_struct *task;
+	int up;
+};
+
 /**
  * up - release the semaphore
  * @sem: the semaphore to release
@@ -177,32 +185,36 @@ EXPORT_SYMBOL(down_timeout);
  */
 void up(struct semaphore *sem)
 {
+	struct semaphore_waiter *waiter;
+	struct task_struct *task;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&sem->lock, flags);
-	if (likely(list_empty(&sem->wait_list)))
+	if (likely(list_empty(&sem->wait_list))) {
 		sem->count++;
-	else
-		__up(sem);
+		raw_spin_unlock_irqrestore(&sem->lock, flags);
+		return;
+	}
+
+	waiter = list_first_entry(&sem->wait_list, struct semaphore_waiter, list);
+	task = waiter->task;
+	list_del(&waiter->list);
+	waiter->up = 1;
+	get_task_struct(task);
 	raw_spin_unlock_irqrestore(&sem->lock, flags);
+
+	wake_up_process(task);
+	put_task_struct(task);
 }
 EXPORT_SYMBOL(up);
 
-/* Functions for the contended case */
-
-struct semaphore_waiter {
-	struct list_head list;
-	struct task_struct *task;
-	int up;
-};
-
 /*
  * Because this function is inlined, the 'state' parameter will be
  * constant, and thus optimised away by the compiler.  Likewise the
  * 'timeout' parameter for the cases without timeouts.
  */
-static inline int __sched __down_common(struct semaphore *sem, long state,
-								long timeout)
+static inline
+int __sched __down_common(struct semaphore *sem, long state, long timeout)
 {
 	struct task_struct *task = current;
 	struct semaphore_waiter waiter;
@@ -253,11 +265,3 @@ static noinline int __sched __down_timeo
 	return __down_common(sem, TASK_UNINTERRUPTIBLE, jiffies);
 }
 
-static noinline void __sched __up(struct semaphore *sem)
-{
-	struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list,
-						struct semaphore_waiter, list);
-	list_del(&waiter->list);
-	waiter->up = 1;
-	wake_up_process(waiter->task);
-}



  parent reply	other threads:[~2011-12-21 11:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-21 10:57 [RFC][PATCH 0/7] improve printk reliability Peter Zijlstra
2011-12-21 10:57 ` [RFC][PATCH 1/7] arch, early_printk: Consolidate early_printk() implementations Peter Zijlstra
2011-12-21 17:01   ` Mike Frysinger
2011-12-21 17:03   ` Peter Zijlstra
2011-12-21 19:23   ` David Miller
2011-12-21 10:57 ` [RFC][PATCH 2/7] lockdep: Provide early_printk() support Peter Zijlstra
2011-12-21 10:57 ` [RFC][PATCH 3/7] printk, lockdep: Remove lockdep_off() usage Peter Zijlstra
2011-12-21 10:57 ` [RFC][PATCH 4/7] printk: Rework printk recursion Peter Zijlstra
2011-12-21 10:57 ` Peter Zijlstra [this message]
2011-12-21 10:57 ` [RFC][PATCH 6/7] printk: Poke printk extra hard Peter Zijlstra
2011-12-22  1:17   ` Linus Torvalds
2011-12-22  7:02     ` Ingo Molnar
2011-12-22  8:43       ` Peter Zijlstra
2011-12-22  9:03         ` Ingo Molnar
2011-12-22  9:14           ` Peter Zijlstra
2011-12-22 10:15             ` Ingo Molnar
2011-12-22 10:19               ` Peter Zijlstra
2011-12-21 10:57 ` [RFC][PATCH 7/7] serial, 8250: Mostly avoid wakeups from under port->lock Peter Zijlstra
2011-12-21 16:03   ` Alan Cox
2011-12-21 16:22     ` Peter Zijlstra
2011-12-21 16:30       ` Peter Zijlstra
2011-12-21 18:51       ` Alan Cox
2011-12-21 11:23 ` [RFC][PATCH 0/7] improve printk reliability 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=20111221111143.568920970@chello.nl \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.