All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, mingo@kernel.org,
	jiangshanlai@gmail.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
	josh@joshtriplett.org, tglx@linutronix.de, rostedt@goodmis.org,
	dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com,
	oleg@redhat.com, kernel-team@android.com
Subject: Re: [PATCH tip/core/rcu 16/27] rcu: Add comment documenting how rcu_seq_snap works
Date: Wed, 27 Jun 2018 11:27:26 -0700	[thread overview]
Message-ID: <20180627182726.GA79165@joelaf.mtv.corp.google.com> (raw)
In-Reply-To: <20180627175436.GC3593@linux.vnet.ibm.com>

On Wed, Jun 27, 2018 at 10:54:36AM -0700, Paul E. McKenney wrote:
> On Tue, Jun 26, 2018 at 09:39:13PM -0700, Joel Fernandes wrote:
> > On Tue, Jun 26, 2018 at 07:30:55PM +0200, Peter Zijlstra wrote:
> > > On Mon, Jun 25, 2018 at 05:35:02PM -0700, Paul E. McKenney wrote:
> > > > +/*
> > > > + * rcu_seq_snap - Take a snapshot of the update side's sequence number.
> > > > + *
> > > > + * This function returns the earliest value of the grace-period sequence number
> > > > + * that will indicate that a full grace period has elapsed since the current
> > > > + * time.  Once the grace-period sequence number has reached this value, it will
> > > > + * be safe to invoke all callbacks that have been registered prior to the
> > > > + * current time. This value is the current grace-period number plus two to the
> > > > + * power of the number of low-order bits reserved for state, then rounded up to
> > > > + * the next value in which the state bits are all zero.
> > > 
> > > If you complete that by saying _why_ you need to round up there, then
> > > the below verbiage is completely redundant.
> > > 
> > > > + * In the current design, RCU_SEQ_STATE_MASK=3 and the least significant bit of
> > > > + * the seq is used to track if a GP is in progress or not. Given this, it is
> > > > + * sufficient if we add (6+1) and mask with ~3 to get the next GP. Let's see
> > > > + * why with an example:
> > > > + *
> > > > + * Say the current seq is 12 which is 0b1100 (GP is 3 and state bits are 0b00).
> > > > + * To get to the next GP number of 4, we have to add 0b100 to this (0x1 << 2)
> > > > + * to account for the shift due to 2 state bits. Now, if the current seq is
> > > > + * 13 (GP is 3 and state bits are 0b01), then it means the current grace period
> > > > + * is already in progress so the next GP that a future call back will be queued
> > > > + * to run at is GP+2 = 5, not 4. To account for the extra +1, we just overflow
> > > > + * the 2 lower bits by adding 0b11. In case the lower bit was set, the overflow
> > > > + * will cause the extra +1 to the GP, along with the usual +1 explained before.
> > > > + * This gives us GP+2. Finally we mask the lower to bits by ~0x3 in case the
> > > > + * overflow didn't occur. This masking is needed because in case RCU was idle
> > > > + * (no GP in progress so lower 2 bits are 0b00), then the overflow of the lower
> > > > + * 2 state bits wouldn't occur, so we mask to zero out those lower 2 bits.
> > > > + *
> > > > + * In other words, the next seq can be obtained by (0b11 + 0b100) & (~0b11)
> > > > + * which can be generalized to:
> > > > + * seq + (RCU_SEQ_STATE_MASK + (RCU_SEQ_STATE_MASK + 1)) & (~RCU_SEQ_STATE_MASK)
> > > > + */
> > > 
> > > Is the below not much simpler:
> > > 
> > > >  static inline unsigned long rcu_seq_snap(unsigned long *sp)
> > > >  {
> > > >  	unsigned long s;
> > > 
> > > 	s = smp_load_aquire(sp);
> > > 
> > > 	/* Add one GP */
> > > 	s += 1 << RCU_SEQ_CTR_SHIFT;
> > > 
> > > 	/* Complete any pending state by rounding up */
> > 
> > I would suggest this comment be changed to "Add another GP if there was a
> > pending state".
> > 
> > > 	s = __ALIGN_MASK(s, RCU_SEQ_STATE_MASK);
> > > 
> > 
> > I agree with Peter's suggestions for both the verbiage reduction in the
> > comments in the header, as the new code he is proposing is more
> > self-documenting. I believe I proposed a big comment just because the code
> > wasn't self-documenting or obvious previously so needed an explanation.
> > 
> > How would you like to proceed? Let me know what you guys decide, I am really
> > Ok with anything. If you guys agree, should I write a follow-up patch with
> > Peter's suggestion that applies on top of this one?  Or do we want to drop
> > this one in favor of Peter's suggestion?
> 
> Shortening the comment would be good, so please do that.
> 
> I cannot say that I am much of a fan of the suggested change to the
> computation, but I don't feel all that strongly about it.  If the two

Did you mean a code generation standpoint or from a higher level coding standpoint?

From a code generation perspective, the code is identical, I did a quick
test to confirm that:

0000000000000000 <rcu_seq_snap_old>:
       0:       e8 00 00 00 00          callq  5 <rcu_seq_snap_old+0x5>
       5:       48 8b 07                mov    (%rdi),%rax
       8:       f0 83 44 24 fc 00       lock addl $0x0,-0x4(%rsp)
       e:       48 83 c0 07             add    $0x7,%rax
      12:       48 83 e0 fc             and    $0xfffffffffffffffc,%rax
      16:       c3                      retq
      17:       66 0f 1f 84 00 00 00    nopw   0x0(%rax,%rax,1)
      1e:       00 00

0000000000000020 <rcu_seq_snap_new>:
      20:       e8 00 00 00 00          callq  25 <rcu_seq_snap_new+0x5>
      25:       48 8b 07                mov    (%rdi),%rax
      28:       f0 83 44 24 fc 00       lock addl $0x0,-0x4(%rsp)
      2e:       48 83 c0 07             add    $0x7,%rax
      32:       48 83 e0 fc             and    $0xfffffffffffffffc,%rax
      36:       c3                      retq
      37:       66 0f 1f 84 00 00 00    nopw   0x0(%rax,%rax,1)
      3e:       00 00

> of you agree on a formulation and get at least one other RCU maintainer
> or reviewer to agree as well, I will take the change.
> 

Cool, sounds good.

thanks!

- Joel


  reply	other threads:[~2018-06-27 18:27 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26  0:34 [PATCH tip/core/rcu 0/27] Post-gp_seq miscellaneous fixes for v4.19 Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 01/27] rcu: Make rcu_read_unlock_special() static Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 02/27] rcu: Improve rcu_note_voluntary_context_switch() reporting Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 03/27] rcu: rcupdate.h: Get rid of Sphinx warnings at rcu_pointer_handoff() Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 04/27] rcu: Use pr_fmt to prefix "rcu: " to logging output Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 05/27] rcu: Improve RCU-tasks naming and comments Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 06/27] rcu: Mark task as .need_qs less aggressively Paul E. McKenney
