All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>, Jason Low <jason.low2@hp.com>,
	Brad Mouring <bmouring@ni.com>
Subject: Re: [patch V3 3/7] rtmutex: Document pi chain walk
Date: Tue, 10 Jun 2014 11:51:16 +0800	[thread overview]
Message-ID: <539680B4.6050908@cn.fujitsu.com> (raw)
In-Reply-To: <20140609204514.4a1e2da7@gandalf.local.home>

On 06/10/2014 08:45 AM, Steven Rostedt wrote:
> On Mon, 09 Jun 2014 20:28:08 -0000
> Thomas Gleixner <tglx@linutronix.de> wrote:
> 
>> Add commentry to document the chain walk and the protection mechanisms
>> and their scope.
>>
>> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
>> ---
>>  kernel/locking/rtmutex.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 52 insertions(+)
>>
>> Index: tip/kernel/locking/rtmutex.c
>> ===================================================================
>> --- tip.orig/kernel/locking/rtmutex.c
>> +++ tip/kernel/locking/rtmutex.c
>> @@ -285,6 +285,47 @@ static inline struct rt_mutex *task_bloc
>>   * @top_task:	the current top waiter
>>   *
>>   * Returns 0 or -EDEADLK.
>> + *
>> + * Chain walk basics and protection scope
>> + *
>> + * [A] refcount on task
>> + * [B] task->pi_lock held
>> + * [C] rtmutex->lock held
> 
> A,B, C is rather meaningless, and requires constant looking back up at
> the key. Perhaps [R],[P] and [L]
> 
>  [R] refcount on task (get_task_struct)
>  [P] task->pi_lock held
>  [L] rtmutex->lock held
> 
> 
> That way we can associate R being refcount, P being pi_lock and L being
> lock. Easier to remember.
> 
> 
>> + *
>> + * call()					Protected by
> 
> "call()"?
> 
>> + *	@task					[A]
>> + *	@orig_lock if != NULL			@top_task is blocked on it
>> + *	@next_lock				Unprotected. Cannot be
>> + *						dereferenced. Only used for
>> + *						comparison.
>> + *	@orig_waiter if != NULL			@top_task is blocked on it
>> + *	@top_task				current, or in case of proxy
>> + *						locking protected by calling
>> + *						code
>> + * again:
>> + *	loop_sanity_check();
>> + * retry:
>> + *	lock(task->pi_lock);			[A] acquire [B]
>> + *	waiter = task->pi_blocked_on;		[B]
>> + *	check_exit_conditions();		[B]
>> + *	lock = waiter->lock;			[B]
>> + *	if (!try_lock(lock->wait_lock)) {	[B] try to acquire [C]
>> + *		unlock(task->pi_lock);		drop [B]
>> + *		goto retry;
>> + *	}
>> + *	check_exit_conditions();		[B] + [C]
>> + *	requeue_lock_waiter(lock, waiter);	[B] + [C]
>> + *	unlock(task->pi_lock);			drop [B]
>> + *	drop_task_ref(task);			drop [A]
> 
> Maybe just state "put_task_struct()", less abstractions.
> 
>> + *	check_exit_conditions();		[C]
>> + *	task = owner(lock);			[C]
>> + *	get_task_ref(task);			[C] acquire [A]
> 
> get_task_struct()
> 
> -- Steve
> 
>> + *	lock(task->pi_lock);			[C] acquire [B]
>> + *	requeue_pi_waiter(task, waiters(lock));	[B] + [C]
>> + *	check_exit_conditions();		[B] + [C]
>> + *	unlock(task->pi_lock);			drop [B]
>> + *	unlock(lock->wait_lock);		drop [C]
>> + *	goto again;
>>   */

There are four check_exit_conditions()s with the same name but with different locking.

I don't think it is a good a idea to copy the code to the comment of
the function description, we will need to always keep them coincident forever.

I prefer to comment them in the function body or comment them
in higher level abstraction.

>>  static int rt_mutex_adjust_prio_chain(struct task_struct *task,
>>  				      int deadlock_detect,
>> @@ -326,6 +367,12 @@ static int rt_mutex_adjust_prio_chain(st
>>  
>>  		return -EDEADLK;
>>  	}
>> +
>> +	/*
>> +	 * We are fully preemptible here and only hold the refcount on
>> +	 * @task. So everything can have changed under us since the
>> +	 * caller or our own code below (goto retry) dropped all locks.
>> +	 */
>>   retry:
>>  	/*
>>  	 * Task can not go away as we did a get_task() before !
>> @@ -383,6 +430,11 @@ static int rt_mutex_adjust_prio_chain(st
>>  	if (!detect_deadlock && waiter->prio == task->prio)
>>  		goto out_unlock_pi;
>>  
>> +	/*
>> +	 * We need to trylock here as we are holding task->pi_lock,
>> +	 * which is the reverse lock order versus the other rtmutex
>> +	 * operations.
>> +	 */
>>  	lock = waiter->lock;
>>  	if (!raw_spin_trylock(&lock->wait_lock)) {
>>  		raw_spin_unlock_irqrestore(&task->pi_lock, flags);
>>
> 
> .
> 


  reply	other threads:[~2014-06-10  3:46 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 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 3/7] rtmutex: Document pi chain walk Thomas Gleixner
2014-06-10  0:45   ` Steven Rostedt
2014-06-10  3:51     ` Lai Jiangshan [this message]
2014-06-10 14:21   ` 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
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=539680B4.6050908@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=bmouring@ni.com \
    --cc=jason.low2@hp.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 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.