From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752562AbcBPCXQ (ORCPT ); Mon, 15 Feb 2016 21:23:16 -0500 Received: from g1t6214.austin.hp.com ([15.73.96.122]:58620 "EHLO g1t6214.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752229AbcBPCXP (ORCPT ); Mon, 15 Feb 2016 21:23:15 -0500 X-Greylist: delayed 414 seconds by postgrey-1.27 at vger.kernel.org; Mon, 15 Feb 2016 21:23:15 EST Message-ID: <1455589334.2276.39.camel@j-VirtualBox> Subject: Re: [PATCH v2 1/4] locking/mutex: Add waiter parameter to mutex_optimistic_spin() From: Jason Low To: Davidlohr Bueso Cc: Peter Zijlstra , Waiman Long , Ingo Molnar , linux-kernel@vger.kernel.org, Linus Torvalds , Ding Tianhong , Jason Low , "Paul E. McKenney" , Thomas Gleixner , Will Deacon , Tim Chen , Waiman Long , jason.low2@hp.com Date: Mon, 15 Feb 2016 18:22:14 -0800 In-Reply-To: <1455588930.2276.36.camel@j-VirtualBox> References: <1455298335-53229-1-git-send-email-Waiman.Long@hpe.com> <1455298335-53229-2-git-send-email-Waiman.Long@hpe.com> <20160212202355.GY6357@twins.programming.kicks-ass.net> <20160212221444.GC16417@linux-uzut.site> <1455588930.2276.36.camel@j-VirtualBox> 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:15 -0800, Jason Low wrote: > On Fri, 2016-02-12 at 14:14 -0800, Davidlohr Bueso wrote: > > On Fri, 12 Feb 2016, Peter Zijlstra wrote: > > > > >On Fri, Feb 12, 2016 at 12:32:12PM -0500, Waiman Long wrote: > > >> static bool mutex_optimistic_spin(struct mutex *lock, > > >> + struct ww_acquire_ctx *ww_ctx, > > >> + const bool use_ww_ctx, int waiter) > > >> { > > >> struct task_struct *task = current; > > >> + bool acquired = false; > > >> > > >> + if (!waiter) { > > >> + if (!mutex_can_spin_on_owner(lock)) > > >> + goto done; > > > > > >Why doesn't the waiter have to check mutex_can_spin_on_owner() ? > > > > afaict because mutex_can_spin_on_owner() fails immediately when the counter > > is -1, which is a nono for the waiters case. > > mutex_can_spin_on_owner() returns false if the task needs to reschedule > or if the lock owner is not on_cpu. In either case, the task will end up > not spinning when it enters the spin loop. So it makes sense if the > waiter also checks mutex_can_spin_on_owner() so that the optimistic spin > queue overhead can be avoided in those cases. Actually, since waiters bypass the optimistic spin queue, that means the the mutex_can_spin_on_owner() isn't really beneficial. So Waiman is right in that it's fine to skip this in the waiter case.