linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>,
	Davidlohr Bueso <dave@stgolabs.net>
Subject: Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt
Date: Thu, 15 Oct 2015 16:44:43 -0400	[thread overview]
Message-ID: <5620103B.2050002@hpe.com> (raw)
In-Reply-To: <20151013204421.GN17308@twins.programming.kicks-ass.net>

On 10/13/2015 04:44 PM, Peter Zijlstra wrote:
> On Tue, Oct 13, 2015 at 04:41:41PM -0400, Waiman Long wrote:
>> On 10/13/2015 02:23 PM, Peter Zijlstra wrote:
>>> On Tue, Sep 22, 2015 at 04:50:43PM -0400, Waiman Long wrote:
>>>>   	for (;; waitcnt++) {
>>>> +		loop = SPIN_THRESHOLD;
>>>> +		while (loop) {
>>>> +			/*
>>>> +			 * Spin until the lock is free
>>>> +			 */
>>>> +			for (; loop&&   READ_ONCE(l->locked); loop--)
>>>> +				cpu_relax();
>>>> +			/*
>>>> +			 * Seeing the lock is free, this queue head vCPU is
>>>> +			 * the rightful next owner of the lock. However, the
>>>> +			 * lock may have just been stolen by another task which
>>>> +			 * has entered the slowpath. So we need to use atomic
>>>> +			 * operation to make sure that we really get the lock.
>>>> +			 * Otherwise, we have to wait again.
>>>> +			 */
>>>> +			if (cmpxchg(&l->locked, 0, _Q_LOCKED_VAL) == 0)
>>>> +				goto gotlock;
>>>>   		}
>>> 		for (loop = SPIN_THRESHOLD; loop; --loop) {
>>> 			if (!READ_ONCE(l->locked)&&
>>> 			cmpxchg(&l->locked, 0, _Q_LOCKED_VA) == 0)
>>> 				goto gotlock;
>>>
>>> 			cpu_relax();
>>> 		}
>>>
>> This was the code that I used in my original patch, but it seems to confuse
>> you about doing too many lock stealing. So I separated it out to make my
>> intention more explicit. I will change it back to the old code.
> Code should be compact; its the purpose of Changelogs and comments to
> explain it if its subtle.
>
> Here you made weird code and the comments still don't explain how its
> starvation proof and the Changelog is almost empty of useful.

You are right. The current patch can't guarantee that there will be no 
lock starvation. I will make some code changes to make sure that lock 
starvation won't happen. I will also try to clean up the code and the 
comments at the same time.

Cheers,
Longman

  reply	other threads:[~2015-10-15 20:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-22 20:50 [PATCH v7 0/5] locking/qspinlock: Enhance pvqspinlock performance Waiman Long
2015-09-22 20:50 ` [PATCH v7 1/5] locking/qspinlock: relaxes cmpxchg & xchg ops in native code Waiman Long
2015-10-13 18:02   ` Peter Zijlstra
2015-10-13 20:38     ` Waiman Long
2015-10-13 20:47       ` Peter Zijlstra
2015-10-14  9:39     ` Will Deacon
2015-09-22 20:50 ` [PATCH v7 2/5] locking/pvqspinlock, x86: Optimize PV unlock code path Waiman Long
2015-09-22 20:50 ` [PATCH v7 3/5] locking/pvqspinlock: Collect slowpath lock statistics Waiman Long
2015-10-13 20:05   ` Peter Zijlstra
2015-10-13 21:06     ` Waiman Long
2015-09-22 20:50 ` [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt Waiman Long
2015-10-13 18:23   ` Peter Zijlstra
2015-10-13 20:41     ` Waiman Long
2015-10-13 20:44       ` Peter Zijlstra
2015-10-15 20:44         ` Waiman Long [this message]
2015-10-13 19:39   ` Peter Zijlstra
2015-10-13 20:45     ` Waiman Long
2015-10-13 19:56   ` Peter Zijlstra
2015-10-13 20:50     ` Waiman Long
2015-10-14  9:28       ` Peter Zijlstra
2015-10-15 21:01         ` Waiman Long
2015-09-22 20:50 ` [PATCH v7 5/5] locking/pvqspinlock: Queue node adaptive spinning Waiman Long

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=5620103B.2050002@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=dave@stgolabs.net \
    --cc=doug.hatch@hpe.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=scott.norton@hpe.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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;
as well as URLs for NNTP newsgroup(s).