From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751813AbbIQPIs (ORCPT ); Thu, 17 Sep 2015 11:08:48 -0400 Received: from g2t4620.austin.hp.com ([15.73.212.81]:58050 "EHLO g2t4620.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751573AbbIQPIq (ORCPT ); Thu, 17 Sep 2015 11:08:46 -0400 Message-ID: <55FAD77B.3040100@hpe.com> Date: Thu, 17 Sep 2015 11:08:43 -0400 From: Waiman Long User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130109 Thunderbird/10.0.12 MIME-Version: 1.0 To: Peter Zijlstra CC: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, Scott J Norton , Douglas Hatch , Davidlohr Bueso Subject: Re: [PATCH v6 5/6] locking/pvqspinlock: Allow 1 lock stealing attempt References: <1441996658-62854-1-git-send-email-Waiman.Long@hpe.com> <1441996658-62854-6-git-send-email-Waiman.Long@hpe.com> <20150914140051.GT18489@twins.programming.kicks-ass.net> <55F71CC8.3050306@hpe.com> <20150915082430.GX16853@twins.programming.kicks-ass.net> <55F8394A.1010809@hpe.com> <20150916150131.GC3604@twins.programming.kicks-ass.net> In-Reply-To: <20150916150131.GC3604@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/16/2015 11:01 AM, Peter Zijlstra wrote: > On Tue, Sep 15, 2015 at 11:29:14AM -0400, Waiman Long wrote: > >> Only the queue head vCPU will be in pv_wait_head() spinning to acquire the >> lock. > But what will guarantee fwd progress for the lock that is the head? > > Suppose CPU0 becomes head and enters the /* claim the lock */ loop. > > Then CPU1 comes in, steals it in pv_wait_head(). CPU1 releases, CPU1 > re-acquires and _again_ steals in pv_wait_head(), etc.. > > All the while CPU0 doesn't go anywhere. > That can't happen. For a given lock, there can only be 1 queue head spinning on the lock at any instance in time. If CPU0 was the head, another CPU could not become head until CPU0 got the lock and pass the MCS lock bit to the next one in the queue. As I said in earlier mail, the only place where lock stealing can happen is in the pv_queued_spin_trylock_unfair() function where I purposely inserted a cpu_relax() to allow an actively spinning queue head CPU a better chance of getting the lock. Once a CPU enters the queue. It won't try to acquire the lock until it becomes the head and there is one and only one head. Cheers, Longman