linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sched: Provide migrate_disable/enable() inlines
@ 2020-02-08 19:48 Thomas Gleixner
  2020-02-09 19:08 ` Ingo Molnar
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thomas Gleixner @ 2020-02-08 19:48 UTC (permalink / raw)
  To: LKML
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Sebastian Andrzej Siewior

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 <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
---
 include/linux/preempt.h |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -322,4 +322,34 @@ static inline void preempt_notifier_init
 
 #endif
 
+/**
+ * migrate_disable - Prevent migration of the current task
+ *
+ * Maps to preempt_disable() which also disables preemption. Use
+ * migrate_disable() to annotate that the intent is to prevent migration
+ * but not necessarily preemption.
+ *
+ * Can be invoked nested like preempt_disable() and needs the corresponding
+ * number of migrate_enable() invocations.
+ */
+static __always_inline void migrate_disable(void)
+{
+	preempt_disable();
+}
+
+/**
+ * migrate_enable - Allow migration of the current task
+ *
+ * Counterpart to migrate_disable().
+ *
+ * As migrate_disable() can be invoked nested only the uttermost invocation
+ * reenables migration.
+ *
+ * Currently mapped to preempt_enable().
+ */
+static __always_inline void migrate_enable(void)
+{
+	preempt_enable();
+}
+
 #endif /* __LINUX_PREEMPT_H */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sched: Provide migrate_disable/enable() inlines
  2020-02-08 19:48 sched: Provide migrate_disable/enable() inlines Thomas Gleixner
@ 2020-02-09 19:08 ` Ingo Molnar
  2020-02-09 19:11 ` [tip: sched/core] sched/rt: " tip-bot2 for Thomas Gleixner
  2020-02-20 20:20 ` [tip: sched/rt] " tip-bot2 for Thomas Gleixner
  2 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2020-02-09 19:08 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Sebastian Andrzej Siewior


* Thomas Gleixner <tglx@linutronix.de> wrote:

> 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 <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Vincent Guittot <vincent.guittot@linaro.org>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ben Segall <bsegall@google.com>
> Cc: Mel Gorman <mgorman@suse.de>
> ---
>  include/linux/preempt.h |   30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> --- a/include/linux/preempt.h
> +++ b/include/linux/preempt.h
> @@ -322,4 +322,34 @@ static inline void preempt_notifier_init
>  
>  #endif
>  
> +/**
> + * migrate_disable - Prevent migration of the current task
> + *
> + * Maps to preempt_disable() which also disables preemption. Use
> + * migrate_disable() to annotate that the intent is to prevent migration
> + * but not necessarily preemption.
> + *
> + * Can be invoked nested like preempt_disable() and needs the corresponding
> + * number of migrate_enable() invocations.
> + */
> +static __always_inline void migrate_disable(void)
> +{
> +	preempt_disable();
> +}
> +
> +/**
> + * migrate_enable - Allow migration of the current task
> + *
> + * Counterpart to migrate_disable().
> + *
> + * As migrate_disable() can be invoked nested only the uttermost invocation
> + * reenables migration.
> + *
> + * Currently mapped to preempt_enable().
> + */
> +static __always_inline void migrate_enable(void)
> +{
> +	preempt_enable();
> +}

