Will your OS support multi-CPU?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Will your OS support multi-CPU?

Post by Brendan »

Hi,

After reading the article at "http://news.com.com/Dual-core+desktops+hit+the+market/2100-1042_3-5675050.html?tag=nefd.top" about desktop machines with dual core CPUs hitting the market, I started wondering what other OS developers are planning.

A quote from the article:
Intel is scheduled to follow up by launching dual-core processors for servers and notebooks in early 2006, although it may trickle them out earlier by, for example, seeding dual-core server chips in the second half of this year.

The chipmaker, which says it has more than 15 multicore projects under way for desktops, notebooks and servers, says it will ship millions of dual-core chips by the end of the year and estimates that by the close of 2006, 70 percent of its server chips and 85 percent of its desktop and notebook chips will be dual core.
By the time the OS's we're developing are usable, dual core (and possibly quad core) will be everywhere.

If anyone is wondering what the difference between SMP and multi-CPU is meant to be, multi-CPU is where the OS supports different CPUs within the same computer while with SMP all CPUs are the same. I know "multi-CPU" isn't the right term for it but I couldn't think of anything better :).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
wacco

Re:Will your OS support multi-CPU?

Post by wacco »

Sort of tricky question, so I didn't vote at all.

First of all, everybody is trying to be realistic, so will vote one cpu only. But, in the end we all want te perfect (or at least 'a better') OS so you want to vote the top-option: ht, smp, numa, you name it, it's supported. Should be interesting results, but they're going to be a bit scewed because not everybody is equally realistic in his/her plans. If somebody votes for one cpu on purpose, I'd like to hear why. :)

Second of all, I'm personally quite sick of the way systems are working and am actually designing my own hardware. But the thing is, you can't actually speak anymore about 'cpu', since it's simply not there (don't ask me what I mean with that, just wait). However, there is going to be a large portion of numa like interfaces scattered all over the place. So multi-cpu: depends on your point of view, numa: absolutely, ht: not my architecture, so no, smp: lots and lots of it.

Just a little side-note for personal clarification: what's the main difference between multi-cpu and smp? You got me slightly confused there...
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Will your OS support multi-CPU?

Post by Brendan »

Hi,
wacco wrote: Just a little side-note for personal clarification: what's the main difference between multi-cpu and smp? You got me slightly confused there...
Most OS's (Windows, Linux, etc) support SMP where all CPUs are identical.

Intel's MP specification (and AFAIK most multi-CPU motherboards) allow for situations where CPUs are different. For example, you could have a dual Pentium computer where one CPU supports MMX and the other doesn't (e.g. different features), or a computer with an 80486DX-33 and an 80486DX2-66 (e.g. different CPU speeds). My OS does support this, and I haven't heard of any other OS that does. This is what I meant by "multi-CPU"...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
wacco

Re:Will your OS support multi-CPU?

Post by wacco »

*Ahem* I'm very sorry but I missed that part in your first post :-X It's getting a little late, and completely missed it. Thanks for the second reply though ;)

In that context, Multi-CPU: Absolutely (it's going to be scalable as hell if it all works out the way I want it, so I'll better be ;) )
srg

Re:Will your OS support multi-CPU?

Post by srg »

Brendan wrote: Hi,
wacco wrote: Just a little side-note for personal clarification: what's the main difference between multi-cpu and smp? You got me slightly confused there...
Most OS's (Windows, Linux, etc) support SMP where all CPUs are identical.

Intel's MP specification (and AFAIK most multi-CPU motherboards) allow for situations where CPUs are different. For example, you could have a dual Pentium computer where one CPU supports MMX and the other doesn't (e.g. different features), or a computer with an 80486DX-33 and an 80486DX2-66 (e.g. different CPU speeds). My OS does support this, and I haven't heard of any other OS that does. This is what I meant by "multi-CPU"...


Cheers,

Brendan
One multi-CPU idea that I had thought up was to have an Opteron or Athlon 64 as the main processor, then a Netburst based chip, say a Northwood or Prescott as a streaming multimedia coprocessor (it'll have each chip doing what it's best at).

srg
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Will your OS support multi-CPU?

Post by Candy »

The vote on the second was me. I consider it quite lame if you can't even be bothered to find compatible processors. Buy similar ones or don't bother multi-cpu at all.

On the rest, support one, support them all. HT at least was supposed to work like that, think dual-core will comply to intels own multiprocessor standard too.
zyp

Re:Will your OS support multi-CPU?

Post by zyp »

I voted one cpu, because multiprocessing is still too far into the future for my os, and for the moment I have a hard time only with one cpu.
Maybe in the future, when (if) I'll get a reasonable working system I'll try SMP, and after that climbing the ladder towards the top.

Besides, I don't own neither a SMP nor a HT system, and is not as fun when they're only running in emus and not on my hardware.
The same reason keeps me from 64bit code, what I otherwise would had a look at.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Will your OS support multi-CPU?

Post by Brendan »

Hi,
Candy wrote:I consider it quite lame if you can't even be bothered to find compatible processors. Buy similar ones or don't bother multi-cpu at all.
To me this is more about upgrade options. For e.g. a company that buys a computer with a 4-way motherboard and only 2 chips, hoping to upgrade with an extra 2 chips when/if the need arises. Six months later they find out they can't get the exact same chips, but can get a pair with larger caches, some extra feature or whatever.

To a lesser degree it's also about marketting - to be able to demonstrate your OS working perfectly on a completely hybrid computer, where all other OSs fail in some way. "If it can run on this, it can run on anything" if you see what I mean...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Will your OS support multi-CPU?

Post by Colonel Kernel »

I voted for HT + SMP, even though realistically my OS will be single-CPU for a long time.

