Skip to contentSkip to conversation

Thread Scheduler

DISCUSSION Mahmood Naderan 5 participants 11 messages Mar 19, 2014 – Mar 24, 2014

lore
Share & tools
lore
#0 lore raw

Hi
Maybe this is a noob question...
Where in the linux kernel source (2.6), the

thread scheduler has been implemented? Searching

the web shows that there should sched_fair.c but

I can not find that in the source directory (the
kernel source has been installed).

Basically, I want to know which part of the code

calculated the priorities of the available

threads and select them for running?

Regards,
Mahmood

#1 lore raw
Quoted 11 lines · Mahmood Naderan

Hi
Maybe this is a noob question...
Where in the linux kernel source (2.6), the

thread scheduler has been implemented? Searching

the web shows that there should sched_fair.c but

I can not find that in the source directory (the
kernel source has been installed).

The scheduler recently moved to kernel/sched directory. For older kernels, it's kernel/sched_*.

-Mike

#2 lore raw
Quoted 15 lines · Mike Galbraith
Quoted 9 lines · Mahmood Naderan

Hi
Maybe this is a noob question...
Where in the linux kernel source (2.6), the

thread scheduler has been implemented? Searching

the web shows that there should sched_fair.c but

Quoted 7 lines
Quoted 2 lines

I can not find that in the source directory (the
kernel source has been installed).

The scheduler recently moved to kernel/sched directory.  For older kernels, it's kernel/sched_*.

-Mike

Please see this information

[root@tiger ~]# uname -a
Linux tiger 2.6.32-279.5.1.el6.x86_64 #1 SMP Tue Aug 14 16:11:42 CDT 2012 x86_64 x86_64 x86_64 GNU/Linux

[root@tiger ~]# ls /usr/src/kernels/2.6.32-279.5.1.el6.x86_64/kernel/
events  gcov  irq  Kconfig.freezer  Kconfig.hz  Kconfig.preempt  Makefile  power  time  trace

[root@tiger ~]# cd /usr/src/kernels/2.6.32-279.5.1.el6.x86_64/

[root@tiger 2.6.32-279.5.1.el6.x86_64]# find . -name sched* ./net/sched
./include/asm-generic/bitops/sched.h ./include/config/group/sched.h ./include/config/cgroup/sched.h ./include/config/schedstats.h ./include/config/fair/group/sched.h ./include/config/have/unstable/sched ./include/config/net/sched.h ./include/config/rt/group/sched.h ./include/config/sched ./include/trace/events/sched.h ./include/linux/sched.h ./include/linux/sunrpc/sched.h

Do you mean include/linux/sched.h ?
Where is he implementation then?


Regards,
Mahmood

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

#3 lore raw
Quoted 4 lines · Mahmood Naderan

[...]
Do you mean include/linux/sched.h ?
Where is he implementation then?

Your kernel source is incomplete. You can fetch a vanilla kernel tarball from http://kernel.org.

jackc@kdev0 ~ $ ls /usr/src/linux-2.6.10/kernel/|grep sched sched.c
jackc@kdev0 ~ $ ls /usr/src/linux-3.13.5/kernel/sched/

auto_group.c  completion.c  cpuacct.h  cputime.c  features.h   proc.c
 stats.c      wait.c
auto_group.h  core.c        cpupri.c   debug.c    idle_task.c  rt.c     stats.h
clock.c       cpuacct.c     cpupri.h   fair.c     Makefile     sched.h

stop_task.c

-J

#4 lore raw
Quoted 19 lines · Jack Carrozzo
Quoted 4 lines · Mahmood Naderan

[...]
Do you mean include/linux/sched.h ?
Where is he implementation then?

Your kernel source is incomplete. You can fetch a vanilla kernel tarball from http://kernel.org.

jackc@kdev0 ~ $ ls /usr/src/linux-2.6.10/kernel/|grep sched sched.c
jackc@kdev0 ~ $ ls /usr/src/linux-3.13.5/kernel/sched/ auto_group.c  completion.c  cpuacct.h  cputime.c  features.h   proc.c stats.c      wait.c
auto_group.h  core.c        cpupri.c   debug.c    idle_task.c  rt.c     stats.h clock.c       cpuacct.c     cpupri.h   fair.c     Makefile     sched.h stop_task.c

Quoted 1 line

-J

OK I installed the full source and now can see the sched*.c files
One more question. Is it possible to dynamically change the scheduling policy, e.g from fair to clock? Basically, I am trying to find the direction on *how to invoke a new scheduling policy*?

