Page 1 of 1
How to assign execution to a specific processor
Posted: Tue Dec 17, 2013 9:00 am
by kemosparc
Hi,
I wrote a small OS that starts with my own boot loader and switches to long mode.
I was able to allocate the GDT and IDT and map 4 GB of memory, set up a small video driver, and access disk using LBA.
My next step now is how to work with processors.
Can any on let me now how can I detect available processors, assign a processor to work on a specific piece of code, and how to switch between different processors.
Basically I would like to write a small multithreading library and start my own schedular.
Where can I read about that step by step with tutorials and examples.
Thanks a lot
Karim.
Re: How to assign execution to a specific processor
Posted: Tue Dec 17, 2013 1:04 pm
by chickendinner
First off jumping straight into a multiprocessor scheduler isn't wise IMO. Write a single processor scheduler first so you can be sure you're context switching properly and have all your interrupt handlers, Timer and IRQ handling code done correctly.
To detect multiple CPU's i believe you can use the MP/ACPI tables to detect them (ACPI being the reccomended way and MP as a backup from what i've read). ACPI requires you to actually write an interpreter for a special language called AML to use it properly, so it's a not trivial exercise to work with. There are freestanding libraries that can do this for you however. There are plenty of articles/threads on this on how to handle these tables and establish what cores you have to work with. Read up on SMP in the intel manuals to see how to actually turn the other cores on and get them working on code.
It would be very silly to start all of this without proper memory management first. You're stuck with using static BSS buffers that you can't free otherwise. If you've just identity mapped the first 4GB without using a memory map it's likely you'll get problems. Memory addresses have holes and reserved areas you can't use. Grab a memory map of usable areas from your bootloaders multiboot header or use the BIOS call to get it. Parse the table into a data structure such as a linked list or bitmap and have a few routines to grab pointers to chunks of memory and free them. and then functions to map and unmap those physical pages into your page table in the form of a heap above your kernel image (or whatever scheme you like). Once you have this done it would be a good point to start worrying about scheduling and multiple cores.
Re: How to assign execution to a specific processor
Posted: Tue Dec 17, 2013 2:29 pm
by Combuster
kemosparc wrote:Can any on let me now how can I detect available processors, assign a processor to work on a specific piece of code, and how to switch between different processors.
This isn't The Sims 4, where you play god and manually take control of individual people. Each processor is an independent worker and they have to
communicate.
Where can I read about that step by step with tutorials and examples.
It's here:
Beginner Mistakes