CPU / CPUCache (Windows): prefers NtQuerySystemInformation(Ex)

This commit is contained in:
李通洲
2026-03-03 16:01:36 +08:00
parent ab041e0ad2
commit 7ea0bbfb21
3 changed files with 19 additions and 7 deletions
+10
View File
@@ -6,6 +6,7 @@
enum {
SystemModuleInformation = 11,
SystemBootEnvironmentInformation = 90,
SystemLogicalProcessorAndGroupInformation = 107,
SystemSecureBootInformation = 146,
};
@@ -395,3 +396,12 @@ typedef struct _SYSTEM_SECUREBOOT_INFORMATION
BOOLEAN SecureBootEnabled;
BOOLEAN SecureBootCapable;
} SYSTEM_SECUREBOOT_INFORMATION, *PSYSTEM_SECUREBOOT_INFORMATION;
NTSTATUS NTAPI NtQuerySystemInformationEx(
_In_ SYSTEM_INFORMATION_CLASS SystemInformationClass,
_In_reads_bytes_(InputBufferLength) PVOID InputBuffer,
_In_ ULONG InputBufferLength,
_Out_writes_bytes_opt_(SystemInformationLength) PVOID SystemInformation,
_In_ ULONG SystemInformationLength,
_Out_opt_ PULONG ReturnLength
);
+5 -3
View File
@@ -6,6 +6,7 @@
#include <windows.h>
#include "common/windows/perflib_.h"
#include "common/windows/nt.h"
#include <wchar.h>
static inline void ffPerfCloseQueryHandle(HANDLE* phQuery)
@@ -212,15 +213,16 @@ static const char* detectMaxSpeedBySmbios(FFCPUResult* cpu)
static const char* detectNCores(FFCPUResult* cpu)
{
DWORD length = 0;
GetLogicalProcessorInformationEx(RelationAll, NULL, &length);
LOGICAL_PROCESSOR_RELATIONSHIP lpr = RelationAll;
ULONG length = 0;
NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), NULL, 0, &length);
if (length == 0)
return "GetLogicalProcessorInformationEx(RelationAll, NULL, &length) failed";
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* FF_AUTO_FREE
pProcessorInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(length);
if (!pProcessorInfo || !GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length))
if (!NT_SUCCESS(NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), pProcessorInfo, length, &length)))
return "GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length) failed";
for(
+4 -4
View File
@@ -1,19 +1,19 @@
#include "cpucache.h"
#include "common/mallocHelper.h"
#include <windows.h>
#include "common/windows/nt.h"
const char* ffDetectCPUCache(FFCPUCacheResult* result)
{
LOGICAL_PROCESSOR_RELATIONSHIP lpr = RelationCache;
DWORD length = 0;
GetLogicalProcessorInformationEx(RelationCache, NULL, &length);
NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), NULL, 0, &length);
if (length == 0)
return "GetLogicalProcessorInformationEx(RelationCache, NULL, &length) failed";
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* FF_AUTO_FREE
pProcessorInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(length);
if (!pProcessorInfo || !GetLogicalProcessorInformationEx(RelationCache, pProcessorInfo, &length))
if (!NT_SUCCESS(NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), pProcessorInfo, length, &length)))
return "GetLogicalProcessorInformationEx(RelationCache, pProcessorInfo, &length) failed";
for(