From 822ddbf8b3ee1b8b5a462bdc45b82bcdc129ffb9 Mon Sep 17 00:00:00 2001 From: Tk-Glitch Date: Sun, 15 Aug 2021 19:57:59 +0200 Subject: [PATCH] linux510-tkg: Update CacULE CPU scheduler patchset --- PKGBUILD | 2 +- linux-tkg-patches/5.10/0003-cacule-5.10.patch | 1364 ++++++++++++++--- 2 files changed, 1112 insertions(+), 254 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 0fe0457..0495ea0 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -330,7 +330,7 @@ case $_basever in 'a447e697cb744283e3e89f300c8a8bda04a9c8108f03677fb48bf9675c992cbd' '7058e57fd68367b029adc77f2a82928f1433daaf02c8c279cb2d13556c8804d7' 'e5ea0bb25ee294c655ac3cc30e1eea497799826108fbfb4ef3258c676c1e8a12' - 'a1758208827816fe01cf34947b0c07553af40b60d8480292e6918966f362d62a' + '502ca6657551a08fd626c098e2bef79b60e3033c1f201577e4cc5eea4dbf7f85' 'c605f638d74c61861ebdc36ebd4cb8b6475eae2f6273e1ccb2bbb3e10a2ec3fe' '2bbbac963b6ca44ef3f8a71ec7c5cad7d66df860869a73059087ee236775970a' 'e00096244e5cddaa5500d08b5f692fd3f25be9401dfa3b0fc624625ff2f5e198' diff --git a/linux-tkg-patches/5.10/0003-cacule-5.10.patch b/linux-tkg-patches/5.10/0003-cacule-5.10.patch index f1d20ca..0c56746 100644 --- a/linux-tkg-patches/5.10/0003-cacule-5.10.patch +++ b/linux-tkg-patches/5.10/0003-cacule-5.10.patch @@ -96,10 +96,10 @@ index 000000000000..82b0847c468a + idle timer scheduler in order to avoid to get into priority + inversion problems which would deadlock the machine. diff --git a/include/linux/sched.h b/include/linux/sched.h -index 2660ee4b08ad..ec38de9296f1 100644 +index 2660ee4b08ad..b54f0660cc86 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h -@@ -456,10 +456,22 @@ struct sched_statistics { +@@ -456,10 +456,23 @@ struct sched_statistics { #endif }; @@ -108,6 +108,7 @@ index 2660ee4b08ad..ec38de9296f1 100644 + struct cacule_node* next; + struct cacule_node* prev; + u64 cacule_start_time; ++ u64 last_run; + u64 vruntime; +}; +#endif @@ -123,27 +124,31 @@ index 2660ee4b08ad..ec38de9296f1 100644 unsigned int on_rq; diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h -index 3c31ba88aca5..4cf162341ab8 100644 +index 3c31ba88aca5..e79ca8c67a70 100644 --- a/include/linux/sched/sysctl.h +++ b/include/linux/sched/sysctl.h -@@ -31,6 +31,12 @@ extern unsigned int sysctl_sched_min_granularity; +@@ -31,6 +31,16 @@ extern unsigned int sysctl_sched_min_granularity; extern unsigned int sysctl_sched_wakeup_granularity; extern unsigned int sysctl_sched_child_runs_first; +#ifdef CONFIG_CACULE_SCHED +extern unsigned int interactivity_factor; -+extern unsigned int interactivity_threshold; +extern unsigned int cacule_max_lifetime; ++extern unsigned int cache_factor; ++extern unsigned int cache_divisor; ++extern unsigned int starve_factor; ++extern unsigned int starve_divisor; ++extern int cacule_yield; +#endif + enum sched_tunable_scaling { SCHED_TUNABLESCALING_NONE, SCHED_TUNABLESCALING_LOG, diff --git a/init/Kconfig b/init/Kconfig -index fc4c9f416fad..16676cfd11d7 100644 +index fc4c9f416fad..e93632e5b7fc 100644 --- a/init/Kconfig +++ b/init/Kconfig -@@ -825,6 +825,17 @@ config UCLAMP_BUCKETS_COUNT +@@ -825,6 +825,51 @@ config UCLAMP_BUCKETS_COUNT endmenu @@ -157,11 +162,45 @@ index fc4c9f416fad..16676cfd11d7 100644 + + If unsure, say Y here. + ++config CACULE_RDB ++ bool "RDB (Response Driven Balancer)" ++ default y ++ depends on CACULE_SCHED ++ help ++ This is an experimental load balancer for CacULE. It is a lightweight ++ load balancer which is a replacement of CFS load balancer. It migrates ++ tasks based on their interactivity scores. ++ ++ If unsure, say Y here. ++ ++config RDB_INTERVAL ++ int "RDB load balancer interval" ++ default 19 ++ depends on CACULE_RDB ++ help ++ This is an interval to control load balance time period. ++ The trigger_load_balance runs in every tick. For High HZ values, the ++ load balance could be overwhelming. RDB load balance includes rq locking ++ which can reduce the performance. The balance interval can help to avoid ++ running load balance on every tick. For example, RDB_INTERVAL=3 will ++ only run load balance every 3ms. Setting RDB_INTERVAL depends on HZ. ++ If you want load balancer run every 2ms while HZ=500 then it is not ++ needed and better to set RDB_INTERVAL=0 since 500HZ already (1000ms ++ / 500HZ = 2ms). However, if you have 1000HZ and want to avoid load ++ balancer from running every 1ms, you could set RDB_INTERVAL=4ms for ++ example to make load balancer run every 4ms. Less RDB_INTERVAL values ++ (or 0 to disable) could make sure tasks are balanced ASAP, but with ++ the cost of locking/blocking time. High RDB_INTERVAL values can relax ++ balancing locking but with the cost of imbalanced workload for that ++ period of time (i.e. if RDB_INTERVAL=100ms) there will be no balancing ++ for 100ms (except for newidle_balance which is not effected by RDB_INTERVAL). ++ ++ If in doubt, use the default value. + # # For architectures that want to enable the support for NUMA-affine scheduler # balancing logic: -@@ -1208,6 +1219,7 @@ config SCHED_AUTOGROUP +@@ -1208,6 +1253,7 @@ config SCHED_AUTOGROUP select CGROUPS select CGROUP_SCHED select FAIR_GROUP_SCHED @@ -192,10 +231,21 @@ index 38ef6d06888e..865f8dbddca8 100644 config SCHED_HRTICK def_bool HIGH_RES_TIMERS diff --git a/kernel/sched/core.c b/kernel/sched/core.c -index 57b236251884..860b1a747dfb 100644 +index 679562d2f55d..b3c4594eb320 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c -@@ -3068,6 +3068,11 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p) +@@ -72,6 +72,10 @@ const_debug unsigned int sysctl_sched_nr_migrate = 32; + */ + unsigned int sysctl_sched_rt_period = 1000000; + ++#ifdef CONFIG_CACULE_SCHED ++int __read_mostly cacule_yield = 1; ++#endif ++ + __read_mostly int scheduler_running; + + /* +@@ -3068,6 +3072,11 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p) p->se.prev_sum_exec_runtime = 0; p->se.nr_migrations = 0; p->se.vruntime = 0; @@ -207,7 +257,7 @@ index 57b236251884..860b1a747dfb 100644 INIT_LIST_HEAD(&p->se.group_node); #ifdef CONFIG_FAIR_GROUP_SCHED -@@ -3352,6 +3357,10 @@ void wake_up_new_task(struct task_struct *p) +@@ -3352,6 +3361,10 @@ void wake_up_new_task(struct task_struct *p) update_rq_clock(rq); post_init_entity_util_avg(p); @@ -218,7 +268,17 @@ index 57b236251884..860b1a747dfb 100644 activate_task(rq, p, ENQUEUE_NOCLOCK); trace_sched_wakeup_new(p); check_preempt_curr(rq, p, WF_FORK); -@@ -4073,6 +4082,7 @@ static void sched_tick_remote(struct work_struct *work) +@@ -4053,7 +4066,9 @@ static void sched_tick_remote(struct work_struct *work) + struct rq *rq = cpu_rq(cpu); + struct task_struct *curr; + struct rq_flags rf; ++#if !defined(CONFIG_CACULE_SCHED) + u64 delta; ++#endif + int os; + + /* +@@ -4073,6 +4088,7 @@ static void sched_tick_remote(struct work_struct *work) update_rq_clock(rq); @@ -226,7 +286,7 @@ index 57b236251884..860b1a747dfb 100644 if (!is_idle_task(curr)) { /* * Make sure the next tick runs within a reasonable -@@ -4081,6 +4091,8 @@ static void sched_tick_remote(struct work_struct *work) +@@ -4081,6 +4097,8 @@ static void sched_tick_remote(struct work_struct *work) delta = rq_clock_task(rq) - curr->se.exec_start; WARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3); } @@ -235,12 +295,30 @@ index 57b236251884..860b1a747dfb 100644 curr->sched_class->task_tick(rq, curr, 0); calc_load_nohz_remote(rq); -@@ -7066,6 +7078,10 @@ void __init sched_init(void) +@@ -6092,6 +6110,13 @@ static void do_sched_yield(void) + struct rq_flags rf; + struct rq *rq; + ++#ifdef CONFIG_CACULE_SCHED ++ struct task_struct *curr = current; ++ struct cacule_node *cn = &curr->se.cacule_node; ++ ++ if (cacule_yield) ++ cn->vruntime |= YIELD_MARK; ++#endif + rq = this_rq_lock_irq(&rf); + + schedstat_inc(rq->yld_count); +@@ -7066,6 +7091,14 @@ void __init sched_init(void) BUG_ON(&dl_sched_class + 1 != &stop_sched_class); #endif +#ifdef CONFIG_CACULE_SCHED -+ printk(KERN_INFO "CacULE CPU scheduler v5.10-r2 by Hamad Al Marri."); ++#ifdef CONFIG_CACULE_RDB ++ printk(KERN_INFO "CacULE CPU scheduler (RDB) v5.10-r3 by Hamad Al Marri."); ++#else ++ printk(KERN_INFO "CacULE CPU scheduler v5.10-r3 by Hamad Al Marri."); ++#endif +#endif + wait_bit_init(); @@ -293,10 +371,10 @@ index 70a578272436..506c0512610c 100644 cfs_rq->nr_spread_over); SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c -index d6e1c90de570..f5565f9d303a 100644 +index 262b02d75007..cf3ae2a8568b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c -@@ -19,6 +19,10 @@ +@@ -19,9 +19,24 @@ * * Adaptive scheduling granularity, math enhancements by Peter Zijlstra * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra @@ -307,7 +385,21 @@ index d6e1c90de570..f5565f9d303a 100644 */ #include "sched.h" -@@ -82,7 +86,11 @@ unsigned int sysctl_sched_child_runs_first __read_mostly; ++#ifdef CONFIG_CACULE_SCHED ++unsigned int __read_mostly cacule_max_lifetime = 22000; // in ms ++unsigned int __read_mostly interactivity_factor = 32768; ++ ++unsigned int __read_mostly cache_factor = 13107; ++unsigned int __read_mostly cache_divisor = 1000000; // 1ms ++ ++unsigned int __read_mostly starve_factor = 19660; ++unsigned int __read_mostly starve_divisor = 3000000; // 3ms ++#endif ++ + /* + * Targeted preemption latency for CPU-bound tasks: + * +@@ -82,7 +97,11 @@ unsigned int sysctl_sched_child_runs_first __read_mostly; unsigned int sysctl_sched_wakeup_granularity = 1000000UL; static unsigned int normalized_sysctl_sched_wakeup_granularity = 1000000UL; @@ -319,24 +411,6 @@ index d6e1c90de570..f5565f9d303a 100644 int sched_thermal_decay_shift; static int __init setup_sched_thermal_decay_shift(char *str) -@@ -113,6 +121,17 @@ int __weak arch_asym_cpu_priority(int cpu) - */ - #define fits_capacity(cap, max) ((cap) * 1280 < (max) * 1024) - -+#endif -+#ifdef CONFIG_CACULE_SCHED -+unsigned int __read_mostly cacule_max_lifetime = 22000; // in ms -+unsigned int __read_mostly interactivity_factor = 32768; -+ -+#ifdef CONFIG_FAIR_GROUP_SCHED -+unsigned int __read_mostly interactivity_threshold = 0; -+#else -+unsigned int __read_mostly interactivity_threshold = 1000; -+#endif -+ - #endif - - #ifdef CONFIG_CFS_BANDWIDTH @@ -253,6 +272,14 @@ static u64 __calc_delta(u64 delta_exec, unsigned long weight, struct load_weight const struct sched_class fair_sched_class; @@ -361,7 +435,7 @@ index d6e1c90de570..f5565f9d303a 100644 static inline u64 max_vruntime(u64 max_vruntime, u64 vruntime) { s64 delta = (s64)(vruntime - max_vruntime); -@@ -568,7 +595,204 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) +@@ -568,7 +595,223 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) cfs_rq->min_vruntime_copy = cfs_rq->min_vruntime; #endif } @@ -395,42 +469,70 @@ index d6e1c90de570..f5565f9d303a 100644 + return score_se; +} + -+static inline int is_interactive(struct cacule_node *cn) ++static unsigned int ++calc_cache_score(u64 now, struct cacule_node *cn) +{ -+ if (!interactivity_threshold || se_of(cn)->vruntime == 0) ++ struct sched_entity *se = se_of(cn); ++ struct cfs_rq *cfs_rq = cfs_rq_of(se); ++ u64 c_div = cache_divisor; ++ u64 cache_period = 1ULL; ++ u64 u64_factor_m = cache_factor; ++ u64 _2m = u64_factor_m << 1; ++ unsigned int score; ++ ++ if (!cache_factor) + return 0; + -+ return calc_interactivity(sched_clock(), cn) < interactivity_threshold; ++ if (se == cfs_rq->curr) ++ return 0; ++ ++ cache_period = (now - se->exec_start) | 1; ++ ++ if (c_div >= cache_period) ++ score = u64_factor_m / (c_div / cache_period); ++ else ++ score = _2m - (u64_factor_m / (cache_period / c_div)); ++ ++ return score; +} + -+static inline int cn_has_idle_policy(struct cacule_node *se) ++static unsigned int ++calc_starve_score(u64 now, struct cacule_node *cn) +{ -+ return task_has_idle_policy(task_of(se_of(se))); ++ struct sched_entity *se = se_of(cn); ++ struct cfs_rq *cfs_rq = cfs_rq_of(se); ++ u64 s_div = starve_divisor; ++ u64 starving = 1ULL; ++ u64 u64_factor_m = starve_factor; ++ u64 _2m = u64_factor_m << 1; ++ unsigned int score; ++ ++ if (!starve_factor) ++ return 0; ++ ++ if (se == cfs_rq->curr) ++ return _2m; ++ ++ starving = (now - cn->last_run) | 1; ++ ++ if (s_div >= starving) ++ score = _2m - (u64_factor_m / (s_div / starving)); ++ else ++ score = u64_factor_m / (starving / s_div); ++ ++ return score; +} + -+static inline int -+entity_before_cached(u64 now, unsigned int score_curr, struct cacule_node *se) ++static inline int cn_has_idle_policy(struct cacule_node *cn) +{ -+ unsigned int score_se; -+ int diff; ++ struct sched_entity *se = se_of(cn); + -+ /* -+ * if se has idle class, then no need to -+ * calculate, since we are sure that score_curr -+ * is a score for non idle class task -+ */ -+ if (cn_has_idle_policy(se)) -+ return -1; ++ if (!entity_is_task(se)) ++ return false; + -+ score_se = calc_interactivity(now, se); -+ diff = score_se - score_curr; -+ -+ if (diff <= 0) -+ return 1; -+ -+ return -1; ++ return task_has_idle_policy(task_of(se)); +} -+ + +/* + * Does se have lower interactivity score value (i.e. interactive) than curr? If yes, return 1, + * otherwise return -1 @@ -453,8 +555,13 @@ index d6e1c90de570..f5565f9d303a 100644 + if (is_curr_idle && !is_se_idle) + return 1; + -+ score_curr = calc_interactivity(now, curr); -+ score_se = calc_interactivity(now, se); ++ score_curr = calc_interactivity(now, curr); ++ score_curr += calc_cache_score(now, curr); ++ score_curr += calc_starve_score(now, curr); ++ ++ score_se = calc_interactivity(now, se); ++ score_se += calc_cache_score(now, se); ++ score_se += calc_starve_score(now, se); + + diff = score_se - score_curr; + @@ -463,65 +570,52 @@ index d6e1c90de570..f5565f9d303a 100644 + + return -1; +} - ++ ++#ifdef CONFIG_CACULE_RDB ++static void update_IS(struct rq *rq) ++{ ++ struct list_head *tasks = &rq->cfs_tasks; ++ struct task_struct *p, *to_migrate = NULL; ++ unsigned int max_IS = ~0, temp_IS; ++ ++ list_for_each_entry(p, tasks, se.group_node) { ++ if (task_running(rq, p)) ++ continue; ++ ++ temp_IS = calc_interactivity(sched_clock(), &p->se.cacule_node); ++ if (temp_IS < max_IS) { ++ to_migrate = p; ++ max_IS = temp_IS; ++ } ++ } ++ ++ if (to_migrate) { ++ WRITE_ONCE(rq->max_IS_score, max_IS); ++ WRITE_ONCE(rq->to_migrate_task, to_migrate); ++ } else if (rq->max_IS_score != ~0) { ++ WRITE_ONCE(rq->max_IS_score, ~0); ++ WRITE_ONCE(rq->to_migrate_task, NULL); ++ } ++} ++#endif ++ +/* + * Enqueue an entity + */ +static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *_se) +{ + struct cacule_node *se = &(_se->cacule_node); -+ struct cacule_node *iter, *next = NULL; -+ u64 now = sched_clock(); -+ unsigned int score_se = calc_interactivity(now, se); -+ int is_idle_task = cn_has_idle_policy(se); + + se->next = NULL; + se->prev = NULL; + -+ if (likely(cfs_rq->head)) { -+ -+ // start from tail -+ iter = cfs_rq->tail; -+ -+ /* -+ * if this task has idle class, then -+ * push it to the tail right away -+ */ -+ if (is_idle_task) -+ goto to_tail; -+ -+ /* here we know that this task isn't idle clas */ -+ -+ // does se have higher IS than iter? -+ while (iter && entity_before_cached(now, score_se, iter) == -1) { -+ next = iter; -+ iter = iter->prev; -+ } -+ -+ // se in tail position -+ if (iter == cfs_rq->tail) { -+to_tail: -+ cfs_rq->tail->next = se; -+ se->prev = cfs_rq->tail; -+ -+ cfs_rq->tail = se; -+ } -+ // else if not head no tail, insert se after iter -+ else if (iter) { -+ se->next = next; -+ se->prev = iter; -+ -+ iter->next = se; -+ next->prev = se; -+ } ++ if (cfs_rq->head) { + // insert se at head -+ else { -+ se->next = cfs_rq->head; -+ cfs_rq->head->prev = se; ++ se->next = cfs_rq->head; ++ cfs_rq->head->prev = se; + -+ // lastly reset the head -+ cfs_rq->head = se; -+ } ++ // lastly reset the head ++ cfs_rq->head = se; + } else { + // if empty rq + cfs_rq->head = se; @@ -537,7 +631,6 @@ index d6e1c90de570..f5565f9d303a 100644 + if (cfs_rq->head == cfs_rq->tail) { + cfs_rq->head = NULL; + cfs_rq->tail = NULL; -+ + } else if (se == cfs_rq->head) { + // if it is the head + cfs_rq->head = cfs_rq->head->next; @@ -566,7 +659,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Enqueue an entity into the rb-tree: */ -@@ -626,16 +850,24 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se) +@@ -626,16 +869,24 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se) return rb_entry(next, struct sched_entity, run_node); } @@ -591,7 +684,7 @@ index d6e1c90de570..f5565f9d303a 100644 } /************************************************************** -@@ -730,6 +962,7 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) +@@ -730,6 +981,7 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) return slice; } @@ -599,7 +692,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * We calculate the vruntime slice of a to-be-inserted task. * -@@ -739,6 +972,7 @@ static u64 sched_vslice(struct cfs_rq *cfs_rq, struct sched_entity *se) +@@ -739,6 +991,7 @@ static u64 sched_vslice(struct cfs_rq *cfs_rq, struct sched_entity *se) { return calc_delta_fair(sched_slice(cfs_rq, se), se); } @@ -607,7 +700,7 @@ index d6e1c90de570..f5565f9d303a 100644 #include "pelt.h" #ifdef CONFIG_SMP -@@ -846,14 +1080,51 @@ static void update_tg_load_avg(struct cfs_rq *cfs_rq) +@@ -846,14 +1099,55 @@ static void update_tg_load_avg(struct cfs_rq *cfs_rq) } #endif /* CONFIG_SMP */ @@ -615,7 +708,7 @@ index d6e1c90de570..f5565f9d303a 100644 +static void normalize_lifetime(u64 now, struct sched_entity *se) +{ + struct cacule_node *cn = &se->cacule_node; -+ u64 max_life_ns, life_time; ++ u64 max_life_ns, life_time, old_hrrn_x; + s64 diff; + + /* @@ -628,8 +721,12 @@ index d6e1c90de570..f5565f9d303a 100644 + diff = life_time - max_life_ns; + + if (diff > 0) { ++ // unmark YIELD. No need to check or remark since ++ // this normalize action doesn't happen very often ++ cn->vruntime &= YIELD_UNMARK; ++ + // multiply life_time by 1024 for more precision -+ u64 old_hrrn_x = (life_time << 7) / ((cn->vruntime >> 3) | 1); ++ old_hrrn_x = (life_time << 7) / ((cn->vruntime >> 3) | 1); + + // reset life to half max_life (i.e ~15s) + cn->cacule_start_time = now - (max_life_ns >> 1); @@ -659,11 +756,12 @@ index d6e1c90de570..f5565f9d303a 100644 if (unlikely(!curr)) return; -@@ -870,8 +1141,15 @@ static void update_curr(struct cfs_rq *cfs_rq) +@@ -870,8 +1164,16 @@ static void update_curr(struct cfs_rq *cfs_rq) curr->sum_exec_runtime += delta_exec; schedstat_add(cfs_rq->exec_clock, delta_exec); +#ifdef CONFIG_CACULE_SCHED ++ curr->cacule_node.last_run = now; + delta_fair = calc_delta_fair(delta_exec, curr); + curr->vruntime += delta_fair; + curr->cacule_node.vruntime += delta_fair; @@ -675,7 +773,7 @@ index d6e1c90de570..f5565f9d303a 100644 if (entity_is_task(curr)) { struct task_struct *curtask = task_of(curr); -@@ -1030,7 +1308,6 @@ update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +@@ -1030,7 +1332,6 @@ update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) static inline void update_stats_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { @@ -683,19 +781,20 @@ index d6e1c90de570..f5565f9d303a 100644 if (!schedstat_enabled()) return; -@@ -1062,7 +1339,11 @@ update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se) +@@ -1062,7 +1363,12 @@ update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se) /* * We are starting a new run period: */ +#ifdef CONFIG_CACULE_SCHED + se->exec_start = sched_clock(); ++ se->cacule_node.last_run = sched_clock(); +#else se->exec_start = rq_clock_task(rq_of(cfs_rq)); +#endif } /************************************************** -@@ -4129,7 +4410,7 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq) {} +@@ -4129,7 +4435,7 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq) {} static void check_spread(struct cfs_rq *cfs_rq, struct sched_entity *se) { @@ -704,7 +803,7 @@ index d6e1c90de570..f5565f9d303a 100644 s64 d = se->vruntime - cfs_rq->min_vruntime; if (d < 0) -@@ -4140,6 +4421,7 @@ static void check_spread(struct cfs_rq *cfs_rq, struct sched_entity *se) +@@ -4140,6 +4446,7 @@ static void check_spread(struct cfs_rq *cfs_rq, struct sched_entity *se) #endif } @@ -712,7 +811,7 @@ index d6e1c90de570..f5565f9d303a 100644 static void place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) { -@@ -4171,6 +4453,7 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) +@@ -4171,6 +4478,7 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) /* ensure we never gain time by being placed backwards. */ se->vruntime = max_vruntime(se->vruntime, vruntime); } @@ -720,7 +819,7 @@ index d6e1c90de570..f5565f9d303a 100644 static void check_enqueue_throttle(struct cfs_rq *cfs_rq); -@@ -4229,18 +4512,23 @@ static inline bool cfs_bandwidth_used(void); +@@ -4229,18 +4537,23 @@ static inline bool cfs_bandwidth_used(void); static void enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { @@ -744,7 +843,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Otherwise, renormalise after, such that we're placed at the current * moment in time, instead of some random moment in the past. Being -@@ -4249,6 +4537,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +@@ -4249,6 +4562,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) */ if (renorm && !curr) se->vruntime += cfs_rq->min_vruntime; @@ -752,7 +851,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * When enqueuing a sched_entity, we must: -@@ -4263,8 +4552,10 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +@@ -4263,8 +4577,10 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) update_cfs_group(se); account_entity_enqueue(cfs_rq, se); @@ -763,7 +862,7 @@ index d6e1c90de570..f5565f9d303a 100644 check_schedstat_required(); update_stats_enqueue(cfs_rq, se, flags); -@@ -4285,6 +4576,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +@@ -4285,6 +4601,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) check_enqueue_throttle(cfs_rq); } @@ -771,7 +870,7 @@ index d6e1c90de570..f5565f9d303a 100644 static void __clear_buddies_last(struct sched_entity *se) { for_each_sched_entity(se) { -@@ -4329,6 +4621,7 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) +@@ -4329,6 +4646,7 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) if (cfs_rq->skip == se) __clear_buddies_skip(se); } @@ -779,7 +878,7 @@ index d6e1c90de570..f5565f9d303a 100644 static __always_inline void return_cfs_rq_runtime(struct cfs_rq *cfs_rq); -@@ -4353,13 +4646,16 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +@@ -4353,13 +4671,16 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) update_stats_dequeue(cfs_rq, se, flags); @@ -796,7 +895,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Normalize after update_curr(); which will also have moved * min_vruntime if @se is the one holding it back. But before doing -@@ -4368,12 +4664,14 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +@@ -4368,12 +4689,14 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) */ if (!(flags & DEQUEUE_SLEEP)) se->vruntime -= cfs_rq->min_vruntime; @@ -811,7 +910,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Now advance min_vruntime if @se was the entity holding it back, * except when: DEQUEUE_SAVE && !DEQUEUE_MOVE, in this case we'll be -@@ -4382,8 +4680,21 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +@@ -4382,8 +4705,23 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) */ if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE) update_min_vruntime(cfs_rq); @@ -819,21 +918,23 @@ index d6e1c90de570..f5565f9d303a 100644 } +#ifdef CONFIG_CACULE_SCHED ++static struct sched_entity * ++pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr); ++ +/* + * Preempt the current task with a newly woken task if needed: + */ +static void +check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) +{ -+ // does head have higher IS than curr -+ if (entity_before(sched_clock(), &curr->cacule_node, cfs_rq->head) == 1) ++ if (pick_next_entity(cfs_rq, curr) != curr) + resched_curr(rq_of(cfs_rq)); +} +#else /* * Preempt the current task with a newly woken task if needed: */ -@@ -4423,6 +4734,7 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) +@@ -4423,6 +4761,7 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) if (delta > ideal_runtime) resched_curr(rq_of(cfs_rq)); } @@ -841,7 +942,7 @@ index d6e1c90de570..f5565f9d303a 100644 static void set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) -@@ -4457,6 +4769,21 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) +@@ -4457,6 +4796,31 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) se->prev_sum_exec_runtime = se->sum_exec_runtime; } @@ -850,12 +951,22 @@ index d6e1c90de570..f5565f9d303a 100644 +pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) +{ + struct cacule_node *se = cfs_rq->head; ++ struct cacule_node *next; ++ u64 now = sched_clock(); + -+ if (unlikely(!se)) -+ se = &curr->cacule_node; -+ else if (unlikely(curr -+ && entity_before(sched_clock(), se, &curr->cacule_node) == 1)) -+ se = &curr->cacule_node; ++ if (!se) ++ return curr; ++ ++ next = se->next; ++ while (next) { ++ if (entity_before(now, se, next) == 1) ++ se = next; ++ ++ next = next->next; ++ } ++ ++ if (curr && entity_before(now, se, &curr->cacule_node) == 1) ++ return curr; + + return se_of(se); +} @@ -863,7 +974,7 @@ index d6e1c90de570..f5565f9d303a 100644 static int wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se); -@@ -4517,6 +4844,7 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) +@@ -4517,6 +4881,7 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) return se; } @@ -871,8 +982,14 @@ index d6e1c90de570..f5565f9d303a 100644 static bool check_cfs_rq_runtime(struct cfs_rq *cfs_rq); -@@ -5610,7 +5938,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) +@@ -5608,9 +5973,15 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) + assert_list_leaf_cfs_rq(rq); + hrtick_update(rq); ++ ++#ifdef CONFIG_CACULE_RDB ++ update_IS(rq); ++#endif } +#if !defined(CONFIG_CACULE_SCHED) @@ -881,7 +998,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * The dequeue_task method is called before nr_running is -@@ -5642,12 +5972,14 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) +@@ -5642,12 +6013,14 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) if (cfs_rq->load.weight) { /* Avoid re-evaluating load for this entity: */ se = parent_entity(se); @@ -896,7 +1013,18 @@ index d6e1c90de570..f5565f9d303a 100644 break; } flags |= DEQUEUE_SLEEP; -@@ -5763,6 +6095,7 @@ static unsigned long capacity_of(int cpu) +@@ -5679,6 +6052,10 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) + dequeue_throttle: + util_est_update(&rq->cfs, p, task_sleep); + hrtick_update(rq); ++ ++#ifdef CONFIG_CACULE_RDB ++ update_IS(rq); ++#endif + } + + #ifdef CONFIG_SMP +@@ -5763,6 +6140,7 @@ static unsigned long capacity_of(int cpu) return cpu_rq(cpu)->cpu_capacity; } @@ -904,7 +1032,7 @@ index d6e1c90de570..f5565f9d303a 100644 static void record_wakee(struct task_struct *p) { /* -@@ -5809,6 +6142,7 @@ static int wake_wide(struct task_struct *p) +@@ -5809,6 +6187,7 @@ static int wake_wide(struct task_struct *p) return 0; return 1; } @@ -912,7 +1040,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * The purpose of wake_affine() is to quickly determine on which CPU we can run -@@ -6485,6 +6819,7 @@ static unsigned long cpu_util_without(int cpu, struct task_struct *p) +@@ -6485,6 +6864,7 @@ static unsigned long cpu_util_without(int cpu, struct task_struct *p) return min_t(unsigned long, util, capacity_orig_of(cpu)); } @@ -920,92 +1048,23 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Predicts what cpu_util(@cpu) would return if @p was migrated (and enqueued) * to @dst_cpu. -@@ -6718,6 +7053,57 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) +@@ -6718,6 +7098,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) return -1; } +#endif /* CONFIG_CACULE_SCHED */ -+ -+#ifdef CONFIG_CACULE_SCHED -+static int -+find_least_IS_cpu(struct task_struct *p) -+{ -+ struct cfs_rq *cfs_rq; -+ unsigned int max_IS = 0; -+ unsigned int IS, IS_c, IS_h; -+ struct sched_entity *curr_se; -+ struct cacule_node *cn, *head; -+ int cpu_i; -+ int new_cpu = -1; -+ -+ for_each_online_cpu(cpu_i) { -+ if (!cpumask_test_cpu(cpu_i, p->cpus_ptr)) -+ continue; -+ -+ cn = NULL; -+ cfs_rq = &cpu_rq(cpu_i)->cfs; -+ -+ curr_se = cfs_rq->curr; -+ head = cfs_rq->head; -+ -+ if (!curr_se && head) -+ cn = head; -+ else if (curr_se && !head) -+ cn = &curr_se->cacule_node; -+ else if (curr_se && head) { -+ IS_c = calc_interactivity(sched_clock(), &curr_se->cacule_node); -+ IS_h = calc_interactivity(sched_clock(), head); -+ -+ IS = IS_c > IS_h? IS_c : IS_h; -+ goto compare; -+ } -+ -+ if (!cn) -+ return cpu_i; -+ -+ IS = calc_interactivity(sched_clock(), cn); -+ -+compare: -+ if (IS > max_IS) { -+ max_IS = IS; -+ new_cpu = cpu_i; -+ } -+ } -+ -+ return new_cpu; -+} -+#endif /* * select_task_rq_fair: Select target runqueue for the waking task in domains -@@ -6740,6 +7126,26 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f +@@ -6740,6 +7121,7 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f int want_affine = 0; int sync = (wake_flags & WF_SYNC) && !(current->flags & PF_EXITING); -+#ifdef CONFIG_CACULE_SCHED -+ struct sched_entity *se = &p->se; -+ -+ if (!is_interactive(&se->cacule_node)) -+ goto cfs_way; -+ -+ // check first if the prev cpu -+ // has 0 tasks -+ if (cpumask_test_cpu(prev_cpu, p->cpus_ptr) && -+ cpu_rq(prev_cpu)->cfs.nr_running == 0) -+ return prev_cpu; -+ -+ new_cpu = find_least_IS_cpu(p); -+ -+ if (new_cpu != -1) -+ return new_cpu; -+ -+ new_cpu = prev_cpu; -+cfs_way: -+#else ++#if !defined(CONFIG_CACULE_SCHED) if (sd_flag & SD_BALANCE_WAKE) { record_wakee(p); -@@ -6752,6 +7158,7 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f +@@ -6752,6 +7134,7 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f want_affine = !wake_wide(p) && cpumask_test_cpu(cpu, p->cpus_ptr); } @@ -1013,7 +1072,7 @@ index d6e1c90de570..f5565f9d303a 100644 rcu_read_lock(); for_each_domain(cpu, tmp) { -@@ -6799,6 +7206,7 @@ static void detach_entity_cfs_rq(struct sched_entity *se); +@@ -6799,6 +7182,7 @@ static void detach_entity_cfs_rq(struct sched_entity *se); */ static void migrate_task_rq_fair(struct task_struct *p, int new_cpu) { @@ -1021,7 +1080,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * As blocked tasks retain absolute vruntime the migration needs to * deal with this by subtracting the old and adding the new -@@ -6824,6 +7232,7 @@ static void migrate_task_rq_fair(struct task_struct *p, int new_cpu) +@@ -6824,6 +7208,7 @@ static void migrate_task_rq_fair(struct task_struct *p, int new_cpu) se->vruntime -= min_vruntime; } @@ -1029,7 +1088,7 @@ index d6e1c90de570..f5565f9d303a 100644 if (p->on_rq == TASK_ON_RQ_MIGRATING) { /* -@@ -6869,6 +7278,7 @@ balance_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) +@@ -6869,6 +7254,7 @@ balance_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) } #endif /* CONFIG_SMP */ @@ -1037,7 +1096,7 @@ index d6e1c90de570..f5565f9d303a 100644 static unsigned long wakeup_gran(struct sched_entity *se) { unsigned long gran = sysctl_sched_wakeup_granularity; -@@ -6947,6 +7357,7 @@ static void set_skip_buddy(struct sched_entity *se) +@@ -6947,6 +7333,7 @@ static void set_skip_buddy(struct sched_entity *se) for_each_sched_entity(se) cfs_rq_of(se)->skip = se; } @@ -1045,7 +1104,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Preempt the current task with a newly woken task if needed: -@@ -6955,9 +7366,12 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ +@@ -6955,9 +7342,12 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ { struct task_struct *curr = rq->curr; struct sched_entity *se = &curr->se, *pse = &p->se; @@ -1058,7 +1117,7 @@ index d6e1c90de570..f5565f9d303a 100644 if (unlikely(se == pse)) return; -@@ -6971,10 +7385,12 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ +@@ -6971,10 +7361,12 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ if (unlikely(throttled_hierarchy(cfs_rq_of(pse)))) return; @@ -1071,7 +1130,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * We can come here with TIF_NEED_RESCHED already set from new task -@@ -7004,6 +7420,11 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ +@@ -7004,6 +7396,11 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ find_matching_se(&se, &pse); update_curr(cfs_rq_of(se)); BUG_ON(!pse); @@ -1083,7 +1142,7 @@ index d6e1c90de570..f5565f9d303a 100644 if (wakeup_preempt_entity(se, pse) == 1) { /* * Bias pick_next to pick the sched entity that is -@@ -7013,11 +7434,14 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ +@@ -7013,11 +7410,14 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ set_next_buddy(pse); goto preempt; } @@ -1098,7 +1157,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Only set the backward buddy when the current task is still * on the rq. This can happen when a wakeup gets interleaved -@@ -7032,6 +7456,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ +@@ -7032,6 +7432,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ if (sched_feat(LAST_BUDDY) && scale && entity_is_task(se)) set_last_buddy(se); @@ -1106,7 +1165,72 @@ index d6e1c90de570..f5565f9d303a 100644 } struct task_struct * -@@ -7206,7 +7631,10 @@ static void yield_task_fair(struct rq *rq) +@@ -7093,6 +7494,11 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf + cfs_rq = group_cfs_rq(se); + } while (cfs_rq); + ++ /* ++ * Here we picked a sched_entity starting from ++ * the same group of curr, but the task could ++ * be a child of the selected sched_entity. ++ */ + p = task_of(se); + + /* +@@ -7103,6 +7509,7 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf + if (prev != p) { + struct sched_entity *pse = &prev->se; + ++ /* while se and pse are not in the same group */ + while (!(cfs_rq = is_same_group(se, pse))) { + int se_depth = se->depth; + int pse_depth = pse->depth; +@@ -7117,6 +7524,9 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf + } + } + ++ /* Here we reached the point were both ++ * sched_entities are in the same group. ++ */ + put_prev_entity(cfs_rq, pse); + set_next_entity(cfs_rq, se); + } +@@ -7127,6 +7537,7 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf + if (prev) + put_prev_task(rq, prev); + ++ /* Going down the hierarchy */ + do { + se = pick_next_entity(cfs_rq, NULL); + set_next_entity(cfs_rq, se); +@@ -7136,6 +7547,14 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf + p = task_of(se); + + done: __maybe_unused; ++#ifdef CONFIG_CACULE_SCHED ++ if (prev) ++ prev->se.cacule_node.vruntime &= YIELD_UNMARK; ++ ++#ifdef CONFIG_CACULE_RDB ++ update_IS(rq); ++#endif ++#endif + #ifdef CONFIG_SMP + /* + * Move the next running task to the front of +@@ -7153,6 +7572,11 @@ done: __maybe_unused; + return p; + + idle: ++#ifdef CONFIG_CACULE_RDB ++ WRITE_ONCE(rq->max_IS_score, ~0); ++ WRITE_ONCE(rq->to_migrate_task, NULL); ++#endif ++ + if (!rf) + return NULL; + +@@ -7206,7 +7630,10 @@ static void yield_task_fair(struct rq *rq) { struct task_struct *curr = rq->curr; struct cfs_rq *cfs_rq = task_cfs_rq(curr); @@ -1117,7 +1241,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Are we the only task in the tree? -@@ -7214,7 +7642,9 @@ static void yield_task_fair(struct rq *rq) +@@ -7214,7 +7641,9 @@ static void yield_task_fair(struct rq *rq) if (unlikely(rq->nr_running == 1)) return; @@ -1127,7 +1251,7 @@ index d6e1c90de570..f5565f9d303a 100644 if (curr->policy != SCHED_BATCH) { update_rq_clock(rq); -@@ -7230,7 +7660,9 @@ static void yield_task_fair(struct rq *rq) +@@ -7230,7 +7659,9 @@ static void yield_task_fair(struct rq *rq) rq_clock_skip_update(rq); } @@ -1137,7 +1261,7 @@ index d6e1c90de570..f5565f9d303a 100644 } static bool yield_to_task_fair(struct rq *rq, struct task_struct *p) -@@ -7241,8 +7673,10 @@ static bool yield_to_task_fair(struct rq *rq, struct task_struct *p) +@@ -7241,8 +7672,10 @@ static bool yield_to_task_fair(struct rq *rq, struct task_struct *p) if (!se->on_rq || throttled_hierarchy(cfs_rq_of(se))) return false; @@ -1148,6 +1272,14 @@ index d6e1c90de570..f5565f9d303a 100644 yield_task_fair(rq); +@@ -7451,6 +7884,7 @@ struct lb_env { + struct list_head tasks; + }; + ++#if !defined(CONFIG_CACULE_RDB) + /* + * Is this task likely cache-hot: + */ @@ -7470,6 +7904,7 @@ static int task_hot(struct task_struct *p, struct lb_env *env) if (env->sd->flags & SD_SHARE_CPUCAPACITY) return 0; @@ -1164,7 +1296,185 @@ index d6e1c90de570..f5565f9d303a 100644 if (sysctl_sched_migration_cost == -1) return 1; -@@ -10513,9 +10949,11 @@ static void nohz_newidle_balance(struct rq *this_rq) +@@ -7854,6 +8290,7 @@ static void attach_tasks(struct lb_env *env) + + rq_unlock(env->dst_rq, &rf); + } ++#endif + + #ifdef CONFIG_NO_HZ_COMMON + static inline bool cfs_rq_has_blocked(struct cfs_rq *cfs_rq) +@@ -7899,6 +8336,7 @@ static inline bool others_have_blocked(struct rq *rq) { return false; } + static inline void update_blocked_load_status(struct rq *rq, bool has_blocked) {} + #endif + ++#if !defined(CONFIG_CACULE_RDB) + static bool __update_blocked_others(struct rq *rq, bool *done) + { + const struct sched_class *curr_class; +@@ -7924,6 +8362,7 @@ static bool __update_blocked_others(struct rq *rq, bool *done) + + return decayed; + } ++#endif + + #ifdef CONFIG_FAIR_GROUP_SCHED + +@@ -7944,6 +8383,7 @@ static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq) + return true; + } + ++#if !defined(CONFIG_CACULE_RDB) + static bool __update_blocked_fair(struct rq *rq, bool *done) + { + struct cfs_rq *cfs_rq, *pos; +@@ -7983,6 +8423,7 @@ static bool __update_blocked_fair(struct rq *rq, bool *done) + + return decayed; + } ++#endif + + /* + * Compute the hierarchical load factor for cfs_rq and all its ascendants. +@@ -8049,6 +8490,7 @@ static unsigned long task_h_load(struct task_struct *p) + } + #endif + ++#if !defined(CONFIG_CACULE_RDB) + static void update_blocked_averages(int cpu) + { + bool decayed = false, done = true; +@@ -8066,6 +8508,7 @@ static void update_blocked_averages(int cpu) + cpufreq_update_util(rq, 0); + rq_unlock_irqrestore(rq, &rf); + } ++#endif + + /********** Helpers for find_busiest_group ************************/ + +@@ -8400,7 +8843,9 @@ static bool update_nohz_stats(struct rq *rq, bool force) + if (!force && !time_after(jiffies, rq->last_blocked_load_update_tick)) + return true; + ++#if !defined(CONFIG_CACULE_RDB) + update_blocked_averages(cpu); ++#endif + + return rq->has_blocked_load; + #else +@@ -9211,6 +9656,7 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s + * different in groups. + */ + ++#if !defined(CONFIG_CACULE_RDB) + /** + * find_busiest_group - Returns the busiest group within the sched_domain + * if there is an imbalance. +@@ -9476,6 +9922,7 @@ static struct rq *find_busiest_queue(struct lb_env *env, + + return busiest; + } ++#endif + + /* + * Max backoff if we encounter pinned tasks. Pretty arbitrary value, but +@@ -9495,6 +9942,7 @@ asym_active_balance(struct lb_env *env) + sched_asym_prefer(env->dst_cpu, env->src_cpu); + } + ++#if !defined(CONFIG_CACULE_RDB) + static inline bool + voluntary_active_balance(struct lb_env *env) + { +@@ -9843,6 +10291,7 @@ static int load_balance(int this_cpu, struct rq *this_rq, + out: + return ld_moved; + } ++#endif + + static inline unsigned long + get_sd_balance_interval(struct sched_domain *sd, int cpu_busy) +@@ -9881,6 +10330,7 @@ update_next_balance(struct sched_domain *sd, unsigned long *next_balance) + *next_balance = next; + } + ++#if !defined(CONFIG_CACULE_RDB) + /* + * active_load_balance_cpu_stop is run by the CPU stopper. It pushes + * running tasks off the busiest CPU onto idle CPUs. It requires at +@@ -9972,6 +10422,7 @@ static int active_load_balance_cpu_stop(void *data) + } + + static DEFINE_SPINLOCK(balancing); ++#endif + + /* + * Scale the max load_balance interval with the number of CPUs in the system. +@@ -9982,6 +10433,7 @@ void update_max_interval(void) + max_load_balance_interval = HZ*num_online_cpus()/10; + } + ++#if !defined(CONFIG_CACULE_RDB) + /* + * It checks each scheduling domain to see if it is due to be balanced, + * and initiates a balancing operation if so. +@@ -10087,6 +10539,7 @@ static void rebalance_domains(struct rq *rq, enum cpu_idle_type idle) + #endif + } + } ++#endif + + static inline int on_null_domain(struct rq *rq) + { +@@ -10116,6 +10569,7 @@ static inline int find_new_ilb(void) + return nr_cpu_ids; + } + ++#if !defined(CONFIG_CACULE_RDB) + /* + * Kick a CPU to do the nohz balancing, if it is time for it. We pick any + * idle CPU in the HK_FLAG_MISC housekeeping set (if there is one). +@@ -10266,6 +10720,7 @@ static void nohz_balancer_kick(struct rq *rq) + if (flags) + kick_ilb(flags); + } ++#endif /* CONFIG_CACULE_RDB */ + + static void set_cpu_sd_state_busy(int cpu) + { +@@ -10373,6 +10828,7 @@ void nohz_balance_enter_idle(int cpu) + WRITE_ONCE(nohz.has_blocked, 1); + } + ++#if !defined(CONFIG_CACULE_RDB) + /* + * Internal function that runs load balance for all idle cpus. The load balance + * can be a simple update of blocked load or a complete load balance with +@@ -10442,6 +10898,7 @@ static bool _nohz_idle_balance(struct rq *this_rq, unsigned int flags, + + if (flags & NOHZ_BALANCE_KICK) + rebalance_domains(rq, CPU_IDLE); ++ + } + + if (time_after(next_balance, rq->next_balance)) { +@@ -10458,6 +10915,7 @@ static bool _nohz_idle_balance(struct rq *this_rq, unsigned int flags, + if (likely(update_next_balance)) + nohz.next_balance = next_balance; + ++#if !defined(CONFIG_CACULE_RDB) + /* Newly idle CPU doesn't need an update */ + if (idle != CPU_NEWLY_IDLE) { + update_blocked_averages(this_cpu); +@@ -10466,6 +10924,7 @@ static bool _nohz_idle_balance(struct rq *this_rq, unsigned int flags, + + if (flags & NOHZ_BALANCE_KICK) + rebalance_domains(this_rq, CPU_IDLE); ++#endif + + WRITE_ONCE(nohz.next_blocked, + now + msecs_to_jiffies(LOAD_AVG_PERIOD)); +@@ -10513,9 +10972,11 @@ static void nohz_newidle_balance(struct rq *this_rq) if (!housekeeping_cpu(this_cpu, HK_FLAG_SCHED)) return; @@ -1176,7 +1486,263 @@ index d6e1c90de570..f5565f9d303a 100644 /* Don't need to update blocked load of idle CPUs*/ if (!READ_ONCE(nohz.has_blocked) || -@@ -10583,7 +11021,10 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) +@@ -10533,8 +10994,10 @@ static void nohz_newidle_balance(struct rq *this_rq) + kick_ilb(NOHZ_STATS_KICK); + raw_spin_lock(&this_rq->lock); + } ++#endif + + #else /* !CONFIG_NO_HZ_COMMON */ ++#if !defined(CONFIG_CACULE_RDB) + static inline void nohz_balancer_kick(struct rq *rq) { } + + static inline bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) +@@ -10543,8 +11006,134 @@ static inline bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle + } + + static inline void nohz_newidle_balance(struct rq *this_rq) { } ++#endif ++ + #endif /* CONFIG_NO_HZ_COMMON */ + ++#ifdef CONFIG_CACULE_RDB ++static int ++can_migrate_task(struct task_struct *p, int dst_cpu, struct rq *src_rq) ++{ ++ if (task_running(src_rq, p)) ++ return 0; ++ ++ /* Disregard pcpu kthreads; they are where they need to be. */ ++ if ((p->flags & PF_KTHREAD) && kthread_is_per_cpu(p)) ++ return 0; ++ ++ if (!cpumask_test_cpu(dst_cpu, p->cpus_ptr)) ++ return 0; ++ ++ if (p->se.exec_start == 0) ++ return 0; ++ ++ return 1; ++} ++ ++static void push_to_unlock(struct rq *this_rq, ++ struct rq *dst_rq, ++ struct task_struct *p, ++ int dst_cpu) ++{ ++ struct rq_flags rf; ++ ++ // detach task ++ deactivate_task(this_rq, p, DEQUEUE_NOCLOCK); ++ set_task_cpu(p, dst_cpu); ++ ++ // unlock this rq ++ raw_spin_unlock(&this_rq->lock); ++ ++ /* push to */ ++ rq_lock_irqsave(dst_rq, &rf); ++ update_rq_clock(dst_rq); ++ ++ activate_task(dst_rq, p, ENQUEUE_NOCLOCK); ++ check_preempt_curr(dst_rq, p, 0); ++ ++ // unlock src rq ++ rq_unlock(dst_rq, &rf); ++ local_irq_restore(rf.flags); ++} ++ ++static void pull_from_unlock(struct rq *this_rq, ++ struct rq *src_rq, ++ struct rq_flags *rf, ++ struct task_struct *p, ++ int dst_cpu) ++{ ++ // detach task ++ deactivate_task(src_rq, p, DEQUEUE_NOCLOCK); ++ set_task_cpu(p, dst_cpu); ++ ++ // unlock src rq ++ rq_unlock(src_rq, rf); ++ local_irq_restore(rf->flags); ++ ++ // lock this rq ++ raw_spin_lock(&this_rq->lock); ++ update_rq_clock(this_rq); ++ ++ activate_task(this_rq, p, ENQUEUE_NOCLOCK); ++ check_preempt_curr(this_rq, p, 0); ++ ++ // unlock this rq ++ raw_spin_unlock(&this_rq->lock); ++} ++ ++static inline struct rq * ++find_max_IS_rq(struct rq *this_rq, int dst_cpu) ++{ ++ struct rq *tmp_rq, *max_rq = NULL; ++ int cpu; ++ unsigned int max_IS = this_rq->max_IS_score; ++ unsigned int local_IS; ++ ++ // find max hrrn ++ for_each_online_cpu(cpu) { ++ if (cpu == dst_cpu) ++ continue; ++ ++ tmp_rq = cpu_rq(cpu); ++ ++ if (tmp_rq->nr_running < 2 || !(READ_ONCE(tmp_rq->to_migrate_task))) ++ continue; ++ ++ local_IS = READ_ONCE(tmp_rq->max_IS_score); ++ ++ if (local_IS < max_IS) { ++ max_IS = local_IS; ++ max_rq = tmp_rq; ++ } ++ } ++ ++ return max_rq; ++} ++ ++static int try_pull_from(struct rq *src_rq, struct rq *this_rq) ++{ ++ struct rq_flags rf; ++ int dst_cpu = cpu_of(this_rq); ++ struct task_struct *p; ++ ++ rq_lock_irqsave(src_rq, &rf); ++ update_rq_clock(src_rq); ++ ++ if (src_rq->to_migrate_task && src_rq->nr_running > 1) { ++ p = src_rq->to_migrate_task; ++ ++ if (can_migrate_task(p, dst_cpu, src_rq)) { ++ pull_from_unlock(this_rq, src_rq, &rf, p, dst_cpu); ++ return 1; ++ } ++ } ++ ++ rq_unlock(src_rq, &rf); ++ local_irq_restore(rf.flags); ++ ++ return 0; ++} ++ + /* + * idle_balance is called by schedule() if this_cpu is about to become + * idle. Attempts to pull tasks from other CPUs. +@@ -10555,6 +11144,109 @@ static inline void nohz_newidle_balance(struct rq *this_rq) { } + * > 0 - success, new (fair) tasks present + */ + static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) ++{ ++ int this_cpu = this_rq->cpu; ++ struct task_struct *p = NULL; ++ struct rq *src_rq; ++ int src_cpu; ++ struct rq_flags src_rf; ++ int pulled_task = 0; ++ int cores_round = 1; ++ ++ update_misfit_status(NULL, this_rq); ++ /* ++ * We must set idle_stamp _before_ calling idle_balance(), such that we ++ * measure the duration of idle_balance() as idle time. ++ */ ++ this_rq->idle_stamp = rq_clock(this_rq); ++ ++ /* ++ * Do not pull tasks towards !active CPUs... ++ */ ++ if (!cpu_active(this_cpu)) ++ return 0; ++ ++ /* ++ * This is OK, because current is on_cpu, which avoids it being picked ++ * for load-balance and preemption/IRQs are still disabled avoiding ++ * further scheduler activity on it and we're being very careful to ++ * re-start the picking loop. ++ */ ++ rq_unpin_lock(this_rq, rf); ++ raw_spin_unlock(&this_rq->lock); ++ ++again: ++ for_each_online_cpu(src_cpu) { ++ ++ if (src_cpu == this_cpu) ++ continue; ++ ++ if (cores_round && !cpus_share_cache(src_cpu, this_cpu)) ++ continue; ++ ++ src_rq = cpu_rq(src_cpu); ++ ++ if (src_rq->nr_running < 2 ++ || !(READ_ONCE(src_rq->to_migrate_task))) ++ continue; ++ ++ rq_lock_irqsave(src_rq, &src_rf); ++ update_rq_clock(src_rq); ++ ++ if (src_rq->nr_running < 2 || !(src_rq->to_migrate_task)) ++ goto next; ++ ++ p = src_rq->to_migrate_task; ++ ++ if (can_migrate_task(p, this_cpu, src_rq)) { ++ pull_from_unlock(this_rq, src_rq, &src_rf, p, this_cpu); ++ ++ pulled_task = 1; ++ goto out; ++ } ++ ++next: ++ rq_unlock(src_rq, &src_rf); ++ local_irq_restore(src_rf.flags); ++ ++ /* ++ * Stop searching for tasks to pull if there are ++ * now runnable tasks on this rq. ++ */ ++ if (pulled_task || this_rq->nr_running > 0) ++ goto out; ++ } ++ ++ if (cores_round) { ++ // now search for all cpus ++ cores_round = 0; ++ goto again; ++ } ++ ++out: ++ raw_spin_lock(&this_rq->lock); ++ ++ /* ++ * While browsing the domains, we released the rq lock, a task could ++ * have been enqueued in the meantime. Since we're not going idle, ++ * pretend we pulled a task. ++ */ ++ if (this_rq->cfs.h_nr_running && !pulled_task) ++ pulled_task = 1; ++ ++ /* Is there a task of a high priority class? */ ++ if (this_rq->nr_running != this_rq->cfs.h_nr_running) ++ pulled_task = -1; ++ ++ if (pulled_task) ++ this_rq->idle_stamp = 0; ++ ++ rq_repin_lock(this_rq, rf); ++ ++ return pulled_task; ++} ++#else ++static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) + { + unsigned long next_balance = jiffies + HZ; + int this_cpu = this_rq->cpu; +@@ -10583,7 +11275,10 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) */ rq_unpin_lock(this_rq, rf); @@ -1188,7 +1754,236 @@ index d6e1c90de570..f5565f9d303a 100644 !READ_ONCE(this_rq->rd->overload)) { rcu_read_lock(); -@@ -10748,11 +11189,30 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) +@@ -10705,6 +11400,217 @@ void trigger_load_balance(struct rq *rq) + + nohz_balancer_kick(rq); + } ++#endif ++ ++#ifdef CONFIG_CACULE_RDB ++static int ++idle_try_pull_any(struct cfs_rq *cfs_rq) ++{ ++ struct task_struct *p = NULL; ++ struct rq *this_rq = rq_of(cfs_rq), *src_rq; ++ int dst_cpu = cpu_of(this_rq); ++ int src_cpu; ++ struct rq_flags rf; ++ int pulled = 0; ++ int cores_round = 1; ++ ++again: ++ for_each_online_cpu(src_cpu) { ++ ++ if (src_cpu == dst_cpu) ++ continue; ++ ++ if (cores_round && !cpus_share_cache(src_cpu, dst_cpu)) ++ continue; ++ ++ src_rq = cpu_rq(src_cpu); ++ ++ if (src_rq->nr_running < 2 ++ || !(READ_ONCE(src_rq->to_migrate_task))) ++ continue; ++ ++ rq_lock_irqsave(src_rq, &rf); ++ update_rq_clock(src_rq); ++ ++ if (src_rq->nr_running < 2 || !(src_rq->to_migrate_task)) ++ goto next; ++ ++ p = src_rq->to_migrate_task; ++ ++ if (can_migrate_task(p, dst_cpu, src_rq)) { ++ pull_from_unlock(this_rq, src_rq, &rf, p, dst_cpu); ++ pulled = 1; ++ goto out; ++ } ++ ++next: ++ rq_unlock(src_rq, &rf); ++ local_irq_restore(rf.flags); ++ } ++ ++ if (cores_round) { ++ // now search for all cpus ++ cores_round = 0; ++ goto again; ++ } ++ ++out: ++ return pulled; ++} ++ ++ ++static int ++try_pull_higher_IS(struct rq *this_rq) ++{ ++ struct rq *max_rq; ++ int dst_cpu = cpu_of(this_rq); ++ ++ max_rq = find_max_IS_rq(this_rq, dst_cpu); ++ ++ if (!max_rq) ++ return 0; ++ ++ if (try_pull_from(max_rq, this_rq)) ++ return 1; ++ ++ return 0; ++} ++ ++static void try_push_any(struct rq *this_rq) ++{ ++ struct task_struct *p = NULL; ++ struct rq *dst_rq; ++ int dst_cpu; ++ int src_cpu = cpu_of(this_rq); ++ int cores_round = 1; ++ ++again: ++ for_each_online_cpu(dst_cpu) { ++ ++ if (dst_cpu == src_cpu) ++ continue; ++ ++ if (cores_round && !cpus_share_cache(src_cpu, dst_cpu)) ++ continue; ++ ++ dst_rq = cpu_rq(dst_cpu); ++ ++ if (dst_rq->nr_running >= this_rq->nr_running - 1) ++ continue; ++ ++ // lock this rq ++ raw_spin_lock(&this_rq->lock); ++ update_rq_clock(this_rq); ++ ++ if (!this_rq->to_migrate_task) { ++ // unlock this rq ++ raw_spin_unlock(&this_rq->lock); ++ return; ++ } ++ ++ p = this_rq->to_migrate_task; ++ ++ if (can_migrate_task(p, dst_cpu, this_rq)) { ++ push_to_unlock(this_rq, dst_rq, p, dst_cpu); ++ return; ++ } ++ ++ // unlock this rq ++ raw_spin_unlock(&this_rq->lock); ++ } ++ ++ if (cores_round) { ++ // now search for all cpus ++ cores_round = 0; ++ goto again; ++ } ++} ++ ++static void try_pull_any(struct rq *this_rq) ++{ ++ struct task_struct *p = NULL; ++ struct rq *src_rq; ++ int dst_cpu = cpu_of(this_rq); ++ int src_cpu; ++ struct rq_flags src_rf; ++ int cores_round = 1; ++ unsigned int this_max_IS = this_rq->max_IS_score; ++ ++again: ++ for_each_online_cpu(src_cpu) { ++ ++ if (src_cpu == dst_cpu) ++ continue; ++ ++ if (cores_round && !cpus_share_cache(src_cpu, dst_cpu)) ++ continue; ++ ++ src_rq = cpu_rq(src_cpu); ++ ++ p = READ_ONCE(src_rq->to_migrate_task); ++ if (src_rq->nr_running < 2 || !p ++ || READ_ONCE(src_rq->max_IS_score) >= this_max_IS) ++ continue; ++ ++ rq_lock_irqsave(src_rq, &src_rf); ++ update_rq_clock(src_rq); ++ ++ if (src_rq->nr_running < 2 || !(src_rq->to_migrate_task) ++ || src_rq->max_IS_score >= this_max_IS) ++ goto next; ++ ++ p = src_rq->to_migrate_task; ++ ++ if (can_migrate_task(p, dst_cpu, src_rq)) { ++ pull_from_unlock(this_rq, src_rq, &src_rf, p, dst_cpu); ++ return; ++ } ++ ++next: ++ rq_unlock(src_rq, &src_rf); ++ local_irq_restore(src_rf.flags); ++ } ++ ++ if (cores_round) { ++ // now search for all cpus ++ cores_round = 0; ++ goto again; ++ } ++} ++ ++static inline void ++active_balance(struct rq *rq) ++{ ++ if (rq->nr_running < 2) ++ try_pull_higher_IS(rq); ++ else { ++ try_push_any(rq); ++ try_pull_any(rq); ++ } ++} ++ ++void trigger_load_balance(struct rq *rq) ++{ ++ unsigned long interval; ++ ++#ifdef CONFIG_RDB_INTERVAL ++ if (time_before(jiffies, rq->next_balance)) ++ return; ++#endif ++ ++ if (rq->idle_balance) ++ idle_try_pull_any(&rq->cfs); ++ else { ++ active_balance(rq); ++ ++#ifdef CONFIG_RDB_INTERVAL ++ /* scale ms to jiffies */ ++ interval = msecs_to_jiffies(CONFIG_RDB_INTERVAL); ++ rq->next_balance = jiffies + interval; ++#endif ++ } ++} ++#endif + + static void rq_online_fair(struct rq *rq) + { +@@ -10741,6 +11647,10 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) + entity_tick(cfs_rq, se, queued); + } + ++#ifdef CONFIG_CACULE_RDB ++ update_IS(rq); ++#endif ++ + if (static_branch_unlikely(&sched_numa_balancing)) + task_tick_numa(rq, curr); + +@@ -10748,11 +11658,30 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) update_overutilized_status(task_rq(curr)); } @@ -1219,7 +2014,7 @@ index d6e1c90de570..f5565f9d303a 100644 static void task_fork_fair(struct task_struct *p) { struct cfs_rq *cfs_rq; -@@ -10783,6 +11243,7 @@ static void task_fork_fair(struct task_struct *p) +@@ -10783,6 +11712,7 @@ static void task_fork_fair(struct task_struct *p) se->vruntime -= cfs_rq->min_vruntime; rq_unlock(rq, &rf); } @@ -1227,7 +2022,7 @@ index d6e1c90de570..f5565f9d303a 100644 /* * Priority of the task has changed. Check to see if we preempt -@@ -10901,6 +11362,8 @@ static void attach_entity_cfs_rq(struct sched_entity *se) +@@ -10901,6 +11831,8 @@ static void attach_entity_cfs_rq(struct sched_entity *se) static void detach_task_cfs_rq(struct task_struct *p) { struct sched_entity *se = &p->se; @@ -1236,7 +2031,7 @@ index d6e1c90de570..f5565f9d303a 100644 struct cfs_rq *cfs_rq = cfs_rq_of(se); if (!vruntime_normalized(p)) { -@@ -10911,6 +11374,7 @@ static void detach_task_cfs_rq(struct task_struct *p) +@@ -10911,6 +11843,7 @@ static void detach_task_cfs_rq(struct task_struct *p) place_entity(cfs_rq, se, 0); se->vruntime -= cfs_rq->min_vruntime; } @@ -1244,7 +2039,7 @@ index d6e1c90de570..f5565f9d303a 100644 detach_entity_cfs_rq(se); } -@@ -10918,12 +11382,17 @@ static void detach_task_cfs_rq(struct task_struct *p) +@@ -10918,12 +11851,17 @@ static void detach_task_cfs_rq(struct task_struct *p) static void attach_task_cfs_rq(struct task_struct *p) { struct sched_entity *se = &p->se; @@ -1262,7 +2057,7 @@ index d6e1c90de570..f5565f9d303a 100644 } static void switched_from_fair(struct rq *rq, struct task_struct *p) -@@ -10979,13 +11448,22 @@ static void set_next_task_fair(struct rq *rq, struct task_struct *p, bool first) +@@ -10979,13 +11917,22 @@ static void set_next_task_fair(struct rq *rq, struct task_struct *p, bool first) void init_cfs_rq(struct cfs_rq *cfs_rq) { cfs_rq->tasks_timeline = RB_ROOT_CACHED; @@ -1285,11 +2080,33 @@ index d6e1c90de570..f5565f9d303a 100644 } #ifdef CONFIG_FAIR_GROUP_SCHED +@@ -11310,7 +12257,9 @@ void show_numa_stats(struct task_struct *p, struct seq_file *m) + __init void init_sched_fair_class(void) + { + #ifdef CONFIG_SMP ++#if !defined(CONFIG_CACULE_RDB) + open_softirq(SCHED_SOFTIRQ, run_rebalance_domains); ++#endif + + #ifdef CONFIG_NO_HZ_COMMON + nohz.next_balance = jiffies; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h -index fdebfcbdfca9..e7fd62e89154 100644 +index 39112ac7ab34..5881814c7e1c 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h -@@ -524,10 +524,13 @@ struct cfs_rq { +@@ -158,6 +158,11 @@ extern void call_trace_sched_update_nr_running(struct rq *rq, int count); + */ + #define RUNTIME_INF ((u64)~0ULL) + ++#ifdef CONFIG_CACULE_SCHED ++#define YIELD_MARK 0x8000000000000000ULL ++#define YIELD_UNMARK 0x7FFFFFFFFFFFFFFFULL ++#endif ++ + static inline int idle_policy(int policy) + { + return policy == SCHED_IDLE; +@@ -524,10 +529,13 @@ struct cfs_rq { unsigned int idle_h_nr_running; /* SCHED_IDLE */ u64 exec_clock; @@ -1303,14 +2120,13 @@ index fdebfcbdfca9..e7fd62e89154 100644 struct rb_root_cached tasks_timeline; -@@ -536,9 +539,15 @@ struct cfs_rq { +@@ -536,9 +544,14 @@ struct cfs_rq { * It is set to NULL otherwise (i.e when none are currently running). */ struct sched_entity *curr; +#ifdef CONFIG_CACULE_SCHED + struct cacule_node *head; + struct cacule_node *tail; -+ +#else struct sched_entity *next; struct sched_entity *last; @@ -1319,11 +2135,23 @@ index fdebfcbdfca9..e7fd62e89154 100644 #ifdef CONFIG_SCHED_DEBUG unsigned int nr_spread_over; +@@ -933,6 +946,11 @@ struct rq { + struct rt_rq rt; + struct dl_rq dl; + ++#ifdef CONFIG_CACULE_RDB ++ unsigned int max_IS_score; ++ struct task_struct *to_migrate_task; ++#endif ++ + #ifdef CONFIG_FAIR_GROUP_SCHED + /* list of leaf cfs_rq on this CPU: */ + struct list_head leaf_cfs_rq_list; diff --git a/kernel/sysctl.c b/kernel/sysctl.c -index b9306d2bb426..2103ee43de9e 100644 +index b9306d2bb426..20f07aa87b8e 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c -@@ -1659,6 +1659,29 @@ static struct ctl_table kern_table[] = { +@@ -1659,6 +1659,59 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, @@ -1336,19 +2164,49 @@ index b9306d2bb426..2103ee43de9e 100644 + .proc_handler = proc_dointvec, + }, + { -+ .procname = "sched_interactivity_threshold", -+ .data = &interactivity_threshold, -+ .maxlen = sizeof(unsigned int), -+ .mode = 0644, -+ .proc_handler = proc_dointvec, -+ }, -+ { + .procname = "sched_max_lifetime_ms", + .data = &cacule_max_lifetime, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, ++ { ++ .procname = "sched_cache_factor", ++ .data = &cache_factor, ++ .maxlen = sizeof(unsigned int), ++ .mode = 0644, ++ .proc_handler = proc_dointvec, ++ }, ++ { ++ .procname = "sched_cache_divisor", ++ .data = &cache_divisor, ++ .maxlen = sizeof(unsigned int), ++ .mode = 0644, ++ .proc_handler = proc_dointvec, ++ }, ++ { ++ .procname = "sched_starve_factor", ++ .data = &starve_factor, ++ .maxlen = sizeof(unsigned int), ++ .mode = 0644, ++ .proc_handler = proc_dointvec, ++ }, ++ { ++ .procname = "sched_starve_divisor", ++ .data = &starve_divisor, ++ .maxlen = sizeof(unsigned int), ++ .mode = 0644, ++ .proc_handler = proc_dointvec, ++ }, ++ { ++ .procname = "sched_cacule_yield", ++ .data = &cacule_yield, ++ .maxlen = sizeof (int), ++ .mode = 0644, ++ .proc_handler = &proc_dointvec_minmax, ++ .extra1 = SYSCTL_ZERO, ++ .extra2 = &one_ul, ++ }, +#endif #ifdef CONFIG_SCHED_DEBUG {