From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753300AbcBPDCx (ORCPT ); Mon, 15 Feb 2016 22:02:53 -0500 Received: from g1t6214.austin.hp.com ([15.73.96.122]:37197 "EHLO g1t6214.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752587AbcBPDCv (ORCPT ); Mon, 15 Feb 2016 22:02:51 -0500 Message-ID: <1455591654.2276.64.camel@j-VirtualBox> Subject: Re: [PATCH v2 1/4] locking/mutex: Add waiter parameter to mutex_optimistic_spin() From: Jason Low To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Linus Torvalds , Ding Tianhong , Jason Low , Davidlohr Bueso , "Paul E. McKenney" , Thomas Gleixner , Will Deacon , Tim Chen , Waiman Long , jason.low2@hp.com Date: Mon, 15 Feb 2016 19:00:54 -0800 In-Reply-To: <56C2655C.9030707@hpe.com> References: <1455298335-53229-1-git-send-email-Waiman.Long@hpe.com> <1455298335-53229-2-git-send-email-Waiman.Long@hpe.com> <20160212204027.GZ6357@twins.programming.kicks-ass.net> <56C2655C.9030707@hpe.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2016-02-15 at 18:55 -0500, Waiman Long wrote: > On 02/12/2016 03:40 PM, Peter Zijlstra wrote: > > On Fri, Feb 12, 2016 at 12:32:12PM -0500, Waiman Long wrote: > >> @@ -358,8 +373,8 @@ static bool mutex_optimistic_spin(struct mutex *lock, > >> } > >> > >> mutex_set_owner(lock); > >> - osq_unlock(&lock->osq); > >> - return true; > >> + acquired = true; > >> + break; > >> } > >> > >> /* > >> @@ -380,7 +395,10 @@ static bool mutex_optimistic_spin(struct mutex *lock, > >> cpu_relax_lowlatency(); > >> } > >> > >> - osq_unlock(&lock->osq); > >> + if (!waiter) > >> + osq_unlock(&lock->osq); > >> + if (acquired || waiter) > >> + return acquired; > >> done: > >> /* > >> * If we fell out of the spin path because of need_resched(), > > Is there a reason to not also preempt in the wait-loop? Surely the same > > reason is still valid there too? > > The waiter does check for need_sched(). So it will break out of the loop > and return false in this case. This causes the waiter to loop back and > goes to sleep if the lock can't be acquired. That is why I don't think > we need to do another schedule_preempt_disabled() here. The purpose of the additional reschedule point is to avoid delaying preemption, which still applies if the spinner is a waiter. If it is a waiter, the difference is that the delay isn't as long since it doesn't need to be added to the wait_list. Nonetheless, preemption delays can still occur, so I think the additional preemption point should also be there in the waiter case.