Windows: Replace GetSystemInfo calls by more reliable function to get number of CPUs active on the PC.

This commit is contained in:
Mounir IDRASSI 2020-07-01 17:13:08 +02:00
parent 3f587a3629
commit ac3cccdd21
No known key found for this signature in database
GPG Key ID: 02C30AE90FAE4A6F
2 changed files with 13 additions and 16 deletions

View File

@ -5578,13 +5578,11 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
BYTE *lpTestBuffer = NULL;
PCRYPTO_INFO ci = NULL;
UINT64_STRUCT startDataUnitNo;
SYSTEM_INFO sysInfo = {0};
GetSystemInfo (&sysInfo);
size_t cpuCount = GetCpuCount(NULL);
startDataUnitNo.Value = 0;
/* set priority to critical only when there are 2 or more CPUs on the system */
if (sysInfo.dwNumberOfProcessors > 1 && (benchmarkType != BENCHMARK_TYPE_ENCRYPTION))
if (cpuCount > 1 && (benchmarkType != BENCHMARK_TYPE_ENCRYPTION))
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
ci = crypto_open ();
@ -6023,13 +6021,12 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
Warning ("DISABLED_HW_AES_AFFECTS_PERFORMANCE", hwndDlg);
}
SYSTEM_INFO sysInfo;
GetSystemInfo (&sysInfo);
size_t cpuCount = GetCpuCount (NULL);
size_t nbrThreads = GetEncryptionThreadCount();
wchar_t nbrThreadsStr [300];
if (sysInfo.dwNumberOfProcessors < 2)
if (cpuCount < 2)
{
StringCbCopyW (nbrThreadsStr, sizeof(nbrThreadsStr), GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
}
@ -6046,8 +6043,8 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
ToHyperlink (hwndDlg, IDC_PARALLELIZATION_LABEL_LINK);
if (nbrThreads < min (sysInfo.dwNumberOfProcessors, GetMaxEncryptionThreadCount())
&& sysInfo.dwNumberOfProcessors > 1)
if (nbrThreads < min (cpuCount, GetMaxEncryptionThreadCount())
&& cpuCount > 1)
{
Warning ("LIMITED_THREAD_COUNT_AFFECTS_PERFORMANCE", hwndDlg);
}

View File

@ -49,6 +49,7 @@
#include "../Platform/Finally.h"
#include "../Platform/ForEach.h"
#include "../Setup/SelfExtract.h"
#include "../Common/EncryptionThreadPool.h"
#include <Strsafe.h>
#include <InitGuid.h>
@ -11285,26 +11286,25 @@ static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM
EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_RAM_ENCRYPTION), FALSE);
}
SYSTEM_INFO sysInfo;
GetSystemInfo (&sysInfo);
size_t cpuCount = GetCpuCount(NULL);
HWND freeCpuCombo = GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT);
uint32 encryptionFreeCpuCount = ReadEncryptionThreadPoolFreeCpuCountLimit();
if (encryptionFreeCpuCount > sysInfo.dwNumberOfProcessors - 1)
encryptionFreeCpuCount = sysInfo.dwNumberOfProcessors - 1;
if (encryptionFreeCpuCount > (uint32) (cpuCount - 1))
encryptionFreeCpuCount = (uint32) (cpuCount - 1);
for (uint32 i = 1; i < sysInfo.dwNumberOfProcessors; ++i)
for (uint32 i = 1; i < cpuCount; ++i)
{
wstringstream s;
s << i;
AddComboPair (freeCpuCombo, s.str().c_str(), i);
}
if (sysInfo.dwNumberOfProcessors < 2 || encryptionFreeCpuCount == 0)
if (cpuCount < 2 || encryptionFreeCpuCount == 0)
EnableWindow (freeCpuCombo, FALSE);
if (sysInfo.dwNumberOfProcessors < 2)
if (cpuCount < 2)
EnableWindow (GetDlgItem (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL), FALSE);
if (encryptionFreeCpuCount != 0)