The most interesting case for AMP (asymmetric multiprocessing -- is this what you meant Brendan?) I've seen is the Cell processor. I think a general-purpose OS that could take advantage of all the SPUs in a Cell would be pretty cool...
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Will your OS support multi-CPU?

Post by distantvoices »

I'm the second for smp only... well, that's what I can test not only in virtuo but also on a real machine, as I've got a dual cpu serverboard recently - and the corresponding xeon's too, so it might be interresting to try out multi-cpu stuff too.

I'd just like to know then, how to swich context with this multi cpu stuff? Any links?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Will your OS support multi-CPU?

Post by Pype.Clicker »

as far as *i* am concerned, i will not write any multi-CPU code for clicker. Reason is limited lifetime (and all i could use for testing is the high-availability computation farm of my university, which wouldn't be a GoodIdea at all).

That being said, i try to keep system design able to receive multi-processors support if someone ever whishes to add it. For instance, the "scheduler" and the "dispatcher" code is clearly separated so that one could instanciate more dispatchers if more CPUs are available.

The scheduler can lookup "services-var.sys.schedule.cpu.*" to locate all the instanciated dispatchers and push threads in their queues
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Will your OS support multi-CPU?

Post by Brendan »

Hi,

[quote author=beyond infinity link=board=1;threadid=7641;start=0#msg64012
date=1113980435]
I'm the second for smp only... well, that's what I can test not only in virtuo but also on a real machine, as I've got a dual cpu serverboard recently - and the corresponding xeon's too, so it might be interresting to try out multi-cpu stuff too.

I'd just like to know then, how to swich context with this multi cpu stuff? Any links?
[quote][/quote]

The actual context switching code is the same as it would be in a single-CPU OS. The main difference is the code that selects which task/thread/process to switch to, and the need for re-entrancy protection everywhere.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Will your OS support multi-CPU?

Post by distantvoices »

@brendan: thanks for reply. :-)

So far, I've understood. What I wanna know is: how to find out to which cpu to hand out a given task? say: I want to switch tasks on cpu0. or task X gave up cpu0. Now, cpu0 is already overloaded with work, and cpu1 is idle: let's give it to cpu1. How to determine the cpu? Are there special registers or locations?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
AR

Re:Will your OS support multi-CPU?

Post by AR »

I'm not speaking from experience but the way I think it works is the timer interrupts CPU 0, the cpu enters the scheduler, accquires the spinlock then finds the another thread to execute, preferring a thread that is part of the same process and belongs to a process that was last executed on CPU 0 and switches itself. The timer then/also interrupts CPU 1 which enters the scheduler, accquires the spinlock and performs the same lookup and switches itself and so on for each additional CPU. (I'm not up on the APIC but there may be an individual timer interrupt for each CPU, at least that's the way it seems according to GNU Hurd)

Initalising is the hard part, if I remember correctly the BIOS inits all the other CPUs into a wait state in real mode, each CPU needs to be interrupted using an inter-CPU interrupt and you need to start Pmode, enable paging and enter the kernel on each one (at a different entry point preferably which directly starts the scheduler since the rest of the kernel has probably already been inited by the primary CPU).

Brendan can correct anything that is wrong, probably most of it but anyway...

In response to the poll, I voted SMP only as I don't have any hardware to test HT on (nor do I know anyone who has a HT enabled system).
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Will your OS support multi-CPU?

Post by Brendan »

Hi,
beyond infinity wrote:So far, I've understood. What I wanna know is: how to find out to which cpu to hand out a given task? say: I want to switch tasks on cpu0. or task X gave up cpu0. Now, cpu0 is already overloaded with work, and cpu1 is idle: let's give it to cpu1. How to determine the cpu? Are there special registers or locations?
Ahh :)

There's no special registers or anything, and there's no right/wrong way to do it (it mostly depends on how you want your scheduler to behave). I'll give a simplified description of what I do, as this should help..

First, start with "CPU affinity", which is just a bit mask (one bit for each CPU) that determines which CPUs the thread can be run on. This can be used by applications for performance reasons, and/or by the OS. It's also optional..

When a thread becomes ready to run, the scheduler checks each bit in it's CPU affinity bitmask and considers each "enabled" CPU. For each possible CPU you'd decide which one is the "best" one (this could mean the CPU with the least load, but (for HT) can also take into account the load on the physical CPU rather than just the load on logical CPUs).

For each CPU there's a "ready-to-run queue", which is sorted according to the priority of the threads on it. The highest priority thread is always at the top of the queue, and is the currently running thread. When a thread becomes ready-to-run the scheduler finds the best CPU (as above) and then inserts the thread into this queue according to it's priority. If the thread that just became ready-to-run is the highest priority thread on the queue then you'd probably want to pre-empt the currently running thread.

If the currently running thread becomes blocked for any reason (goes to sleep, is waiting for a message, gets terminated, etc) then you'd remove it from the CPU's ready-to-run queue, and select a new thread to run. When you're selecting the next thread to run, all you need to do is grab the thread on the top of the CPUs ready-to-run queue and run that.

Now, something I've missed is how you figure out which CPU has the most load. You could just keep track of the number of threads on each CPUs queue and use that, but you've probably already got some ideas of your own :).

That's all there is to it :). This scheduler would always run the highest priority thread that can run (prioritized co-operative). It simple enough, but it's also easy to change - for example, the "ready-to-run" queue could be sorted differently, or the CPU could run each thread in the list rather than just the first (highest priority) thread, or you can dynamically adjust priorities, or you could have more than one "ready-to-run" queue for each CPU (for e.g. one queue for high priority threads, one for normal threads and another for idle threads).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply