preempt.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #ifndef __ASM_PREEMPT_H
  2. #define __ASM_PREEMPT_H
  3. #include <asm/current.h>
  4. #include <linux/thread_info.h>
  5. #include <asm/atomic_ops.h>
  6. #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
  7. #define PREEMPT_ENABLED (0 + PREEMPT_NEED_RESCHED)
  8. static inline int preempt_count(void)
  9. {
  10. return READ_ONCE(S390_lowcore.preempt_count) & ~PREEMPT_NEED_RESCHED;
  11. }
  12. static inline void preempt_count_set(int pc)
  13. {
  14. int old, new;
  15. do {
  16. old = READ_ONCE(S390_lowcore.preempt_count);
  17. new = (old & PREEMPT_NEED_RESCHED) |
  18. (pc & ~PREEMPT_NEED_RESCHED);
  19. } while (__atomic_cmpxchg(&S390_lowcore.preempt_count,
  20. old, new) != old);
  21. }
  22. #define init_task_preempt_count(p) do { } while (0)
  23. #define init_idle_preempt_count(p, cpu) do { \
  24. S390_lowcore.preempt_count = PREEMPT_ENABLED; \
  25. } while (0)
  26. static inline void set_preempt_need_resched(void)
  27. {
  28. __atomic_and(~PREEMPT_NEED_RESCHED, &S390_lowcore.preempt_count);
  29. }
  30. static inline void clear_preempt_need_resched(void)
  31. {
  32. __atomic_or(PREEMPT_NEED_RESCHED, &S390_lowcore.preempt_count);
  33. }
  34. static inline bool test_preempt_need_resched(void)
  35. {
  36. return !(READ_ONCE(S390_lowcore.preempt_count) & PREEMPT_NEED_RESCHED);
  37. }
  38. static inline void __preempt_count_add(int val)
  39. {
  40. if (__builtin_constant_p(val) && (val >= -128) && (val <= 127))
  41. __atomic_add_const(val, &S390_lowcore.preempt_count);
  42. else
  43. __atomic_add(val, &S390_lowcore.preempt_count);
  44. }
  45. static inline void __preempt_count_sub(int val)
  46. {
  47. __preempt_count_add(-val);
  48. }
  49. static inline bool __preempt_count_dec_and_test(void)
  50. {
  51. return __atomic_add(-1, &S390_lowcore.preempt_count) == 1;
  52. }
  53. static inline bool should_resched(int preempt_offset)
  54. {
  55. return unlikely(READ_ONCE(S390_lowcore.preempt_count) ==
  56. preempt_offset);
  57. }
  58. #else /* CONFIG_HAVE_MARCH_Z196_FEATURES */
  59. #define PREEMPT_ENABLED (0)
  60. static inline int preempt_count(void)
  61. {
  62. return READ_ONCE(S390_lowcore.preempt_count);
  63. }
  64. static inline void preempt_count_set(int pc)
  65. {
  66. S390_lowcore.preempt_count = pc;
  67. }
  68. #define init_task_preempt_count(p) do { } while (0)
  69. #define init_idle_preempt_count(p, cpu) do { \
  70. S390_lowcore.preempt_count = PREEMPT_ENABLED; \
  71. } while (0)
  72. static inline void set_preempt_need_resched(void)
  73. {
  74. }
  75. static inline void clear_preempt_need_resched(void)
  76. {
  77. }
  78. static inline bool test_preempt_need_resched(void)
  79. {
  80. return false;
  81. }
  82. static inline void __preempt_count_add(int val)
  83. {
  84. S390_lowcore.preempt_count += val;
  85. }
  86. static inline void __preempt_count_sub(int val)
  87. {
  88. S390_lowcore.preempt_count -= val;
  89. }
  90. static inline bool __preempt_count_dec_and_test(void)
  91. {
  92. return !--S390_lowcore.preempt_count && tif_need_resched();
  93. }
  94. static inline bool should_resched(int preempt_offset)
  95. {
  96. return unlikely(preempt_count() == preempt_offset &&
  97. tif_need_resched());
  98. }
  99. #endif /* CONFIG_HAVE_MARCH_Z196_FEATURES */
  100. #ifdef CONFIG_PREEMPT
  101. extern asmlinkage void preempt_schedule(void);
  102. #define __preempt_schedule() preempt_schedule()
  103. extern asmlinkage void preempt_schedule_notrace(void);
  104. #define __preempt_schedule_notrace() preempt_schedule_notrace()
  105. #endif /* CONFIG_PREEMPT */
  106. #endif /* __ASM_PREEMPT_H */