Single threaded process being executed on 2 cores

2

0

On my quad core cpu, it seems like a single thread (endless while loop) is being executed on 2 cores simultaneously. Why is this? Shouldn't a single thread be executed on one core only? enter image description here

agz

Posted 2013-10-03T08:13:57.863

Reputation: 6 820

Nevermind that an average process always has more than one thread, set the process affinity to limit the process to running all its threads on one core. – ta.speot.is – 2013-10-06T09:15:51.270

Answers

4

A single tread can be run on as many cores as you have, but it will be limited to a single core at the same time.

Think of it as a phone conversation. You only have one single phone*1 and you need to keep talking into the phone*2. You have four people in the office, each capable of speaking*3 . Nothing prevents you from handing over the phone to another person while taking a toilet break.

Note that there is only one person speaking into the phone at the same time.


*1 The phone is the single tread.
*2 Need to keep talking as in it runs endlessly.
*3 The four people are ofc. the four cores.

Hennes

Posted 2013-10-03T08:13:57.863

Reputation: 60 739

An actual advantage of switching cores is the temperature - by switching, you are not heating the same area of the chip all the time. That will also make it possible to run at a higher clock speed because the maximum temperature is lower. – gnasher729 – 2014-07-11T21:55:28.683

This could be a good point for modern CPU's. Though once again I do not have the knowledge on heat dissipation and internal microcode which manages the turbo's. For a core2 this should not matter though since they do not have turbo. That feature was introduced with the Nehalem series (core i7 9x0 and later). – Hennes – 2016-01-15T08:21:49.803

How would the resources be managed? Is there a need to transfer L1 cache across the cores? Why doesn't it just execute on one core rather than 2 cores (is there a benefit...it seems like quite the contrary imo)? – agz – 2013-10-05T20:20:37.057

>

  • Which resources? Could you expand that to be a bit more specific?

  • It is the scheduler in the OS decides on which core the process will run. Usually those try to keep the same process on the same core in order to benefit from cache hits and potential turbo boost features.

  • Cache coherency is handled by the CPU itself on the x86 architecture. You did not specify that you are using x86, but the picture of a task manager strongly hints at window and thus usually to x86.

  • – Hennes – 2013-10-05T20:26:24.080

    Did you take that taskmanager picture on a 2 physical, 4 logical core CPU? – Hennes – 2013-10-05T20:28:13.277

    It is a core 2 quad q9650, 4 physical cores and 4 threads – agz – 2013-10-05T20:48:37.947

    "Usually those try to keep the same process on the same core in order to benefit from cache hits and potential turbo boost features" That is what I was looking for. Is there a specific reason why it executes on 2 cores? On my dual core system the same process executes on one core only. – agz – 2013-10-05T20:49:41.483

    2I do not have access to the windows task scheduler source or its logic. So I can not answer that for windows. The best I can do is guess. E.g. a driver which has a strong preference for core 0 which pushed the tread to another core. But I repeat: Guess – Hennes – 2013-10-05T21:01:11.020

    0

    In your screenshot I can see not two, but 4 threads using 4 cores in perfect harmony, with one couple of cores using their CPU more than the other couple, but the highs and lows of all the 4 cores are more or less synchronized to the same time segments.

    This doesn't look at all like a single threaded process, but more like a 4-threaded process. This needs more examination.

    The tool to use is Process Explorer. After you launch it, you can right-click the column-headers and select more columns if needed.

    Once you locate the process that is using these CPUs, you can double-click it and choose the Threads tab to see how many threads it has and what they are doing (which system calls they use).

    If the process is just svchost.exe, it is a system service, which can be identified. The one most likely to be using heavily the CPU is Windows Search.

    harrymc

    Posted 2013-10-03T08:13:57.863

    Reputation: 306 093

    0

    That display in your posting is showing you how much activity is going on for each core but it tells you nothing about which processes/threads are running on which core.

    I suspect that as your single threaded program gets it's "time slice" the OS is running it on one core half the time and another core the other half of the time. Maybe it even runs on the other cores some small part of the time too.

    As an infinite loop it is using the core fully for the duration of it's time-slice, but any time increment of core activity (in the Task Manager) will represent MUCH MORE than the duration of single time slices.

    For further insight as to what is going on, switch to the Processes tab on the Task Manager. On the View Menu, click Select Columns then tick the "Threads" column. Then on the Image name column find your process. Confirm that it is a single thread.

    As I sit here with not that much "load" on my XP box there are 662 threads running. My Antivirus is running 78 threads, Firefox is running 45 threads, Dropbox is running 33. Winamp is not playing anything at all right now and it is still running 17 threads. Any increment in the Task Manager display could have had all of those threads on any core.

    Arbalest

    Posted 2013-10-03T08:13:57.863

    Reputation: 163