Add javadoc
This commit is contained in:
committed by
Sheepit Renderfarm
parent
1ef0b2f4b7
commit
42d2095c0b
@@ -29,11 +29,17 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Provides attributes to store various characteristic about the CPU and to detect the CPU architecture and core count
|
||||
*/
|
||||
@Getter @Setter public class CPU {
|
||||
public static final int MIN_CORES = Runtime.getRuntime().availableProcessors() > 1 ? 2 : 1;
|
||||
private String name;
|
||||
private String model;
|
||||
private String family;
|
||||
/**
|
||||
* The detail is limited to only if it's 32 or 64bit
|
||||
*/
|
||||
private String arch; // 32 or 64 bits
|
||||
private static final Log log = Log.getInstance(null);
|
||||
private static Integer logicalCores = -1; // Store core count throughout instances
|
||||
@@ -45,6 +51,17 @@ import java.io.InputStreamReader;
|
||||
this.generateArch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of processors available.
|
||||
* On Linux and Mac this functions returns and works exactly like availableProcessors.
|
||||
* @see Runtime#availableProcessors()
|
||||
* On Windows 10 (and earlier) the maximum reported number of processor is never over 64
|
||||
* due to the nature of Processor Groups pre-Windows 11 and that JDK 11 goes not operate NUMA aware by default.
|
||||
* Therefore, on Windows, the system is quieried via powershell about the number logical cores.
|
||||
* in order te reflect what Blender will be able to utilize.
|
||||
* @see <a href="https://learn.microsoft.com/en-us/windows/win32/procthread/processor-groups">Processor Groups</a>
|
||||
* @return the maximum number of processors available; never smaller than one
|
||||
*/
|
||||
public int cores() {
|
||||
// If logicalCores is -1, then haven't run the core-checking script yet
|
||||
// Only want to run it once since cores is called multiple times
|
||||
@@ -52,6 +69,9 @@ import java.io.InputStreamReader;
|
||||
// Use normal method for systems other than windows, and in case script fails.
|
||||
logicalCores = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
/* It is worth revisiting if this core detection logic is still needed
|
||||
once support for either Windows 10 or OpenJDK 11 has been phased out, because as mentioned in the javadoc
|
||||
JDK12+ may now run NUMA-aware out of the box or Win11+ Proc Groups now properly reflect the entire system*/
|
||||
if (OS.getOS() instanceof Windows) {
|
||||
ProcessBuilder powershellProcess = new ProcessBuilder("powershell.exe",
|
||||
"((Get-CimInstance -ClassName Win32_Processor).NumberOfLogicalProcessors | Measure-Object -Sum ).Sum");
|
||||
@@ -99,6 +119,9 @@ import java.io.InputStreamReader;
|
||||
return logicalCores;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects whether the CPU is currently operating in 32 or 64 bit mode
|
||||
*/
|
||||
public void generateArch() {
|
||||
String arch = System.getProperty("os.arch").toLowerCase();
|
||||
switch (arch) {
|
||||
@@ -119,6 +142,10 @@ import java.io.InputStreamReader;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if we have any data on the CPU
|
||||
* @return boolean reflecting if all attributes of the CPU are empty
|
||||
*/
|
||||
public boolean haveData() {
|
||||
return this.name != null && this.model != null && this.family != null && this.arch != null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user