lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 07 Jan 2009 15:34:47 +0800
From:	Lai Jiangshan <laijs@...fujitsu.com>
To:	Peter Zijlstra <peterz@...radead.org>
CC:	Linus Torvalds <torvalds@...ux-foundation.org>,
	paulmck@...ux.vnet.ibm.com, Gregory Haskins <ghaskins@...ell.com>,
	Ingo Molnar <mingo@...e.hu>, Matthew Wilcox <matthew@....cx>,
	Andi Kleen <andi@...stfloor.org>,
	Chris Mason <chris.mason@...cle.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org,
	linux-fsdevel <linux-fsdevel@...r.kernel.org>,
	linux-btrfs <linux-btrfs@...r.kernel.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Steven Rostedt <rostedt@...dmis.org>,
	Nick Piggin <npiggin@...e.de>,
	Peter Morreale <pmorreale@...ell.com>,
	Sven Dietrich <SDietrich@...ell.com>
Subject: Re: [PATCH][RFC]: mutex: adaptive spin

Peter Zijlstra wrote:
> On Wed, 2009-01-07 at 11:57 +0800, Lai Jiangshan wrote:
>> Peter Zijlstra wrote:
>>> +void mutex_spin_or_schedule(struct mutex_waiter *waiter, long state, unsigned long *flags)
>>> +{
>>> +	struct mutex *lock = waiter->lock;
>>> +	struct task_struct *task = waiter->task;
>>> +	struct task_struct *owner = lock->owner;
>>> +	struct rq *rq;
>>> +
>>> +	if (!owner)
>>> +		goto do_schedule;
>>> +
>>> +	rq = task_rq(owner);
>>> +
>>> +	if (rq->curr != owner) {
>>> +do_schedule:
>>> +		__set_task_state(task, state);
>>> +		spin_unlock_mutex(&lock->wait_lock, *flags);
>>> +		schedule();
>>> +	} else {
>>> +		spin_unlock_mutex(&lock->wait_lock, *flags);
>>> +		for (;;) {
>>> +			/* Stop spinning when there's a pending signal. */
>>> +			if (signal_pending_state(state, task))
>>> +				break;
>>> +
>>> +			/* Owner changed, bail to revalidate state */
>>> +			if (lock->owner != owner)
>>> +				break;
>>> +
>>> +			/* Owner stopped running, bail to revalidate state */
>>> +			if (rq->curr != owner)
>>> +				break;
>>> +
>> 2 questions from my immature thought:
>>
>> 1) Do we need keep gcc from optimizing when we access lock->owner
>>    and rq->curr in the loop?
> 
> cpu_relax() is a compiler barrier iirc.
> 
>> 2) "if (rq->curr != owner)" need become smarter.
>>    schedule()
>>    {
>> 	select_next
>> 	rq->curr = next;
>> 	contex_swith
>>    }
>> we also spin when owner is select_next-ing in schedule().
>> but select_next is not fast enough.
> 
> I'm not sure what you're saying here..
> 
> 

I means when mutex owner calls schedule(), current task is also spinning
until rq->curr is changed.

I think such spin is not necessary, it is doing nothing but wasting time.
And this spin period is not short, and when this spin period ended,
rq->curr is changed too, current task has to sleep.

So I think current task should sleep earlier when it detects that
mutex owner start schedule().



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