Files
fastfetch/src/detection/cpu/cpu_windows.c
T

54 lines
1.9 KiB
C
Raw Normal View History

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"
2022-11-21 22:26:50 +08:00
2022-12-17 11:39:10 +08:00
void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)
2022-11-21 22:26:50 +08:00
{
FF_UNUSED(instance);
cpu->temperature = FF_CPU_TEMP_UNSET;
cpu->coresPhysical = cpu->coresLogical = cpu->coresOnline = 0;
cpu->frequencyMax = cpu->frequencyMin = 0;
ffStrbufInit(&cpu->name);
ffStrbufInit(&cpu->vendor);
{
DWORD length = 0;
GetLogicalProcessorInformationEx(RelationProcessorCore, NULL, &length);
2022-11-23 15:10:40 +08:00
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* FF_AUTO_FREE
2022-11-21 22:26:50 +08:00
pLogicalInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(length);
if(pLogicalInfo && GetLogicalProcessorInformationEx(RelationProcessorCore, pLogicalInfo, &length))
{
for(
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* ptr = pLogicalInfo;
(uint8_t*)ptr < ((uint8_t*)pLogicalInfo) + length;
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((uint8_t*)ptr) + ptr->Size)
)
{
if(ptr->Relationship == RelationProcessorCore)
++cpu->coresPhysical;
}
}
}
cpu->coresOnline = (uint16_t)GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
cpu->coresLogical = (uint16_t)GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
FF_HKEY_AUTO_DESTROY hKey;
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hKey, NULL))
2022-11-21 22:26:50 +08:00
return;
{
uint32_t mhz;
if(ffRegReadUint(hKey, L"~MHz", &mhz, NULL))
2022-11-21 22:26:50 +08:00
cpu->frequencyMax = mhz / 1000.0;
}
ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL);
ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL);
2023-02-23 21:31:33 +08:00
if(instance->config.cpuTemp)
ffDetectSmbiosTemp(&cpu->temperature, NULL);
2022-11-21 22:26:50 +08:00
}