[25/30] sched: support preempt=full under PREEMPT_AUTO

Message ID 20240213055554.1802415-26-ankur.a.arora@oracle.com
State New
Headers
Series PREEMPT_AUTO: support lazy rescheduling |

Commit Message

Ankur Arora Feb. 13, 2024, 5:55 a.m. UTC
  The default preemption policy for preempt-full under PREEMPT_AUTO is
to minimize latency, and thus to always schedule eagerly. This is
identical to CONFIG_PREEMPT, and so should result in similar
performance.

Comparing scheduling/IPC workload:

 # perf stat -a -e cs --repeat 10 -- perf bench sched messaging -g 20 -t -l 5000

 PREEMPT_AUTO, preempt=full

         3,080,508            context-switches      ( +-  0.64% )
	   3.65171 +- 0.00654 seconds time elapsed  ( +-  0.18% )

 PREEMPT_DYNAMIC, preempt=full

	 3,087,527            context-switches      ( +-  0.33% )
	   3.60163 +- 0.00633 seconds time elapsed  ( +-  0.18% )

Looking at the breakup between voluntary and involuntary context-switches, we
see almost identical behaviour as well.

 PREEMPT_AUTO, preempt=full

           2087910.00 +- 34720.95 voluntary context-switches   ( +- 1.660% )
            784437.60 +- 19827.79 involuntary context-switches ( +- 2.520% )

 PREEMPT_DYNAMIC, preempt=full

           2102879.60 +- 22767.11 voluntary context-switches   ( +- 1.080% )
            801189.90 +- 21324.18 involuntary context-switches ( +- 2.660% )

Comparing kernbench half load (-j 32), we see that both voluntary
and involuntary context switches, and their stdev is fairly similar.
So is the percentage of CPU taken and various process times.

  # Half load (-j 32)
                          PREEMPT_AUTO                              PREEMPT_DYNAMIC

  wall            74.45 +-     0.39 sec ( +-  0.53% )          74.08 +-     0.20 sec ( +-  0.27% )
  utime         1419.68 +-     5.12 sec ( +-  0.36% )        1419.76 +-     3.63 sec ( +-  0.25% )
  stime          250.56 +-     1.08 sec ( +-  0.43% )         248.94 +-     0.80 sec ( +-  0.32% )
  %cpu          2243.20 +-    19.57     ( +-  0.87% )        2251.80 +-    11.12     ( +-  0.49% )
  inv-csw      20286.60 +-   547.48     ( +-  2.69% )       20175.60 +-   214.20     ( +-  1.06% )
  vol-csw     187688.00 +-  5097.26     ( +-  2.71% )      182914.00 +-  2525.59     ( +-  1.38% )

Same for kernbench optimal and maximal loads.

  # Optimal load (-j 256)

                          PREEMPT_AUTO                              PREEMPT_DYNAMIC

  wall            65.10 +-      0.09 sec ( +-  0.14% )          65.11 +-      0.27 sec ( +-  0.42% )
  utime         1875.03 +-    479.98 sec ( +- 25.59% )        1874.55 +-    479.39 sec ( +- 25.57% )
  stime          297.70 +-     49.68 sec ( +- 16.69% )         297.04 +-     50.69 sec ( +- 17.06% )
  %cpu          3175.60 +-    982.93     ( +- 30.95% )        3179.40 +-    977.87     ( +- 30.75% )
  inv-csw     391147.00 +- 390941.00     ( +- 99.94% )      392298.00 +- 392268.00     ( +- 99.99% )
  vol-csw     212039.00 +-  26419.90     ( +- 12.45% )      211349.00 +-  30227.30     ( +- 14.30% )

  # Maximal load (-j 256)

                          PREEMPT_AUTO                              PREEMPT_DYNAMIC

  wall            66.55 +-      0.34 sec ( +-  0.51% )          66.41 +-      0.72 sec ( +-  1.09% )
  utime         2028.83 +-    445.86 sec ( +- 21.97% )        2027.59 +-    444.89 sec ( +- 21.94% )
  stime          316.16 +-     48.29 sec ( +- 15.27% )         313.97 +-     47.61 sec ( +- 15.16% )
  %cpu          3463.93 +-    894.12     ( +- 25.81% )        3465.33 +-    889.04     ( +- 25.65% )
  inv-csw     491115.00 +- 345936.00     ( +- 70.43% )      492028.00 +- 346745.00     ( +- 70.47% )
  vol-csw     200509.00 +-  32922.60     ( +- 16.41% )      187447.00 +-  42567.20     ( +- 22.70% )

Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Ziljstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Originally-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/87jzshhexi.ffs@tglx/
Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
---
 kernel/sched/core.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
  

Patch

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 2d33f3ff51a3..aaa87d5fecdd 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1035,8 +1035,9 @@  void wake_up_q(struct wake_q_head *head)
  * For preemption models other than PREEMPT_AUTO: always schedule
  * eagerly.
  *
- * For PREEMPT_AUTO: schedule idle threads eagerly, allow everything
- * else, whether running in user or kernel context, to finish its time
+ * For PREEMPT_AUTO: schedule idle threads eagerly, and under full
+ * preemption all tasks eagerly. Otherwise, allow everything else,
+ * whether running in user or kernel context, to finish its time
  * quanta, and mark for rescheduling at the next exit to user.
  *
  * Note: to avoid the hog problem, where the user does not relinquish
@@ -1052,6 +1053,9 @@  static resched_t resched_opt_translate(struct task_struct *curr,
 	if (opt == RESCHED_FORCE)
 		return NR_now;
 
+	if (preempt_model_preemptible())
+		return NR_now;
+
 	if (is_idle_task(curr))
 		return NR_now;
 
@@ -8982,7 +8986,9 @@  static void __sched_dynamic_update(int mode)
 			pr_warn("%s: preempt=full is not recommended with CONFIG_PREEMPT_RCU=n",
 				PREEMPT_MODE);
 
-		preempt_dynamic_mode = preempt_dynamic_undefined;
+		if (mode != preempt_dynamic_mode)
+			pr_info("%s: full\n", PREEMPT_MODE);
+		preempt_dynamic_mode = mode;
 		break;
 	}
 }