0001
0002 #ifndef __ASM_PREEMPT_H
0003 #define __ASM_PREEMPT_H
0004
0005 #include <asm/rmwcc.h>
0006 #include <asm/percpu.h>
0007 #include <linux/thread_info.h>
0008 #include <linux/static_call_types.h>
0009
0010 DECLARE_PER_CPU(int, __preempt_count);
0011
0012
0013 #define PREEMPT_NEED_RESCHED 0x80000000
0014
0015
0016
0017
0018
0019 #define PREEMPT_ENABLED (0 + PREEMPT_NEED_RESCHED)
0020
0021
0022
0023
0024
0025 static __always_inline int preempt_count(void)
0026 {
0027 return raw_cpu_read_4(__preempt_count) & ~PREEMPT_NEED_RESCHED;
0028 }
0029
0030 static __always_inline void preempt_count_set(int pc)
0031 {
0032 int old, new;
0033
0034 do {
0035 old = raw_cpu_read_4(__preempt_count);
0036 new = (old & PREEMPT_NEED_RESCHED) |
0037 (pc & ~PREEMPT_NEED_RESCHED);
0038 } while (raw_cpu_cmpxchg_4(__preempt_count, old, new) != old);
0039 }
0040
0041
0042
0043
0044 #define init_task_preempt_count(p) do { } while (0)
0045
0046 #define init_idle_preempt_count(p, cpu) do { \
0047 per_cpu(__preempt_count, (cpu)) = PREEMPT_DISABLED; \
0048 } while (0)
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 static __always_inline void set_preempt_need_resched(void)
0060 {
0061 raw_cpu_and_4(__preempt_count, ~PREEMPT_NEED_RESCHED);
0062 }
0063
0064 static __always_inline void clear_preempt_need_resched(void)
0065 {
0066 raw_cpu_or_4(__preempt_count, PREEMPT_NEED_RESCHED);
0067 }
0068
0069 static __always_inline bool test_preempt_need_resched(void)
0070 {
0071 return !(raw_cpu_read_4(__preempt_count) & PREEMPT_NEED_RESCHED);
0072 }
0073
0074
0075
0076
0077
0078 static __always_inline void __preempt_count_add(int val)
0079 {
0080 raw_cpu_add_4(__preempt_count, val);
0081 }
0082
0083 static __always_inline void __preempt_count_sub(int val)
0084 {
0085 raw_cpu_add_4(__preempt_count, -val);
0086 }
0087
0088
0089
0090
0091
0092
0093 static __always_inline bool __preempt_count_dec_and_test(void)
0094 {
0095 return GEN_UNARY_RMWcc("decl", __preempt_count, e, __percpu_arg([var]));
0096 }
0097
0098
0099
0100
0101 static __always_inline bool should_resched(int preempt_offset)
0102 {
0103 return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset);
0104 }
0105
0106 #ifdef CONFIG_PREEMPTION
0107
0108 extern asmlinkage void preempt_schedule(void);
0109 extern asmlinkage void preempt_schedule_thunk(void);
0110
0111 #define preempt_schedule_dynamic_enabled preempt_schedule_thunk
0112 #define preempt_schedule_dynamic_disabled NULL
0113
0114 extern asmlinkage void preempt_schedule_notrace(void);
0115 extern asmlinkage void preempt_schedule_notrace_thunk(void);
0116
0117 #define preempt_schedule_notrace_dynamic_enabled preempt_schedule_notrace_thunk
0118 #define preempt_schedule_notrace_dynamic_disabled NULL
0119
0120 #ifdef CONFIG_PREEMPT_DYNAMIC
0121
0122 DECLARE_STATIC_CALL(preempt_schedule, preempt_schedule_dynamic_enabled);
0123
0124 #define __preempt_schedule() \
0125 do { \
0126 __STATIC_CALL_MOD_ADDRESSABLE(preempt_schedule); \
0127 asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule) : ASM_CALL_CONSTRAINT); \
0128 } while (0)
0129
0130 DECLARE_STATIC_CALL(preempt_schedule_notrace, preempt_schedule_notrace_dynamic_enabled);
0131
0132 #define __preempt_schedule_notrace() \
0133 do { \
0134 __STATIC_CALL_MOD_ADDRESSABLE(preempt_schedule_notrace); \
0135 asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule_notrace) : ASM_CALL_CONSTRAINT); \
0136 } while (0)
0137
0138 #else
0139
0140 #define __preempt_schedule() \
0141 asm volatile ("call preempt_schedule_thunk" : ASM_CALL_CONSTRAINT);
0142
0143 #define __preempt_schedule_notrace() \
0144 asm volatile ("call preempt_schedule_notrace_thunk" : ASM_CALL_CONSTRAINT);
0145
0146 #endif
0147
0148 #endif
0149
0150 #endif