From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751685AbcBLWDG (ORCPT ); Fri, 12 Feb 2016 17:03:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:33334 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751014AbcBLWDE (ORCPT ); Fri, 12 Feb 2016 17:03:04 -0500 Date: Fri, 12 Feb 2016 14:02:49 -0800 From: Davidlohr Bueso To: Waiman Long Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org, Linus Torvalds , Ding Tianhong , Jason Low , "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: <20160212220249.GA16417@linux-uzut.site> 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; format=flowed Content-Disposition: inline In-Reply-To: <1455298335-53229-2-git-send-email-Waiman.Long@hpe.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 12 Feb 2016, 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. > >Signed-off-by: Waiman Long >--- > kernel/locking/mutex.c | 55 ++++++++++++++++++++++++++++++++--------------- > 1 files changed, 37 insertions(+), 18 deletions(-) > >diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c >index 0551c21..3c41448 100644 >--- a/kernel/locking/mutex.c >+++ b/kernel/locking/mutex.c >@@ -273,11 +273,15 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock) > > /* > * Atomically try to take the lock when it is available >+ * >+ * For waiter-spinner, the count needs to be set to -1 first which will be >+ * cleared to 0 later on if the list becomes empty. For regular spinner, >+ * the count will be set to 0. > */ >-static inline bool mutex_try_to_acquire(struct mutex *lock) >+static inline bool mutex_try_to_acquire(struct mutex *lock, int waiter) > { > return !mutex_is_locked(lock) && >- (atomic_cmpxchg_acquire(&lock->count, 1, 0) == 1); >+ (atomic_cmpxchg_acquire(&lock->count, 1, waiter ? -1 : 0) == 1); > } This can be a really hot path, could we get rid of the waiter check and just introduce mutex_tro_to_acquire_waiter() or such and set the counter to -1 there? Thanks, Davidlohr