summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Schneider <valentin.schneider@arm.com>2021-08-11 23:13:52 +0300
committerMinda Chen <minda.chen@starfivetech.com>2023-11-06 14:24:37 +0300
commit1cf350e52a4e7220b9ab5e09f546b9ce05295bea (patch)
tree231fa059290cbe75668af17b57b470b8ef710334
parent47a0858334bfa170d06e04bff807d8c6a41230aa (diff)
downloadlinux-1cf350e52a4e7220b9ab5e09f546b9ce05295bea.tar.xz
sched: Introduce migratable()
Some areas use preempt_disable() + preempt_enable() to safely access per-CPU data. The PREEMPT_RT folks have shown this can also be done by keeping preemption enabled and instead disabling migration (and acquiring a sleepable lock, if relevant). Introduce a helper which checks whether the current task can be migrated elsewhere, IOW if it is pinned to its local CPU in the current context. This can help determining if per-CPU properties can be safely accessed. Note that CPU affinity is not checked here, as a preemptible task can have its affinity changed at any given time (including if it has PF_NO_SETAFFINITY, when hotplug gets involved). Signed-off-by: Valentin Schneider <valentin.schneider@arm.com> [bigeasy: Return false on UP, call it is_migratable().] Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Link: https://lore.kernel.org/r/20210811201354.1976839-3-valentin.schneider@arm.com
-rw-r--r--include/linux/sched.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index c1a927ddec64..33789b6abdc3 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1730,6 +1730,16 @@ static __always_inline bool is_percpu_thread(void)
#endif
}
+/* Is the current task guaranteed to stay on its current CPU? */
+static inline bool is_migratable(void)
+{
+#ifdef CONFIG_SMP
+ return preemptible() && !current->migration_disabled;
+#else
+ return false;
+#endif
+}
+
/* Per-process atomic flags. */
#define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */
#define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */