top | item 10058121

(no title)

k4st | 10 years ago

That is fine ;-) Sum up the counters.

discuss

order

haberman|10 years ago

I don't think that works. You can't get a consistent view of the counters without a lock. Consider the following scenario:

       CPU1                   CPU2
       ----                   ----
                              T1 rcu_read_lock (+1)
       read counter (0)
       T2 rcu_read_lock (+1)
                              T2 rcu_read_unlock (-1)
                              read counter (0)
We'll find that zero is the sum of all counters, even though T1 is still in its read lock.

k4st|10 years ago

Indeed! I think I missed that in the original algorithm it doesn't wait for all slots to be zero, just that each slot go to zero. In that way it is just like waiting for each reader to go through a period of quiescence. This is a lot like the the version of rcu where the writer shuttles itself across cpus to use syscalls returns as a proxy for knowing that a particular cpu is not in any read side critical sections.

If there were a nice way to swap out the counters then summing would work, unfortunately that introduces an even bigger race :-(

Thanks for the correction!