122fc Writing a scheduler - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > FreeBSD Development

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

Reply
 
Thread Tools Display Modes
  #1  
Old January 23rd, 2010, 04:33
justint justint is offline
Junior Member
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Writing a scheduler

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 global: custom_scheduler = 0, which the user can toggle
2. in kern/kern_switch.c:
Code:
runq_choose() {
...
  if(custom_scheduler)
     return my_scheduler(rq);
...
}
What's the best way to include my function my_scheduler(struct runq* rq)? Can I create a kld module? Or must I #include <kern/my_scheduler.c> or something along those lines?

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

Thanks!

Last edited by DutchDaemon; November 26th, 2010 at 01:22.
Reply With Quote
  #2  
Old January 23rd, 2010, 14:57
GPF's Avatar
GPF GPF is offline
Junior Member
 
Join Date: Oct 2009
Location: Athens, Greece
Posts: 25
Thanks: 5
Thanked 7 Times in 6 Posts
Default

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 /sys/kern/sched_4bsd.c and /sys/kern/sched_ule.c

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!

Last edited by DutchDaemon; January 23rd, 2010 at 19:41. Reason: typofix
Reply With Quote
  #3  
Old November 11th, 2010, 14:53
FDeveloper FDeveloper is offline
Junior Member
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default I don't understand

Hi,

can you tell me what's wrong with justint's solution for implementing the new scheduler if we change all runq_choose functions?
Reply With Quote
  #4  
Old November 25th, 2010, 09:52
FDeveloper FDeveloper is offline
Junior Member
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to call syscall in kernel

Hello,
I have another question.
I want to change the ule scheduler a little.
for this purpose I decided to call a lkm(syscall) in tdq_choose function in sched_ule.c 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 syscall(syscall_num,...) it has compile error and the error is:
Code:
usr/src/sys/kern/sched_ule.c:1233: warning: implicit declaration of function 'syscall'
can anyone help me how to fix the problem?
thanks.

Last edited by DutchDaemon; November 25th, 2010 at 16:45. Reason: proper formatting: http://forums.freebsd.org/showthread.php?t=8816
Reply With Quote
  #5  
Old November 25th, 2010, 21:56
richardpl richardpl is offline
Member
 
Join Date: Nov 2008
Location: Croatia
Posts: 841
Thanks: 6
Thanked 68 Times in 67 Posts
Default

Isn't syscall for userland?
Reply With Quote
  #6  
Old November 26th, 2010, 15:41
FDeveloper FDeveloper is offline
Junior Member
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
Reply With Quote
  #7  
Old November 26th, 2010, 16:05
Alt's Avatar
Alt Alt is offline
Member
 
Join Date: Nov 2008
Location: Mother Russia
Posts: 726
Thanks: 32
Thanked 77 Times in 71 Posts
Default

fork/exit in kernel ? o_O
Reply With Quote
  #8  
Old November 26th, 2010, 18:20
richardpl richardpl is offline
Member
 
Join Date: Nov 2008
Location: Croatia
Posts: 841
Thanks: 6
Thanked 68 Times in 67 Posts
Default

You can certainly fork and exit kernel processes and kernel threads in kernel.
Reply With Quote
  #9  
Old November 27th, 2010, 07:07
FDeveloper FDeveloper is offline
Junior Member
 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So, does anyone know how can we call a syscall (lkm) in kernel codes?
Reply With Quote
  #10  
Old November 27th, 2010, 09:48
richardpl richardpl is offline
Member
 
Join Date: Nov 2008
Location: Croatia
Posts: 841
Thanks: 6
Thanked 68 Times in 67 Posts
Default

Ask on mailing lists.
Reply With Quote
  #11  
Old October 22nd, 2011, 09:54
fidaj fidaj is offline
Junior Member
 
Join Date: Nov 2008
Posts: 49
Thanks: 9
Thanked 4 Times in 4 Posts
Default

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/
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about writing a daemon in C overmind Userland Programming & Scripting 4 February 11th, 2010 00:51
Writing a GUI (C++) for a chat app (C) - how? caesius Userland Programming & Scripting 12 January 4th, 2010 01:15
how to check how fast ZFS is read/writing? wonslung General 11 July 6th, 2009 10:59
CPU limit for jails under ULE scheduler kostjn FreeBSD Development 7 May 30th, 2009 09:59
Writing a new helper function bsd_newbie Porting New Software 3 February 11th, 2009 18:22


All times are GMT +1. The time now is 01:40.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0