qspinlock_types.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Queued spinlock
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
  15. *
  16. * Authors: Waiman Long <waiman.long@hp.com>
  17. */
  18. #ifndef __ASM_GENERIC_QSPINLOCK_TYPES_H
  19. #define __ASM_GENERIC_QSPINLOCK_TYPES_H
  20. /*
  21. * Including atomic.h with PARAVIRT on will cause compilation errors because
  22. * of recursive header file incluson via paravirt_types.h. So don't include
  23. * it if PARAVIRT is on.
  24. */
  25. #ifndef CONFIG_PARAVIRT
  26. #include <linux/types.h>
  27. #include <linux/atomic.h>
  28. #endif
  29. typedef struct qspinlock {
  30. atomic_t val;
  31. } arch_spinlock_t;
  32. /*
  33. * Initializier
  34. */
  35. #define __ARCH_SPIN_LOCK_UNLOCKED { ATOMIC_INIT(0) }
  36. /*
  37. * Bitfields in the atomic value:
  38. *
  39. * When NR_CPUS < 16K
  40. * 0- 7: locked byte
  41. * 8: pending
  42. * 9-15: not used
  43. * 16-17: tail index
  44. * 18-31: tail cpu (+1)
  45. *
  46. * When NR_CPUS >= 16K
  47. * 0- 7: locked byte
  48. * 8: pending
  49. * 9-10: tail index
  50. * 11-31: tail cpu (+1)
  51. */
  52. #define _Q_SET_MASK(type) (((1U << _Q_ ## type ## _BITS) - 1)\
  53. << _Q_ ## type ## _OFFSET)
  54. #define _Q_LOCKED_OFFSET 0
  55. #define _Q_LOCKED_BITS 8
  56. #define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED)
  57. #define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS)
  58. #if CONFIG_NR_CPUS < (1U << 14)
  59. #define _Q_PENDING_BITS 8
  60. #else
  61. #define _Q_PENDING_BITS 1
  62. #endif
  63. #define _Q_PENDING_MASK _Q_SET_MASK(PENDING)
  64. #define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)
  65. #define _Q_TAIL_IDX_BITS 2
  66. #define _Q_TAIL_IDX_MASK _Q_SET_MASK(TAIL_IDX)
  67. #define _Q_TAIL_CPU_OFFSET (_Q_TAIL_IDX_OFFSET + _Q_TAIL_IDX_BITS)
  68. #define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)
  69. #define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU)
  70. #define _Q_TAIL_OFFSET _Q_TAIL_IDX_OFFSET
  71. #define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)
  72. #define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
  73. #define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
  74. #endif /* __ASM_GENERIC_QSPINLOCK_TYPES_H */