Skip to content

Commit cfe43f4

Browse files
Valentin SchneiderPeter Zijlstra
authored andcommitted
preempt/dynamic: Introduce preemption model accessors
CONFIG_PREEMPT{_NONE, _VOLUNTARY} designate either: o The build-time preemption model when !PREEMPT_DYNAMIC o The default boot-time preemption model when PREEMPT_DYNAMIC IOW, using those on PREEMPT_DYNAMIC kernels is meaningless - the actual model could have been set to something else by the "preempt=foo" cmdline parameter. Same problem applies to CONFIG_PREEMPTION. Introduce a set of helpers to determine the actual preemption model used by the live kernel. Suggested-by: Marco Elver <[email protected]> Signed-off-by: Valentin Schneider <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Marco Elver <[email protected]> Acked-by: Frederic Weisbecker <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3123109 commit cfe43f4

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

include/linux/sched.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,47 @@ static inline void cond_resched_rcu(void)
21172117
#endif
21182118
}
21192119

2120+
#ifdef CONFIG_PREEMPT_DYNAMIC
2121+
2122+
extern bool preempt_model_none(void);
2123+
extern bool preempt_model_voluntary(void);
2124+
extern bool preempt_model_full(void);
2125+
2126+
#else
2127+
2128+
static inline bool preempt_model_none(void)
2129+
{
2130+
return IS_ENABLED(CONFIG_PREEMPT_NONE);
2131+
}
2132+
static inline bool preempt_model_voluntary(void)
2133+
{
2134+
return IS_ENABLED(CONFIG_PREEMPT_VOLUNTARY);
2135+
}
2136+
static inline bool preempt_model_full(void)
2137+
{
2138+
return IS_ENABLED(CONFIG_PREEMPT);
2139+
}
2140+
2141+
#endif
2142+
2143+
static inline bool preempt_model_rt(void)
2144+
{
2145+
return IS_ENABLED(CONFIG_PREEMPT_RT);
2146+
}
2147+
2148+
/*
2149+
* Does the preemption model allow non-cooperative preemption?
2150+
*
2151+
* For !CONFIG_PREEMPT_DYNAMIC kernels this is an exact match with
2152+
* CONFIG_PREEMPTION; for CONFIG_PREEMPT_DYNAMIC this doesn't work as the
2153+
* kernel is *built* with CONFIG_PREEMPTION=y but may run with e.g. the
2154+
* PREEMPT_NONE model.
2155+
*/
2156+
static inline bool preempt_model_preemptible(void)
2157+
{
2158+
return preempt_model_full() || preempt_model_rt();
2159+
}
2160+
21202161
/*
21212162
* Does a critical section need to be broken due to another
21222163
* task waiting?: (technically does not depend on CONFIG_PREEMPTION,

kernel/sched/core.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8409,6 +8409,18 @@ static void __init preempt_dynamic_init(void)
84098409
}
84108410
}
84118411

8412+
#define PREEMPT_MODEL_ACCESSOR(mode) \
8413+
bool preempt_model_##mode(void) \
8414+
{ \
8415+
WARN_ON_ONCE(preempt_dynamic_mode == preempt_dynamic_undefined); \
8416+
return preempt_dynamic_mode == preempt_dynamic_##mode; \
8417+
} \
8418+
EXPORT_SYMBOL_GPL(preempt_model_##mode)
8419+
8420+
PREEMPT_MODEL_ACCESSOR(none);
8421+
PREEMPT_MODEL_ACCESSOR(voluntary);
8422+
PREEMPT_MODEL_ACCESSOR(full);
8423+
84128424
#else /* !CONFIG_PREEMPT_DYNAMIC */
84138425

84148426
static inline void preempt_dynamic_init(void) { }

0 commit comments

Comments
 (0)