You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ability to tell how many physical CPU's are on a system #353
PR welcomeNot maintainer's priority to do but will accept contributions!good first issueGood issues for new contributors to work onnew featureSomething OSHI doesn't do now but could do
Apologies as this is my first foray onto Github after lurking for many many years, so if this is a really dumb question, I'll take my licks.
I'm trying to gather a bunch of information about our testing machines so that when we record performance results, we can also include the server configuration of the test machine to see a complete picture.
Ideally I'd like to be able to determine that there are:
1 CPU / 4 Cores for my work station and
2 CPU's / 12 Cores for my test machine that I'm currently working with.
Note that I'm specifically avoiding the use of the term "Processor".
Currently I'm hung up on trying to determine if a test machine has more than one physical CPU (as in more than one CPU on the motherboard).
When I run the following code on my single quad-core CPU workstation, I get 4 for both:
int cpuCount = centralProcessor.getPhysicalProcessorCount(); -- returns 4
int coreCount = centralProcessor.getLogicalProcessorCount(); -- returns 4
We have test machines that have 1-2 CPU's installed, and we want to make that determination. Is there anyway to do this with OSHI?
There's no stupid questions, only stupid people that won't learn when advised :P
That said, the problem is that the stats recovered by OSHI are for physical and logical processors.
And, just like you avoided using that term for your needs (which is perfect for your situation), these values are only peripherally related to the ones you need.
Just as a simple run down:
A QuadCore CPU has 4 Physical Processors.
Every Physical Processor, depending on their internal architecture, can be used as 1 or more Logical Processors.
For example, AMD MultiCore Archs were notorious for giving you 2 Logical Processors for every Physical Processor.
So, Physical Processors is actually your Core Count.
For the Microprocessor Count you'd need to check if your system has more than one Processor. I'm pretty sure that most of the SO functionalities OSHI checks for processor data does give you separate data for each Microprocessor, so it shouldn't be impossible
At oshi/oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
private void initVars() lines ? to ?:
{
final String cpuRegistryRoot = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor";
String[] processorIds = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, cpuRegistryRoot);
if (processorIds.length > 0) {
String cpuRegistryPath = cpuRegistryRoot + "\\" + processorIds[0];
//All the processor var setting is here
}
//... Rest of the method
As you can see, when running on Windows, we get all the processors, but discard everyone but the first one if there's more than one.
Maybe, we could refactor the code to some kind of linked list?
To avoid modifying th API too much, at least until the next major release, we could have each processor have a field linking to the next processor.
I'll check on the other classes, but I think I'll find something pretty similar
Cheers for your reply, the terminology was giving me fits just writing my question. ;)
Having looked at the Windows Registry information that the code you shared is referencing, it just lists all the Processors/Cores on the system. The only difference in the registry is the Component Information binary value, which isn't very helpful.
It'd be nice if there were unique identifiers to tie each processor to the physical Microprocessor, but I don't think I see one at that spot in the registry.
There must be some way to get at that information, perhaps via some mechanism like "wmis".
OSHI's MO for data recovery is always to go directly to the SO's data first, then (if that wasn't possible) call one of the SO's APIs for the data, and then go for any util library that might be common to find preinstalled.
Also, the tool gives precedence to solutions that won't require admin/root equivalent privileges to ones that would require them.
That's why most Windows stats are recovered directly from the registry if possible.
However, some info is recovered from WMI...
I'm happy to grab processor info from WMI rather than the registry.
But as I understand we're actually looking for 3 layers of data here? Chip, core, and virtual processor (which really is only intended to model hyperthreading)?
As a stopgap method, that would work pretty well.
I'd love to come back to this for the next major release, and actually try to parse WMI's data on the processors to have the Hardware Interface actually show each processor as a separate CentralProcessor object
Taking notes in case this ever gets done. For macOS, system_profiler SPHardwareDataType has an entry Number of Processors that represents the physical package. (My system has 1 processor, 4 cores (physical cpu), and 8 logical cpu.)
FreeBSD/SMP: Multiprocessor System Detected: 4 CPUs
FreeBSD/SMP: 1 package(s) x 4 core(s)
Also it appears our current parsing of sysctl kern.sched.topology_spec may have that -- count the number of group level 2's. The below is an example of a 2-package system:
PR welcomeNot maintainer's priority to do but will accept contributions!good first issueGood issues for new contributors to work onnew featureSomething OSHI doesn't do now but could do
Activity
YoshiEnVerde commentedon May 5, 2017
There's no stupid questions, only stupid people that won't learn when advised :P
That said, the problem is that the stats recovered by OSHI are for physical and logical processors.
And, just like you avoided using that term for your needs (which is perfect for your situation), these values are only peripherally related to the ones you need.
Just as a simple run down:
A QuadCore CPU has 4 Physical Processors.
Every Physical Processor, depending on their internal architecture, can be used as 1 or more Logical Processors.
For example, AMD MultiCore Archs were notorious for giving you 2 Logical Processors for every Physical Processor.
So, Physical Processors is actually your Core Count.
For the Microprocessor Count you'd need to check if your system has more than one Processor. I'm pretty sure that most of the SO functionalities OSHI checks for processor data does give you separate data for each Microprocessor, so it shouldn't be impossible
YoshiEnVerde commentedon May 5, 2017
After checking the code, we can see:
At oshi/oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
private void initVars() lines ? to ?:
As you can see, when running on Windows, we get all the processors, but discard everyone but the first one if there's more than one.
Maybe, we could refactor the code to some kind of linked list?
To avoid modifying th API too much, at least until the next major release, we could have each processor have a field linking to the next processor.
I'll check on the other classes, but I think I'll find something pretty similar
saintGH commentedon May 5, 2017
Cheers for your reply, the terminology was giving me fits just writing my question. ;)
Having looked at the Windows Registry information that the code you shared is referencing, it just lists all the Processors/Cores on the system. The only difference in the registry is the Component Information binary value, which isn't very helpful.
It'd be nice if there were unique identifiers to tie each processor to the physical Microprocessor, but I don't think I see one at that spot in the registry.
There must be some way to get at that information, perhaps via some mechanism like "wmis".
YoshiEnVerde commentedon May 5, 2017
OSHI's MO for data recovery is always to go directly to the SO's data first, then (if that wasn't possible) call one of the SO's APIs for the data, and then go for any util library that might be common to find preinstalled.
Also, the tool gives precedence to solutions that won't require admin/root equivalent privileges to ones that would require them.
That's why most Windows stats are recovered directly from the registry if possible.
However, some info is recovered from WMI...
saintGH commentedon May 5, 2017
I did notice WMIUtil, and also noticed the command is "wmic" not "wmis" as I had previous stated. Getting my acronyms mixed up.
I just noticed that you can run:
C:\Users\Administrator>wmic cpu get SocketDesignation
From the command line and get:
SocketDesignation
Proc 1
Proc 2
Meaning, there's two processors on my server. When I run against my single-CPU workstation I get:
SocketDesignation
SOCKET 1
saintGH commentedon May 5, 2017
Just playing around, looks like the following would work:
public int getCpuCount() {
return WmiUtil.selectStringsFrom((String)null, "Win32_Processor", "SocketDesignation", (String)null).size();
}
Coincidentally I also need the Core Speed, which I was able to do with the following:
public long getCPUSpeed() {
return WmiUtil.selectUint32From((String)null, "Win32_Processor", "MaxClockSpeed", (String)null).longValue();
}
My naming conventions aren't the best (was just playing around), but this does seem to work...
dbwiddis commentedon May 5, 2017
I'm happy to grab processor info from WMI rather than the registry.
But as I understand we're actually looking for 3 layers of data here? Chip, core, and virtual processor (which really is only intended to model hyperthreading)?
YoshiEnVerde commentedon May 5, 2017
Yup. That's pretty much it
dbwiddis commentedon May 5, 2017
We could probably add a
getSocketCount()method.YoshiEnVerde commentedon May 5, 2017
As a stopgap method, that would work pretty well.
I'd love to come back to this for the next major release, and actually try to parse WMI's data on the processors to have the Hardware Interface actually show each processor as a separate CentralProcessor object
hakanai commentedon May 5, 2017
The MS terminology for this was something like "physical package", presumably because some CPUs aren't socketed.
dbwiddis commentedon May 5, 2017
Here's how you can count it on Linux (not suggesting we use
awkbut pointing out the line prefixes involved!Output:
saintGH commentedon May 8, 2017
Beauty. For my immediate purposes, I'll just utilize the WmiUtil class to poll the information I need.
Thanks everyone!
dbwiddis commentedon May 9, 2017
Taking notes in case this ever gets done. For macOS,
system_profiler SPHardwareDataTypehas an entryNumber of Processorsthat represents the physical package. (My system has 1 processor, 4 cores (physical cpu), and 8 logical cpu.)dbwiddis commentedon May 9, 2017
FreeBSD, we can parse the
dmesglog:Also it appears our current parsing of
sysctl kern.sched.topology_specmay have that -- count the number of group level 2's. The below is an example of a 2-package system:dbwiddis commentedon May 9, 2017
Solaris: existing kstat on cpu_info, look for
chip_idsaintGH commentedon Apr 16, 2018
Fantastic, thanks!