Haiku Scheduler

Hello, I am new to Haiku and doing some research on the OS. Can anyone tell me about it’s current scheduler? I’ve read Andre’s blog and I read the “Experiments in Scheduling” blog, but it doesn’t look like anything has been updated in a while. Is the current scheduler based on CFS, or something else? Is Andre still working on this project? Anyone know? Thanks.

Haiku has three schedulers, the “simple” scheduler, the “simple SMP” scheduler and the “affine” scheduler. The affine scheduler is disabled by default, the “simple” scheduler is selected if your machine is not capable of more than one execution context (no HT, no multi-core, one CPU) otherwise the “simple SMP” scheduler is chosen.

As the names suggest they are all fairly primitive, and not comparable to the scheduler in any mainstream OS kernel. They’ve been tinkered with in a fairly aimless way over the past few years. Just two small changes this year as a result of other changes in Haiku.

Andre never actually wrote any scheduler code for Haiku per se. For GSOC 2007 he built toy models and wrote long posts name-checking people and quoting academic work. He wrote a few posts later on offering excuses for not having delivered anything of substance and promising it would be forthcoming soon. Then even those dried up.

Versailles, I would strongly recommend that instead of relying on 2nd hand information, you instead download and review the scheduler code itself. For all you know the person who states an online opinion could be an internet chatbot gone loco.

http://svn.haiku-os.org/haiku/haiku/trunk/src/system/kernel/scheduler/

I think the fact that the name on the reply is from “NoHaikuForMe” says all one needs to know about what to think of their posts on this board.

He’s actually very lovable as a person, but holds strong opinions.

Forgot the smiley face that should have gone at the end of my previous post.

“Strong Opinions” might be one of the biggest understatements I have heard in a while. :slight_smile: and I work a support desk…

[quote=NoHaikuForMe]Haiku has three schedulers, the “simple” scheduler, the “simple SMP” scheduler and the “affine” scheduler. The affine scheduler is disabled by default, the “simple” scheduler is selected if your machine is not capable of more than one execution context (no HT, no multi-core, one CPU) otherwise the “simple SMP” scheduler is chosen.

As the names suggest they are all fairly primitive, and not comparable to the scheduler in any mainstream OS kernel. They’ve been tinkered with in a fairly aimless way over the past few years. Just two small changes this year as a result of other changes in Haiku.

Andre never actually wrote any scheduler code for Haiku per se. For GSOC 2007 he built toy models and wrote long posts name-checking people and quoting academic work. He wrote a few posts later on offering excuses for not having delivered anything of substance and promising it would be forthcoming soon. Then even those dried up.[/quote]

Haiku doesn’t use a heuristic scheduler similar to other mainstream OS’s. The Scheduler has its cpu time slices set by threading priority and then it puts threads in order of priority. so in Haiku the Application sets its own priority and scheduler try’s to to obey these time slice requirements.

while you claim its primitive, I think it works very well.

This is a hilarious travesty. I’ve spent the past few days reading numerous posts in the forum, so I’m already aware of this cynical NoHaikuForMe character. As for the validity of this person’s posts however, I am only partially concerned. What matters to me is if I can present a substantial amount of information concerning Haiku’s scheduling in a paper so that it not only meets the length requirements of the assignment, but is also convincing to my instructor. So since I am a newbie at this, the descriptions of the schedulers in said post are convincing to me. I will also take the advice about looking at the original code (thank you for the link), and I would like to discuss this more when I’m not rushing off to work. For now, thank you for your prompt responses, as well as the laugh. :wink:

[quote=thatguy]Haiku doesn’t use a heuristic scheduler similar to other mainstream OS’s. The Scheduler has its cpu time slices set by threading priority and then it puts threads in order of priority. so in Haiku the Application sets its own priority and scheduler try’s to to obey these time slice requirements.
[/quote]

I’m not sure what you think you mean by “time slices set by threading priority” but otherwise this is a simplified but essentially correct description of what the BeBook tells you, and it may even be a correct description of how BeOS works. Haiku isn’t BeOS.

Someone suggested reading the source code - I actively encourage it, check out the “simple_smp” scheduler in particular since this will be what most people use. As a thought experiment, work out what this scheduler does when scheduling five busy threads on a dual-core CPU, where two of the threads have NORMAL + 1 priority, two have NORMAL and one has NORMAL - 1 priority.

Is this behaviour arguably “correct” according to the BeBook? Do you think it would surprise developers?

[quote=NoHaikuForMe][quote=thatguy]Haiku doesn’t use a heuristic scheduler similar to other mainstream OS’s. The Scheduler has its cpu time slices set by threading priority and then it puts threads in order of priority. so in Haiku the Application sets its own priority and scheduler try’s to to obey these time slice requirements.
[/quote]

I’m not sure what you think you mean by “time slices set by threading priority” but otherwise this is a simplified but essentially correct description of what the BeBook tells you, and it may even be a correct description of how BeOS works. Haiku isn’t BeOS.

Someone suggested reading the source code - I actively encourage it, check out the “simple_smp” scheduler in particular since this will be what most people use. As a thought experiment, work out what this scheduler does when scheduling five busy threads on a dual-core CPU, where two of the threads have NORMAL + 1 priority, two have NORMAL and one has NORMAL - 1 priority.

Is this behaviour arguably “correct” according to the BeBook? Do you think it would surprise developers?[/quote]

then riddle me this, what effect would pre-emption have on either of the normal priority thread is a display thread comes along.

the scheduler works pretty similar to the BeOS scheduler.Though it could use a few small improvements, I don’t mind the pre-epmtion overhead to be honest.

What else are you bitter about today ?

