[PATCH v6 08/20] sched: Add CONFIG_PROXY_EXEC & boot argument to enable/disable

From: John Stultz
Date: Mon Nov 06 2023 - 14:36:19 EST


This patch adds the CONFIG_PROXY_EXEC option, along with
a boot argument prox_exec= that can be used to disable the
feature at boot time if CONFIG_PROXY_EXEC was enabled.

Cc: Joel Fernandes <joelaf@xxxxxxxxxx>
Cc: Qais Yousef <qyousef@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
Cc: Valentin Schneider <vschneid@xxxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Ben Segall <bsegall@xxxxxxxxxx>
Cc: Zimuzo Ezeozue <zezeozue@xxxxxxxxxx>
Cc: Youssef Esmat <youssefesmat@xxxxxxxxxx>
Cc: Mel Gorman <mgorman@xxxxxxx>
Cc: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
Cc: Will Deacon <will@xxxxxxxxxx>
Cc: Waiman Long <longman@xxxxxxxxxx>
Cc: Boqun Feng <boqun.feng@xxxxxxxxx>
Cc: "Paul E . McKenney" <paulmck@xxxxxxxxxx>
Cc: kernel-team@xxxxxxxxxxx
Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
---
.../admin-guide/kernel-parameters.txt | 4 +++
include/linux/sched.h | 13 ++++++++
init/Kconfig | 7 +++++
kernel/sched/core.c | 31 +++++++++++++++++++
4 files changed, 55 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 0a1731a0f0ef..199578ae1606 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4648,6 +4648,10 @@
that).
Format: <bool>

+ proxy_exec= [KNL] Enable or disables "proxy execution" style
+ solution to mutex based priority inversion.
+ Format: "enable" or "disable"
+
psi= [KNL] Enable or disable pressure stall information
tracking.
Format: <bool>
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 81334677e008..5f05d9a4cc3f 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1551,6 +1551,19 @@ struct task_struct {
*/
};

+#ifdef CONFIG_PROXY_EXEC
+DECLARE_STATIC_KEY_TRUE(__sched_proxy_exec);
+static inline bool sched_proxy_exec(void)
+{
+ return static_branch_likely(&__sched_proxy_exec);
+}
+#else
+static inline bool sched_proxy_exec(void)
+{
+ return false;
+}
+#endif
+
static inline struct pid *task_pid(struct task_struct *task)
{
return task->thread_pid;
diff --git a/init/Kconfig b/init/Kconfig
index 6d35728b94b2..884f94d8ee9e 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -908,6 +908,13 @@ config NUMA_BALANCING_DEFAULT_ENABLED
If set, automatic NUMA balancing will be enabled if running on a NUMA
machine.

+config PROXY_EXEC
+ bool "Proxy Execution"
+ default n
+ help
+ This option enables proxy execution, a mechanism for mutex owning
+ tasks to inherit the scheduling context of higher priority waiters.
+
menuconfig CGROUPS
bool "Control Group support"
select KERNFS
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 802551e0009b..a38bf8ef5798 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -117,6 +117,37 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_update_nr_running_tp);

DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);

+#ifdef CONFIG_PROXY_EXEC
+DEFINE_STATIC_KEY_TRUE(__sched_proxy_exec);
+static int __init setup_proxy_exec(char *str)
+{
+ int ret = 0;
+
+ if (!str)
+ goto out;
+
+ if (!strcmp(str, "enable")) {
+ static_branch_enable(&__sched_proxy_exec);
+ ret = 1;
+ } else if (!strcmp(str, "disable")) {
+ static_branch_disable(&__sched_proxy_exec);
+ ret = 1;
+ }
+out:
+ if (!ret)
+ pr_warn("Unable to parse proxy_exec=\n");
+
+ return ret;
+}
+#else
+static int __init setup_proxy_exec(char *str)
+{
+ pr_warn("CONFIG_PROXY_EXEC=n, so it cannot be enabled or disabled at boottime\n");
+ return 0;
+}
+#endif
+__setup("proxy_exec=", setup_proxy_exec);
+
#ifdef CONFIG_SCHED_DEBUG
/*
* Debugging: various feature bits
--
2.42.0.869.gea05f2083d-goog