1*e3ff7c60SJosh Poimboeuf /* SPDX-License-Identifier: GPL-2.0-or-later */
2*e3ff7c60SJosh Poimboeuf #ifndef _LINUX_LIVEPATCH_SCHED_H_
3*e3ff7c60SJosh Poimboeuf #define _LINUX_LIVEPATCH_SCHED_H_
4*e3ff7c60SJosh Poimboeuf 
5*e3ff7c60SJosh Poimboeuf #include <linux/jump_label.h>
6*e3ff7c60SJosh Poimboeuf #include <linux/static_call_types.h>
7*e3ff7c60SJosh Poimboeuf 
8*e3ff7c60SJosh Poimboeuf #ifdef CONFIG_LIVEPATCH
9*e3ff7c60SJosh Poimboeuf 
10*e3ff7c60SJosh Poimboeuf void __klp_sched_try_switch(void);
11*e3ff7c60SJosh Poimboeuf 
12*e3ff7c60SJosh Poimboeuf #if !defined(CONFIG_PREEMPT_DYNAMIC) || !defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL)
13*e3ff7c60SJosh Poimboeuf 
14*e3ff7c60SJosh Poimboeuf DECLARE_STATIC_KEY_FALSE(klp_sched_try_switch_key);
15*e3ff7c60SJosh Poimboeuf 
klp_sched_try_switch(void)16*e3ff7c60SJosh Poimboeuf static __always_inline void klp_sched_try_switch(void)
17*e3ff7c60SJosh Poimboeuf {
18*e3ff7c60SJosh Poimboeuf 	if (static_branch_unlikely(&klp_sched_try_switch_key))
19*e3ff7c60SJosh Poimboeuf 		__klp_sched_try_switch();
20*e3ff7c60SJosh Poimboeuf }
21*e3ff7c60SJosh Poimboeuf 
22*e3ff7c60SJosh Poimboeuf #endif /* !CONFIG_PREEMPT_DYNAMIC || !CONFIG_HAVE_PREEMPT_DYNAMIC_CALL */
23*e3ff7c60SJosh Poimboeuf 
24*e3ff7c60SJosh Poimboeuf #else /* !CONFIG_LIVEPATCH */
klp_sched_try_switch(void)25*e3ff7c60SJosh Poimboeuf static inline void klp_sched_try_switch(void) {}
__klp_sched_try_switch(void)26*e3ff7c60SJosh Poimboeuf static inline void __klp_sched_try_switch(void) {}
27*e3ff7c60SJosh Poimboeuf #endif /* CONFIG_LIVEPATCH */
28*e3ff7c60SJosh Poimboeuf 
29*e3ff7c60SJosh Poimboeuf #endif /* _LINUX_LIVEPATCH_SCHED_H_ */
30