Merge tag 'pm-fixes-4.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux/fpc-iii.git] / arch / s390 / include / asm / preempt.h
blob23a14d187fb1ba72b294ac3cd21aae49f69200dc
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_PREEMPT_H
3 #define __ASM_PREEMPT_H
5 #include <asm/current.h>
6 #include <linux/thread_info.h>
7 #include <asm/atomic_ops.h>
9 #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
11 #define PREEMPT_ENABLED (0 + PREEMPT_NEED_RESCHED)
13 static inline int preempt_count(void)
15 return READ_ONCE(S390_lowcore.preempt_count) & ~PREEMPT_NEED_RESCHED;
18 static inline void preempt_count_set(int pc)
20 int old, new;
22 do {
23 old = READ_ONCE(S390_lowcore.preempt_count);
24 new = (old & PREEMPT_NEED_RESCHED) |
25 (pc & ~PREEMPT_NEED_RESCHED);
26 } while (__atomic_cmpxchg(&S390_lowcore.preempt_count,
27 old, new) != old);
30 #define init_task_preempt_count(p) do { } while (0)
32 #define init_idle_preempt_count(p, cpu) do { \
33 S390_lowcore.preempt_count = PREEMPT_ENABLED; \
34 } while (0)
36 static inline void set_preempt_need_resched(void)
38 __atomic_and(~PREEMPT_NEED_RESCHED, &S390_lowcore.preempt_count);
41 static inline void clear_preempt_need_resched(void)
43 __atomic_or(PREEMPT_NEED_RESCHED, &S390_lowcore.preempt_count);
46 static inline bool test_preempt_need_resched(void)
48 return !(READ_ONCE(S390_lowcore.preempt_count) & PREEMPT_NEED_RESCHED);
51 static inline void __preempt_count_add(int val)
53 if (__builtin_constant_p(val) && (val >= -128) && (val <= 127))
54 __atomic_add_const(val, &S390_lowcore.preempt_count);
55 else
56 __atomic_add(val, &S390_lowcore.preempt_count);
59 static inline void __preempt_count_sub(int val)
61 __preempt_count_add(-val);
64 static inline bool __preempt_count_dec_and_test(void)
66 return __atomic_add(-1, &S390_lowcore.preempt_count) == 1;
69 static inline bool should_resched(int preempt_offset)
71 return unlikely(READ_ONCE(S390_lowcore.preempt_count) ==
72 preempt_offset);
75 #else /* CONFIG_HAVE_MARCH_Z196_FEATURES */
77 #define PREEMPT_ENABLED (0)
79 static inline int preempt_count(void)
81 return READ_ONCE(S390_lowcore.preempt_count);
84 static inline void preempt_count_set(int pc)
86 S390_lowcore.preempt_count = pc;
89 #define init_task_preempt_count(p) do { } while (0)
91 #define init_idle_preempt_count(p, cpu) do { \
92 S390_lowcore.preempt_count = PREEMPT_ENABLED; \
93 } while (0)
95 static inline void set_preempt_need_resched(void)
99 static inline void clear_preempt_need_resched(void)
103 static inline bool test_preempt_need_resched(void)
105 return false;
108 static inline void __preempt_count_add(int val)
110 S390_lowcore.preempt_count += val;
113 static inline void __preempt_count_sub(int val)
115 S390_lowcore.preempt_count -= val;
118 static inline bool __preempt_count_dec_and_test(void)
120 return !--S390_lowcore.preempt_count && tif_need_resched();
123 static inline bool should_resched(int preempt_offset)
125 return unlikely(preempt_count() == preempt_offset &&
126 tif_need_resched());
129 #endif /* CONFIG_HAVE_MARCH_Z196_FEATURES */
131 #ifdef CONFIG_PREEMPT
132 extern asmlinkage void preempt_schedule(void);
133 #define __preempt_schedule() preempt_schedule()
134 extern asmlinkage void preempt_schedule_notrace(void);
135 #define __preempt_schedule_notrace() preempt_schedule_notrace()
136 #endif /* CONFIG_PREEMPT */
138 #endif /* __ASM_PREEMPT_H */