All of lore.kernel.org
 help / color / mirror / Atom feed
* Probably redundant code at listing 7.7
@ 2017-10-21 13:58 Yubin Ruan
  2017-10-21 17:45 ` Paul E. McKenney
  0 siblings, 1 reply; 5+ messages in thread
From: Yubin Ruan @ 2017-10-21 13:58 UTC (permalink / raw)
  To: perfbook

Hi,

In Listing 7.7, a hierarchy/conditional locking example is used to
show how to reduce how contention:

1 void force_quiescent_state(struct rcu_node *rnp_leaf)
2 {
3      int ret;
4      struct rcu_node *rnp = rnp_leaf;
5      struct rcu_node *rnp_old = NULL;
6
7      for (; rnp != NULL; rnp = rnp->parent) {
8          ret = (ACCESS_ONCE(gp_flags)) ||
9                  !raw_spin_trylock(&rnp->fqslock);
10         if (rnp_old != NULL)
11             raw_spin_unlock(&rnp_old->fqslock);
12         if (ret)
13             return;
14         rnp_old = rnp;
15     }
16     if (!ACCESS_ONCE(gp_flags)) {
17         ACCESS_ONCE(gp_flags) = 1;
18         do_force_quiescent_state();
19         ACCESS_ONCE(gp_flags) = 0;
20     }
21     raw_spin_unlock(&rnp_old->fqslock);
22 }

I understand the purpose and most of the implementation of the code.
But one thing I don't really understand is that why we need line 16
here? By reaching line 16, we can be sure that that particular process
have already acquired the fqslock of the root node and it should be
the only one to reach there. So, it will always see gp_flags == 0 when
reaching line 16.

Did I miss anything? I read Quick Quiz 7.21 and it seems that there
might be some tricky things there.

Yubin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-23  5:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-21 13:58 Probably redundant code at listing 7.7 Yubin Ruan
2017-10-21 17:45 ` Paul E. McKenney
2017-10-22  6:41   ` Yubin Ruan
2017-10-23  2:01     ` Paul E. McKenney
2017-10-23  5:47       ` Yubin Ruan

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.