#5 lore raw
Quoted 3 lines · Mahmood Naderan

One more question. Is it possible to dynamically change the scheduling policy, e.g from fair to clock?

marge:~ # man -k setscheduler getscheduler
sched_setscheduler (2) - set and get scheduling policy/parameters sched_setscheduler (3p) - set scheduling policy and parameters (REALTIME) sched_getscheduler (2) - set and get scheduling policy/parameters sched_getscheduler (3p) - get scheduling policy (REALTIME)

#6 lore raw
Quoted 13 lines · Mike Galbraith

marge:~ # man -k setscheduler getscheduler
sched_setscheduler (2) - set and get scheduling policy/parameters sched_setscheduler (3p) - set scheduling policy and parameters (REALTIME) sched_getscheduler (2) - set and get scheduling policy/parameters sched_getscheduler (3p) - get scheduling policy (REALTIME)

OK I read them and it seems that in order to change the scheduler, I have to write a C code and call the sched_set* functions. Please correct that if I am wrong.

So in order to use my custom scheduler, I have to do the following steps.

1- Write my  code using the APIs and save that in kernel/sched_custom.c 2- Invoke sched_custom.c in kernel/sched.c
3- Recompile the kernel source
4- Reboot using the new kernel
5- write a C code and call sched_setschedule() to use my scheduler.

Is that all? Your reply is appreciated.

Regards,
Mahmood

#7 lore raw
Quoted 31 lines · Mahmood Naderan
Quoted 13 lines · Mike Galbraith

marge:~ # man -k setscheduler getscheduler
sched_setscheduler (2) - set and get scheduling policy/parameters sched_setscheduler (3p) - set scheduling policy and parameters (REALTIME) sched_getscheduler (2) - set and get scheduling policy/parameters sched_getscheduler (3p) - get scheduling policy (REALTIME)

OK I read them and it seems that in order to change the scheduler, I have to write a C code and call the sched_set* functions. Please correct that if I am wrong.

So in order to use my custom scheduler, I have to do the following steps.

1- Write my code using the APIs and save that in kernel/sched_custom.c 2- Invoke sched_custom.c in kernel/sched.c
3- Recompile the kernel source
4- Reboot using the new kernel
5- write a C code and call sched_setschedule() to use my scheduler.

Is that all? Your reply is appreciated.

Quoted 7 lines

Regards,
Mahmood
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

In terms of changing the scheduler I think that you possibly missed reading Documentation/block/switching-sched.txt in the kernel's documentation directory.

HTH,
Mark

#8 lore raw
Quoted 6 lines · Mark Knecht

In terms of changing the scheduler I think that you possibly missed reading Documentation/block/switching-sched.txt in the kernel's documentation directory.

HTH,
Mark

That is IO scheduler. Can we use the same for threads/processes? echo deadline > /proc/10100

Or something like that?


Regards,
Mahmood

#9 lore raw
Quoted 15 lines · Mahmood Naderan
Quoted 6 lines · Mark Knecht

In terms of changing the scheduler I think that you possibly missed reading Documentation/block/switching-sched.txt in the kernel's documentation directory.

HTH,
Mark

That is IO scheduler. Can we use the same for threads/processes? echo deadline > /proc/10100

Quoted 7 lines

Or something like that?

Regards,
Mahmood

Sorry, you're right. My mistake.

- Mark

#10 lore raw
In reply to Mahmood Naderan

Hi,

Quoted 11 lines

OK I read them and it seems that in order to change the scheduler, I have to write a C code and call the sched_set* functions. Please correct that if I am wrong.

So in order to use my custom scheduler, I have to do the following steps.

1- Write my code using the APIs and save that in kernel/sched_custom.c 2- Invoke sched_custom.c in kernel/sched.c
3- Recompile the kernel source
4- Reboot using the new kernel
5- write a C code and call sched_setschedule() to use my scheduler.

Is that all? Your reply is appreciated.

No, AFAIK these are *user-space* APIs, thus they're supposed to be used by applications (correct me if I'm wrong).

So the question would be what exactly you're trying to achieve:
either you want to actively modify the kernel-side scheduler sources, in which case these APIs probably are not what you want (to use there), or you're trying to modify scheduling configuration of user-space applications, in which case they possibly are.
Or you want both, in which case you probably
modify kernel scheduler implementation *and* use sched_*() in user-space with the intent to ensure that that modified scheduler implementation gets chosen.

HTH,

Andreas Mohr