Skip to content

Commit 6663005

Browse files
committed
sched/rt: Provide migrate_disable/enable() inlines
Code which solely needs to prevent migration of a task uses preempt_disable()/enable() pairs. This is the only reliable way to do so as setting the task affinity to a single CPU can be undone by a setaffinity operation from a different task/process. RT provides a seperate migrate_disable/enable() mechanism which does not disable preemption to achieve the semantic requirements of a (almost) fully preemptible kernel. As it is unclear from looking at a given code path whether the intention is to disable preemption or migration, introduce migrate_disable/enable() inline functions which can be used to annotate code which merely needs to disable migration. Map them to preempt_disable/enable() for now. The RT substitution will be provided later. Code which is annotated that way documents that it has no requirement to protect against reentrancy of a preempting task. Either this is not required at all or the call sites are already serialized by other means. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Vincent Guittot <[email protected]> Cc: Dietmar Eggemann <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Ben Segall <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 11a48a5 commit 6663005

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

include/linux/preempt.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,34 @@ static inline void preempt_notifier_init(struct preempt_notifier *notifier,
322322

323323
#endif
324324

325+
/**
326+
* migrate_disable - Prevent migration of the current task
327+
*
328+
* Maps to preempt_disable() which also disables preemption. Use
329+
* migrate_disable() to annotate that the intent is to prevent migration,
330+
* but not necessarily preemption.
331+
*
332+
* Can be invoked nested like preempt_disable() and needs the corresponding
333+
* number of migrate_enable() invocations.
334+
*/
335+
static __always_inline void migrate_disable(void)
336+
{
337+
preempt_disable();
338+
}
339+
340+
/**
341+
* migrate_enable - Allow migration of the current task
342+
*
343+
* Counterpart to migrate_disable().
344+
*
345+
* As migrate_disable() can be invoked nested, only the outermost invocation
346+
* reenables migration.
347+
*
348+
* Currently mapped to preempt_enable().
349+
*/
350+
static __always_inline void migrate_enable(void)
351+
{
352+
preempt_enable();
353+
}
354+
325355
#endif /* __LINUX_PREEMPT_H */

0 commit comments

Comments
 (0)