I am trying to hack the Linux kernel and I am wondering. How can I change the default Linux Process scheduler with another one? And can I just set every processes as a real time process?
Asked
Active
Viewed 1.8k times
6
-
See the ans here to change the scheduler: http://stackoverflow.com/questions/1009577/selecting-a-linux-i-o-scheduler – brokenfoot Apr 13 '14 at 23:04
-
1@brokenfoot Are the I/O scheduler and CPU Scheduler same? I believe they are different – Güngör Basa Apr 13 '14 at 23:07
-
1Do you wanna change scheduling policy of a process or completely different scheduling algorithm?. The default scheduler is CFS. Yes u can set every process as a real-time process, you can enforce it in kernel by doing some changes. – Sasi V Apr 14 '14 at 06:52
-
1@Sasi I want to change the scheduling policy. I want every process use Round Robin or FIFO. I tried to change "__sched_setschedueler()" function in the "sched.c" but it didn't work. – Güngör Basa Apr 14 '14 at 14:55
-
You have to start look from forking process, take a look at sched_fork". Also Did you take look at "normalize_rt_tasks", it is sys-rq. you can have proc entry similar to normalize_rt_tasks sysrq and After starting all process set proc entry to update all process to sched policy to FIFO or RR. – Sasi V Apr 14 '14 at 17:29
-
@Sasi to be honest I set the policy in the __sched_setpolicy to the one of my algorithm but it didn't work. I will look at ached_fork – Güngör Basa Apr 14 '14 at 19:32
-
1. Nobody calls "sched_setscheduler" for all process and sched_setscheduler is called in very few locations def not from core process creation. If process A want to change its sched params then it must call sched_setscheduler with appropriate args 2. In my opinion best location would be sched_fork. – Sasi V Apr 14 '14 at 19:45
-
@Sasi I added to the ached_fork and it looks like working but only thing I consider is priority values. It gives 0 priority for most of the processes. Is it completely normal? – Güngör Basa Apr 14 '14 at 20:12
-
1Take a look at sched_fork. It has priority information. Change it if you need or else go with default one. in sched_fork p->prio = current->normal_prio; also check unlikely(p->sched_reset_on_fork) case too – Sasi V Apr 14 '14 at 20:35
1 Answers
3
This post is a little bit dated, but anyway I hope this can help... I had similar problem and I implemented a hack to Linux Kernel to make RR the default CPU scheduler. In the end the hack basically changes the shed_fork function, as pointed out in previous comments. Here is the code I made to implement that: https://aelseb.wordpress.com/2016/01/06/change-linux-cpu-default-scheduler/

Lorenzo Nava
- 54
- 2
-
9Hi, welcome to Stack Overflow. Please don't post a link as answer, it becomes useless if it is changed or goes offline. Instead, use the info and code to build your answer and use the link as reference only. Thanks. – Cthulhu Jan 06 '16 at 17:37
-
1Basically the changes must be done in the sched_fork function in kernel/sched/core.c. You have to modify the p->policy attribute (for example with SCHED_RR) and the priorities accordingly. This change will place all processes in the selected scheduling domain. You can also change the default process priority modifying the priority attributes. – Lorenzo Nava Jan 07 '16 at 18:41
-
in case we need it: https://web.archive.org/web/20191105141418/https://aelseb.wordpress.com/2016/01/06/change-linux-cpu-default-scheduler/ – xdevs23 Jan 19 '20 at 20:19