Messages in this thread | | | Date | Tue, 15 Jul 2014 03:11:50 -0700 | From | "Paul E. McKenney" <> | Subject | Re: [PATCH RFC] percpu: add data dependency barrier in percpu accessors and operations |
| |
On Mon, Jul 14, 2014 at 10:22:08AM -0500, Christoph Lameter wrote: > On Mon, 14 Jul 2014, Paul E. McKenney wrote: > > > Here is the sort of thing that I would be concerned about: > > > > p = alloc_percpu(struct foo); > > for_each_possible_cpu(cpu) > > initialize(per_cpu_ptr(p, cpu); > > gp = p; > > > > We clearly need a memory barrier in there somewhere, and it cannot > > be buried in alloc_percpu(). Some cases avoid trouble due to locking, > > for example, initialize() might acquire a per-CPU lock and later uses > > might acquire that same lock. Clearly, use of a global lock would not > > be helpful from a scalability viewpoint. > > The knowledge about the offset p is not available before gp is assigned > to. > > gp usually is part of a struct that contains some form of serialization. > F.e. in the slab allocators there is a kmem_cache structure that contains > gp. > > After alloc_percpu() and other preparatory work the structure is inserted > into a linked list while holding the global semaphore (slab_mutex). After > release of the semaphore the kmem_cache address is passed to the > subsystem. Then other processors can potentially use that new kmem_cache > structure to access new percpu data related to the new cache. > > There is no scalability issue for the initialization since there cannot > be a concurrent access since the offset of the percpu value is not known > by other processors at that point.
If I understand your initialization procedure correctly, you need at least an smp_wmb() on the update side and at least an smp_read_barrier_depends() on the read side.
Thanx, Paul
| |