On Sat, Jun 29, 2013 at 1:23 PM, Waiman Long <waiman.long@xxxxxx> wrote: >> >> But more importantly, I think this needs to be architecture-specific, >> and using<linux/spinlock_refcount.h> to try to do some generic 64-bit >> cmpxchg() version is a bad bad idea. > > Yes, I can put the current implementation into > asm-generic/spinlock_refcount.h. Now I need to put an > asm/spinlock_refcount.h into every arch's include/asm directory. Right? No, I'd suggest something slightly different: we did something fairly similar to this with the per-arch optimized version of the word-at-a-time filename hashing/lookup. So the sanest approach is something like this: STEP 1: - create a new set of config option (say "CONFIG_[ARCH_]SPINLOCK_REFCOUNT") that defaults to 'y' and isn't actually asked about anywhere. Just a simple config ARCH_SPINLOCK_REFCOUNT bool config SPINLOCK_REFCOUNT depends on ARCH_SPINLOCK_REFCOUNT depends on !GENERIC_LOCKBREAK depends on !DEBUG_SPINLOCK depends on !DEBUG_LOCK_ALLOC bool in init/Kconfig will do that. - create a <linux/spinlock-refcount.h> that looks something like this #ifdef CONFIG_SPINLOCK_REFCOUNT #include <asm/spinlock-refcount.h> #else .. fallback implementation with normal spinlocks that works for all cases, including lockdep etc .. #endif and now you should have something that should already work, it just doesn't actually do the optimized cases for any architecture. Equally importantly, it already self-disables itself if any of the complicated debug options are set that means that a spinlock is anything but the raw architecture spinlock. STEP 2: - Now, step #2 is *not* to do per-architecture version, but to do the generic cmpxchg version, and make that in <asm-generic/spinlock-refcount.h> At this point, any architecture can decide to hook into the generic version with something like this in their own architecture Kconfig file: select CONFIG_ARCH_SPINLOCK_REFCOUNT and adding the line generic-y += spinlock-refcount.h to their architecture Kbuild file. So after step two, you basically have an easy way for architectures to step in one by one with the cmpxchg version, after they have verified that their spinlocks work for it. And notice how little the architecture actually needed to do? STEP 3: - This is the "architecture decides to not use the <asm-generic/spinlock-refcount.h> file, and instead creates its own optimized version of it. All these steps are nice and easy and can be tested on their own. And make sense on their own. Even that first step is important, since that's when you create the logic, and that's the code that will be used when spinlock debugging is enabled etc. The third step may not ever happen for all architectures. Even the second step might be something that some architecture decides is not worth it (ie slow and complex atomics, but fast spinlocks). And all three steps should be fairly small and logical, I think. Linus -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html