Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1246030 > unrolled thread

Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt

Started byPeter Zijlstra <peterz@infradead.org>
First post2015-10-13 20:30 +0200
Last post2015-10-15 22:50 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt Peter Zijlstra <peterz@infradead.org> - 2015-10-13 20:30 +0200
    Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt Waiman Long <waiman.long@hpe.com> - 2015-10-13 22:50 +0200
      Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt Peter Zijlstra <peterz@infradead.org> - 2015-10-13 22:50 +0200
        Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt Waiman Long <waiman.long@hpe.com> - 2015-10-15 22:50 +0200

#1246030 — Re: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt

FromPeter Zijlstra <peterz@infradead.org>
Date2015-10-13 20:30 +0200
SubjectRe: [PATCH v7 4/5] locking/pvqspinlock: Allow 1 lock stealing attempt
Message-ID<qjcuK-6f1-9@gated-at.bofh.it>
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();
		}

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

[toc] | [next] | [standalone]


#1246134

FromWaiman Long <waiman.long@hpe.com>
Date2015-10-13 22:50 +0200
Message-ID<qjeGf-Xw-45@gated-at.bofh.it>
In reply to#1246030
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.

Cheers,
Longman


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

[toc] | [prev] | [next] | [standalone]


#1246138

FromPeter Zijlstra <peterz@infradead.org>
Date2015-10-13 22:50 +0200
Message-ID<qjeGg-Xw-57@gated-at.bofh.it>
In reply to#1246134
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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1248159

FromWaiman Long <waiman.long@hpe.com>
Date2015-10-15 22:50 +0200
Message-ID<qjXDk-11G-23@gated-at.bofh.it>
In reply to#1246138
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web