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
)
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
,
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; \
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
);
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
) ==
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; \
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)
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
&&
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 */