From: Mark Rutland <mark.rutland@arm.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: linux-kernel@vger.kernel.org,
"Paul E . McKenney " <paulmck@linux.vnet.ibm.com>,
Josh Triplett <josh@joshtriplett.org>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Colin King <colin.king@canonical.com>
Subject: Re: [RFC v2 1/5] rcu: Introduce for_each_leaf_node_cpu()
Date: Thu, 15 Dec 2016 11:43:52 +0000 [thread overview]
Message-ID: <20161215114351.GA21758@leverpostej> (raw)
In-Reply-To: <20161215024204.28620-2-boqun.feng@gmail.com>
On Thu, Dec 15, 2016 at 10:42:00AM +0800, Boqun Feng wrote:
> There are some places inside RCU core, where we need to iterate all mask
> (->qsmask, ->expmask, etc) bits in a leaf node, in order to iterate all
> corresponding CPUs. The current code iterates all possible CPUs in this
> leaf node and then checks with the mask to see whether the bit is set.
>
> However, given the fact that most bits in cpu_possible_mask are set but
> rare bits in an RCU leaf node mask are set(in other words, ->qsmask and
> its friends are usually more sparse than cpu_possible_mask), it's better
> to iterate in the other way, that is iterating mask bits in a leaf node.
> By doing so, we can save several checks in the loop, moreover, that fast
> path checking(e.g. ->qsmask == 0) could then be consolidated into the
> loop logic.
>
> This patch introduce for_each_leaf_node_cpu() to iterate mask bits in a
> more efficient way.
>
> By design, The CPUs whose bits are set in the leaf node masks should be
> a subset of possible CPUs, so we don't need extra check with
> cpu_possible(), however, a WARN_ON_ONCE() is put in the loop to check
> whether there are some nasty cases we miss.
>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> ---
> kernel/rcu/tree.h | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
> index c0a4bf8f1ed0..70ef44a082e0 100644
> --- a/kernel/rcu/tree.h
> +++ b/kernel/rcu/tree.h
> @@ -295,6 +295,22 @@ struct rcu_node {
> cpu <= rnp->grphi; \
> cpu = cpumask_next((cpu), cpu_possible_mask))
>
> +
> +#define MASK_BITS(mask) (BITS_PER_BYTE * sizeof(mask))
> +/*
> + * Iterate over all CPUs a leaf RCU node which are still masked in
> + * @mask.
> + *
> + * Note @rnp has to be a leaf node and @mask has to belong to @rnp.
Not a big deal, but perhaps it's worth enforcing this? If we took just
the name of the mask here, (e.g. qsmask rather than rnp->qsmask), we
could have the macro always use (rnp)->(mask). That would also make the
invocations shorter.
> And we
> + * assume that no CPU is masked in @mask but not set in cpu_possible_mask. IOW,
> + * masks of a leaf node never set a bit for an "impossible" CPU.
> + */
> +#define for_each_leaf_node_cpu(rnp, mask, cpu) \
> + for ((cpu) = (rnp)->grplo + find_first_bit(&(mask), MASK_BITS(mask)); \
> + (cpu) <= (rnp)->grphi && !WARN_ON_ONCE(!cpu_possible(cpu)); \
If this happens, we'll exit the loop. If there are any reamining
possible CPUs, we'll skip them, which would be less than ideal.
I guess this shouldn't happen anyway, but it might be worth continuing.
> + (cpu) = (rnp)->grplo + find_next_bit(&(mask), MASK_BITS(mask), \
> + (cpu) - (rnp)->grplo + 1))
> +
I was going to ask if that + 1 was correct, but I see that it is!
So FWIW:
Acked-by: Mark Rutland <mark.rutland@arm.com>
I had a go at handling my comments above, but I'm not sure it's any
better:
#define cpu_to_grp(rnp, cpu) ((cpu) - (rnp)->grplo)
#define grp_to_cpu(rnp, cpu) ((cpu) + (rnp)->grplo)
#define node_first_cpu(rnp, mask) \
grp_to_cpu(find_first_bit(&(rnp)->mask, MASK_BITS((rnp)->mask)))
#define node_next_cpu(rnp, mask, cpu)
grp_to_cpu(rnp, find_next_bit(&(rnp)->mask, MASK_BITS((rnp)->mask),
cpu_to_grp(rnp, cpu) + 1))
#define for_each_leaf_node_cpu(rnp, mask, cpu) \
for ((cpu) = node_first_cpu(rnp, mask); \
(cpu) <= (rnp)->grphi; \
(cpu) = node_next_cpu(rnp, mask, cpu)) \
if (WARN_ON_ONCE(!cpu_possible(cpu))) \
continue; \
else
Thanks,
Mark.
next prev parent reply other threads:[~2016-12-15 11:44 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-15 2:41 [RFC v2 0/5] rcu: Introduce for_each_leaf_node_cpu() Boqun Feng
2016-12-15 2:42 ` [RFC v2 1/5] " Boqun Feng
2016-12-15 11:43 ` Mark Rutland [this message]
2016-12-15 14:38 ` Boqun Feng
2016-12-15 15:10 ` Mark Rutland
2016-12-15 15:14 ` Boqun Feng
2016-12-15 15:21 ` [RFC v2.1 " Boqun Feng
2016-12-15 15:29 ` Mark Rutland
2016-12-15 2:42 ` [RFC v2 2/5] rcu: Use for_each_leaf_node_cpu() in RCU stall checking Boqun Feng
2016-12-15 2:42 ` [RFC v2 3/5] rcu: Use for_each_leaf_node_cpu() in ->expmask iteration Boqun Feng
2016-12-15 2:42 ` [RFC v2 4/5] rcu: Use for_each_leaf_node_cpu() in force_qs_rnp() Boqun Feng
2016-12-15 12:04 ` Mark Rutland
2016-12-15 14:42 ` Boqun Feng
2016-12-15 14:51 ` Colin Ian King
2016-12-19 15:15 ` Boqun Feng
2016-12-20 5:09 ` Paul E. McKenney
2016-12-20 5:59 ` Boqun Feng
2016-12-20 8:11 ` Boqun Feng
2016-12-20 15:32 ` Paul E. McKenney
2016-12-20 15:23 ` Paul E. McKenney
2016-12-21 2:34 ` Boqun Feng
2016-12-21 3:40 ` Paul E. McKenney
2016-12-21 4:18 ` Boqun Feng
2016-12-21 16:48 ` Paul E. McKenney
2016-12-22 1:08 ` Boqun Feng
2016-12-15 2:42 ` [RFC v2 5/5] rcu: Use for_each_leaf_node_cpu() in online CPU iteration Boqun Feng
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=20161215114351.GA21758@leverpostej \
--to=mark.rutland@arm.com \
--cc=boqun.feng@gmail.com \
--cc=colin.king@canonical.com \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).