From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426044AbcFHO0q (ORCPT ); Wed, 8 Jun 2016 10:26:46 -0400 Received: from terminus.zytor.com ([198.137.202.10]:34650 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423138AbcFHO0m (ORCPT ); Wed, 8 Jun 2016 10:26:42 -0400 Date: Wed, 8 Jun 2016 07:25:55 -0700 From: tip-bot for Waiman Long Message-ID: Cc: doug.hatch@hpe.com, linux-kernel@vger.kernel.org, jason.low2@hp.com, akpm@linux-foundation.org, Waiman.Long@hpe.com, paulmck@linux.vnet.ibm.com, scott.norton@hpe.com, david@fromorbit.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, dave@stgolabs.net, torvalds@linux-foundation.org, peter@hurleysoftware.com, hpa@zytor.com Reply-To: hpa@zytor.com, peterz@infradead.org, dave@stgolabs.net, peter@hurleysoftware.com, torvalds@linux-foundation.org, mingo@kernel.org, tglx@linutronix.de, david@fromorbit.com, scott.norton@hpe.com, paulmck@linux.vnet.ibm.com, Waiman.Long@hpe.com, jason.low2@hp.com, akpm@linux-foundation.org, doug.hatch@hpe.com, linux-kernel@vger.kernel.org In-Reply-To: <1463534783-38814-5-git-send-email-Waiman.Long@hpe.com> References: <1463534783-38814-5-git-send-email-Waiman.Long@hpe.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/rwsem: Improve reader wakeup code Git-Commit-ID: bf7b4c472db44413251bcef79ca1f6bf1ec81475 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: bf7b4c472db44413251bcef79ca1f6bf1ec81475 Gitweb: http://git.kernel.org/tip/bf7b4c472db44413251bcef79ca1f6bf1ec81475 Author: Waiman Long AuthorDate: Tue, 17 May 2016 21:26:22 -0400 Committer: Ingo Molnar CommitDate: Wed, 8 Jun 2016 15:17:00 +0200 locking/rwsem: Improve reader wakeup code In __rwsem_do_wake(), the reader wakeup code will assume a writer has stolen the lock if the active reader/writer count is not 0. However, this is not as reliable an indicator as the original "< RWSEM_WAITING_BIAS" check. If another reader is present, the code will still break out and exit even if the writer is gone. This patch changes it to check the same "< RWSEM_WAITING_BIAS" condition to reduce the chance of false positive. Signed-off-by: Waiman Long Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Peter Hurley Cc: Andrew Morton Cc: Dave Chinner Cc: Davidlohr Bueso Cc: Douglas Hatch Cc: Jason Low Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Scott J Norton Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1463534783-38814-5-git-send-email-Waiman.Long@hpe.com Signed-off-by: Ingo Molnar --- kernel/locking/rwsem-xadd.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index 6b0d060..4f1daf5 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -156,9 +156,14 @@ __rwsem_mark_wake(struct rw_semaphore *sem, oldcount = atomic_long_add_return(adjustment, &sem->count) - adjustment; if (unlikely(oldcount < RWSEM_WAITING_BIAS)) { - /* A writer stole the lock. Undo our reader grant. */ - if (atomic_long_sub_return(adjustment, &sem->count) & - RWSEM_ACTIVE_MASK) + /* + * If the count is still less than RWSEM_WAITING_BIAS + * after removing the adjustment, it is assumed that + * a writer has stolen the lock. We have to undo our + * reader grant. + */ + if (atomic_long_add_return(-adjustment, &sem->count) < + RWSEM_WAITING_BIAS) goto out; /* Last active locker left. Retry waking readers. */ goto try_reader_grant;