From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: paulmck@linux.vnet.ibm.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 8/8] srcu: use ACCESS_ONCE() to access sp->completed in srcu_read_lock()
Date: Fri, 30 Nov 2012 16:14:02 +0800 [thread overview]
Message-ID: <50B86ACA.2060408@cn.fujitsu.com> (raw)
In-Reply-To: <20121129220525.GD2474@linux.vnet.ibm.com>
On 11/30/2012 06:05 AM, Paul E. McKenney wrote:
> On Thu, Nov 29, 2012 at 04:46:09PM +0800, Lai Jiangshan wrote:
>> Old srcu implement requires sp->completed is loaded in
>> RCU-sched(preempt_disable()) section.
>>
>> The new srcu is now not RCU-sched based, it doesn't require the load of
>> sp->completed and the access to counter must be in the same RCU-sched
>> read site C.S., so we use ACCESS_ONCE() instead, and move it out of
>> the preempt_disable() section, preempt_disable() section is only used
>> for percpu data, not for RCU-sched.
>>
>> The resulted code is almost as the same as before, but it helps people to
>> understand the code, and it avoids to add surprise to reviewer: "why we need
>> rcu_read_lock_sched_held() here?"
>
> The first seven patches look good!
>
> One question about this one -- the current code provided dependency
> ordering between the fetch of idx and the increment, but the code after
> this patch would not provide this ordering (at least not on Alpha,
> and maybe also not in presence of aggressive compiler optimizations).
>
> In the immortal words of MSDOS, "Are you sure?"
Sure, the update site doesn't modify the percpu counter, so there is
no dependency mb needed in read-site. I can ask "where is the corresponding
mb which is paired with this dependency mb?"
The correctness of SRCU is based on
the wait in synchrinize_srcu()
the counter and seq and the mbs between them
X: sp->completed is not necessary here except for reporting how many GP passed.
The starvation-free of SRCU is based on
split counter and seq into two index,
split the wait into two waits for both index
add sp->completed field
the flip between the two waits
-> the index for wait and the index for late-enough-after-flip read-site are different.
Thanks,
Lai
>> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
>> ---
>> kernel/srcu.c | 3 +--
>> 1 files changed, 1 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/srcu.c b/kernel/srcu.c
>> index 38a762f..224400a 100644
>> --- a/kernel/srcu.c
>> +++ b/kernel/srcu.c
>> @@ -294,9 +294,8 @@ int __srcu_read_lock(struct srcu_struct *sp)
>> {
>> int idx;
>>
>> + idx = ACCESS_ONCE(sp->completed) & 0x1;
>> preempt_disable();
>> - idx = rcu_dereference_index_check(sp->completed,
>> - rcu_read_lock_sched_held()) & 0x1;
>> ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
>> smp_mb(); /* B */ /* Avoid leaking the critical section. */
>> ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
>> --
>> 1.7.4.4
>>
>
>
prev parent reply other threads:[~2012-11-30 8:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-29 8:46 [PATCH 0/8] srcu: cleanup for 3.8 Lai Jiangshan
2012-11-29 8:46 ` [PATCH 1/8] srcu: simplify __srcu_read_unlock() via this_cpu_dec() Lai Jiangshan
2012-11-29 8:46 ` [PATCH 2/8] srcu: add might_sleep() annotation to synchronize_srcu() Lai Jiangshan
2012-11-29 8:46 ` [PATCH 3/8] srcu: simple cleanup for cleanup_srcu_struct() Lai Jiangshan
2012-11-29 8:46 ` [PATCH 4/8] srcu: srcu_read_lock() can be called from offline cpu Lai Jiangshan
2012-12-04 19:15 ` Paul E. McKenney
2012-11-29 8:46 ` [PATCH 5/8] srcu: srcu_read_lock() can be called from idle loop Lai Jiangshan
2012-11-29 8:46 ` [PATCH 6/8] srcu: update the comments of synchronize_srcu() Lai Jiangshan
2012-11-29 8:46 ` [PATCH 7/8] srcu: update the comments of synchronize_srcu_expedited() Lai Jiangshan
2012-11-29 8:46 ` [PATCH 8/8] srcu: use ACCESS_ONCE() to access sp->completed in srcu_read_lock() Lai Jiangshan
2012-11-29 22:05 ` Paul E. McKenney
2012-11-30 8:14 ` Lai Jiangshan [this message]
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=50B86ACA.2060408@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.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
Powered by JetHome