From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Mike Kravetz <mike.kravetz@oracle.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, Davidlohr Bueso <dave@stgolabs.net>,
Waiman Long <longman@redhat.com>
Subject: [PATCH 4/5] locking/rwsem: Enable timeout check when staying in the OSQ
Date: Wed, 11 Sep 2019 16:05:36 +0100 [thread overview]
Message-ID: <20190911150537.19527-5-longman@redhat.com> (raw)
In-Reply-To: <20190911150537.19527-1-longman@redhat.com>
Use the break function allowed by the new osq_lock() to enable early
break from the OSQ when a timeout value is specified and expiration
time has been reached.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/locking/rwsem.c | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index c15926ecb21e..78708097162a 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -794,23 +794,50 @@ static inline u64 rwsem_rspin_threshold(struct rw_semaphore *sem)
return sched_clock() + delta;
}
+struct rwsem_break_arg {
+ u64 timeout;
+ int loopcnt;
+};
+
+static bool rwsem_osq_break(void *brk_arg)
+{
+ struct rwsem_break_arg *arg = brk_arg;
+
+ arg->loopcnt++;
+ /*
+ * Check sched_clock() only once every 256 iterations.
+ */
+ if (!(arg->loopcnt++ & 0xff) && (sched_clock() >= arg->timeout))
+ return true;
+ return false;
+}
+
static bool rwsem_optimistic_spin(struct rw_semaphore *sem, bool wlock,
ktime_t timeout)
{
- bool taken = false;
+ bool taken = false, locked;
int prev_owner_state = OWNER_NULL;
int loop = 0;
u64 rspin_threshold = 0, curtime;
+ struct rwsem_break_arg break_arg;
unsigned long nonspinnable = wlock ? RWSEM_WR_NONSPINNABLE
: RWSEM_RD_NONSPINNABLE;
preempt_disable();
/* sem->wait_lock should not be held when doing optimistic spinning */
- if (!osq_lock(&sem->osq, NULL, NULL))
- goto done;
+ if (timeout) {
+ break_arg.timeout = ktime_to_ns(timeout);
+ break_arg.loopcnt = 0;
+ locked = osq_lock(&sem->osq, rwsem_osq_break, &break_arg);
+ curtime = sched_clock();
+ } else {
+ locked = osq_lock(&sem->osq, NULL, NULL);
+ curtime = 0;
+ }
- curtime = timeout ? sched_clock() : 0;
+ if (!locked)
+ goto done;
/*
* Optimistically spin on the owner field and attempt to acquire the
--
2.18.1
next prev parent reply other threads:[~2019-09-11 15:06 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-11 15:05 [PATCH 0/5] hugetlbfs: Disable PMD sharing for large systems Waiman Long
2019-09-11 15:05 ` [PATCH 1/5] locking/rwsem: Add down_write_timedlock() Waiman Long
2019-09-11 15:05 ` [PATCH 2/5] locking/rwsem: Enable timeout check when spinning on owner Waiman Long
2019-09-11 15:05 ` [PATCH 3/5] locking/osq: Allow early break from OSQ Waiman Long
2019-09-11 15:05 ` Waiman Long [this message]
2019-09-11 15:05 ` [PATCH 5/5] hugetlbfs: Limit wait time when trying to share huge PMD Waiman Long
2019-09-11 15:14 ` Matthew Wilcox
2019-09-11 15:44 ` Waiman Long
2019-09-11 17:03 ` Mike Kravetz
2019-09-11 17:15 ` Waiman Long
2019-09-11 17:22 ` Qian Cai
2019-09-11 17:28 ` Waiman Long
2019-09-11 16:01 ` Qian Cai
2019-09-11 16:34 ` Waiman Long
2019-09-11 19:42 ` Qian Cai
2019-09-11 20:54 ` Waiman Long
2019-09-11 21:57 ` Qian Cai
2019-09-11 19:57 ` Matthew Wilcox
2019-09-11 20:51 ` Waiman Long
2019-09-12 3:26 ` Mike Kravetz
2019-09-12 3:41 ` Matthew Wilcox
2019-09-12 4:40 ` Davidlohr Bueso
2019-09-16 13:53 ` Waiman Long
2019-09-12 9:06 ` Waiman Long
2019-09-12 16:43 ` Mike Kravetz
2019-09-13 18:23 ` Waiman Long
2019-09-13 1:50 ` [PATCH 0/5] hugetlbfs: Disable PMD sharing for large systems Dave Chinner
2019-09-25 8:35 ` Peter Zijlstra
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=20190911150537.19527-5-longman@redhat.com \
--to=longman@redhat.com \
--cc=dave@stgolabs.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=viro@zeniv.linux.org.uk \
--cc=will.deacon@arm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).