How to verify if your processor supports hyper-threading?

899 views Asked by At

This is my first post on StackOverflow so I apologize if I have broken some rules.

My Professor, (not a great one) has just told us we have 24 hours to write a program under 10 lines of code that verifies if your processor architecture provides support for hyperthreading operation.

To say the least, I don't know what he wants as well as even how to begin. I believe he wants it in C++ but got upset when I asked that question and didn't tell me what language to do it in.

When I told him I didn't understand what he was asking he got very upset and told me that I must not have been paying attention. I honestly have been and even have been taking notes. I guess this Operating Systems course just isn't sinking in with me.

I have tried my own research by reading the intel manual, but no luck (Also it is 5000+ pages). I have googled around to understand the basics of hyper-threading, that you can run 2 processes at the same time (If that is correct), but have no idea how to turn that into code.

Any help would be amazing!

1

There are 1 answers

4
eerorika On

How to verify if your processor supports hyper-threading? ... in C++

There is no standard way to do this in C++.

If you know the CPU that the program will run on, then you may find a way described in the documentation of the CPU. For example, 486 and later x86 processors have the CPUID instruction. The relevant information that you need is "Number of logical processors per physical processor package (CPUID.1.EBX[23:16])". If this value is greater than 1, then Hyper-Threading or similar is enabled.

To execute instructions such as CPUID, you need to write in assembly language rather than C++. That said, if you are within an operating system, then it may offer a nice API to access this functionality (see comments for examples).

A less CPU-specific way to implement this is to read the SMBIOS if that is supported on your target system. Here, you can divide processor thread count by core count to get the same value as above. You can, for example, see the implementation of the dmidecode program on Linux to see how that can be read.