2022-11-21 22:26:50 +08:00
|
|
|
#include "cpu.h"
|
2023-02-23 21:31:33 +08:00
|
|
|
#include "detection/temps/temps_windows.h"
|
2022-11-26 12:55:48 +08:00
|
|
|
#include "util/windows/registry.h"
|
2022-11-23 15:10:40 +08:00
|
|
|
#include "util/mallocHelper.h"
|
2024-01-06 14:00:53 +08:00
|
|
|
#include "util/smbiosHelper.h"
|
2022-11-21 22:26:50 +08:00
|
|
|
|
2024-01-06 14:00:53 +08:00
|
|
|
// 7.5
|
|
|
|
|
typedef struct FFSmbiosProcessorInfo
|
|
|
|
|
{
|
|
|
|
|
FFSmbiosHeader Header;
|
|
|
|
|
|
|
|
|
|
uint8_t SocketDesignation; // string
|
|
|
|
|
uint8_t ProcessorType; // enum
|
|
|
|
|
uint8_t ProcessorFamily; // enum
|
|
|
|
|
uint8_t ProcessorManufacturer; // string
|
|
|
|
|
uint64_t ProcessorID; // varies
|
|
|
|
|
uint8_t ProcessorVersion; // string
|
|
|
|
|
uint8_t Voltage; // varies
|
|
|
|
|
uint16_t ExternalClock; // varies
|
|
|
|
|
uint16_t MaxSpeed; // varies
|
|
|
|
|
uint16_t CurrentSpeed; // varies
|
|
|
|
|
uint8_t Status; // varies
|
|
|
|
|
uint8_t ProcessorUpgrade; // enum
|
|
|
|
|
|
|
|
|
|
// 2.1+
|
|
|
|
|
uint16_t L1CacheHandle; // varies
|
|
|
|
|
uint16_t L2CacheHandle; // varies
|
|
|
|
|
uint16_t L3CacheHandle; // varies
|
|
|
|
|
|
|
|
|
|
// 2.3+
|
|
|
|
|
uint8_t SerialNumber; // string
|
|
|
|
|
uint8_t AssertTag; // string
|
|
|
|
|
uint8_t PartNumber; // string
|
|
|
|
|
|
|
|
|
|
// 2.5+
|
|
|
|
|
uint8_t CoreCount; // varies
|
|
|
|
|
uint8_t CoreEnabled; // varies
|
|
|
|
|
uint8_t ThreadCount; // varies
|
|
|
|
|
uint16_t ProcessorCharacteristics; // bit field
|
|
|
|
|
|
|
|
|
|
// 2.6+
|
|
|
|
|
uint16_t ProcessorFamily2; // enum
|
|
|
|
|
|
|
|
|
|
// 3.0+
|
|
|
|
|
uint16_t CoreCount2; // varies
|
|
|
|
|
uint16_t CoreEnabled2; // varies
|
|
|
|
|
uint16_t ThreadCount2; // varies
|
|
|
|
|
|
|
|
|
|
// 3.6+
|
|
|
|
|
uint16_t ThreadEnabled; // varies
|
|
|
|
|
} FFSmbiosProcessorInfo;
|
|
|
|
|
|
2024-01-06 18:00:59 +08:00
|
|
|
static const char* detectMaxSpeedBySmbios(FFCPUResult* cpu)
|
2024-01-06 14:00:53 +08:00
|
|
|
{
|
2024-01-06 14:46:54 +08:00
|
|
|
const FFSmbiosProcessorInfo* data = (const FFSmbiosProcessorInfo*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_PROCESSOR_INFO];
|
2024-01-06 14:00:53 +08:00
|
|
|
|
2024-01-06 14:46:54 +08:00
|
|
|
if (!data)
|
|
|
|
|
return "Processor information is not found in SMBIOS data";
|
|
|
|
|
|
|
|
|
|
while (data->ProcessorType != 0x03 /*Central Processor*/ || (data->Status & 0b00000111) != 1 /*Enabled*/)
|
2024-01-06 14:00:53 +08:00
|
|
|
{
|
2024-01-06 14:46:54 +08:00
|
|
|
data = (const FFSmbiosProcessorInfo*) ffSmbiosNextEntry(&data->Header);
|
|
|
|
|
if (data->Header.Type != FF_SMBIOS_TYPE_PROCESSOR_INFO)
|
2024-01-06 18:00:59 +08:00
|
|
|
return "No active CPU is found in SMBIOS data";
|
2024-01-06 14:46:54 +08:00
|
|
|
}
|
2024-01-06 14:00:53 +08:00
|
|
|
|
2024-01-06 18:00:59 +08:00
|
|
|
double speed;
|
2024-01-06 16:44:12 +08:00
|
|
|
if (data->MaxSpeed > 0 && data->MaxSpeed < 30000) // VMware reports weird values
|
2024-01-06 18:00:59 +08:00
|
|
|
speed = data->MaxSpeed / 1000.0;
|
2024-01-06 14:46:54 +08:00
|
|
|
else
|
2024-01-06 18:00:59 +08:00
|
|
|
speed = data->CurrentSpeed / 1000.0;
|
2024-01-06 16:20:07 +08:00
|
|
|
|
2024-01-06 18:00:59 +08:00
|
|
|
if (cpu->frequencyMax < speed)
|
|
|
|
|
cpu->frequencyMax = speed;
|
2024-01-06 14:00:53 +08:00
|
|
|
|
2024-01-06 14:46:54 +08:00
|
|
|
return NULL;
|
2024-01-06 14:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char* detectByOS(FFCPUResult* cpu)
|
2022-11-21 22:26:50 +08:00
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
DWORD length = 0;
|
2023-06-17 15:23:05 +08:00
|
|
|
GetLogicalProcessorInformationEx(RelationAll, NULL, &length);
|
|
|
|
|
if (length == 0)
|
2023-06-12 09:56:03 +08:00
|
|
|
return "GetLogicalProcessorInformationEx(RelationAll, NULL, &length) failed";
|
|
|
|
|
|
2022-11-23 15:10:40 +08:00
|
|
|
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* FF_AUTO_FREE
|
2023-03-21 15:27:04 +08:00
|
|
|
pProcessorInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(length);
|
2022-11-21 22:26:50 +08:00
|
|
|
|
2023-06-12 09:56:03 +08:00
|
|
|
if (pProcessorInfo && GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length))
|
2022-11-21 22:26:50 +08:00
|
|
|
{
|
|
|
|
|
for(
|
2023-03-21 15:27:04 +08:00
|
|
|
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* ptr = pProcessorInfo;
|
|
|
|
|
(uint8_t*)ptr < ((uint8_t*)pProcessorInfo) + length;
|
2022-11-21 22:26:50 +08:00
|
|
|
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((uint8_t*)ptr) + ptr->Size)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if(ptr->Relationship == RelationProcessorCore)
|
|
|
|
|
++cpu->coresPhysical;
|
2023-03-21 15:27:04 +08:00
|
|
|
else if(ptr->Relationship == RelationGroup)
|
|
|
|
|
{
|
|
|
|
|
cpu->coresOnline += ptr->Group.GroupInfo->ActiveProcessorCount;
|
|
|
|
|
cpu->coresLogical += ptr->Group.GroupInfo->MaximumProcessorCount;
|
|
|
|
|
}
|
2022-11-21 22:26:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-12 09:56:03 +08:00
|
|
|
else
|
|
|
|
|
return "GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length) failed";
|
2022-11-21 22:26:50 +08:00
|
|
|
}
|
|
|
|
|
|
2023-09-07 17:03:24 +08:00
|
|
|
FF_HKEY_AUTO_DESTROY hKey = NULL;
|
2022-11-23 15:42:19 +08:00
|
|
|
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hKey, NULL))
|
2023-06-12 09:56:03 +08:00
|
|
|
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\", &hKey, NULL) failed";
|
2022-11-21 22:26:50 +08:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
uint32_t mhz;
|
2022-11-23 15:42:19 +08:00
|
|
|
if(ffRegReadUint(hKey, L"~MHz", &mhz, NULL))
|
2024-01-06 18:00:59 +08:00
|
|
|
cpu->frequencyMin = cpu->frequencyMax = mhz / 1000.0;
|
2022-11-21 22:26:50 +08:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 15:42:19 +08:00
|
|
|
ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL);
|
|
|
|
|
ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL);
|
2023-02-23 21:31:33 +08:00
|
|
|
|
2024-01-06 14:00:53 +08:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
|
|
|
|
|
{
|
2024-01-06 18:00:59 +08:00
|
|
|
const char* error = detectByOS(cpu);
|
|
|
|
|
if (error)
|
|
|
|
|
return error;
|
|
|
|
|
|
2023-06-12 09:56:03 +08:00
|
|
|
if(options->temp)
|
2023-02-23 21:31:33 +08:00
|
|
|
ffDetectSmbiosTemp(&cpu->temperature, NULL);
|
2023-06-12 09:56:03 +08:00
|
|
|
|
2024-01-06 18:00:59 +08:00
|
|
|
detectMaxSpeedBySmbios(cpu);
|
|
|
|
|
return NULL;
|
2022-11-21 22:26:50 +08:00
|
|
|
}
|