I've applied this with s/uttermost/outermost, which I suspect was the 
intention?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: sched/core] sched/rt: Provide migrate_disable/enable() inlines
  2020-02-08 19:48 sched: Provide migrate_disable/enable() inlines Thomas Gleixner
  2020-02-09 19:08 ` Ingo Molnar
@ 2020-02-09 19:11 ` tip-bot2 for Thomas Gleixner
  2020-02-20 20:20 ` [tip: sched/rt] " tip-bot2 for Thomas Gleixner
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Thomas Gleixner @ 2020-02-09 19:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Sebastian Andrzej Siewior, x86, LKML

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     9fe65747dbacf0c9fcf12350c3afb5fcf7e78534
Gitweb:        https://git.kernel.org/tip/9fe65747dbacf0c9fcf12350c3afb5fcf7e78534
Author:        Thomas Gleixner <tglx@linutronix.de>
AuthorDate:    Sat, 08 Feb 2020 20:48:29 +01:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 09 Feb 2020 20:07:41 +01:00

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 <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/r/878slclv1u.fsf@nanos.tec.linutronix.de
---
 include/linux/preempt.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/include/linux/preempt.h b/include/linux/preempt.h
index bbb68db..bc3f1ae 100644
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -322,4 +322,34 @@ static inline void preempt_notifier_init(struct preempt_notifier *notifier,
 
 #endif
 
+/**
+ * migrate_disable - Prevent migration of the current task
+ *
+ * Maps to preempt_disable() which also disables preemption. Use
+ * migrate_disable() to annotate that the intent is to prevent migration,
+ * but not necessarily preemption.
+ *
+ * Can be invoked nested like preempt_disable() and needs the corresponding
+ * number of migrate_enable() invocations.
+ */
+static __always_inline void migrate_disable(void)
+{
+	preempt_disable();
+}
+
+/**
+ * migrate_enable - Allow migration of the current task
+ *
+ * Counterpart to migrate_disable().
+ *
+ * As migrate_disable() can be invoked nested, only the outermost invocation
+ * reenables migration.
+ *
+ * Currently mapped to preempt_enable().
+ */
+static __always_inline void migrate_enable(void)
+{
+	preempt_enable();
+}
+
 #endif /* __LINUX_PREEMPT_H */

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [tip: sched/rt] sched/rt: Provide migrate_disable/enable() inlines
  2020-02-08 19:48 sched: Provide migrate_disable/enable() inlines Thomas Gleixner
  2020-02-09 19:08 ` Ingo Molnar
  2020-02-09 19:11 ` [tip: sched/core] sched/rt: " tip-bot2 for Thomas Gleixner
@ 2020-02-20 20:20 ` tip-bot2 for Thomas Gleixner
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Thomas Gleixner @ 2020-02-20 20:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Sebastian Andrzej Siewior, x86, LKML

The following commit has been merged into the sched/rt branch of tip:

Commit-ID:     66630058e56b26b3a9cf2625e250a8c592dd0207
Gitweb:        https://git.kernel.org/tip/66630058e56b26b3a9cf2625e250a8c592dd0207
Author:        Thomas Gleixner <tglx@linutronix.de>
AuthorDate:    Sat, 08 Feb 2020 20:48:29 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 20 Feb 2020 21:17:24 +01:00

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 <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/r/878slclv1u.fsf@nanos.tec.linutronix.de

---
 include/linux/preempt.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/include/linux/preempt.h b/include/linux/preempt.h
index bbb68db..bc3f1ae 100644
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -322,4 +322,34 @@ static inline void preempt_notifier_init(struct preempt_notifier *notifier,
 
 #endif
 
+/**
+ * migrate_disable - Prevent migration of the current task
+ *
+ * Maps to preempt_disable() which also disables preemption. Use
+ * migrate_disable() to annotate that the intent is to prevent migration,
+ * but not necessarily preemption.
+ *
+ * Can be invoked nested like preempt_disable() and needs the corresponding
+ * number of migrate_enable() invocations.
+ */
+static __always_inline void migrate_disable(void)
+{
+	preempt_disable();
+}
+
+/**
+ * migrate_enable - Allow migration of the current task
+ *
+ * Counterpart to migrate_disable().
+ *
+ * As migrate_disable() can be invoked nested, only the outermost invocation
+ * reenables migration.
+ *
+ * Currently mapped to preempt_enable().
+ */
+static __always_inline void migrate_enable(void)
+{
+	preempt_enable();
+}
+
 #endif /* __LINUX_PREEMPT_H */

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-20 20:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-08 19:48 sched: Provide migrate_disable/enable() inlines Thomas Gleixner
2020-02-09 19:08 ` Ingo Molnar
2020-02-09 19:11 ` [tip: sched/core] sched/rt: " tip-bot2 for Thomas Gleixner
2020-02-20 20:20 ` [tip: sched/rt] " tip-bot2 for Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).