public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Brad Mouring" <bmouring@ni.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	Jason Low <jason.low2@hp.com>, Brad Mouring <bmouring@ni.com>
Subject: Re: [patch V3 7/7] rtmutex: Avoid pointless requeueing in the deadlock detection chain walk
Date: Tue, 10 Jun 2014 09:57:25 -0500	[thread overview]
Message-ID: <20140610145725.GA29976@linuxgetsreal> (raw)
In-Reply-To: <20140609202336.506044876@linutronix.de>

On Mon, Jun 09, 2014 at 08:28:10PM -0000, Thomas Gleixner wrote:
> In case the dead lock detector is enabled we follow the lock chain to
> the end in rt_mutex_adjust_prio_chain, even if we could stop earlier
> due to the priority/waiter constellation.
> 
> But once we are not longer the top priority waiter in a certain step
> or the task holding the lock has already the same priority then there
> is no point in dequeing and enqueing along the lock chain as there is
> no change at all.
> 
> So stop the requeueing at this point.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  kernel/locking/rtmutex.c |   61 +++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 54 insertions(+), 7 deletions(-)
> 
> Index: tip/kernel/locking/rtmutex.c
> ===================================================================
> --- tip.orig/kernel/locking/rtmutex.c
> +++ tip/kernel/locking/rtmutex.c
> @@ -359,6 +359,7 @@ static int rt_mutex_adjust_prio_chain(st
>  	struct rt_mutex *lock;
>  	bool detect_deadlock;
>  	unsigned long flags;
> +	bool requeue = true;
>  
>  	detect_deadlock = rt_mutex_cond_detect_deadlock(orig_waiter, chwalk);
>  
> @@ -436,18 +437,31 @@ static int rt_mutex_adjust_prio_chain(st
>  			goto out_unlock_pi;
>  		/*
>  		 * If deadlock detection is off, we stop here if we
> -		 * are not the top pi waiter of the task.
> +		 * are not the top pi waiter of the task. If deadlock
> +		 * detection is enabled we continue, but stop the
> +		 * requeueing in the chain walk.
>  		 */
> -		if (!detect_deadlock && top_waiter != task_top_pi_waiter(task))
> -			goto out_unlock_pi;
> +		if (top_waiter != task_top_pi_waiter(task)) {
> +			if (!detect_deadlock)
> +				goto out_unlock_pi;
> +			else
> +				requeue = false;
> +		}
>  	}
>  
>  	/*
> -	 * When deadlock detection is off then we check, if further
> -	 * priority adjustment is necessary.
> +	 * If the waiter priority is the same as the task priority
> +	 * then there is no further priority adjustment necessary.  If
> +	 * deadlock detection is off, we stop the chain walk. If its
s/its/it's/
> +	 * enabled we continue, but stop the requeueing in the chain
> +	 * walk.
>  	 */
> -	if (!detect_deadlock && waiter->prio == task->prio)
> -		goto out_unlock_pi;
> +	if (waiter->prio == task->prio) {
> +		if (!detect_deadlock)
> +			goto out_unlock_pi;
> +		else
> +			requeue = false;
> +	}
>  
>  	/*
>  	 * We need to trylock here as we are holding task->pi_lock,
> @@ -475,6 +489,39 @@ static int rt_mutex_adjust_prio_chain(st
>  	}
>  
>  	/*
> +	 * If we just follow the lock chain for deadlock detection, no
> +	 * need to do all the requeue operations. We avoid a truckload
> +	 * of conditinals around the various places below and just do
> +	 * the minimum chain walk checks here.
> +	 */
> +	if (!requeue) {
> +		/* Release the task */
> +		raw_spin_unlock_irqrestore(&task->pi_lock, flags);
> +		put_task_struct(task);
> +
> +		/* If there is no owner of the lock, end of chain. */
> +		if (!rt_mutex_owner(lock)) {
> +			raw_spin_unlock(&lock->wait_lock);
> +			return 0;
> +		}
> +
> +		/* Grab the next task, i.e. owner of @lock */
> +		task = rt_mutex_owner(lock);
> +		get_task_struct(task);
> +		raw_spin_lock_irqsave(&task->pi_lock, flags);
> +
> +		/* Store whether owner is blocked itself and drop locks */
> +		next_lock = task_blocked_on(task);
task_blocked_on(task) is not clear to me, the recipient of the
return is the only clue that hints at what the function does.
> +		raw_spin_unlock_irqrestore(&task->pi_lock, flags);
> +		raw_spin_unlock(&lock->wait_lock);
> +
> +		/* If owner is not blocked, end of chain. */
> +		if (!next_lock)
> +			goto out_put_task;
> +		goto again;
> +	}
> +
> +	/*
>  	 * Store the current top waiter before doing the requeue
>  	 * operation on @lock. We need it for the boost/deboost
>  	 * decision below.
> 
> 

  parent reply	other threads:[~2014-06-10 14:58 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09 20:28 [patch V3 0/7] rtmutex: Code clarification and optimization Thomas Gleixner
2014-06-09 20:28 ` [patch V3 1/7] rtmutex: Deobfuscate chain walk Thomas Gleixner
2014-06-09 20:59   ` Steven Rostedt
2014-06-10  3:52     ` Lai Jiangshan
2014-06-10  3:21   ` Jason Low
2014-06-10 13:57   ` Brad Mouring
2014-06-09 20:28 ` [patch V3 2/7] rtmutex: Clarify the boost/deboost part Thomas Gleixner
2014-06-10  0:37   ` Steven Rostedt
2014-06-10  3:22   ` Jason Low
2014-06-10 14:04   ` Brad Mouring
2014-06-09 20:28 ` [patch V3 3/7] rtmutex: Document pi chain walk Thomas Gleixner
2014-06-10  0:45   ` Steven Rostedt
2014-06-10  3:51     ` Lai Jiangshan
2014-06-10 14:21   ` Brad Mouring
2014-06-09 20:28 ` [patch V3 4/7] rtmutex: Siplify remove_waiter() Thomas Gleixner
2014-06-10  0:53   ` Steven Rostedt
2014-06-10  3:35     ` Lai Jiangshan
2014-06-10  3:44     ` Jason Low
2014-06-10 14:10   ` Brad Mouring
2014-06-09 20:28 ` [patch V3 5/7] rtmutex: Confine deadlock logic to futex Thomas Gleixner
2014-06-10  0:59   ` Steven Rostedt
2014-06-10  4:03     ` Lai Jiangshan
2014-06-10 17:39     ` Thomas Gleixner
2014-06-09 20:28 ` [patch V3 6/7] rtmutex: Cleanup deadlock detector debug logic Thomas Gleixner
2014-06-10  1:04   ` Steven Rostedt
2014-06-10 15:09   ` Brad Mouring
2014-06-09 20:28 ` [patch V3 7/7] rtmutex: Avoid pointless requeueing in the deadlock detection chain walk Thomas Gleixner
2014-06-10  1:20   ` Steven Rostedt
2014-06-10  3:48     ` Jason Low
2014-06-10 17:41     ` Thomas Gleixner
2014-06-10 17:47       ` Steven Rostedt
2014-06-10 20:45         ` Thomas Gleixner
2014-06-10 14:57   ` Brad Mouring [this message]
2014-06-10 15:19     ` Steven Rostedt
2014-06-10 17:43       ` Thomas Gleixner
2014-06-10 17:51         ` Steven Rostedt
2014-06-10 20:46           ` Thomas Gleixner
2014-06-10  0:27 ` [patch V3 0/7] rtmutex: Code clarification and optimization Steven Rostedt
2014-06-10  0:35   ` Steven Rostedt
2014-06-10  3:00     ` Lai Jiangshan

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=20140610145725.GA29976@linuxgetsreal \
    --to=bmouring@ni.com \
    --cc=jason.low2@hp.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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