How do SMP cores, processes, and threads work together?

On one central processor, each process runs in the OS, and the processor jumps from one process to another in order to make the best use of it. A process can have many threads, in which case the CPU starts through these threads when it is running in the corresponding process.

Now, on a multi-core processor:

  • Are kernels supported in each process, or can kernels work separately in different processes at a particular point in time? For example, you have program A that starts two threads. Can a dual-core processor run both threads of this program? I think the answer should be yes if we use something like OpenMP . But while the cores work in this OpenMP process, can one of the cores simply switch to another process?

  • For programs created for a single core, at startup at 100%, why use the CPU load of each core? (for example, a dual-core processor 80% and 20%. The utilization rate of all cores can always be up to 100% for this case.) Are the cores capable of helping each other by controlling each thread of each process, in a sense

+44
multithreading cpu-architecture multiprocessing operating-system multicore
Jun 07 2018-10-06T00:
source share
5 answers

Kernels (or processors) are the physical elements of your computer that execute code. Usually each core has all the necessary elements for performing calculations, registering files, interrupt lines, etc.

Most operating systems present applications as processes . This means that the application has its own address space (== memory view), where the OS ensures that this view and its contents are isolated from other applications.

A process consists of one or more threads that perform the actual work of the application by executing machine code on the CPU. The operating system determines which thread runs on which CPU (using smart heuristics to improve load balance, power consumption, etc.). If your application consists of only one thread, then your entire multiprocessor system will not help you, since it will use only one processor for your application. (However, overall performance may still improve, since the OS will run other applications on different processors so that they do not mix with the first).

Now to your specific questions:

1) The OS usually allows you to at least give hints about which kernel you want to execute certain threads on. What OpenMP does is generate code that generates a certain number of threads to distribute the total computing work from your program's loops into multiple threads. He can use the OS prompt tool (see: Thread Affinity) for this. However, OpenMP applications will still run simultaneously with others, and therefore, the OS may interrupt one of the threads and schedule other (potentially unrelated) work with the CPU. In fact, there are many different planning schemes that you might want to apply depending on your situation, but this is very specific, and most of the time you need to be sure that your operating system will do the right thing for you.

2) Even if you use a single-threaded application on a multi-core processor, you will notice that other processors also work. This happens: a) from the OS that does its work, and b) due to the fact that your application never starts alone - each working system consists of a whole group of simultaneously performing tasks. Check Windows Task Manager (or ps / top on Linux) to see if it works.

+42
Jun 07 '10 at 6:23
source share
β€” -

Note also that the OS does not care about which process the threads come from. Typically, they plan threads for processors / cores regardless of which process the thread comes from. This can lead to the fact that four threads from one process will be executed simultaneously, in the same way as one thread from four processes working simultaneously.

+9
Jun 07 '10 at 3:59
source share

@BjoernD, you mentioned that ..

.. If your application consists of only one thread, then your whole multiprocessor system will not help you, because it will still use one processor for your application ...

I think that even if it is a single-threaded application, this application flow can run on different cores throughout its life cycle. With each correction and subsequent assignment to the processor, a different core may be assigned to this thread.

+6
Jul 20 '13 at 10:16
source share

Yes, threads and processes can run simultaneously on multi-core CPUs, so it works as you describe (regardless of how you create these threads and processes, OpenMP or otherwise). One process or thread runs only one core at a time. If there are more threads that require CPU time than available kernels (in the general case), the operating system scheduler will move the threads to and off the kernels as needed.

The reason single-threaded processes run on multiple processors or cores is related to your operating system, and not to any hardware feature. Some operating systems do not have any sense of "thread affinity" - they don’t care which processor is running in the thread, so when it comes time to reevaluate which resources are used (at least several times per second) Move the thread / process from one core / processor in another. Besides skipping the cache, this usually does not affect the performance of your process.

+4
Jun 07 '10 at 3:45
source share

If there is one thread application that says 10 threads, it initially runs on the same processor / core. After some time, several threads will be distributed among other cores / processors due to load balancing in Linux. If there are several such thread applications, I think that all application threads are mostly running on the same core / processor, since the locals / globals of the threads are easily accessible in the l1 / l2 cache of the kernel in which they were running. they take a lot of time from the kernel than their execution time. If threads should run in a different kernel. I think we need to provide information about proximity to the stream.

0
Jun 23 '16 at 6:41
source share



All Articles