lglock.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Specialised local-global spinlock. Can only be declared as global variables
  3. * to avoid overhead and keep things simple (and we don't want to start using
  4. * these inside dynamically allocated structures).
  5. *
  6. * "local/global locks" (lglocks) can be used to:
  7. *
  8. * - Provide fast exclusive access to per-CPU data, with exclusive access to
  9. * another CPU's data allowed but possibly subject to contention, and to
  10. * provide very slow exclusive access to all per-CPU data.
  11. * - Or to provide very fast and scalable read serialisation, and to provide
  12. * very slow exclusive serialisation of data (not necessarily per-CPU data).
  13. *
  14. * Brlocks are also implemented as a short-hand notation for the latter use
  15. * case.
  16. *
  17. * Copyright 2009, 2010, Nick Piggin, Novell Inc.
  18. */
  19. #ifndef __LINUX_LGLOCK_H
  20. #define __LINUX_LGLOCK_H
  21. #include <linux/spinlock.h>
  22. #include <linux/lockdep.h>
  23. #include <linux/percpu.h>
  24. #include <linux/cpu.h>
  25. #include <linux/notifier.h>
  26. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  27. #define LOCKDEP_INIT_MAP lockdep_init_map
  28. #else
  29. #define LOCKDEP_INIT_MAP(a, b, c, d)
  30. #endif
  31. struct lglock {
  32. arch_spinlock_t __percpu *lock;
  33. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  34. struct lock_class_key lock_key;
  35. struct lockdep_map lock_dep_map;
  36. #endif
  37. };
  38. #define DEFINE_LGLOCK(name) \
  39. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  40. = __ARCH_SPIN_LOCK_UNLOCKED; \
  41. struct lglock name = { .lock = &name ## _lock }
  42. #define DEFINE_STATIC_LGLOCK(name) \
  43. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  44. = __ARCH_SPIN_LOCK_UNLOCKED; \
  45. static struct lglock name = { .lock = &name ## _lock }
  46. void lg_lock_init(struct lglock *lg, char *name);
  47. void lg_local_lock(struct lglock *lg);
  48. void lg_local_unlock(struct lglock *lg);
  49. void lg_local_lock_cpu(struct lglock *lg, int cpu);
  50. void lg_local_unlock_cpu(struct lglock *lg, int cpu);
  51. void lg_global_lock(struct lglock *lg);
  52. void lg_global_unlock(struct lglock *lg);
  53. #endif