using all 4 CPU cores....

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator: Moderators

Post Reply
nikoj
Posts: 8
Joined: Sat Oct 04, 2008 11:59 pm

using all 4 CPU cores....

Post by nikoj » Thu Dec 04, 2008 1:34 pm

let's say that we have Core 2 Quad processor and we want applications to use all 4 cores. Which job is this? operating system or the application? Do we need to code the application in a way that we will tell to use all 4 cores or this is job for the OS?

Wabbit
Posts: 4
Joined: Thu Dec 04, 2008 8:31 pm

Post by Wabbit » Thu Dec 04, 2008 8:48 pm

The operating system needs to support multi-threading and it needs to know how to schedule threads to run on different cores.

Then the application needs to be running multiple threads. If the application uses 4 threads then in theory it could run on all 4 cores at once, but in reality a multi-threaded application would have to be specifically written to work efficiently on more than one core at once (e.g. balancing the workload between the threads equally). A lot of applications are multi-threaded these days, but I think most of them aren't really written to take advantage of more than one core, because it can make the coding quite a bit more complicated.

Andyhhp
Moderator
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1
Contact:

Post by Andyhhp » Sat Dec 06, 2008 6:43 am

Yeah - you need a working thread scheduler to run on multiple cores at once. You also need to do some APIC magic to start the other cores. By default, a multi core computer starts up with the first core running and all others in standby, but with interrupts enabled so they can be started.

On the other hand, writing multi threaded programs is a black art in itself which a large number of such programs fail at.

The best way to write multi threaded programs is to split your program into discrete units that require the bare minimum of communication between each other, and if possible, no data sharing between each other.

When you get into situations like this, 2 or more threads can spend most of their time trying to access each others data which just results in a huge waste of time. In fact, even moderate examples of this can result in 2 threads ultimately being slower than a single thread (possibly with cooperative multitasking as a substitute for real multi threading).

Hope this makes sense

~Andrew
Image

nikoj
Posts: 8
Joined: Sat Oct 04, 2008 11:59 pm

Post by nikoj » Sun Dec 07, 2008 2:19 am

so if i write huge program for banking it will not use all cores...

why then we are buying this kind of CPU's if they dont use all the power?

roboman
Posts: 12
Joined: Fri Nov 28, 2008 10:02 pm
Location: usa
Contact:

Post by roboman » Sun Dec 07, 2008 10:19 am

Games, CAD, CAM, 3d Animation, Engineering apps and a few other things go a lot faster. Besides people like the fastest new gizmo....

Andyhhp
Moderator
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1
Contact:

Post by Andyhhp » Sun Dec 07, 2008 10:41 am

so if i write huge program for banking it will not use all cores...

why then we are buying this kind of CPU's if they don't use all the power?


What you are slightly confused about is the difference between thread multitasking and process multitasking.

To start with, I shall clarify what I mean (because some people use different definitions). A process nominally has a 4GB virtual address space and 1 or more threads. A thread, on the other hand, is what your thread scheduler uses to get the program to run.

If a process has a single thread, its a single threaded process (i hope that's clear :P) whereas if it has more than one thread, its a multi threaded process. With a multi threaded process, it is possible to run each thread on a different core at the same time. However, we run into the problems we talked about before when this starts happening.

Now, because you have 4 cores (for sake of argument), there is nothing to stop you running 4 processes at once. Each process nominally has a different 4GB virtual address space so they don't interfere with each other. If they need to communicate, they have to use the kernel.

Because of that, it is perfectly possible for you to have your kernel running on the first core, your <insert> playing music on the second core while you sit and play your <insert> on the third core, all topped off with your fourth core sitting and compiling the latest version of your kernel (why else are you on these forums :P).

I hope this clarifys the use of use of many cores with many single threaded processes.

~Andrew
Image

nikoj
Posts: 8
Joined: Sat Oct 04, 2008 11:59 pm

Post by nikoj » Mon Dec 08, 2008 3:44 am

u miss understand me.

anyway good explanation for my friend to understand something :)

Post Reply