0

I have been interested in hyper threading and how can applications benefit from it. From what I have read, hyper threading is directly managed by the operating system and it is related to how virtual threads running on each core access shared execution units on each core. Most posts were suggesting that it is something you should not care about, and should let the operating system manage it.

I was okay with the answer until I ran into a setting in one game which completely put me off. There is a game called Arma 3 which has a "Hyper threading" setting in the options. I bothered to google around a bit and stumbled upon a post from the developer which explains what the setting does. He said exactly this

what it does is tell the engine to use HT cores only for threads with minor tasks / micro jobs ... just remember that -cpuCount= negates the -enableHT

Now from what I have read about HT and how it works, there should not be any direct way to tell the application to use hyper-threading. Apparently the setting "does some magic" inside the engine which tells is to use HT for specific tasks.

Could anyone please clear this up for me? Because it is honestly confusing. Thanks.

0

Explaining the reason Hyper Threading helps at all requires some explanation of what exactly it is, and in turn how resources are shared in a processor.

Background

A traditional multi-core CPU shares very little in terms of internal resources between the cores. In most older cases, only the L3 (and possibly L4 if it existed) cache was shared between cores, everything else was unique to each core. Because of how computers work, this ends up resulting in most parts of a core not actually being used by every instruction executed on it.

Dealing with that inefficiency is where Hyper Threading comes in. The general idea is that by sharing many of the resources between two (or more) cores, you can achieve nearly the same amount of work using far less space (and power). The limitation to this is, of course, that you can't truly run 100% of what you could on a CPU with a number of physical cores equal to however many total threads you have.

It's probably worth noting that Hyper Threading is not the same thing as the Symmetric MultiThreading provided by some other CPU architectures (POWER, SPARC, and (probably) AMD's Ryzen chips). SMT is much closer to a classical multi-core design, and doesn't suffer from most of the issues that Hyper Threading does.

So, if you can't just run anything on all the cores, what exactly is it good for?

Well, it's actually kind of hard to say. To get the most benefit possible, you actually have to group similar code onto pairs of threads that share resources inside the CPU), but even then it's hard to be certain if Hyper Threading will actually help much. Some older operating systems did not do this type of grouping at all, and the results are still considered a prime example of the phrase 'pathologically bad'. Newer systems do some level of grouping, but it's still not perfect.

I/O heavy tasks (for example, web-servers and databases) actually tend to benefit at least some from Hyper Threading, but how much they will benefit depends on exactly what they are doing, and they're one of the few cases that has a reasonably clear-cut benefit.

It is however reasonably well known what types of workloads do worse with SMT. Pretty much anything that needs to utilize all the cores of the CPU at 100% load is going to not get much, if any, benefit from SMT. On HT chips, it actually will sometimes run slower than with HT off. On some other implementations it may or may not improve things or make them worse, depending on what's being done (for example, SPARC chips do fine with such workloads, provided they don't do really deeply nested function calls).

OK, so what's with this Arma 3 thing?

As mentioned above, Hyper Threading can do very bad things to your performance if you aren't grouping things sensibly on each core. The logic needed to do that grouping is usually specific to a particular piece of software. The aforementioned switch for Arma 3 is just controlling whether this logic is on or not. Now, as to why it's not autodetected, I'm not quite sure (it's not like it's hard to figure out if Hyper Threading is being used or not).

  • Can you specifiy what you mean by "Grouping the code". I have been googling around C++ channels (Since I am a C++ Developer) and from what I have read there is no way to programmaticaly use hyperthreading. All you have to do is fire up a thread and let the OS handle it. Can you clarify that? – Erik9631 Sep 5 '18 at 21:01
  • @Erik9631 There's no way to programmatically use HyperThreading directly. You can however tell the scheduler what logical core to put each of your threads and processes on, which lets you control which thread on which physical core they get run on. The system call for this on Linux is called sched_setaffinity, I'm not quite sure what the Windows equivalent is but I know one exists. On most systems, the two threads are grouped together in the logical core ordering (so 0 and 1 are one physical core, 2 and 3 are the next, etc), so figuring out placement isn't hard. – Austin Hemmelgarn Sep 6 '18 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.