Skip to content

Commit 0ef130f

Browse files
firelzrdopsiff
authored andcommitted
FROMEXT: linux6.18.22-bore-6.6.3
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 9624e83 commit 0ef130f

13 files changed

Lines changed: 769 additions & 11 deletions

File tree

include/linux/sched.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,37 @@ struct kmap_ctrl {
817817
#endif
818818
};
819819

820+
#ifdef CONFIG_SCHED_BORE
821+
#define BORE_BC_TIMESTAMP_SHIFT 16
822+
823+
struct bore_bc {
824+
union {
825+
struct {
826+
u64 timestamp: 48;
827+
u64 penalty: 16;
828+
};
829+
u64 value;
830+
};
831+
};
832+
833+
struct bore_ctx {
834+
u64 burst_time;
835+
u16 prev_penalty;
836+
u16 curr_penalty;
837+
union {
838+
u16 penalty;
839+
struct {
840+
u8 _;
841+
u8 score;
842+
};
843+
};
844+
bool stop_update;
845+
bool futex_waiting;
846+
struct bore_bc subtree;
847+
struct bore_bc group;
848+
};
849+
#endif /* CONFIG_SCHED_BORE */
850+
820851
struct task_struct {
821852
#ifdef CONFIG_THREAD_INFO_IN_TASK
822853
/*
@@ -875,6 +906,9 @@ struct task_struct {
875906
#ifdef CONFIG_SCHED_CLASS_EXT
876907
struct sched_ext_entity scx;
877908
#endif
909+
#ifdef CONFIG_SCHED_BORE
910+
struct bore_ctx bore;
911+
#endif /* CONFIG_SCHED_BORE */
878912
const struct sched_class *sched_class;
879913

880914
#ifdef CONFIG_SCHED_CORE

include/linux/sched/bore.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef _KERNEL_SCHED_BORE_H
2+
#define _KERNEL_SCHED_BORE_H
3+
4+
#include <linux/sched.h>
5+
#include <linux/sched/cputime.h>
6+
#include <linux/atomic.h>
7+
#include <linux/list.h>
8+
#include <linux/rcupdate.h>
9+
#include <linux/jump_label.h>
10+
11+
#define SCHED_BORE_AUTHOR "Masahito Suzuki"
12+
#define SCHED_BORE_PROGNAME "BORE CPU Scheduler modification"
13+
14+
#define SCHED_BORE_VERSION "6.6.3"
15+
16+
extern u8 __read_mostly sched_bore;
17+
DECLARE_STATIC_KEY_TRUE(sched_bore_key);
18+
extern u8 __read_mostly sched_burst_inherit_type;
19+
extern u8 __read_mostly sched_burst_smoothness;
20+
extern u8 __read_mostly sched_burst_penalty_offset;
21+
extern uint __read_mostly sched_burst_penalty_scale;
22+
extern uint __read_mostly sched_burst_cache_lifetime;
23+
24+
extern u8 effective_prio_bore(struct task_struct *p);
25+
extern void update_curr_bore(struct task_struct *p, u64 delta_exec);
26+
extern void restart_burst_bore(struct task_struct *p);
27+
extern void restart_burst_rescale_deadline_bore(struct task_struct *p);
28+
extern void task_fork_bore(struct task_struct *p, struct task_struct *parent,
29+
u64 clone_flags, u64 now);
30+
extern void sched_init_bore(void);
31+
extern void reset_task_bore(struct task_struct *p);
32+
33+
extern int sched_bore_update_handler(const struct ctl_table *table,
34+
int write, void __user *buffer, size_t *lenp, loff_t *ppos);
35+
extern int sched_burst_inherit_type_update_handler(const struct ctl_table *table,
36+
int write, void __user *buffer, size_t *lenp, loff_t *ppos);
37+
38+
extern void reweight_entity(
39+
struct cfs_rq *cfs_rq, struct sched_entity *se, unsigned long weight);
40+
41+
#endif /* _KERNEL_SCHED_BORE_H */

init/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,23 @@ config CHECKPOINT_RESTORE
14231423

14241424
If unsure, say N here.
14251425

1426+
config SCHED_BORE
1427+
bool "Burst-Oriented Response Enhancer"
1428+
default y
1429+
help
1430+
In Desktop and Mobile computing, one might prefer interactive
1431+
tasks to keep responsive no matter what they run in the background.
1432+
1433+
Enabling this kernel feature modifies the scheduler to discriminate
1434+
tasks by their burst time (runtime since it last went sleeping or
1435+
yielding state) and prioritize those that run less bursty.
1436+
Such tasks usually include window compositor, widgets backend,
1437+
terminal emulator, video playback, games and so on.
1438+
With a little impact to scheduling fairness, it may improve
1439+
responsiveness especially under heavy background workload.
1440+
1441+
If unsure, say Y here.
1442+
14261443
config SCHED_AUTOGROUP
14271444
bool "Automatic process group scheduling"
14281445
select CGROUPS

kernel/Kconfig.hz

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ config HZ
5757

5858
config SCHED_HRTICK
5959
def_bool HIGH_RES_TIMERS
60+
61+
config MIN_BASE_SLICE_NS
62+
int "Default value for min_base_slice_ns"
63+
default 2000000
64+
help
65+
The BORE Scheduler automatically calculates the optimal base
66+
slice for the configured HZ using the following equation:
67+
68+
base_slice_ns =
69+
1000000000/HZ * DIV_ROUNDUP(min_base_slice_ns, 1000000000/HZ)
70+
71+
This option sets the default lower bound limit of the base slice
72+
to prevent the loss of task throughput due to overscheduling.
73+
74+
Setting this value too high can cause the system to boot with
75+
an unnecessarily large base slice, resulting in high scheduling
76+
latency and poor system responsiveness.

kernel/exit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ static void __unhash_process(struct release_task_post *post, struct task_struct
147147
detach_pid(post->pids, p, PIDTYPE_SID);
148148

149149
list_del_rcu(&p->tasks);
150+
#ifdef CONFIG_SCHED_BORE
151+
list_del_rcu(&p->sibling);
152+
#else /* !CONFIG_SCHED_BORE */
150153
list_del_init(&p->sibling);
154+
#endif /* CONFIG_SCHED_BORE */
151155
__this_cpu_dec(process_counts);
152156
}
153157
list_del_rcu(&p->thread_node);

kernel/fork.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@
116116
/* For dup_mmap(). */
117117
#include "../mm/internal.h"
118118

119+
#ifdef CONFIG_SCHED_BORE
120+
#include <linux/sched/bore.h>
121+
#endif /* CONFIG_SCHED_BORE */
122+
119123
#include <trace/events/sched.h>
120124

121125
#define CREATE_TRACE_POINTS
@@ -2320,6 +2324,11 @@ __latent_entropy struct task_struct *copy_process(
23202324
p->start_time = ktime_get_ns();
23212325
p->start_boottime = ktime_get_boottime_ns();
23222326

2327+
#ifdef CONFIG_SCHED_BORE
2328+
if (likely(p->pid))
2329+
task_fork_bore(p, current, clone_flags, p->start_time);
2330+
#endif /* CONFIG_SCHED_BORE */
2331+
23232332
/*
23242333
* Make it visible to the rest of the system, but dont wake it up yet.
23252334
* Need tasklist lock for parent etc handling!
@@ -2393,7 +2402,11 @@ __latent_entropy struct task_struct *copy_process(
23932402
*/
23942403
p->signal->has_child_subreaper = p->real_parent->signal->has_child_subreaper ||
23952404
p->real_parent->signal->is_child_subreaper;
2405+
#ifdef CONFIG_SCHED_BORE
2406+
list_add_tail_rcu(&p->sibling, &p->real_parent->children);
2407+
#else /* !CONFIG_SCHED_BORE */
23962408
list_add_tail(&p->sibling, &p->real_parent->children);
2409+
#endif /* CONFIG_SCHED_BORE */
23972410
list_add_tail_rcu(&p->tasks, &init_task.tasks);
23982411
attach_pid(p, PIDTYPE_TGID);
23992412
attach_pid(p, PIDTYPE_PGID);

kernel/futex/waitwake.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <linux/sched/task.h>
55
#include <linux/sched/signal.h>
66
#include <linux/freezer.h>
7+
#ifdef CONFIG_SCHED_BORE
8+
#include <linux/sched/bore.h>
9+
#endif /* CONFIG_SCHED_BORE */
710

811
#include "futex.h"
912

@@ -355,7 +358,15 @@ void futex_do_wait(struct futex_q *q, struct hrtimer_sleeper *timeout)
355358
* is no timeout, or if it has yet to expire.
356359
*/
357360
if (!timeout || timeout->task)
361+
#ifdef CONFIG_SCHED_BORE
362+
{
363+
current->bore.futex_waiting = true;
364+
#endif /* CONFIG_SCHED_BORE */
358365
schedule();
366+
#ifdef CONFIG_SCHED_BORE
367+
current->bore.futex_waiting = false;
368+
}
369+
#endif /* CONFIG_SCHED_BORE */
359370
}
360371
__set_current_state(TASK_RUNNING);
361372
}

kernel/sched/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ obj-y += core.o
3737
obj-y += fair.o
3838
obj-y += build_policy.o
3939
obj-y += build_utility.o
40+
obj-$(CONFIG_SCHED_BORE) += bore.o

0 commit comments

Comments
 (0)