最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

multithreading - Context switching in hardware threads - Stack Overflow

programmeradmin6浏览0评论

In Hyper-threading (or SMT) when two threads of a CPU core gets swapped in and out, does a context-switch occur.

Would it be called a context switch?, if not what is the terminology for it.

In Hyper-threading (or SMT) when two threads of a CPU core gets swapped in and out, does a context-switch occur.

Would it be called a context switch?, if not what is the terminology for it.

Share Improve this question edited Mar 23 at 11:48 Peter Cordes 367k49 gold badges717 silver badges981 bronze badges asked Mar 23 at 4:47 RishiRishi 415 bronze badges 4
  • 2 Threads share the same core cpu and memory/resources in a process; when the core is the same; no context is being switched. – www Commented Mar 23 at 4:57
  • 2 Each logical core of an SMT machine behaves like a separate CPU. If both are active at once, they're not "swapping", they're alternating cycles in the front end but instructions from both logical cores can be executing simultaneously in the back-end. realworldtech/alpha-ev8-smt The ROB (reorder buffer) is normally partitioned in half. (Or in quarters or 8ths, depending on number of logical cores per physical core). Physical registers are normally competitively shared. The right terminology to describe how such a CPU works is "SMT". – Peter Cordes Commented Mar 23 at 11:46
  • 1 See also en.wikipedia./wiki/Simultaneous_multithreading . Or are you talking about something else, like when the kernel on one or both logical cores does a context-switch to different software threads? – Peter Cordes Commented Mar 23 at 11:49
  • @PeterCordes No, you answered my question perfectly. Thank you so much. – Rishi Commented Mar 23 at 23:57
Add a comment  | 

1 Answer 1

Reset to default 2

...Would it be called a context switch?

There is no "it" there.

A thread's context consists of the contents of all of the hardware registers that the OS must save to memory when suspending execution of the thread and which, the OS must load back into hardware registers in order to resume execution of the thread. "Context switch" is what we call it when the operating system suspends the thread that currently is running on a certain CPU, and then resumes a different thread on the same CPU.

A hyperthreaded/SMT CPU has more than one set of context registers. As mentioned in comments by Peter Cordes and www, it can concurrently execute instructions on behalf of two or more threads without any context switching. (That is to say, without any saving of register contents to memory and restoring register contents from memory.) The hyperthreaded/SMT CPU behaves as if it was two or more, separate logical CPUs, and it's those separate logical CPUs that are the target of context switches that are performed by the operating system.


P.S., The motivation for "hyperthreading" is that the logical CPUs share some hardware resources, and on average they perform almost as well as if they were entirely independent of each other, but they occupy a considerably smaller footprint on the silicon than the same number of fully independent CPUs would occupy.

发布评论

评论列表(0)

  1. 暂无评论