linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>
Subject: [PATCH 1/2] sched: Add default dynamic preempt mode Kconfig
Date: Tue,  8 Jun 2021 14:04:41 +0200	[thread overview]
Message-ID: <20210608120442.93587-2-frederic@kernel.org> (raw)
In-Reply-To: <20210608120442.93587-1-frederic@kernel.org>

Currently the default behaviour for CONFIG_PREEMPT_DYNAMIC is
preempt=full. So distros always have to override that with the boot
option if it's not their default choice.

Make things more convenient for them with providing that choice at
Kconfig time.

This should also encourage automatic testing robots relying on randconfig
to run through all the various preempt dynamic flavours.

(Unfortunately this involved copy-pasting help text for static PREEMPT
Kconfig entries. Perhaps referring to them would be enough?)

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 kernel/Kconfig.preempt | 53 ++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/core.c    | 23 +++++++++++++++++-
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
index bd7c4147b9a8..384110d1a215 100644
--- a/kernel/Kconfig.preempt
+++ b/kernel/Kconfig.preempt
@@ -100,6 +100,59 @@ config PREEMPT_DYNAMIC
 	  Interesting if you want the same pre-built kernel should be used for
 	  both Server and Desktop workloads.
 
+choice
+	prompt "Preemption dynamic default boot mode"
+	default PREEMPT_DYNAMIC_FULL
+	depends on PREEMPT_DYNAMIC
+
+config PREEMPT_DYNAMIC_NONE
+	bool "Default boot with no Forced Preemption (Server)"
+	help
+	  This is the traditional Linux preemption model, geared towards
+	  throughput. It will still provide good latencies most of the
+	  time, but there are no guarantees and occasional longer delays
+	  are possible.
+
+	  Select this option if you are building a kernel for a server or
+	  scientific/computation system, or if you want to maximize the
+	  raw processing power of the kernel, irrespective of scheduling
+	  latencies.
+
+config PREEMPT_DYNAMIC_VOLUNTARY
+	bool "Default boot with Voluntary Kernel Preemption (Desktop)"
+	help
+	  This option reduces the latency of the kernel by adding more
+	  "explicit preemption points" to the kernel code. These new
+	  preemption points have been selected to reduce the maximum
+	  latency of rescheduling, providing faster application reactions,
+	  at the cost of slightly lower throughput.
+
+	  This allows reaction to interactive events by allowing a
+	  low priority process to voluntarily preempt itself even if it
+	  is in kernel mode executing a system call. This allows
+	  applications to run more 'smoothly' even when the system is
+	  under load.
+
+	  Select this if you are building a kernel for a desktop system.
+
+config PREEMPT_DYNAMIC_FULL
+	bool "Default boot with Preemptible Kernel (Low-Latency Desktop)"
+	help
+	  This option reduces the latency of the kernel by making
+	  all kernel code (that is not executing in a critical section)
+	  preemptible.  This allows reaction to interactive events by
+	  permitting a low priority process to be preempted involuntarily
+	  even if it is in kernel mode executing a system call and would
+	  otherwise not be about to reach a natural preemption point.
+	  This allows applications to run more 'smoothly' even when the
+	  system is under load, at the cost of slightly lower throughput
+	  and a slight runtime overhead to kernel code.
+
+	  Select this if you are building a kernel for a desktop or
+	  embedded system with latency requirements in the milliseconds
+	  range.
+endchoice
+
 config SCHED_CORE
 	bool "Core Scheduling for SMT"
 	default y
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 9e9a5be35cde..df47a8275c37 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6238,6 +6238,14 @@ enum {
 
 int preempt_dynamic_mode = preempt_dynamic_full;
 
+#if defined(CONFIG_PREEMPT_DYNAMIC_FULL)
+static __initdata int preempt_dynamic_mode_init = preempt_dynamic_full;
+#elif defined(CONFIG_PREEMPT_DYNAMIC_VOLUNTARY)
+static __initdata int preempt_dynamic_mode_init = preempt_dynamic_voluntary;
+#elif defined(CONFIG_PREEMPT_DYNAMIC_NONE)
+static __initdata int preempt_dynamic_mode_init = preempt_dynamic_none;
+#endif
+
 int sched_dynamic_mode(const char *str)
 {
 	if (!strcmp(str, "none"))
@@ -6254,6 +6262,9 @@ int sched_dynamic_mode(const char *str)
 
 void sched_dynamic_update(int mode)
 {
+	if (preempt_dynamic_mode == mode)
+		return;
+
 	/*
 	 * Avoid {NONE,VOLUNTARY} -> FULL transitions from ever ending up in
 	 * the ZERO state, which is invalid.
@@ -6304,13 +6315,22 @@ static int __init setup_preempt_mode(char *str)
 		return 1;
 	}
 
-	sched_dynamic_update(mode);
+	preempt_dynamic_mode_init = mode;
+
 	return 0;
 }
 __setup("preempt=", setup_preempt_mode);
 
+static void __init init_preempt(void)
+{
+	if (preempt_dynamic_mode_init != preempt_dynamic_full)
+		sched_dynamic_update(preempt_dynamic_mode_init);
+}
+#else
+static inline void init_preempt(void) { }
 #endif /* CONFIG_PREEMPT_DYNAMIC */
 
+
 /*
  * This is the entry point to schedule() from kernel preemption
  * off of irq context.
@@ -9079,6 +9099,7 @@ void __init sched_init(void)
 	psi_init();
 
 	init_uclamp();
+	init_preempt();
 
 	scheduler_running = 1;
 }
-- 
2.25.1


  reply	other threads:[~2021-06-08 12:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 12:04 [PATCH 0/2] sched: Define default preempt dynamic boot mode on Kconfig Frederic Weisbecker
2021-06-08 12:04 ` Frederic Weisbecker [this message]
2021-06-08 13:55   ` [PATCH 1/2] sched: Add default dynamic preempt mode Kconfig Peter Zijlstra
2021-06-08 14:04     ` Peter Zijlstra
2021-06-09 11:27       ` Frederic Weisbecker
2021-06-09 11:13     ` Frederic Weisbecker
2021-06-08 13:55   ` Peter Zijlstra
2021-06-09 11:25     ` Frederic Weisbecker
2021-06-08 12:04 ` [PATCH 2/2] sched: Always print out preempt dynamic state Frederic Weisbecker
2021-06-08 13:56   ` 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=20210608120442.93587-2-frederic@kernel.org \
    --to=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /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).