1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_HARDIRQ_H
3 #define LINUX_HARDIRQ_H
5 #include <linux/context_tracking_state.h>
6 #include <linux/preempt.h>
7 #include <linux/lockdep.h>
8 #include <linux/ftrace_irq.h>
9 #include <linux/vtime.h>
10 #include <asm/hardirq.h>
12 extern void synchronize_irq(unsigned int irq);
13 extern bool synchronize_hardirq(unsigned int irq);
15 #ifdef CONFIG_NO_HZ_FULL
16 void __rcu_irq_enter_check_tick(void);
18 static inline void __rcu_irq_enter_check_tick(void) { }
21 static __always_inline void rcu_irq_enter_check_tick(void)
23 if (context_tracking_enabled())
24 __rcu_irq_enter_check_tick();
28 * It is safe to do non-atomic ops on ->hardirq_context,
29 * because NMI handlers may not preempt and the ops are
30 * always balanced, so the interrupted value of ->hardirq_context
31 * will always be restored.
33 #define __irq_enter() \
35 account_irq_enter_time(current); \
36 preempt_count_add(HARDIRQ_OFFSET); \
37 lockdep_hardirq_enter(); \
41 * Enter irq context (on NO_HZ, update jiffies):
45 * Like irq_enter(), but RCU is already watching.
47 void irq_enter_rcu(void);
50 * Exit irq context without processing softirqs:
52 #define __irq_exit() \
54 lockdep_hardirq_exit(); \
55 account_irq_exit_time(current); \
56 preempt_count_sub(HARDIRQ_OFFSET); \
60 * Exit irq context and process softirqs if needed:
65 * Like irq_exit(), but return with RCU watching.
67 void irq_exit_rcu(void);
69 #ifndef arch_nmi_enter
70 #define arch_nmi_enter() do { } while (0)
71 #define arch_nmi_exit() do { } while (0)
74 #ifdef CONFIG_TINY_RCU
75 static inline void rcu_nmi_enter(void) { }
76 static inline void rcu_nmi_exit(void) { }
78 extern void rcu_nmi_enter(void);
79 extern void rcu_nmi_exit(void);
86 * We must not land in a tracer until (or after) we've changed preempt_count
87 * such that in_nmi() becomes true. To that effect all NMI C entry points must
88 * be marked 'notrace' and call nmi_enter() as soon as possible.
92 * nmi_enter() can nest up to 15 times; see NMI_BITS.
99 BUG_ON(in_nmi() == NMI_MASK); \
100 __preempt_count_add(NMI_OFFSET + HARDIRQ_OFFSET); \
102 lockdep_hardirq_enter(); \
103 instrumentation_begin(); \
104 ftrace_nmi_enter(); \
105 instrumentation_end(); \
110 instrumentation_begin(); \
112 instrumentation_end(); \
113 lockdep_hardirq_exit(); \
116 __preempt_count_sub(NMI_OFFSET + HARDIRQ_OFFSET); \
122 #endif /* LINUX_HARDIRQ_H */