From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org,
linux-rt-users <linux-rt-users@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Carsten Emde <C.Emde@osadl.org>, John Kacur <jkacur@redhat.com>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH RT 1/2] rwsem-rt: Do not allow readers to nest
Date: Wed, 18 Feb 2015 20:57:10 +0100 [thread overview]
Message-ID: <20150218195710.GH28763@linutronix.de> (raw)
In-Reply-To: <20140409025231.998774075@goodmis.org>
* Steven Rostedt | 2014-04-08 22:47:01 [-0400]:
>From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
>
>The readers of mainline rwsems are not allowed to nest, the rwsems in the
>PREEMPT_RT kernel should not nest either.
I applied this and this is the reason why cpufreq isn't working. What I
see in cpufreq is:
| test.sh-788 [004] ....... 61.416288: store: down_read_try
| test.sh-788 [004] ....... 61.416296: cpufreq_cpu_get: down_read_try
| test.sh-788 [004] ....... 61.416301: cpufreq_cpu_put.part.6: up_read
| test.sh-788 [004] ....... 61.416332: store: up_read
as you see, one code path takes the read path of rw_sema twice.
Looking at the generic implementation, we have:
|#define RWSEM_UNLOCKED_VALUE 0x00000000L
|#define RWSEM_ACTIVE_BIAS 0x00000001L
|#define RWSEM_WAITING_BIAS (-RWSEM_ACTIVE_MASK-1)
| static inline int __down_read_trylock(struct rw_semaphore *sem)
| {
| long tmp;
|
| while ((tmp = sem->count) >= 0) {
| if (tmp == cmpxchg(&sem->count, tmp,
| tmp + RWSEM_ACTIVE_READ_BIAS)) {
| return 1;
| }
| }
| return 0;
| }
While sem->count is >= 0 we loop and take the semaphore. So we can have
five readers at once. The first writer would set count to a negative
value resulting in trylock failure.
|static inline void __down_read(struct rw_semaphore *sem)
|{
| if (unlikely(atomic_long_inc_return((atomic_long_t*)&sem->count) <= 0))
| rwsem_down_read_failed(sem);
|}
Here the same thing but without cmpxchg(). _If_ after an increment the
value is negative then we take slowpath. Otherwise we have the lock.
I think I'm going to revert this patch. Where is it written that
multiple readers of a RW-semaphore can not nest? According to the code
we can even have multiple readers without nesting (two+ processes may
take a reader lock).
Sebastian
next prev parent reply other threads:[~2015-02-18 19:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-09 2:47 [PATCH RT 0/2] rwsem-rt: Make rwsem rt closer to mainline Steven Rostedt
2014-04-09 2:47 ` [PATCH RT 1/2] rwsem-rt: Do not allow readers to nest Steven Rostedt
2014-05-02 9:04 ` Sebastian Andrzej Siewior
2015-02-18 19:57 ` Sebastian Andrzej Siewior [this message]
2015-02-18 20:13 ` Steven Rostedt
2015-02-20 5:07 ` Jason Low
2015-02-25 12:15 ` Sebastian Andrzej Siewior
2014-04-09 2:47 ` [PATCH RT 2/2] rtmutex: Remove duplicate rt_mutex_init() Steven Rostedt
2014-05-02 9:08 ` Sebastian Andrzej Siewior
2014-05-02 13:12 ` Steven Rostedt
2014-05-02 13:21 ` Sebastian Andrzej Siewior
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=20150218195710.GH28763@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=C.Emde@osadl.org \
--cc=a.p.zijlstra@chello.nl \
--cc=hpa@zytor.com \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=paul.gortmaker@windriver.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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