15

Can two processes simultaneously run on one CPU core, which has hyper threading? I learn from the Internet. But, I do not see a clear straight answer.

Edit: Thanks for discussion and sharing! My purse to post my question here is not to discuss about parallel computing. It will be too big to be discussed here. I just want to know if a multithread application can benefit more from hyper threading than a multi process application. After further reading, I have following as my learning notes.

1) A Hyper-Threading Technology enabled CPU Core has two set of CPU state and Interrupt Logic. Meanwhile, it has only one set of Execution Units and Cache. (I have not study what is pipeline yet)

2) Multi threading benefits from Hyper Threading only if there is latency happen in some executed thread. I think this point can exactly map to the common reason for why and when software programmer use multi thread. If the multi thread application has been optimized. It may not gain any benefit from Hypter threading.

3) If the CPU state maps to process state, I believe Marc is correct that multiple process application can even benefit more from hyper threading technology.

4) When CPU vendor says "thread", it looks like their "thread" is different from thread that I know as a java programmer?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Yiyu Jia
  • 171
  • 1
  • 1
  • 8

3 Answers3

2

No, a hyperthreaded CPU core still only has a single execution pipeline. Even though it appears as two CPUs to the overlying OS, there's still only ever one instruction being executed at any given time.

Hyperthreading was intended to allow the CPU to continue executing one thread while another thread was stalled waiting for a resource or other operation to complete, without leaving too many stages of the pipeline empty and useless. This goes back to the Pentium 4 days, with its absurdly long pipeline - a stall was essentially catastrophic for efficiency and throughput, and hyperthreading allowed Intel to keep the cpu busy doing other things while it cleaned up from the stall.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Thanks for confirm that two process can not run on same CPU core at same time. But, you also mentioned about thread in your answer. It looks for me that two thread can not run simultaneously too? Or, you only talk about the case where two thread has shared resources? Two threads, which has no shared resource, can run simultaneously on same core having hyper threading, right? – Yiyu Jia Jan 18 '12 at 21:52
  • There can be two threads coexisting within the pipeline of any given core, in various stages of decoding/preprocessing/execution/finalizing. Where in all of that the actual "execution" occurs depends on how you define 'execution'. There will never be more than one thread's instruction(s) at any given pipeline stage at the same time, so there's still no parallel execution. merely parallel-appearing. – Marc B Jan 18 '12 at 21:54
  • thanks for clarifying. looks like our discussion is sliding to parallel execution and multitask and multithread programming. According to my understanding so far, I think we can say a multi-threaded application have chance to get benefit from hyperthreading CPU. and a multi process application can not get benefit from hyper threading. will you agree with me? – Yiyu Jia Jan 18 '12 at 22:02
  • 1
    Actually, multi-process is what benefits the most from hyperthreading, because each process is more likely to NOT depend on the same resource(s) as other processes, unlike threads which will more likely be accessing those same resources. – Marc B Jan 18 '12 at 22:06
  • Hi Marc, I am confused now. I learned that "The advantages of hyper-threading are listed as: improved support for multi-threaded code, allowing multiple threads to run simultaneously". I never saw any article, which explicitly declares that Hyper Threading benefit multi process application more than multi thread application. Are you saying two process can run on one hyper threading core simultaneously? If not, how come multi-process benefits the most from hyperthreading? – Yiyu Jia Jan 18 '12 at 23:49
  • http://stackoverflow.com/questions/680684/multi-cpu-multi-core-and-hyper-thread This post says "One chip on the mainboard but it had some parts twice internally so it could execute two instructions at the same time." But, it did not answer my question about if multiple process applicaiton can not get benefit from hyperthreading CPU core as multi threading app may have chance to have. – Yiyu Jia Jan 18 '12 at 23:58
  • 2
    "there's still only ever one instruction being executed at any given time" -- this is simply not true for modern superscalar CPUs, even without hyper-threading - there are multiple pipelines and execution units which may be executing several instructions concurrently – Paul R Jan 19 '12 at 09:19
  • @PaulR: true, but that's only because there's multiple cores and multiple pipelines. Hyperthreading doesn't add more pipes, it just makes a single pipe look like more. In any give pipeline there's still only ever one instruction executing at a time. – Marc B Jan 19 '12 at 14:21
  • @Marc Hi Marc, thanks for answer my questions. Will you agree with my conclusion in my original question? – Yiyu Jia Jan 19 '12 at 15:09
  • @Marc B: not really anything to to do with multiple cores - even single core superscalar CPUs have multiple pipelines and execution units which enables multiple instructions to be issued/executed/retired per clock cycle giving a throughput of > 1 instruction per clock. – Paul R Jan 19 '12 at 15:29
  • @PaulR Hi Paul, I learn a new term superscalar CPU from you. But, after a quick searching on the internet. it looks like superscalar CPU only adopted in supercomputer? – Yiyu Jia Jan 19 '12 at 15:49
  • 2
    @Yiyu Jia: no, that may have been true 20 - 30 years ago, but superscalar CPUs have been pretty much the norm for all desktop and server CPUs for the last 10 years or more, and are increasingly finding their way into low end embedded applications such as phones and tablets. – Paul R Jan 19 '12 at 16:05
  • @PaulR I got my conclusion as above after I read this article: http://www.intel.com/intelpress/samples/mcp_samplech01.pdf . its name is . On page 9, there is a diagram. But, there is no word about superscalar in the document. Maybe we will see superscalar once we dig deep into Execution units? – Yiyu Jia Jan 19 '12 at 16:12
  • 2
    @Yiyu: superscalar relates to the micro-architecture of a core - the document you are looking at relates to multi-core architectures, which is a higher level concept. – Paul R Jan 19 '12 at 16:16
  • @PaulR Thank you for pointing out. Then, do you agree with the following statement? "3) If the CPU state maps to process state, I believe Marc is correct that multiple process application can even benefit more from hyper threading technology." – Yiyu Jia Jan 19 '12 at 16:45
  • Copied from wiki: "limits drive investigation into alternative architectural changes such as Very Long Instruction Word (VLIW), Explicitly Parallel Instruction Computing (EPIC), simultaneous multithreading (SMT), and multi-core processors." URL: http://en.wikipedia.org/wiki/Superscalar For me, it implies that we superscarlar has been replaced by multi core. – Yiyu Jia Jan 19 '12 at 18:27
  • 2
    Sorry, I was wrong. i did not see the last statement. "cited from wiki : "he various alternative techniques are not mutually exclusive—they can be (and frequently are) combined in a single processor. Thus a multicore CPU is possible where each core is an independent processor containing multiple parallel pipelines, each pipeline being superscalar. Some processors also include vector capability." http://en.wikipedia.org/wiki/Superscalar" – Yiyu Jia Jan 19 '12 at 18:36
  • 1
    @yiyu: nothing magical about multi-core. not too different than old school SMP multi-socket motherboards, except it's multiple cores per chip, rather than per motherboard, and each of those cores is still almost certainly a superscalar design. – Marc B Jan 19 '12 at 18:40
  • @MarcB Thanks Marc. So, will you agree with my third conclusion "3) If the CPU state maps to process state, I believe Marc is correct that multiple process application can even benefit more from hyper threading technology." ? I guess you will. Also, I feel is that the supersclar may not affect application level multithreading programming as it is a instruction level parallelism. – Yiyu Jia Jan 19 '12 at 19:03
  • Note that absolutely none of the above is relevant to modern hyper-threaded CPUs which work very differently from the ones back in 2011. – David Schwartz Aug 07 '16 at 03:42
  • @DavidSchwartz: no, Nehalem / Sandybridge (2011 vintage) hyperthreading works almost exactly the same as in Haswell and Skylake (and Zen): statically partition some resources, competitively share others, with uops from both threads in flight in the back end at once. At the level this answer gets into, they work the same as even the ancient P4 it mentions. The parts that are wrong (like 1 instruction per clock max) have always been wrong for Intel Hyperthreading. It was true for simpler in-order CPUs like UltraSPARC Niagara which focused on throughput not latency, and having many cores. – Peter Cordes Feb 02 '21 at 07:46
  • For some details of how it does work, see https://www.realworldtech.com/haswell-cpu/3/ - a physical Haswell core is 4-wide (at the issue/rename bottleneck), with the front-end alternating between the two logical cores, unless one is stalled or in a sleep state. – Peter Cordes Feb 02 '21 at 07:54
2

While Marc B's answer is pretty much the definitive summary of how HT works, I just want to make a small contribution by linking this article, which should clear up a lot of things about HT: http://software.intel.com/en-us/articles/performance-insights-to-intel-hyper-threading-technology/

Tudor
  • 61,523
  • 12
  • 102
  • 142
  • Thanks for sharing. After a quick reading, I learn two terms: software thread and hardware thread. Let me learn more. – Yiyu Jia Jan 23 '12 at 21:29
1

Short answer, yes.

A single core cpu(a processor), can run 2 or more threads simultaneously. These threads may belong to the one program, or they may belong different programs and thus processes. This type of multithreading is called Simultaneous MultiThreading(SMT).

Information that claims cpu core can execute only one instruction at any given time is also not true. Modern CPUs exploit Instruction Level Parallelism(ILP) by duplicating pipeline resources(e.g 2 ALUs instead of 1). This type of pipeline is called "superscalar" pipeline.

Wikipedia page of Simultaneous Multithreading:

Simultaneous multithreading