linux-pikaos-template/patches/0002-eevdfbore.patch

553 lines
16 KiB
Diff
Raw Normal View History

2023-09-28 19:31:36 +02:00
From c92de794ee60ef526ca33cfee59e96f0d95b0697 Mon Sep 17 00:00:00 2001
2023-08-22 19:16:01 +02:00
From: Piotr Gorski <lucjan.lucjanov@gmail.com>
2023-09-28 19:31:36 +02:00
Date: Sun, 17 Sep 2023 22:51:20 +0200
2023-06-14 21:49:41 +02:00
Subject: [PATCH] bore-eevdf
2023-03-12 20:40:20 +01:00
2023-08-22 19:16:01 +02:00
Signed-off-by: Piotr Gorski <lucjan.lucjanov@gmail.com>
2023-03-12 20:40:20 +01:00
---
2023-09-28 19:31:36 +02:00
include/linux/sched.h | 31 ++++++++
init/Kconfig | 20 +++++
kernel/sched/core.c | 160 +++++++++++++++++++++++++++++++++++++++
kernel/sched/debug.c | 3 +
kernel/sched/fair.c | 169 +++++++++++++++++++++++++++++++++++++++++-
5 files changed, 381 insertions(+), 2 deletions(-)
2023-03-12 20:40:20 +01:00
diff --git a/include/linux/sched.h b/include/linux/sched.h
2023-09-28 19:31:36 +02:00
index c940c4dc8..e88251927 100644
2023-03-12 20:40:20 +01:00
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
2023-08-22 19:16:01 +02:00
@@ -545,6 +545,24 @@ struct sched_statistics {
2023-08-10 19:30:38 +02:00
#endif /* CONFIG_SCHEDSTATS */
} ____cacheline_aligned;
+#ifdef CONFIG_SCHED_BORE
2023-08-22 19:16:01 +02:00
+typedef union {
2023-08-10 19:30:38 +02:00
+ u16 u16;
+ s16 s16;
+ u8 u8[2];
+ s8 s8[2];
2023-08-22 19:16:01 +02:00
+} x16;
2023-08-10 19:30:38 +02:00
+
2023-08-22 19:16:01 +02:00
+typedef union {
2023-08-10 19:30:38 +02:00
+ u32 u32;
+ s32 s32;
+ u16 u16[2];
+ s16 s16[2];
+ u8 u8[4];
+ s8 s8[4];
2023-08-22 19:16:01 +02:00
+} x32;
2023-08-10 19:30:38 +02:00
+#endif // CONFIG_SCHED_BORE
+
struct sched_entity {
/* For load-balancing: */
struct load_weight load;
2023-08-22 19:16:01 +02:00
@@ -559,6 +577,12 @@ struct sched_entity {
2023-03-12 20:40:20 +01:00
u64 sum_exec_runtime;
u64 prev_sum_exec_runtime;
2023-06-14 21:49:41 +02:00
u64 vruntime;
+#ifdef CONFIG_SCHED_BORE
+ u64 burst_time;
2023-08-10 19:30:38 +02:00
+ u16 prev_burst_penalty;
+ u16 curr_burst_penalty;
+ u16 burst_penalty;
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
s64 vlag;
u64 slice;
2023-09-28 19:31:36 +02:00
@@ -990,6 +1014,13 @@ struct task_struct {
2023-06-14 21:49:41 +02:00
struct list_head children;
struct list_head sibling;
struct task_struct *group_leader;
+#ifdef CONFIG_SCHED_BORE
2023-08-10 19:30:38 +02:00
+ u16 child_burst_cache;
2023-08-22 19:16:01 +02:00
+ u16 child_burst_count_cache;
2023-06-14 21:49:41 +02:00
+ u64 child_burst_last_cached;
2023-09-28 19:31:36 +02:00
+ u16 group_burst_cache;
+ u64 group_burst_last_cached;
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
2023-03-12 20:40:20 +01:00
2023-06-14 21:49:41 +02:00
/*
* 'ptraced' is the list of tasks this task is using ptrace() on.
diff --git a/init/Kconfig b/init/Kconfig
2023-09-28 19:31:36 +02:00
index 25193a9d5..acc02af18 100644
2023-06-14 21:49:41 +02:00
--- a/init/Kconfig
+++ b/init/Kconfig
2023-09-28 19:31:36 +02:00
@@ -1278,6 +1278,26 @@ config CHECKPOINT_RESTORE
2023-06-14 21:49:41 +02:00
If unsure, say N here.
+config SCHED_BORE
+ bool "Burst-Oriented Response Enhancer"
+ default y
+ help
+ In Desktop and Mobile computing, one might prefer interactive
+ tasks to keep responsive no matter what they run in the background.
+
+ Enabling this kernel feature modifies the scheduler to discriminate
+ tasks by their burst time (runtime since it last went sleeping or
+ yielding state) and prioritize those that run less bursty.
+ Such tasks usually include window compositor, widgets backend,
+ terminal emulator, video playback, games and so on.
+ With a little impact to scheduling fairness, it may improve
+ responsiveness especially under heavy background workload.
+
+ You can turn it off by setting the sysctl kernel.sched_bore = 0.
+ Enabling this feature implies NO_GENTLE_FAIR_SLEEPERS by default.
+
+ If unsure say Y here.
+
config SCHED_AUTOGROUP
bool "Automatic process group scheduling"
select CGROUPS
2023-03-12 20:40:20 +01:00
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
2023-09-28 19:31:36 +02:00
index aff81e124..2cc47b723 100644
2023-03-12 20:40:20 +01:00
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
2023-09-28 19:31:36 +02:00
@@ -4491,6 +4491,155 @@ int wake_up_state(struct task_struct *p, unsigned int state)
2023-06-14 21:49:41 +02:00
return try_to_wake_up(p, state, 0);
2023-03-12 20:40:20 +01:00
}
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
+extern unsigned int sched_burst_cache_lifetime;
2023-08-22 19:16:01 +02:00
+extern unsigned int sched_bore;
2023-07-26 11:45:05 +02:00
+extern unsigned int sched_burst_fork_atavistic;
2023-03-12 20:40:20 +01:00
+
2023-06-14 21:49:41 +02:00
+void __init sched_init_bore(void) {
+ init_task.child_burst_cache = 0;
2023-08-22 19:16:01 +02:00
+ init_task.child_burst_count_cache = 0;
2023-06-14 21:49:41 +02:00
+ init_task.child_burst_last_cached = 0;
2023-09-28 19:31:36 +02:00
+ init_task.group_burst_cache = 0;
+ init_task.group_burst_last_cached = 0;
2023-06-14 21:49:41 +02:00
+ init_task.se.burst_time = 0;
2023-08-10 19:30:38 +02:00
+ init_task.se.prev_burst_penalty = 0;
+ init_task.se.curr_burst_penalty = 0;
+ init_task.se.burst_penalty = 0;
2023-03-12 20:40:20 +01:00
+}
+
2023-07-26 11:45:05 +02:00
+void inline sched_fork_bore(struct task_struct *p) {
2023-06-14 21:49:41 +02:00
+ p->child_burst_cache = 0;
2023-08-22 19:16:01 +02:00
+ p->child_burst_count_cache = 0;
2023-06-14 21:49:41 +02:00
+ p->child_burst_last_cached = 0;
2023-09-28 19:31:36 +02:00
+ p->group_burst_cache = 0;
+ p->group_burst_last_cached = 0;
2023-06-14 21:49:41 +02:00
+ p->se.burst_time = 0;
2023-08-10 19:30:38 +02:00
+ p->se.curr_burst_penalty = 0;
2023-06-14 21:49:41 +02:00
+}
2023-03-12 20:40:20 +01:00
+
2023-07-26 11:45:05 +02:00
+static u32 count_child_tasks(struct task_struct *p) {
+ struct task_struct *child;
2023-06-14 21:49:41 +02:00
+ u32 cnt = 0;
2023-07-26 11:45:05 +02:00
+ list_for_each_entry(child, &p->children, sibling) {cnt++;}
+ return cnt;
+}
+
+static inline bool child_burst_cache_expired(struct task_struct *p, u64 now) {
+ return (p->child_burst_last_cached + sched_burst_cache_lifetime < now);
+}
+
2023-09-28 19:31:36 +02:00
+static inline bool group_burst_cache_expired(struct task_struct *p, u64 now) {
+ return (p->group_burst_last_cached + sched_burst_cache_lifetime < now);
+}
+
2023-07-26 11:45:05 +02:00
+static void __update_child_burst_cache(
2023-08-10 19:30:38 +02:00
+ struct task_struct *p, u32 cnt, u32 sum, u64 now) {
+ u16 avg = 0;
+ if (cnt) avg = DIV_ROUND_CLOSEST(sum, cnt);
+ p->child_burst_cache = max(avg, p->se.burst_penalty);
2023-08-22 19:16:01 +02:00
+ p->child_burst_count_cache = cnt;
2023-07-26 11:45:05 +02:00
+ p->child_burst_last_cached = now;
+}
+
+static void update_child_burst_cache(struct task_struct *p, u64 now) {
2023-06-14 21:49:41 +02:00
+ struct task_struct *child;
2023-07-26 11:45:05 +02:00
+ u32 cnt = 0;
2023-08-10 19:30:38 +02:00
+ u32 sum = 0;
2023-03-12 20:40:20 +01:00
+
2023-06-14 21:49:41 +02:00
+ list_for_each_entry(child, &p->children, sibling) {
+ cnt++;
2023-08-10 19:30:38 +02:00
+ sum += child->se.burst_penalty;
2023-06-14 21:49:41 +02:00
+ }
2023-03-12 20:40:20 +01:00
+
2023-07-26 11:45:05 +02:00
+ __update_child_burst_cache(p, cnt, sum, now);
2023-03-12 20:40:20 +01:00
+}
+
2023-07-26 11:45:05 +02:00
+static void update_child_burst_cache_atavistic(
2023-08-10 19:30:38 +02:00
+ struct task_struct *p, u64 now, u32 depth, u32 *acnt, u32 *asum) {
2023-07-26 11:45:05 +02:00
+ struct task_struct *child, *dec;
+ u32 cnt = 0, dcnt = 0;
2023-08-10 19:30:38 +02:00
+ u32 sum = 0;
2023-03-12 20:40:20 +01:00
+
2023-07-26 11:45:05 +02:00
+ list_for_each_entry(child, &p->children, sibling) {
+ dec = child;
+ while ((dcnt = count_child_tasks(dec)) == 1)
+ dec = list_first_entry(&dec->children, struct task_struct, sibling);
+
+ if (!dcnt || !depth) {
+ cnt++;
2023-08-10 19:30:38 +02:00
+ sum += dec->se.burst_penalty;
2023-07-26 11:45:05 +02:00
+ } else {
+ if (child_burst_cache_expired(dec, now))
+ update_child_burst_cache_atavistic(dec, now, depth - 1, &cnt, &sum);
+ else {
2023-08-22 19:16:01 +02:00
+ cnt += dec->child_burst_count_cache;
+ sum += (u32)dec->child_burst_cache * dec->child_burst_count_cache;
2023-07-26 11:45:05 +02:00
+ }
2023-06-14 21:49:41 +02:00
+ }
+ }
2023-03-12 20:40:20 +01:00
+
2023-07-26 11:45:05 +02:00
+ __update_child_burst_cache(p, cnt, sum, now);
+ *acnt += cnt;
+ *asum += sum;
+}
+
2023-09-28 19:31:36 +02:00
+static void update_group_burst_cache(struct task_struct *p, u64 now) {
+ struct task_struct *member;
+ u32 cnt = 0, sum = 0;
+ u16 avg = 0;
+
+ for_each_thread(p, member) {
+ cnt++;
+ sum += member->se.burst_penalty;
+ }
+
+ if (cnt) avg = DIV_ROUND_CLOSEST(sum, cnt);
+ p->group_burst_cache = max(avg, p->se.burst_penalty);
+ p->group_burst_last_cached = now;
+}
+
+#define forked_task_is_process(p) (p->pid == p->tgid)
+
2023-08-10 19:30:38 +02:00
+static void fork_burst_penalty(struct task_struct *p) {
2023-07-26 11:45:05 +02:00
+ struct sched_entity *se = &p->se;
2023-09-28 19:31:36 +02:00
+ struct task_struct *anc;
2023-07-26 11:45:05 +02:00
+ u64 now = ktime_get_ns();
2023-09-28 19:31:36 +02:00
+ u32 cnt = 0, sum = 0;
+ u16 burst_cache;
+
+ if (likely(sched_bore)) {
+ read_lock(&tasklist_lock);
+
+ if (forked_task_is_process(p)) {
+ anc = p->real_parent;
+ if (likely(sched_burst_fork_atavistic)) {
+ while ((anc->real_parent != anc) &&
+ (count_child_tasks(anc) == 1))
+ anc = anc->real_parent;
+ if (child_burst_cache_expired(anc, now))
+ update_child_burst_cache_atavistic(
+ anc, now, sched_burst_fork_atavistic - 1, &cnt, &sum);
+ } else
+ if (child_burst_cache_expired(anc, now))
+ update_child_burst_cache(anc, now);
+
+ burst_cache = anc->child_burst_cache;
+ } else {
+ anc = p->group_leader;
+ if (group_burst_cache_expired(anc, now))
+ update_group_burst_cache(anc, now);
+
+ burst_cache = anc->group_burst_cache;
+ }
2023-07-26 11:45:05 +02:00
+
2023-09-28 19:31:36 +02:00
+ read_unlock(&tasklist_lock);
+ se->prev_burst_penalty = max(se->prev_burst_penalty, burst_cache);
+ }
+ se->burst_penalty = se->prev_burst_penalty;
2023-03-12 20:40:20 +01:00
+}
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
+
/*
* Perform scheduler related setup for a newly forked process p.
* p is forked by current.
2023-09-28 19:31:36 +02:00
@@ -4507,6 +4656,9 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
2023-06-14 21:49:41 +02:00
p->se.prev_sum_exec_runtime = 0;
p->se.nr_migrations = 0;
p->se.vruntime = 0;
+#ifdef CONFIG_SCHED_BORE
2023-07-26 11:45:05 +02:00
+ sched_fork_bore(p);
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
p->se.vlag = 0;
INIT_LIST_HEAD(&p->se.group_node);
2023-03-12 20:40:20 +01:00
2023-09-28 19:31:36 +02:00
@@ -4828,6 +4980,9 @@ void sched_cgroup_fork(struct task_struct *p, struct kernel_clone_args *kargs)
2023-07-26 11:45:05 +02:00
void sched_post_fork(struct task_struct *p)
2023-06-14 21:49:41 +02:00
{
+#ifdef CONFIG_SCHED_BORE
2023-08-10 19:30:38 +02:00
+ fork_burst_penalty(p);
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
2023-07-26 11:45:05 +02:00
uclamp_post_fork(p);
}
2023-09-28 19:31:36 +02:00
@@ -9954,6 +10109,11 @@ void __init sched_init(void)
2023-06-14 21:49:41 +02:00
BUG_ON(&dl_sched_class != &stop_sched_class + 1);
2023-03-12 20:40:20 +01:00
#endif
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
+ sched_init_bore();
2023-09-28 19:31:36 +02:00
+ printk(KERN_INFO "BORE (Burst-Oriented Response Enhancer) CPU Scheduler modification 3.1.4 by Masahito Suzuki");
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
+
wait_bit_init();
#ifdef CONFIG_FAIR_GROUP_SCHED
2023-03-12 20:40:20 +01:00
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
2023-09-28 19:31:36 +02:00
index e7e83181f..6ebd52247 100644
2023-03-12 20:40:20 +01:00
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
2023-09-28 19:31:36 +02:00
@@ -594,6 +594,9 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
2023-06-14 21:49:41 +02:00
SPLIT_NS(schedstat_val_or_zero(p->stats.sum_sleep_runtime)),
SPLIT_NS(schedstat_val_or_zero(p->stats.sum_block_runtime)));
2023-03-12 20:40:20 +01:00
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
2023-08-10 19:30:38 +02:00
+ SEQ_printf(m, " %2d", ((x16*)&p->se.burst_penalty)->u8[1]);
2023-06-14 21:49:41 +02:00
+#endif
#ifdef CONFIG_NUMA_BALANCING
SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
2023-03-12 20:40:20 +01:00
#endif
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
2023-09-28 19:31:36 +02:00
index d49c0f979..dffee0766 100644
2023-03-12 20:40:20 +01:00
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
2023-06-14 21:49:41 +02:00
@@ -19,6 +19,9 @@
*
* Adaptive scheduling granularity, math enhancements by Peter Zijlstra
* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
+ *
+ * Burst-Oriented Response Enhancer (BORE) CPU Scheduler
+ * Copyright (C) 2021-2023 Masahito Suzuki <firelzrd@gmail.com>
*/
#include <linux/energy_model.h>
#include <linux/mmap_lock.h>
2023-09-28 19:31:36 +02:00
@@ -86,6 +89,67 @@ unsigned int sysctl_sched_child_runs_first __read_mostly;
2023-04-10 19:42:41 +02:00
2023-06-14 21:49:41 +02:00
const_debug unsigned int sysctl_sched_migration_cost = 500000UL;
+#ifdef CONFIG_SCHED_BORE
2023-08-10 19:30:38 +02:00
+unsigned int __read_mostly sched_bore = 1;
2023-09-28 19:31:36 +02:00
+unsigned int __read_mostly sched_bore_extra_flags = 0;
2023-08-10 19:30:38 +02:00
+unsigned int __read_mostly sched_burst_cache_lifetime = 60000000;
2023-08-22 19:16:01 +02:00
+unsigned int __read_mostly sched_burst_penalty_offset = 22;
+unsigned int __read_mostly sched_burst_penalty_scale = 1366;
2023-08-10 19:30:38 +02:00
+unsigned int __read_mostly sched_burst_smoothness_up = 1;
+unsigned int __read_mostly sched_burst_smoothness_down = 0;
+unsigned int __read_mostly sched_burst_fork_atavistic = 2;
2023-06-14 21:49:41 +02:00
+static int three = 3;
+static int sixty_four = 64;
+static int maxval_12_bits = 4095;
+
2023-08-22 19:16:01 +02:00
+#define MAX_BURST_PENALTY ((40U << 8) - 1)
2023-06-14 21:49:41 +02:00
+
2023-08-10 19:30:38 +02:00
+static inline u32 log2plus1_u64_u32f8(u64 v) {
+ x32 result;
+ int msb = fls64(v);
2023-08-22 19:16:01 +02:00
+ int excess_bits = msb - 9;
+ result.u8[0] = (0 <= excess_bits)? v >> excess_bits: v << -excess_bits;
2023-08-10 19:30:38 +02:00
+ result.u8[1] = msb;
+ return result.u32;
+}
+
2023-08-22 19:16:01 +02:00
+static inline u32 calc_burst_penalty(u64 burst_time) {
2023-08-10 19:30:38 +02:00
+ u32 greed, tolerance, penalty, scaled_penalty;
+
2023-08-22 19:16:01 +02:00
+ greed = log2plus1_u64_u32f8(burst_time);
+ tolerance = sched_burst_penalty_offset << 8;
2023-08-10 19:30:38 +02:00
+ penalty = max(0, (s32)greed - (s32)tolerance);
+ scaled_penalty = penalty * sched_burst_penalty_scale >> 10;
2023-06-14 21:49:41 +02:00
+
2023-08-10 19:30:38 +02:00
+ return min(MAX_BURST_PENALTY, scaled_penalty);
+}
2023-06-14 21:49:41 +02:00
+
2023-08-10 19:30:38 +02:00
+static void update_burst_penalty(struct sched_entity *se) {
2023-08-22 19:16:01 +02:00
+ se->curr_burst_penalty = calc_burst_penalty(se->burst_time);
2023-08-10 19:30:38 +02:00
+ se->burst_penalty = max(se->prev_burst_penalty, se->curr_burst_penalty);
2023-03-12 20:40:20 +01:00
+}
+
2023-08-22 19:16:01 +02:00
+static inline u64 penalty_scale(u64 delta, struct sched_entity *se, bool half) {
+ u32 score = ((x16*)&se->burst_penalty)->u8[1];
+ if (half) score >>= 1;
2023-08-10 19:30:38 +02:00
+ return mul_u64_u32_shr(delta, sched_prio_to_wmult[score], 22);
2023-03-12 20:40:20 +01:00
+}
+
2023-08-10 19:30:38 +02:00
+static inline u32 binary_smooth(u32 new, u32 old) {
2023-08-22 19:16:01 +02:00
+ int increment = new - old;
+ return (0 <= increment)?
+ old + ( increment >> sched_burst_smoothness_up):
+ old - (-increment >> sched_burst_smoothness_down);
2023-04-10 19:42:41 +02:00
+}
+
2023-08-10 19:30:38 +02:00
+static void restart_burst(struct sched_entity *se) {
+ se->burst_penalty = se->prev_burst_penalty =
+ binary_smooth(se->curr_burst_penalty, se->prev_burst_penalty);
+ se->curr_burst_penalty = 0;
2023-06-14 21:49:41 +02:00
+ se->burst_time = 0;
2023-03-12 20:40:20 +01:00
+}
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
2023-03-12 20:40:20 +01:00
+
2023-06-14 21:49:41 +02:00
int sched_thermal_decay_shift;
static int __init setup_sched_thermal_decay_shift(char *str)
2023-06-06 18:53:04 +02:00
{
2023-09-28 19:31:36 +02:00
@@ -145,6 +209,78 @@ static unsigned int sysctl_numa_balancing_promote_rate_limit = 65536;
2023-03-12 20:40:20 +01:00
2023-06-14 21:49:41 +02:00
#ifdef CONFIG_SYSCTL
static struct ctl_table sched_fair_sysctls[] = {
+#ifdef CONFIG_SCHED_BORE
+ {
+ .procname = "sched_bore",
+ .data = &sched_bore,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE,
+ },
+ {
2023-09-28 19:31:36 +02:00
+ .procname = "sched_bore_extra_flags",
+ .data = &sched_bore_extra_flags,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE,
+ },
+ {
2023-06-14 21:49:41 +02:00
+ .procname = "sched_burst_cache_lifetime",
+ .data = &sched_burst_cache_lifetime,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+ },
+ {
2023-07-26 11:45:05 +02:00
+ .procname = "sched_burst_fork_atavistic",
+ .data = &sched_burst_fork_atavistic,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = &three,
+ },
+ {
2023-06-14 21:49:41 +02:00
+ .procname = "sched_burst_penalty_offset",
+ .data = &sched_burst_penalty_offset,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = &sixty_four,
+ },
+ {
+ .procname = "sched_burst_penalty_scale",
+ .data = &sched_burst_penalty_scale,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = &maxval_12_bits,
+ },
+ {
2023-08-10 19:30:38 +02:00
+ .procname = "sched_burst_smoothness_down",
+ .data = &sched_burst_smoothness_down,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = &three,
+ },
+ {
+ .procname = "sched_burst_smoothness_up",
+ .data = &sched_burst_smoothness_up,
2023-06-14 21:49:41 +02:00
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = &three,
+ },
+#endif // CONFIG_SCHED_BORE
{
.procname = "sched_child_runs_first",
.data = &sysctl_sched_child_runs_first,
2023-09-28 19:31:36 +02:00
@@ -308,11 +444,22 @@ static u64 __calc_delta(u64 delta_exec, unsigned long weight, struct load_weight
2023-03-12 20:40:20 +01:00
/*
2023-06-14 21:49:41 +02:00
* delta /= w
2023-03-12 20:40:20 +01:00
*/
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
2023-09-28 19:31:36 +02:00
+#define bore_start_debit_full_penalty (sched_bore_extra_flags)
+#define calc_delta_fair_debit(delta, se) \
+ __calc_delta_fair(delta, se, !bore_start_debit_full_penalty)
2023-08-22 19:16:01 +02:00
+#define calc_delta_fair(delta, se) __calc_delta_fair(delta, se, false)
+static inline u64 __calc_delta_fair(u64 delta, struct sched_entity *se, bool half)
2023-06-14 21:49:41 +02:00
+#else // CONFIG_SCHED_BORE
static inline u64 calc_delta_fair(u64 delta, struct sched_entity *se)
+#endif // CONFIG_SCHED_BORE
2023-03-12 20:40:20 +01:00
{
2023-06-14 21:49:41 +02:00
if (unlikely(se->load.weight != NICE_0_LOAD))
delta = __calc_delta(delta, NICE_0_LOAD, &se->load);
2023-03-12 20:40:20 +01:00
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
2023-08-22 19:16:01 +02:00
+ if (likely(sched_bore)) delta = penalty_scale(delta, se, half);
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
return delta;
2023-03-12 20:40:20 +01:00
}
2023-09-28 19:31:36 +02:00
@@ -1128,7 +1275,11 @@ static void update_curr(struct cfs_rq *cfs_rq)
2023-06-14 21:49:41 +02:00
curr->sum_exec_runtime += delta_exec;
2023-03-12 20:40:20 +01:00
schedstat_add(cfs_rq->exec_clock, delta_exec);
2023-08-22 19:16:01 +02:00
- curr->vruntime += calc_delta_fair(delta_exec, curr);
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
+ curr->burst_time += delta_exec;
2023-08-10 19:30:38 +02:00
+ update_burst_penalty(curr);
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
2023-08-22 19:16:01 +02:00
+ curr->vruntime += max(1ULL, calc_delta_fair(delta_exec, curr));
2023-06-14 21:49:41 +02:00
update_deadline(cfs_rq, curr);
2023-03-12 20:40:20 +01:00
update_min_vruntime(cfs_rq);
2023-08-22 19:16:01 +02:00
2023-09-28 19:31:36 +02:00
@@ -4926,7 +5077,11 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq) {}
2023-08-22 19:16:01 +02:00
static void
place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
{
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
2023-09-28 19:31:36 +02:00
+ u64 vslice = calc_delta_fair_debit(se->slice, se);
+#else // CONFIG_SCHED_BORE
u64 vslice = calc_delta_fair(se->slice, se);
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
2023-09-28 19:31:36 +02:00
u64 vruntime = avg_vruntime(cfs_rq);
s64 lag = 0;
2023-03-12 20:40:20 +01:00
2023-09-28 19:31:36 +02:00
@@ -6482,6 +6637,9 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
2023-06-14 21:49:41 +02:00
util_est_dequeue(&rq->cfs, p);
for_each_sched_entity(se) {
+#ifdef CONFIG_SCHED_BORE
+ if (task_sleep) restart_burst(se);
+#endif // CONFIG_SCHED_BORE
cfs_rq = cfs_rq_of(se);
dequeue_entity(cfs_rq, se, flags);
2023-09-28 19:31:36 +02:00
@@ -8206,8 +8364,12 @@ static void yield_task_fair(struct rq *rq)
2023-06-14 21:49:41 +02:00
/*
* Are we the only task in the tree?
2023-08-22 19:16:01 +02:00
*/
- if (unlikely(rq->nr_running == 1))
+ if (unlikely(rq->nr_running == 1)) {
2023-06-14 21:49:41 +02:00
+#ifdef CONFIG_SCHED_BORE
2023-08-22 19:16:01 +02:00
+ restart_burst(se);
2023-06-14 21:49:41 +02:00
+#endif // CONFIG_SCHED_BORE
2023-08-22 19:16:01 +02:00
return;
+ }
2023-03-12 20:40:20 +01:00
2023-08-22 19:16:01 +02:00
clear_buddies(cfs_rq, se);
2023-09-28 19:31:36 +02:00
@@ -8216,6 +8378,9 @@ static void yield_task_fair(struct rq *rq)
2023-08-22 19:16:01 +02:00
* Update run-time statistics of the 'current'.
*/
update_curr(cfs_rq);
+#ifdef CONFIG_SCHED_BORE
+ restart_burst(se);
+#endif // CONFIG_SCHED_BORE
/*
* Tell update_rq_clock() that we've just updated,
* so we don't do microscopic update in schedule()
2023-03-12 20:40:20 +01:00
--
2023-09-28 19:31:36 +02:00
2.42.0