From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu,
laijs@cn.fujitsu.com, dipankar@in.ibm.com,
akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca,
josh@joshtriplett.org, niv@us.ibm.com, tglx@linutronix.de,
peterz@infradead.org, rostedt@goodmis.org,
Valdis.Kletnieks@vt.edu, dhowells@redhat.com,
eric.dumazet@gmail.com, darren@dvhart.com
Subject: Re: [PATCH RFC tip/core/rcu 13/20] rcu: increase synchronize_sched_expedited() batching
Date: Sat, 18 Dec 2010 12:14:19 -0800 [thread overview]
Message-ID: <20101218201419.GD2143@linux.vnet.ibm.com> (raw)
In-Reply-To: <4D0CDD93.7040907@kernel.org>
On Sat, Dec 18, 2010 at 05:13:07PM +0100, Tejun Heo wrote:
> Hello,
>
> On 12/17/2010 09:54 PM, Paul E. McKenney wrote:
> > From: Tejun Heo <tj@kernel.org>
> >
> > The fix in commit #6a0cc49 requires more than three concurrent instances
> > of synchronize_sched_expedited() before batching is possible. This
> > patch uses a ticket-counter-like approach that is also not unrelated to
> > Lai Jiangshan's Ring RCU to allow sharing of expedited grace periods even
> > when there are only two concurrent instances of synchronize_sched_expedited().
> >
> > This commit builds on Tejun's original posting, which may be found at
> > http://lkml.org/lkml/2010/11/9/204, adding memory barriers, avoiding
> > overflow of signed integers (other than via atomic_t), and fixing the
> > detection of batching.
> >
> > Signed-off-by: Tejun Heo <tj@kernel.org>
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
>
> Acked-by: Tejun Heo <tj@kernel.org>
Thank you again!
> Some comments on the sequence testing tho.
>
> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > index 49e8e16..af56148 100644
> > --- a/include/linux/rcupdate.h
> > +++ b/include/linux/rcupdate.h
> > @@ -47,6 +47,8 @@
> > extern int rcutorture_runnable; /* for sysctl */
> > #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
> >
> > +#define UINT_CMP_GE(a, b) (UINT_MAX / 2 >= (a) - (b))
> > +#define UINT_CMP_LT(a, b) (UINT_MAX / 2 < (a) - (b))
> > #define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b))
> > #define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
>
> I don't think the original comparison had overflow problem. (a) < (b)
> gives the wrong result on overflow but (int)((a) - (b)) < 0 is
> correct.
You are right that it does give the correct result now, but the C
standard never has defined overflow for signed integers, as noted in
Section 6.3.1.3p3 of the N1494 Working Draft of the C standard:
Otherwise, the new type is signed and the value cannot be
represented in it; either the result is implementation-defined
or an implementation-defined signal is raised.
I have heard too many compiler guys gleefully discussing optimizations
that they could use if they took full advantage of this clause, so I
am not comfortable relying on the intuitive semantics for signed
arithmetic. (Now atomic_t is another story -- both C and C++ will
be requiring twos-complement semantics, thankfully.)
> I find the latter approach cleaner and that way the constant in the
> instruction can be avoided too although if the compiler might generate
> the same code regardless.
I would like your way better if it was defined in the C standard.
But it unfortunately is not. :-(
> Also, I think the names are misleading. They aren't testing whether
> one is greater or less than the other. They're testing whether one is
> before or after the other where the counters are used as monotonically
> incrementing (with wrapping) sequence, so wouldn't something like the
> following be better?
They are comparing the twos-complement difference between the two
numbers against zero.
> #define SEQ_TEST(a, b, test_op) ({ \
> typeof(a) __seq_a = (a); \
> typeof(b) __seq_b = (b); \
> bool __ret; \
> (void)(&__seq_a == &__seq_b); \
> switch (sizeof(__seq_a)) { \
> case sizeof(char): \
> __ret = (char)(__seq_a - __seq_b) test_op 0; \
> break; \
> case sizeof(int): \
> __ret = (int)(__seq_a - __seq_b) test_op 0; \
> break; \
> case sizeof(long): \
> __ret = (long)(__seq_a - __seq_b) test_op 0; \
> break; \
> case sizeof(long long): \
> __ret = (long long)(__seq_a - __seq_b) test_op 0; \
> break; \
> default: \
> __make_build_fail; \
> } \
> __ret; \
> })
>
> #define SEQ_BEFORE(a, b) SEQ_TEST((a), (b), <)
> and so on...
>
> Please note that the above macro is completely untested.
If you make something similar to these macros, but in a way that avoids
overflowing signed integers, I would be happy to use it. Might be a
good addition to compiler.h, for example.
Thanx, Paul
> Thanks.
>
> --
> tejun
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2010-12-18 20:14 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-17 20:54 [PATCH tip/core/rcu 0/20] second preview of RCU patches for 2.6.38 Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 01/20] rcu: add priority-inversion testing to rcutorture Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 02/20] rcu: move TINY_RCU from softirq to kthread Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 03/20] rcu: priority boosting for TINY_PREEMPT_RCU Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 04/20] rcu: add tracing for TINY_RCU and TINY_PREEMPT_RCU Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 05/20] rcu: document TINY_RCU and TINY_PREEMPT_RCU tracing Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 06/20] rcu: Distinguish between boosting and boosted Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 07/20] rcu: get rid of obsolete "classic" names in TREE_RCU tracing Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 08/20] rcu,cleanup: move synchronize_sched_expedited() out of sched.c Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 09/20] rcu,cleanup: simplify the code when cpu is dying Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 10/20] rcu: update documentation/comments for Lai's adoption patch Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 11/20] rcu: fix race condition in synchronize_sched_expedited() Paul E. McKenney
2010-12-18 15:52 ` Tejun Heo
2010-12-18 19:58 ` Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 12/20] rcu: Make synchronize_srcu_expedited() fast if running readers Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 13/20] rcu: increase synchronize_sched_expedited() batching Paul E. McKenney
2010-12-18 16:13 ` Tejun Heo
2010-12-18 20:14 ` Paul E. McKenney [this message]
2010-12-19 9:43 ` Tejun Heo
2010-12-19 16:35 ` Paul E. McKenney
2010-12-20 10:33 ` Peter Zijlstra
2010-12-20 13:40 ` Mathieu Desnoyers
2010-12-20 10:31 ` Peter Zijlstra
2010-12-21 7:58 ` Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 14/20] rcu: Stop chasing QS if another CPU did it for us Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 15/20] rcu: Keep gpnum and completed fields synchronized Paul E. McKenney
2010-12-20 2:13 ` Lai Jiangshan
2010-12-20 2:14 ` Frederic Weisbecker
2010-12-20 16:51 ` Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 16/20] rcu: fine-tune grace-period begin/end checks Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 17/20] rcu: limit rcu_node leaf-level fanout Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 18/20] rcu: reduce __call_rcu()-induced contention on rcu_node structures Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 19/20] rculist: fix borked __list_for_each_rcu() macro Paul E. McKenney
2010-12-17 20:54 ` [PATCH RFC tip/core/rcu 20/20] rcu: remove unused " Paul E. McKenney
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=20101218201419.GD2143@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=akpm@linux-foundation.org \
--cc=darren@dvhart.com \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=eric.dumazet@gmail.com \
--cc=josh@joshtriplett.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@polymtl.ca \
--cc=mingo@elte.hu \
--cc=niv@us.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tj@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox