Writing a scheduler

Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

Writing a scheduler

Postby justint » 23 Jan 2010, 03:33

Hi, I'm trying to write my own custom scheduler.

I'm having trouble knowing where to declare my code and what's the best way to "stick it into the kernel".

1. I have a [FILE]global: custom_scheduler = 0[/FILE], which the user can toggle
2. in k[FILE]ern/kern_switch.c[/FILE]:
Code: Select all
runq_choose() {
...
  if(custom_scheduler)
     return my_scheduler(rq);
...
}


What's the best way to include my function [FILE]my_scheduler(struct runq* rq)[/FILE]? Can I create a kld module? Or must I [FILE]#include <kern/my_scheduler.c>[/FILE] or something along those lines?

Sorry for such a dumb question, but I'm just starting with freebsd development.

Thanks!
justint
Junior Member
 
Posts: 5
Joined: 22 Jan 2010, 19:46

Postby GPF » 23 Jan 2010, 13:57

Questions concerning the low level implementation of the kernel are better addressed at the hackers mailing list. I'll give you enough to get you started though.

Take a look at [FILE]/sys/kern/sched_4bsd.c[/FILE] and [FILE]/sys/kern/sched_ule.c[/FILE]

These are the two schedulers you 'll find in fbsd, ule is used by default. grep the code in /sys/kern with the right keyword and perhaps you 'll find your answer alone before someone just hands it to you.

Good luck!
User avatar
GPF
Junior Member
 
Posts: 25
Joined: 13 Oct 2009, 20:33
Location: Athens, Greece

I don't understand

Postby FDeveloper » 11 Nov 2010, 13:53

Hi,

can you tell me what's wrong with justint's solution for implementing the new scheduler if we change all runq_choose functions?
FDeveloper
Junior Member
 
Posts: 4
Joined: 11 Nov 2010, 13:41

how to call syscall in kernel

Postby FDeveloper » 25 Nov 2010, 08:52

Hello,
I have another question.
I want to change the ule scheduler a little.
for this purpose I decided to call a [FILE]lkm(syscall)[/FILE] in tdq_choose function in [FILE]sched_ule.c[/FILE] file and implement my code in that module.
Is that correct to do call a lkm in kernel?
If yes, how can I call the module?
I used [FILE]syscall(syscall_num,...)[/FILE] it has compile error and the error is:
Code: Select all
usr/src/sys/kern/sched_ule.c:1233: warning: implicit declaration of function 'syscall'


can anyone help me how to fix the problem?
thanks.
FDeveloper
Junior Member
 
Posts: 4
Joined: 11 Nov 2010, 13:41

Postby richardpl » 25 Nov 2010, 20:56

Isn't syscall for userland?
richardpl
Member
 
Posts: 841
Joined: 17 Nov 2008, 17:02
Location: Croatia

Postby FDeveloper » 26 Nov 2010, 14:41

I think, we can open, exit, fork and other syscalls in kernel, don't we?

I don't know how we should call a syscall(lkm) in kernel codes?
FDeveloper
Junior Member
 
Posts: 4
Joined: 11 Nov 2010, 13:41

Postby Alt » 26 Nov 2010, 15:05

fork/exit in kernel ? o_O
User avatar
Alt
Member
 
Posts: 726
Joined: 18 Nov 2008, 12:22
Location: Mother Russia

Postby richardpl » 26 Nov 2010, 17:20

You can certainly fork and exit kernel processes and kernel threads in kernel.
richardpl
Member
 
Posts: 841
Joined: 17 Nov 2008, 17:02
Location: Croatia

Postby FDeveloper » 27 Nov 2010, 06:07

So, does anyone know how can we call a syscall (lkm) in kernel codes?
FDeveloper
Junior Member
 
Posts: 4
Joined: 11 Nov 2010, 13:41

Postby richardpl » 27 Nov 2010, 08:48

Ask on mailing lists.
richardpl
Member
 
Posts: 841
Joined: 17 Nov 2008, 17:02
Location: Croatia

Postby fidaj » 22 Oct 2011, 08:54

Hi!
Well - there are some results?
Can I have something to test?

Do you know about the existence of alternative scheduling FBFS? http://rudot.blog.com/
fidaj
Junior Member
 
Posts: 49
Joined: 16 Nov 2008, 17:29


Return to FreeBSD Development

Who is online

Users browsing this forum: No registered users and 0 guests