From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752366AbcHHR1Y (ORCPT ); Mon, 8 Aug 2016 13:27:24 -0400 Received: from merlin.infradead.org ([205.233.59.134]:56656 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752128AbcHHR1W (ORCPT ); Mon, 8 Aug 2016 13:27:22 -0400 Date: Mon, 8 Aug 2016 19:26:59 +0200 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 , Imre Deak , Waiman Long Subject: Re: [PATCH v4 1/3] locking/mutex: Add waiter parameter to mutex_optimistic_spin() Message-ID: <20160808172659.GX6862@twins.programming.kicks-ass.net> References: <1468874366-56955-1-git-send-email-Waiman.Long@hpe.com> <1468874366-56955-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: <1468874366-56955-2-git-send-email-Waiman.Long@hpe.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 18, 2016 at 04:39:24PM -0400, Waiman Long wrote: > @@ -302,22 +306,42 @@ static inline bool mutex_try_to_acquire(struct mutex *lock) > * > * Returns true when the lock was taken, otherwise false, indicating > * that we need to jump to the slowpath and sleep. > + * > + * The waiter flag is set to true if the spinner is a waiter in the wait > + * queue. As the waiter has slept for a while, it should have priority to > + * get the lock over the regular spinners. So going to wait at the end of > + * the OSQ isn't fair to the waiter. If the OSQ lock were a full FIFO it would in fact be fair, but its not and things can drop out the middle and go (back) to sleep. This has nothing to do with the end or not. > Instead, it will spin on the lock > + * directly and concurrently with the spinner at the head of the OSQ, if > + * present. Note that this isn't starvation proof in any way. > There may be a bit more cacheline contention in this case. This is relevant how ? > + * The waiter also needs to set the lock to -1 instead of 0 on lock > + * acquisition. This is unrelated to the previous bits and thus should not be in the same paragraph. Also, a 'why' would be more helpful. > */ > static bool mutex_optimistic_spin(struct mutex *lock, > - struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx) > + struct ww_acquire_ctx *ww_ctx, > + const bool use_ww_ctx, int waiter) > {