2018-06-26 17:08   ` Peter Zijlstra
2018-06-26 18:03     ` Paul E. McKenney
2018-06-26 21:38       ` Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 07/27] rcu: Inline rcu_dynticks_momentary_idle() into its sole caller Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 08/27] rcu: Clarify and correct the rcu_preempt_qs() header comment Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 09/27] rcu: Remove unused rcu_kick_nohz_cpu() function Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 10/27] rcu: Remove unused local variable "cpu" Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 11/27] rcu: Remove "inline" from panic_on_rcu_stall() and rcu_blocking_is_gp() Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 12/27] rcu: Remove "inline" from rcu_torture_print_module_parms() Paul E. McKenney
2018-06-26  0:34 ` [PATCH tip/core/rcu 13/27] rcu: Remove "inline" from rcu_perf_print_module_parms() Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 14/27] rcu: Remove __maybe_unused from rcu_cpu_has_callbacks() Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 15/27] rcu: Use RCU CPU stall timeout for rcu_check_gp_start_stall() Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 16/27] rcu: Add comment documenting how rcu_seq_snap works Paul E. McKenney
2018-06-26 17:14   ` Peter Zijlstra
2018-06-26 18:08     ` Paul E. McKenney
2018-06-26 19:21       ` Peter Zijlstra
2018-06-26 19:31         ` Paul E. McKenney
2018-06-26 20:15           ` Peter Zijlstra
2018-06-26 22:27             ` Paul E. McKenney
2018-06-26 17:30   ` Peter Zijlstra
2018-06-26 18:10     ` Paul E. McKenney
2018-06-26 19:27       ` Peter Zijlstra
2018-06-27  4:39     ` Joel Fernandes
2018-06-27 17:54       ` Paul E. McKenney
2018-06-27 18:27         ` Joel Fernandes [this message]
2018-06-27 19:11           ` Paul E. McKenney
2018-06-28  5:10           ` Joel Fernandes
2018-06-28 17:42             ` Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 17/27] rcu: Speed up calling of RCU tasks callbacks Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 18/27] rcu: Add comment to the last sleep in the rcu tasks loop Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 19/27] rcu: Add diagnostics for rcutorture writer stall warning Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 20/27] rcu: Check the range of jiffies_till_{first,next}_fqs when setting them Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 21/27] doc: Update synchronize_rcu() definition in whatisRCU.txt Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 22/27] rcu: Make rcu_seq_diff() more exact Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 23/27] MAINTAINERS: Update RCU, SRCU, and TORTURE-TEST entries Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 24/27] rcu: Print stall-warning NMI dyntick state in hexadecimal Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 25/27] srcu: Add grace-period number to rcutorture statistics printout Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 26/27] rculist: Improve documentation for list_for_each_entry_from_rcu() Paul E. McKenney
2018-06-26  0:35 ` [PATCH tip/core/rcu 27/27] rcu: Assign higher prio to RCU threads if rcutorture is built-in 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=20180627182726.GA79165@joelaf.mtv.corp.google.com \
    --to=joel@joelfernandes.org \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=edumazet@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.