From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751067AbcBLUYK (ORCPT ); Fri, 12 Feb 2016 15:24:10 -0500 Received: from casper.infradead.org ([85.118.1.10]:47402 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbcBLUYD (ORCPT ); Fri, 12 Feb 2016 15:24:03 -0500 Date: Fri, 12 Feb 2016 21:23:55 +0100 From: Peter Zijlstra To: Waiman Long Cc: 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 Subject: Re: [PATCH v2 1/4] locking/mutex: Add waiter parameter to mutex_optimistic_spin() Message-ID: <20160212202355.GY6357@twins.programming.kicks-ass.net> References: <1455298335-53229-1-git-send-email-Waiman.Long@hpe.com> <1455298335-53229-2-git-send-email-Waiman.Long@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1455298335-53229-2-git-send-email-Waiman.Long@hpe.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 12, 2016 at 12:32:12PM -0500, Waiman Long wrote: > This patch adds a new waiter parameter to the mutex_optimistic_spin() > function to prepare it to be used by a waiter-spinner that doesn't > need to go into the OSQ as there can only be one waiter-spinner which > is the head of the waiting queue. Does not explain why.. > 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() ? > > + /* > + * In order to avoid a stampede of mutex spinners trying to > + * acquire the mutex all at once, the spinners need to take a > + * MCS (queued) lock first before spinning on the owner field. > + */ > + if (!osq_lock(&lock->osq)) > + goto done; > + } > > while (true) { > struct task_struct *owner;