treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / s390 / include / asm / preempt.h
blob6ede29907fbf76424ed52de165db93af0e600933
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 /* We use the MSB mostly because its available */
12 #define PREEMPT_NEED_RESCHED 0x80000000
13 #define PREEMPT_ENABLED (0 + PREEMPT_NEED_RESCHED)
15 static inline int preempt_count(void)
17 return READ_ONCE(S390_lowcore.preempt_count) & ~PREEMPT_NEED_RESCHED;
20 static inline void preempt_count_set(int pc)
22 int old, new;
24 do {
25 old = READ_ONCE(S390_lowcore.preempt_count);
26 new = (old & PREEMPT_NEED_RESCHED) |
27 (pc & ~PREEMPT_NEED_RESCHED);
28 } while (__atomic_cmpxchg(&S390_lowcore.preempt_count,
29 old, new) != old);
32 #define init_task_preempt_count(p) do { } while (0)
34 #define init_idle_preempt_count(p, cpu) do { \
35 S390_lowcore.preempt_count = PREEMPT_ENABLED; \
36 } while (0)
38 static inline void set_preempt_need_resched(void)
40 __atomic_and(~PREEMPT_NEED_RESCHED, &S390_lowcore.preempt_count);
43 static inline void clear_preempt_need_resched(void)
45 __atomic_or(PREEMPT_NEED_RESCHED, &S390_lowcore.preempt_count);
48 static inline bool test_preempt_need_resched(void)
50 return !(READ_ONCE(S390_lowcore.preempt_count) & PREEMPT_NEED_RESCHED);
53 static inline void __preempt_count_add(int val)
55 if (__builtin_constant_p(val) && (val >= -128) && (val <= 127))
56 __atomic_add_const(val, &S390_lowcore.preempt_count);
57 else
58 __atomic_add(val, &S390_lowcore.preempt_count);
61 static inline void __preempt_count_sub(int val)
63 __preempt_count_add(-val);
66 static inline bool __preempt_count_dec_and_test(void)
68 return __atomic_add(-1, &S390_lowcore.preempt_count) == 1;
71 static inline bool should_resched(int preempt_offset)
73 return unlikely(READ_ONCE(S390_lowcore.preempt_count) ==
74 preempt_offset);
77 #else /* CONFIG_HAVE_MARCH_Z196_FEATURES */
79 #define PREEMPT_ENABLED (0)
81 static inline int preempt_count(void)
83 return READ_ONCE(S390_lowcore.preempt_count);
86 static inline void preempt_count_set(int pc)
88 S390_lowcore.preempt_count = pc;
91 #define init_task_preempt_count(p) do { } while (0)
93 #define init_idle_preempt_count(p, cpu) do { \
94 S390_lowcore.preempt_count = PREEMPT_ENABLED; \
95 } while (0)
97 static inline void set_preempt_need_resched(void)
101 static inline void clear_preempt_need_resched(void)
105 static inline bool test_preempt_need_resched(void)
107 return false;
110 static inline void __preempt_count_add(int val)
112 S390_lowcore.preempt_count += val;
115 static inline void __preempt_count_sub(int val)
117 S390_lowcore.preempt_count -= val;
120 static inline bool __preempt_count_dec_and_test(void)
122 return !--S390_lowcore.preempt_count && tif_need_resched();
125 static inline bool should_resched(int preempt_offset)
127 return unlikely(preempt_count() == preempt_offset &&
128 tif_need_resched());
131 #endif /* CONFIG_HAVE_MARCH_Z196_FEATURES */
133 #ifdef CONFIG_PREEMPTION
134 extern asmlinkage void preempt_schedule(void);
135 #define __preempt_schedule() preempt_schedule()
136 extern asmlinkage void preempt_schedule_notrace(void);
137 #define __preempt_schedule_notrace() preempt_schedule_notrace()
138 #endif /* CONFIG_PREEMPTION */
140 #endif /* __ASM_PREEMPT_H */