]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - arch/s390/include/asm/preempt.h
1 #ifndef __ASM_PREEMPT_H
2 #define __ASM_PREEMPT_H
4 #include <asm/current.h>
5 #include <linux/thread_info.h>
6 #include <asm/atomic_ops.h>
8 #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
10 #define PREEMPT_ENABLED (0 + PREEMPT_NEED_RESCHED)
12 static inline int preempt_count(void)
14 return READ_ONCE(S390_lowcore
.preempt_count
) & ~PREEMPT_NEED_RESCHED
;
17 static inline void preempt_count_set(int pc
)
22 old
= READ_ONCE(S390_lowcore
.preempt_count
);
23 new = (old
& PREEMPT_NEED_RESCHED
) |
24 (pc
& ~PREEMPT_NEED_RESCHED
);
25 } while (__atomic_cmpxchg(&S390_lowcore
.preempt_count
,
29 #define init_task_preempt_count(p) do { } while (0)
31 #define init_idle_preempt_count(p, cpu) do { \
32 S390_lowcore.preempt_count = PREEMPT_ENABLED; \
35 static inline void set_preempt_need_resched(void)
37 __atomic_and(~PREEMPT_NEED_RESCHED
, &S390_lowcore
.preempt_count
);
40 static inline void clear_preempt_need_resched(void)
42 __atomic_or(PREEMPT_NEED_RESCHED
, &S390_lowcore
.preempt_count
);
45 static inline bool test_preempt_need_resched(void)
47 return !(READ_ONCE(S390_lowcore
.preempt_count
) & PREEMPT_NEED_RESCHED
);
50 static inline void __preempt_count_add(int val
)
52 if (__builtin_constant_p(val
) && (val
>= -128) && (val
<= 127))
53 __atomic_add_const(val
, &S390_lowcore
.preempt_count
);
55 __atomic_add(val
, &S390_lowcore
.preempt_count
);
58 static inline void __preempt_count_sub(int val
)
60 __preempt_count_add(-val
);
63 static inline bool __preempt_count_dec_and_test(void)
65 return __atomic_add(-1, &S390_lowcore
.preempt_count
) == 1;
68 static inline bool should_resched(int preempt_offset
)
70 return unlikely(READ_ONCE(S390_lowcore
.preempt_count
) ==
74 #else /* CONFIG_HAVE_MARCH_Z196_FEATURES */
76 #define PREEMPT_ENABLED (0)
78 static inline int preempt_count(void)
80 return READ_ONCE(S390_lowcore
.preempt_count
);
83 static inline void preempt_count_set(int pc
)
85 S390_lowcore
.preempt_count
= pc
;
88 #define init_task_preempt_count(p) do { } while (0)
90 #define init_idle_preempt_count(p, cpu) do { \
91 S390_lowcore.preempt_count = PREEMPT_ENABLED; \
94 static inline void set_preempt_need_resched(void)
98 static inline void clear_preempt_need_resched(void)
102 static inline bool test_preempt_need_resched(void)
107 static inline void __preempt_count_add(int val
)
109 S390_lowcore
.preempt_count
+= val
;
112 static inline void __preempt_count_sub(int val
)
114 S390_lowcore
.preempt_count
-= val
;
117 static inline bool __preempt_count_dec_and_test(void)
119 return !--S390_lowcore
.preempt_count
&& tif_need_resched();
122 static inline bool should_resched(int preempt_offset
)
124 return unlikely(preempt_count() == preempt_offset
&&
128 #endif /* CONFIG_HAVE_MARCH_Z196_FEATURES */
130 #ifdef CONFIG_PREEMPT
131 extern asmlinkage
void preempt_schedule(void);
132 #define __preempt_schedule() preempt_schedule()
133 extern asmlinkage
void preempt_schedule_notrace(void);
134 #define __preempt_schedule_notrace() preempt_schedule_notrace()
135 #endif /* CONFIG_PREEMPT */
137 #endif /* __ASM_PREEMPT_H */