Before a non-sense discussion arises, please have a look at the discussion in the comments of an ars technica article. There, stippi and I were trying to explain why the simple and primitive scheduler (“NoHaikuForMe” is certainly correct there) works so well on Haiku, and why a fair scheduler might even end up being counter productive.

I’m not sure that the Ars discussion is helpful at this point. The practice of explicitly assigning priorities to mundane programs at development time on Haiku is worth knowing about for someone interested in the scheduler, but it’s not enough. More helpful might be think about two separate issues:

  1. What is the Haiku scheduler supposed to do?

  2. What does it actually do today?

My previous post about the source code encourages people to think about the latter. One thing we do see in the Ars thread is that Haiku developers don’t necessarily know much about Haiku’s internals. Stippi would be recognised by many Haiku fans as a very important developer, but he had not the first idea what the scheduler is really doing. DrPizza has to spell that out.

There are a lot of opportunities to make mistakes in the scheduler. For example in earlier NT kernels a thread which sets its priority would get a new quantum even if its new priority was the same, so it could do:

while (1) { /* do a few milliseconds worth of work here */ setpriority(myDefaultPriority); // no-op? }

and thereby run “forever” despite the availability of other runnable threads at the same priority. In the Ars thread Stippi tries an experiment to see if he understands how the Haiku scheduler works. The experiment does not do what he expected, but he loses interest without investigating. And indeed no Haiku developer ever followed this up.

Since you caused me to read that thread I will clear up something important DrPizza got wrong. The changes in the “kill-the-bkl” git tree, and the eventual removal of the BKL from Linux were not really motivated by performance considerations. Not on single Celeron-based home PCs and not on zillion-core supercomputers. The BKL was finally targeted for removal starting in 2008 because it made Linux unnecessarily difficult to maintain. Why wasn’t it about performance? Well, go check the changes in that tree, are they touching widely used high performance code paths in disk access, memory management or networking? Nope, the BKL was already gone from those code paths. The changes are in less used corners of the system where performance is irrelevant. The last few years of work removing the BKL made it easier to ensure the kernel is correct with no real difference to performance

Some of the other tangents in that Ars discussion (e.g. DrPizza not understanding copyright, axeld suggesting Linus Torvalds could have run 4.3BSD [VAX software] on his i386 PC) are interesting but even more irrelevant to this thread than the BKL.

Once again, thanks for the prompt replies as well as the laughs. Please have patience with me as I am just beginning to understand the concept of scheduling, prioritizing, and threads.

NoHaikuForMe: Thanks for the breakdown. For now I’m gonna roll with the simple SMP answer, and research that, unless someone points me in a different direction. Yes I am a little disappointed about Andre’s disappearance since I read most of his blog and had high hopes. Would it be fair to describe BeOs’s scheduler as a basic description of Haiku’s, or are they different animals? Also, where in the BeBook is the scheduler discussed? I don’t remember seeing a description. I’m just beginning to understand prioritizing too, so I’m wanting to know how Haiku schedules its processing classes.

AndrewZ: I read the code for simple.h. Thank you for that. I am not yet a programmer so the only bits I can make sense of are the comments. How are processes prioritized, and how are the classes scheduled?

DFergATL: Why does a person spend so much time on a forum celebrating something he chooses not to enjoy in his life? Can you explain this?

thatguy: How does Haiku prioritize its processes and classes?

axeld: Thank you for that link! I have already cited one of your articles from that site, about the OS booting in 4 seconds. Pretty impressive.

http://haiku-os.org/legacy-docs/bebook/TheKernelKit_ThreadsAndTeams_Overview.html#ThreadsAndTeams_ThreadPriorities

and

http://haiku-os.org/legacy-docs/bebook/TheKernelKit_ThreadsAndTeams.html#Constants_ThreadPriorities

I assume Haiku’s scheduler is intended to behave as described there (perhaps axeld can clarify if not). It doesn’t. I can’t tell you whether, or to what extent the same deviations exist in any specific version of BeOS.

[quote=Versailles]Once again, thanks for the prompt replies as well as the laughs. Please have patience with me as I am just beginning to understand the concept of scheduling, prioritizing, and threads.

NoHaikuForMe: Thanks for the breakdown. For now I’m gonna roll with the simple SMP answer, and research that, unless someone points me in a different direction. Yes I am a little disappointed about Andre’s disappearance since I read most of his blog and had high hopes. Would it be fair to describe BeOs’s scheduler as a basic description of Haiku’s, or are they different animals? Also, where in the BeBook is the scheduler discussed? I don’t remember seeing a description. I’m just beginning to understand prioritizing too, so I’m wanting to know how Haiku schedules its processing classes.

AndrewZ: I read the code for simple.h. Thank you for that. I am not yet a programmer so the only bits I can make sense of are the comments. How are processes prioritized, and how are the classes scheduled?

DFergATL: Why does a person spend so much time on a forum celebrating something he chooses not to enjoy in his life? Can you explain this?

thatguy: How does Haiku prioritize its processes and classes?

axeld: Thank you for that link! I have already cited one of your articles from that site, about the OS booting in 4 seconds. Pretty impressive.[/quote]

Each application can set its thread priority at the time of being written. IE there are defaults. As to how the actual time slice and latency works out, I’d have to do a bit more reading but its really pretty simple from outward appearance. the scheduler see the threads priority and put it in the cue to be run based on this priority. which is different from linux where it appears that the scheduler try’s to determine the threads priority by heuristics. Haiku’s scheduler just runs threads based on the preassigned thread priority’s. Simple is good IMHO and the result is a system I get much satisfaction out of using.

I am not great with c/c++ yet but I can see the design approach is very simple. Which doesn’t mean it is inferior. One of the design goals of Beos and Haiku is low latency and the threading model and priority settings work around this idea.

Feel free to dive in and correct me if I am wrong however. Axel sums it up very well in the ARS Technica article.