We are developing a very low-level app-system which runs before OS boot, in-fact a boot application.
the question is how we should utilize CPU cores/threads?
And how many thread we would run?
Is it possible at all?! is there any link/tutorial?

- 34,448
- 50
- 182
- 322
-
3If you need OS services like turning on cores and scheduling across them but want to run before the OS, then you'll have to implement them all yourself. You can use any OS that runs on the same hardware as reference code. – David Schwartz Oct 31 '13 at 21:42
-
2I suggest you give some hand of `Linux` or `Unix` kernel. – Oct 31 '13 at 21:44
-
@DavidSchwartz so the question exactly is how does a OS utilize CPU cores? – Oct 31 '13 at 21:45
-
@parsaporahmad And the answer is to look at the code of any OS that runs on the same hardware. I think you'll find it's quite complicated, particularly if you plan to support a wide array of hardware. – David Schwartz Oct 31 '13 at 21:54
-
@DavidSchwartz I just was thinking that there is should be some native(hw-level) functions for doing parallel at low-level, like SSE extension, so you mean I'm wrong?! concurrency is kinda completely software thing? – Oct 31 '13 at 22:03
-
3@parsaporahmad It sounds like you actually want to know what this question asked: http://stackoverflow.com/questions/980999 (SSE is a completely different kind of parallelism, it's data parallelism on a single core, nothing to do with threads.) On a different note, I'm not convinced that any kind of "boot application" would benefit from multithreading. – us2012 Oct 31 '13 at 22:11
-
@us2012 thanks, I think the link you provided solve the issue – Nov 01 '13 at 08:03
1 Answers
Since you're talking about threading before booting the OS, I'm going to assume that no kernel is available to you yet. That means no system calls, so no fork() or clone(). For the purpose of this answer, however, I'm also going to assume that you have already set up the A20-gate, a GDT, either protected (for IA-32) or long (for x86-64) mode, and so on. If you don't know what these are, we probably shouldn't be talking about threads before booting to begin with.
There are opcodes and tricks you can use to let your processor use other cores, thus implementing threading quite directly. You can find all these things in the Intel x86 (you are working on x86, are you? You obviously need a different set of manuals if you're on a different architecture) manuals here: http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf
The reason there are no tutorials for something like this is, quite frankly, that it's not very useful. The entire point of setting things up before loading the kernel into memory is to make it easier to load the kernel into memory. Threading does not exactly contribute to this goal. It would be advisable to simply let the kernel deal with such low-level implementation requirements, so that you can then use the fork() and clone() system calls for all your threading needs.
EDIT: Good correction by Sinn: fork() create a new process, which of course isn't actually threading.

- 431
- 3
- 9
-
2Nice Argument Sir, have my upvote, but a small correction. Actually fork is not considered Threading, as it creates a new process which doesn't share resources, even though you still have (pseudo-if 1 core)parallelism. – Sinn Nov 01 '13 at 15:01