All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: locking/core] locking/rwsem: Fold __down_{read,write}*()
Date: Wed, 09 Dec 2020 18:38:48 -0000	[thread overview]
Message-ID: <160753912826.3364.3121296739044708542.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20201207090243.GE3040@hirez.programming.kicks-ass.net>

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     c995e638ccbbc65a76d1713c4fdcf927e7e2cb83
Gitweb:        https://git.kernel.org/tip/c995e638ccbbc65a76d1713c4fdcf927e7e2cb83
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Tue, 08 Dec 2020 10:27:41 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 09 Dec 2020 17:08:47 +01:00

locking/rwsem: Fold __down_{read,write}*()

There's a lot needless duplication in __down_{read,write}*(), cure
that with a helper.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20201207090243.GE3040@hirez.programming.kicks-ass.net
---
 kernel/locking/rwsem.c | 45 ++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 7915456..67ae366 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -1354,32 +1354,29 @@ static struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
 /*
  * lock for reading
  */
-static inline void __down_read(struct rw_semaphore *sem)
+static inline int __down_read_common(struct rw_semaphore *sem, int state)
 {
 	if (!rwsem_read_trylock(sem)) {
-		rwsem_down_read_slowpath(sem, TASK_UNINTERRUPTIBLE);
+		if (IS_ERR(rwsem_down_read_slowpath(sem, state)))
+			return -EINTR;
 		DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem);
 	}
+	return 0;
+}
+
+static inline void __down_read(struct rw_semaphore *sem)
+{
+	__down_read_common(sem, TASK_UNINTERRUPTIBLE);
 }
 
 static inline int __down_read_interruptible(struct rw_semaphore *sem)
 {
-	if (!rwsem_read_trylock(sem)) {
-		if (IS_ERR(rwsem_down_read_slowpath(sem, TASK_INTERRUPTIBLE)))
-			return -EINTR;
-		DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem);
-	}
-	return 0;
+	return __down_read_common(sem, TASK_INTERRUPTIBLE);
 }
 
 static inline int __down_read_killable(struct rw_semaphore *sem)
 {
-	if (!rwsem_read_trylock(sem)) {
-		if (IS_ERR(rwsem_down_read_slowpath(sem, TASK_KILLABLE)))
-			return -EINTR;
-		DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem);
-	}
-	return 0;
+	return __down_read_common(sem, TASK_KILLABLE);
 }
 
 static inline int __down_read_trylock(struct rw_semaphore *sem)
@@ -1405,22 +1402,26 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
 /*
  * lock for writing
  */
-static inline void __down_write(struct rw_semaphore *sem)
-{
-	if (unlikely(!rwsem_write_trylock(sem)))
-		rwsem_down_write_slowpath(sem, TASK_UNINTERRUPTIBLE);
-}
-
-static inline int __down_write_killable(struct rw_semaphore *sem)
+static inline int __down_write_common(struct rw_semaphore *sem, int state)
 {
 	if (unlikely(!rwsem_write_trylock(sem))) {
-		if (IS_ERR(rwsem_down_write_slowpath(sem, TASK_KILLABLE)))
+		if (IS_ERR(rwsem_down_write_slowpath(sem, state)))
 			return -EINTR;
 	}
 
 	return 0;
 }
 
+static inline void __down_write(struct rw_semaphore *sem)
+{
+	__down_write_common(sem, TASK_UNINTERRUPTIBLE);
+}
+
+static inline int __down_write_killable(struct rw_semaphore *sem)
+{
+	return __down_write_common(sem, TASK_KILLABLE);
+}
+
 static inline int __down_write_trylock(struct rw_semaphore *sem)
 {
 	DEBUG_RWSEMS_WARN_ON(sem->magic != sem, sem);

  parent reply	other threads:[~2020-12-09 18:40 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 20:09 [PATCH 0/3] exec: Transform exec_update_mutex into a rw_semaphore Eric W. Biederman
2020-12-03 20:10 ` [PATCH 1/3] rwsem: Implement down_read_killable_nested Eric W. Biederman
2020-12-04  1:58   ` Waiman Long
2020-12-09 18:38   ` [tip: locking/core] " tip-bot2 for Eric W. Biederman
2020-12-03 20:11 ` [PATCH 2/3] rwsem: Implement down_read_interruptible Eric W. Biederman
2020-12-04  1:59   ` Waiman Long
2020-12-07  9:02     ` Peter Zijlstra
2020-12-07 15:33       ` Waiman Long
2020-12-07 16:58         ` David Laight
2020-12-07 19:02           ` Waiman Long
2020-12-08  9:12             ` David Laight
2020-12-08 12:32               ` Peter Zijlstra
2020-12-08 13:13                 ` David Laight
2020-12-08 15:34               ` Waiman Long
2020-12-08 16:23                 ` David Laight
2020-12-07 15:56       ` Eric W. Biederman
2020-12-08 14:52         ` Peter Zijlstra
2020-12-08 18:27           ` Eric W. Biederman
2020-12-09 18:36             ` Peter Zijlstra
2020-12-10 19:33               ` Eric W. Biederman
2020-12-11  8:16                 ` Peter Zijlstra
2020-12-09 18:38       ` [tip: locking/core] locking/rwsem: Introduce rwsem_write_trylock() tip-bot2 for Peter Zijlstra
2020-12-09 18:38       ` tip-bot2 for Peter Zijlstra [this message]
2020-12-09 18:38       ` [tip: locking/core] locking/rwsem: Better collate rwsem_read_trylock() tip-bot2 for Peter Zijlstra
2020-12-09 18:38   ` [tip: locking/core] rwsem: Implement down_read_interruptible tip-bot2 for Eric W. Biederman
2020-12-03 20:12 ` [PATCH 3/3] exec: Transform exec_update_mutex into a rw_semaphore Eric W. Biederman
2020-12-04 16:08   ` Bernd Edlinger
2020-12-04 17:21     ` Linus Torvalds
2020-12-04 19:34       ` Eric W. Biederman
2020-12-04 20:10         ` Linus Torvalds
2020-12-04 20:30           ` Bernd Edlinger
2020-12-04 20:48             ` Linus Torvalds
2020-12-04 21:48               ` Davidlohr Bueso
2020-12-05 18:05                 ` Eric W. Biederman
2020-12-07  9:15                   ` Peter Zijlstra
2020-12-07  9:09               ` Peter Zijlstra
2020-12-07 18:40                 ` Linus Torvalds
2020-12-08  8:34                   ` [PATCH] perf: Break deadlock involving exec_update_mutex Peter Zijlstra
2020-12-08 18:37                     ` Linus Torvalds
2020-12-10 18:38                     ` Davidlohr Bueso
2020-12-10 19:40                       ` Eric W. Biederman
2020-12-05 17:43           ` [PATCH 3/3] exec: Transform exec_update_mutex into a rw_semaphore Eric W. Biederman
2020-12-04 17:39     ` Eric W. Biederman
2020-12-03 22:42 ` [PATCH 0/3] " Linus Torvalds
2020-12-04  1:56   ` Waiman Long
2020-12-04  4:54   ` Davidlohr Bueso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160753912826.3364.3121296739044708542.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.