How to create a multicore OS ?

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.
Post Reply
User avatar
Coconut9
Member
Member
Posts: 51
Joined: Sat May 20, 2017 1:25 am
Location: PCI bus: 3, slot: 9, function: 5

How to create a multicore OS ?

Post by Coconut9 »

I mean who a can enable all the cores and force them to execute instructions ?
How people react when a new update of your OS is coming:
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: How to create a multicore OS ?

Post by sortie »

User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to create a multicore OS ?

Post by iansjack »

Don't force your cores to execute instructions. Ask them nicely; it's only polite.
xmm15
Member
Member
Posts: 27
Joined: Mon Dec 16, 2013 6:50 pm

Re: How to create a multicore OS ?

Post by xmm15 »

Basically:
Computer starts with 1 logical processor, others are halted.
Find the number of cpus by scanning memory for mp structures
Use apic to send SIPI, an interrupt that will wake up the other cpus. When sending sipi, you provide an address that you want your cpus to start executing from.

Once they start executing, setup long mode, setup a timer uaing their local apic and make that timer execute the scheduling function. Now you have tasks running on each cpus note that you task list will be global and all cpus will compete to run a task. A task should not run on 2 cpu at the same time.

The wiki page referenced above is a good start. Intel manuals are your best friend.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to create a multicore OS ?

Post by iansjack »

The task list doesn't have to be global. You can always set up per-cpu task lists and determine which CPU to run a process on, rather than letting it happen randomly. This can simplify scheduling but it is then up to you to ensure that processes are spread evenly amongst CPUs.

Also, you don't need to use individual timers for each CPU. It's possible to have just one timer running, which then notifies the other CPUs.
Post Reply