Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the number of Hardware Threads

What is meant by a hardware thread. Is it always double the number of processor cores available? How to determine the number of hardware threads in an Intel Core2 Duo processor? Can it be determined through Java code?

like image 526
softwarematter Avatar asked Nov 25 '10 08:11

softwarematter


2 Answers

What is meant by a hardware thread.

You tell us. It's not really an established term.

Is it always double the number of processor cores available?

Ah, now it seems like you're talking about hyperthreading where partial redundancies within a CPU core are used to "fake" an additional core.

How to determine the number of hardware threads in an Intel Core2 Duo processor? Can it be determined through Java code?

You could try to find something in the system properties, but it's not going to be standard (i.e. depends on the JVM and OS).

Personally, I'd just use a sensible default (4 or 8 threads - having a few too many is perferable to not using available cores) and make it configurable.

like image 111
Michael Borgwardt Avatar answered Sep 19 '22 00:09

Michael Borgwardt


It's definately not the case that the number of hardware threads is twice the number of cores -- AMD processors don't have any sort of hyperthreading ( yet ), and hyperthreading may be turned off in the BIOS (as is usually was for pre-nehalem processors, as it really didn't buy you very much in practice). There's also no reason why it would necessarily have to only be two hardware threads per core -- Power7 systems have 4 per core.

There's no OS- or hardware-independant way to do these checks. The only library I know that fairly portably can query this information is the hardware locality (hwloc) library . It's a C library, so should be pretty simple to call from Java.

like image 28
Jonathan Dursi Avatar answered Sep 18 '22 00:09

Jonathan Dursi