0

The idea behind Intels hyperthreading is (as far as I understand) that one core is used for two threads in a time-multiplexed manner.

The HW support this by having the state-related resources doubled and time-sharing other resources. If the running thread stalls (e.g. because it has to fetch new data from RAM), the other thread gets access to the shared resources. The result is a better utilization of the shared resources.

So if one thread isn't ready, the other thread is allowed to run. In other words - a thread switch can happen when the executing thread stalls.

I've tried to find out what will happen if both threads are ready for a long time but I haven't been able to find the information.

What happens if the running thread doesn't stall?

Will the running thread continue as long as it is ready?

Will the core switch to the other thread after some time? If so - what is the criteria for the switch? Is it controlled by HW or SW?

Support Ukraine
  • 42,271
  • 4
  • 38
  • 63

1 Answers1

1

Hyperthreading is simultaneous multithreading (SMT). So it doesn't just switch back and forth on some relatively coarse-grain scale (like stalls), in the case of Sandy Bridge and newer, the fetcher and the decoder alternate between the threads. Execution units are shared competitively, so even if neither thread is stalling they can still together achieve a better utilization than if they ran alone (but that's not typical). So the problems you identified don't apply, because it doesn't work like that in the first place.

harold
  • 61,398
  • 6
  • 86
  • 164
  • thanks for the answer. So you say I have misunderstood the concept. I'm a bit surprised as I have read this on several internet sites. Example: http://en.wikipedia.org/wiki/Hyper-threading which states "These shared resources allow the two logical processors to work with each other more efficiently, and lets one borrow resources from the other when one is stalled" ... (continued in next comment) – Support Ukraine May 09 '15 at 17:13
  • (continued comment) ... and "and especially when the processor is stalled, a hyper-threading equipped processor can use those execution resources to execute another scheduled task. (The processor may stall due to a cache miss, branch misprediction, or data dependency.)". Another example is http://stackoverflow.com/questions/23078766/is-hyperthreading-smt-a-flawed-concept Anyway, if I got it all wrong, I like to read up on it - can you provide a/some good links? Thanks. – Support Ukraine May 09 '15 at 17:14
  • Well, it's still true that if a thread is stalled, the other thread can fill the gap. But it doesn't "switch to that thread", it was already executing it all along, now it just has more resources available to it. – harold May 09 '15 at 17:20
  • your answer states "Execution units are shared competitively". Can you elaborate that a bit. How is it decided which thread will get the execution unit that the both threads needs? – Support Ukraine May 09 '15 at 17:26
  • The same way as usual, the oldest µop that is ready (ie it is not waiting for its operands to become available) will be selected, doesn't matter which thread it's from. – harold May 09 '15 at 18:01