forked from madhur-tandon/rtnice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.patch
169 lines (160 loc) · 4.77 KB
/
10.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
diff --git a/linux-3.19/Makefile b/linux-3.19/Makefile
index b15036b..70f5419 100644
--- a/linux-3.19/Makefile
+++ b/linux-3.19/Makefile
@@ -879,7 +879,7 @@ export mod_sign_cmd
ifeq ($(KBUILD_EXTMOD),)
-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ rtnice/
vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \
diff --git a/linux-3.19/arch/x86/syscalls/syscall_64.tbl b/linux-3.19/arch/x86/syscalls/syscall_64.tbl
index 8d656fb..df01676 100644
--- a/linux-3.19/arch/x86/syscalls/syscall_64.tbl
+++ b/linux-3.19/arch/x86/syscalls/syscall_64.tbl
@@ -329,7 +329,7 @@
320 common kexec_file_load sys_kexec_file_load
321 common bpf sys_bpf
322 64 execveat stub_execveat
-
+323 common rtnice sys_rtnice
#
# x32-specific system call numbers start at 512 to avoid cache impact
# for native 64-bit operation.
diff --git a/linux-3.19/include/linux/sched.h b/linux-3.19/include/linux/sched.h
index 8db31ef..7c4fe71 100644
--- a/linux-3.19/include/linux/sched.h
+++ b/linux-3.19/include/linux/sched.h
@@ -1170,6 +1170,7 @@ struct sched_entity {
u64 prev_sum_exec_runtime;
u64 nr_migrations;
+ u64 rtnice;
#ifdef CONFIG_SCHEDSTATS
struct sched_statistics statistics;
diff --git a/linux-3.19/include/linux/syscalls.h b/linux-3.19/include/linux/syscalls.h
index 85893d7..4c30b55 100644
--- a/linux-3.19/include/linux/syscalls.h
+++ b/linux-3.19/include/linux/syscalls.h
@@ -881,5 +881,5 @@ asmlinkage long sys_bpf(int cmd, union bpf_attr *attr, unsigned int size);
asmlinkage long sys_execveat(int dfd, const char __user *filename,
const char __user *const __user *argv,
const char __user *const __user *envp, int flags);
-
+asmlinkage long sys_rtnice(long givenPID, long rtnice);
#endif
diff --git a/linux-3.19/kernel/sched/core.c b/linux-3.19/kernel/sched/core.c
index 5eab11d..ed20cc4 100644
--- a/linux-3.19/kernel/sched/core.c
+++ b/linux-3.19/kernel/sched/core.c
@@ -1829,13 +1829,13 @@ void __dl_clear_params(struct task_struct *p)
static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
{
p->on_rq = 0;
-
p->se.on_rq = 0;
p->se.exec_start = 0;
p->se.sum_exec_runtime = 0;
p->se.prev_sum_exec_runtime = 0;
p->se.nr_migrations = 0;
p->se.vruntime = 0;
+ p->se.rtnice = 0;
INIT_LIST_HEAD(&p->se.group_node);
#ifdef CONFIG_SCHEDSTATS
diff --git a/linux-3.19/kernel/sched/fair.c b/linux-3.19/kernel/sched/fair.c
index fe331fc..af46511 100644
--- a/linux-3.19/kernel/sched/fair.c
+++ b/linux-3.19/kernel/sched/fair.c
@@ -456,6 +456,17 @@ static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime)
static inline int entity_before(struct sched_entity *a,
struct sched_entity *b)
{
+ if(a->rtnice>0 || b->rtnice>0)
+ {
+ if(b->rtnice >= a->rtnice)
+ {
+ return 0;
+ }
+ else if(a->rtnice > b->rtnice)
+ {
+ return 1;
+ }
+ }
return (s64)(a->vruntime - b->vruntime) < 0;
}
@@ -711,8 +722,23 @@ static void update_curr(struct cfs_rq *cfs_rq)
curr->sum_exec_runtime += delta_exec;
schedstat_add(cfs_rq, exec_clock, delta_exec);
-
- curr->vruntime += calc_delta_fair(delta_exec, curr);
+ unsigned long long soft;
+ soft = curr->rtnice;
+ if(soft==0)
+ {
+ curr->vruntime += calc_delta_fair(delta_exec, curr);
+ }
+ else
+ {
+ if(delta_exec<soft)
+ {
+ curr->rtnice = soft - delta_exec;
+ }
+ else
+ {
+ curr->rtnice = 0;
+ }
+ }
update_min_vruntime(cfs_rq);
if (entity_is_task(curr)) {
diff --git a/linux-3.19/rtnice/Makefile b/linux-3.19/rtnice/Makefile
new file mode 100644
index 0000000..ee91de9
--- /dev/null
+++ b/linux-3.19/rtnice/Makefile
@@ -0,0 +1 @@
+obj-y:=rtnice.o
diff --git a/linux-3.19/rtnice/rtnice.c b/linux-3.19/rtnice/rtnice.c
new file mode 100644
index 0000000..a5f9119
--- /dev/null
+++ b/linux-3.19/rtnice/rtnice.c
@@ -0,0 +1,33 @@
+#include<linux/kernel.h>
+#include<linux/init.h>
+#include<linux/sched.h>
+#include<linux/syscalls.h>
+#include<linux/module.h>
+#include<linux/mm.h>
+#include "rtnice.h"
+
+asmlinkage long sys_rtnice(long givenPID, long rtnice) {
+ struct task_struct *proces;
+ int flag = 0;
+ unsigned long long soft = rtnice*1000000000;
+ if(givenPID<0 || givenPID>4194304 || rtnice<0)
+ {
+ return EINVAL;
+ }
+ for_each_process(proces) {
+ if((long)task_pid_nr(proces)==givenPID)
+ {
+ flag = 1;
+ proces->se.rtnice = soft;
+ printk("%llu\n",proces->se.rtnice);
+ }
+ }
+
+ if(flag==0)
+ {
+ printk("No process with the given PID found\n");
+ return ESRCH;
+ }
+
+ return 0;
+}
diff --git a/linux-3.19/rtnice/rtnice.h b/linux-3.19/rtnice/rtnice.h
new file mode 100644
index 0000000..86fe910
--- /dev/null
+++ b/linux-3.19/rtnice/rtnice.h
@@ -0,0 +1 @@
+asmlinkage long sys_rtnice(long givenPID, long rtnice);