Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4202381pxu; Wed, 9 Dec 2020 10:47:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxc5gvbyfTiipC9qnkrNLMvrdQcW25Q4QOleejYtU2noJs1mp4vdK9aoWA0HDlIPrSbAiQJ X-Received: by 2002:a17:906:3b8b:: with SMTP id u11mr3152513ejf.489.1607539635945; Wed, 09 Dec 2020 10:47:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607539635; cv=none; d=google.com; s=arc-20160816; b=d+ZwSahugG6261lfPypCCZNtjoE302FXHH0mtN5F3ROovMHXTL3IJ6fc4KKSqpt3i7 wT1Goak7UK+b//xBNvL0o5bqeaebfDankmASkPJ8yKYWYRw+r00rM0hZi8ci8zNn5K+T O8S1qXtau2b9UaADCWGIb0ur+5TDiDk3N4OBtQVTC0lNClNP1EaCbExu4gLjhSEpx6Mh EvQMVsj3uPWvrCxe+WYZaXCK7HCkfNwNLQyqTKwMMaDVx6fYO++gZO4x98DFyN1nwL2y 8zCUUP41QJM5/WjnBS93/UXkxpKjGMS3OYlArB9vEXaGefplnfG/J1XsOLvYBDopZe5g TcVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=HCHLpzsf+qtSYP5Z/O54VFcXA3bDvoqQyI7mhQmeTKc=; b=gxmpSLMyPQrVtzeMjV+0Nx/MldMd7XOncS+ocnhnUKvLCLxBcX4PQP3iX7YVkB/i6C 3RIKBsZ1rucaFTMs57hfR51Suz8WMtA6jExE6XQ0jKhYUT5u1vv1fTeFRf2+wGvq1bWn 9rvmMmY/Pju7mz1tHoM9KFCMcI1myXbicxyJVQPaTrR9HUkFirxAHwJW5D0bTWnBziId 0LW8QTZAF2+oVLoYCpLH4g4PFpuGLnue8K2r2sY2gM56S7AOTW8043ghRbd8CtI9h26F ioa/1ODBIQj1IrZMTTNqWWAHoUZaEnz4CJRuc1szC/0NDJwNJMEz05smqVak1GPz3Txf CpJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WF05ShpG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2LUzseco; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si1254347edd.596.2020.12.09.10.46.53; Wed, 09 Dec 2020 10:47:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WF05ShpG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2LUzseco; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733106AbgLISmM (ORCPT + 99 others); Wed, 9 Dec 2020 13:42:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732961AbgLISjb (ORCPT ); Wed, 9 Dec 2020 13:39:31 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A84B6C061793; Wed, 9 Dec 2020 10:38:50 -0800 (PST) Date: Wed, 09 Dec 2020 18:38:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1607539128; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HCHLpzsf+qtSYP5Z/O54VFcXA3bDvoqQyI7mhQmeTKc=; b=WF05ShpGIjiZJ+JI6srxt4K4E7W9Mu/tZEyFOt6mkyE33/b0I2SXS0Snu2kKZT51YYEnc1 8XlIknHzJCGxDngm9QJTXQYZdC9naNlD1psU3ARhWamaOqBNF0S4dTOO/1lgIzDBDE3YnB 477RXEA/zTcwNaECsOKHlVnrB2S+Z6hPMEknnsFKjOBKhifKuR7cia9Q7Ff+yTuWxRvb62 Bs0Cc0o/ANlGeaxDhLU4UNYVl1UkR5fV++ZsfNOmQkrnyocb4Yd3/QFmKrwWliKwJEIuqT CQQqiEb71lzSnBbSd62fGJ+6Rk00zRaC/6ttF3SRv4C9/k/urtj6yzBXuckSxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1607539128; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HCHLpzsf+qtSYP5Z/O54VFcXA3bDvoqQyI7mhQmeTKc=; b=2LUzseco1rMfLByyqmWGYHxtujJM9R92Ha7WkUxFUQqPi9w14fK3twWELdcMREZ64nkeqd rv8OvpJ3Zlim+eBg== From: "tip-bot2 for Waiman Long" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/rwsem: Pass the current atomic count to rwsem_down_read_slowpath() Cc: Waiman Long , "Peter Zijlstra (Intel)" , Davidlohr Bueso , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20201121041416.12285-2-longman@redhat.com> References: <20201121041416.12285-2-longman@redhat.com> MIME-Version: 1.0 Message-ID: <160753912803.3364.4437531645113964830.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: c8fe8b0564388f41147326f31e4587171aacccd4 Gitweb: https://git.kernel.org/tip/c8fe8b0564388f41147326f31e4587171aacccd4 Author: Waiman Long AuthorDate: Fri, 20 Nov 2020 23:14:12 -05:00 Committer: Peter Zijlstra CommitterDate: Wed, 09 Dec 2020 17:08:47 +01:00 locking/rwsem: Pass the current atomic count to rwsem_down_read_slowpath() The atomic count value right after reader count increment can be useful to determine the rwsem state at trylock time. So the count value is passed down to rwsem_down_read_slowpath() to be used when appropriate. Signed-off-by: Waiman Long Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Davidlohr Bueso Link: https://lkml.kernel.org/r/20201121041416.12285-2-longman@redhat.com --- kernel/locking/rwsem.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 67ae366..5768b90 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -270,14 +270,14 @@ static inline void rwsem_set_nonspinnable(struct rw_semaphore *sem) owner | RWSEM_NONSPINNABLE)); } -static inline bool rwsem_read_trylock(struct rw_semaphore *sem) +static inline bool rwsem_read_trylock(struct rw_semaphore *sem, long *cntp) { - long cnt = atomic_long_add_return_acquire(RWSEM_READER_BIAS, &sem->count); + *cntp = atomic_long_add_return_acquire(RWSEM_READER_BIAS, &sem->count); - if (WARN_ON_ONCE(cnt < 0)) + if (WARN_ON_ONCE(*cntp < 0)) rwsem_set_nonspinnable(sem); - if (!(cnt & RWSEM_READ_FAILED_MASK)) { + if (!(*cntp & RWSEM_READ_FAILED_MASK)) { rwsem_set_reader_owned(sem); return true; } @@ -1008,9 +1008,9 @@ rwsem_spin_on_owner(struct rw_semaphore *sem, unsigned long nonspinnable) * Wait for the read lock to be granted */ static struct rw_semaphore __sched * -rwsem_down_read_slowpath(struct rw_semaphore *sem, int state) +rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, int state) { - long count, adjustment = -RWSEM_READER_BIAS; + long adjustment = -RWSEM_READER_BIAS; struct rwsem_waiter waiter; DEFINE_WAKE_Q(wake_q); bool wake = false; @@ -1356,8 +1356,10 @@ static struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem) */ static inline int __down_read_common(struct rw_semaphore *sem, int state) { - if (!rwsem_read_trylock(sem)) { - if (IS_ERR(rwsem_down_read_slowpath(sem, state))) + long count; + + if (!rwsem_read_trylock(sem, &count)) { + if (IS_ERR(rwsem_down_read_slowpath(sem, count, state))) return -EINTR; DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem); }