From: Michal Hocko <mhocko@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Mel Gorman <mgorman@suse.de>,
Frederic Weisbecker <fweisbecker@suse.de>,
Ingo Molnar <mingo@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Michal Hocko <mhocko@suse.com>
Subject: [RFC PATCH v2 4/5] kernel: introduce CONFIG_PREEMPT_DYNAMIC
Date: Fri, 9 Oct 2020 14:29:25 +0200 [thread overview]
Message-ID: <20201009122926.29962-5-mhocko@kernel.org> (raw)
In-Reply-To: <20201009122926.29962-1-mhocko@kernel.org>
From: Michal Hocko <mhocko@suse.com>
Boot time preemption mode selection is currently hardcoded for
!CONFIG_PREEMPTION. Peter has suggested to introduce a dedicated
option for the functionality because not each archiveture implements
implements static branches (jump labels) effectively and therefore
an additional overhead might be prohibitive or undesirable.
Introduce CONFIG_PREEMPT_DYNAMIC that allows boot time preemption mode
override. The functionality is currently implemented for PREEMPT_NONE
and PREEMPT_VOLUNTARY preemption modes.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
include/linux/kernel.h | 20 ++++++++++++++++++--
include/linux/sched.h | 12 ------------
kernel/Kconfig.preempt | 19 +++++++++++++++++++
kernel/sched/core.c | 6 +++++-
4 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d2d37bd5ecd5..b61ab02dba84 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -193,20 +193,36 @@ struct completion;
struct pt_regs;
struct user;
+/*
+ * cond_resched() and cond_resched_lock(): latency reduction via
+ * explicit rescheduling in places that are safe. The return
+ * value indicates whether a reschedule was done in fact.
+ * cond_resched_lock() will drop the spinlock before scheduling,
+ */
#ifndef CONFIG_PREEMPTION
+extern int _cond_resched(void);
+#else
+static inline int _cond_resched(void) { return 0; }
+#endif
+
+#ifdef CONFIG_PREEMPT_DYNAMIC
#ifdef CONFIG_PREEMPT_VOLUNTARY
DECLARE_STATIC_KEY_TRUE(preempt_voluntary_key);
#else
DECLARE_STATIC_KEY_FALSE(preempt_voluntary_key);
#endif
-extern int _cond_resched(void);
# define might_resched() \
do { if (static_branch_likely(&preempt_voluntary_key)) _cond_resched(); } while (0)
#else
+
+#ifdef CONFIG_PREEMPT_VOLUNTARY
# define might_resched() \
- do { } while (0)
+ do { _cond_resched(); } while (0)
+#else
+# define might_resched() do { } while (0)
#endif
+#endif /* CONFIG_PREEMPT_DYNAMIC */
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
extern void ___might_sleep(const char *file, int line, int preempt_offset);
diff --git a/include/linux/sched.h b/include/linux/sched.h
index afe01e232935..184b5e162184 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1812,18 +1812,6 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)
return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
}
-/*
- * cond_resched() and cond_resched_lock(): latency reduction via
- * explicit rescheduling in places that are safe. The return
- * value indicates whether a reschedule was done in fact.
- * cond_resched_lock() will drop the spinlock before scheduling,
- */
-#ifndef CONFIG_PREEMPTION
-extern int _cond_resched(void);
-#else
-static inline int _cond_resched(void) { return 0; }
-#endif
-
#define cond_resched() ({ \
___might_sleep(__FILE__, __LINE__, 0); \
_cond_resched(); \
diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
index c460a9a2373b..e142f36dd429 100644
--- a/kernel/Kconfig.preempt
+++ b/kernel/Kconfig.preempt
@@ -73,6 +73,25 @@ config PREEMPT_RT
endchoice
+config PREEMPT_DYNAMIC
+ bool "Allow boot time preemption model selection"
+ depends on PREEMPT_NONE || PREEMPT_VOLUNTARY
+ help
+ This option allows to define the preemption model on the kernel
+ command line parameter and thus override the default preemption
+ model defined during compile time.
+
+ The feature is primarily interesting for Linux distributions which
+ provide a pre-built kernel binary to reduce the number of kernel
+ flavors they offer while still offering different usecases.
+
+ The runtime overhead is negligible with JUMP_LABELS enabled but if
+ runtime patching is not available for the specific architecture then
+ the potential overhead should be considered.
+
+ Select if you the same pre-built kernel should be used for both Server
+ and Desktop workloads.
+
config PREEMPT_COUNT
bool
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 07d37d862637..fe22b2fca864 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -43,6 +43,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_update_nr_running_tp);
DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
+#ifdef CONFIG_PREEMPT_DYNAMIC
+
#ifdef CONFIG_PREEMPT_VOLUNTARY
DEFINE_STATIC_KEY_TRUE(preempt_voluntary_key);
#else
@@ -51,6 +53,8 @@ DEFINE_STATIC_KEY_FALSE(preempt_voluntary_key);
#endif
EXPORT_SYMBOL(preempt_voluntary_key);
+#endif
+
#if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_JUMP_LABEL)
/*
* Debugging: various feature bits
@@ -8491,7 +8495,7 @@ void call_trace_sched_update_nr_running(struct rq *rq, int count)
trace_sched_update_nr_running_tp(rq, count);
}
-#ifndef CONFIG_PREEMPTION
+#ifdef CONFIG_PREEMPT_DYNAMIC
static int __init setup_non_preempt_mode(char *str)
{
if (!strcmp(str, "none")) {
--
2.28.0
next prev parent reply other threads:[~2020-10-09 12:30 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 12:04 [RFC PATCH] kernel: allow to configure PREEMPT_NONE, PREEMPT_VOLUNTARY on kernel command line Michal Hocko
2020-10-07 12:19 ` Peter Zijlstra
2020-10-07 12:29 ` Michal Hocko
2020-10-07 13:01 ` Mel Gorman
2020-10-07 12:21 ` Peter Zijlstra
2020-10-07 12:35 ` Michal Hocko
2020-10-09 9:47 ` Peter Zijlstra
2020-10-09 10:14 ` Michal Hocko
2020-10-09 10:20 ` Peter Zijlstra
2020-10-09 10:48 ` Michal Hocko
2020-10-09 11:17 ` Michal Hocko
2020-10-09 11:26 ` Michal Hocko
2020-10-09 11:39 ` Peter Zijlstra
2020-10-09 9:12 ` Michal Hocko
2020-10-09 9:42 ` Peter Zijlstra
2020-10-09 10:10 ` Michal Hocko
2020-10-09 10:14 ` Peter Zijlstra
2020-10-09 10:37 ` Michal Hocko
2020-10-09 11:42 ` Peter Zijlstra
2020-10-09 12:29 ` [RFC PATCH v2 0/5] allow overriding default preempt mode from " Michal Hocko
2020-10-09 12:29 ` [RFC PATCH v2 1/5] jump_label: split out declaration parts into its own headers Michal Hocko
2020-10-09 12:29 ` [RFC PATCH v2 2/5] kernel: allow to configure PREEMPT_NONE, PREEMPT_VOLUNTARY on kernel command line Michal Hocko
2020-10-09 12:29 ` [RFC PATCH v2 3/5] kernel: ARCH_NO_PREEMPT shouldn't exclude PREEMPT_VOLUNTARY Michal Hocko
2020-10-09 12:29 ` Michal Hocko [this message]
2020-10-09 12:29 ` [RFC PATCH v2 5/5] kernel: drop PREEMPT_NONE compile time option Michal Hocko
2020-10-09 12:50 ` [RFC PATCH v2 0/5] allow overriding default preempt mode from command line Peter Zijlstra
2020-10-09 13:03 ` Michal Hocko
2020-10-09 13:22 ` Peter Zijlstra
2020-10-09 17:45 ` Peter Zijlstra
2020-10-27 12:22 ` Frederic Weisbecker
2020-10-27 12:28 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201009122926.29962-5-mhocko@kernel.org \
--to=mhocko@kernel.org \
--cc=fweisbecker@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).