From b3da6b0e89c0decb9ea648e1d98a75fa6ac40225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 21 Mar 2023 15:27:04 +0800 Subject: [PATCH] CPU (Windows): try improving performance --- src/detection/cpu/cpu_windows.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index 05116870f..b38d5bb63 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -15,25 +15,28 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu) { DWORD length = 0; - GetLogicalProcessorInformationEx(RelationProcessorCore, NULL, &length); + GetLogicalProcessorInformationEx(RelationAll, NULL, &length); SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* FF_AUTO_FREE - pLogicalInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(length); + pProcessorInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(length); - if(pLogicalInfo && GetLogicalProcessorInformationEx(RelationProcessorCore, pLogicalInfo, &length)) + if(pProcessorInfo && GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length)) { for( - SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* ptr = pLogicalInfo; - (uint8_t*)ptr < ((uint8_t*)pLogicalInfo) + length; + SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* ptr = pProcessorInfo; + (uint8_t*)ptr < ((uint8_t*)pProcessorInfo) + length; ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((uint8_t*)ptr) + ptr->Size) ) { if(ptr->Relationship == RelationProcessorCore) ++cpu->coresPhysical; + else if(ptr->Relationship == RelationGroup) + { + cpu->coresOnline += ptr->Group.GroupInfo->ActiveProcessorCount; + cpu->coresLogical += ptr->Group.GroupInfo->MaximumProcessorCount; + } } } } - 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))