VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortechvintage <sachin.keswani@amd.com>2020-01-29 02:10:00 -0800
committerGitHub <noreply@github.com>2020-01-29 11:10:00 +0100
commit123b187af597cbe4524bbbd4decafa3536599645 (patch)
tree2fc0edcef088acfe71c2c9a9171f64f8623f89b1 /src
parent247a16cb5ffef4dbf09615dd3d934fd7d06fdb76 (diff)
downloadVeraCrypt-123b187af597cbe4524bbbd4decafa3536599645.tar.gz
VeraCrypt-123b187af597cbe4524bbbd4decafa3536599645.zip
Adding Processor Groups support for more than 64 processors (#581)
* Adding Processor Groups support for more than 64 processors * Revert " Adding Processor Groups support for more than 64 processors" This reverts commit e1d5fe0a55f46a53549450972c5b5506a43ca94c. * Adding Processor Groups support for >64 logical processors
Diffstat (limited to 'src')
-rw-r--r--src/Common/EncryptionThreadPool.c60
1 files changed, 57 insertions, 3 deletions
diff --git a/src/Common/EncryptionThreadPool.c b/src/Common/EncryptionThreadPool.c
index 461f2847..c11182a2 100644
--- a/src/Common/EncryptionThreadPool.c
+++ b/src/Common/EncryptionThreadPool.c
@@ -10,13 +10,19 @@
code distribution packages.
*/
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined (WIN64)
+#include <Windows.h>
+#include <Versionhelpers.h>
+#endif
+
#include "EncryptionThreadPool.h"
#include "Pkcs5.h"
#ifdef DEVICE_DRIVER
#include "Driver/Ntdriver.h"
#endif
-#define TC_ENC_THREAD_POOL_MAX_THREAD_COUNT 64
+//Increasing the maximum number of threads
+#define TC_ENC_THREAD_POOL_MAX_THREAD_COUNT 256 //64
#define TC_ENC_THREAD_POOL_QUEUE_SIZE (TC_ENC_THREAD_POOL_MAX_THREAD_COUNT * 2)
#ifdef DEVICE_DRIVER
@@ -111,6 +117,10 @@ static TC_MUTEX DequeueMutex;
static TC_EVENT WorkItemReadyEvent;
static TC_EVENT WorkItemCompletedEvent;
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined (WIN64)
+static uint32 totalProcessors;
+#endif
+
#if defined(_WIN64)
void EncryptDataUnitsCurrentThreadEx (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci)
{
@@ -163,6 +173,12 @@ static void SetWorkItemState (EncryptionThreadPoolWorkItem *workItem, WorkItemSt
static TC_THREAD_PROC EncryptionThreadProc (void *threadArg)
{
+
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
+ GROUP_AFFINITY groupAffinity = { ~0ULL, *(int*)(threadArg), { 0, 0, 0 } };
+ BOOL value = SetThreadGroupAffinity(GetCurrentThread(), &groupAffinity, NULL);
+#endif
+
EncryptionThreadPoolWorkItem *workItem;
while (!StopPending)
@@ -263,11 +279,26 @@ static TC_THREAD_PROC EncryptionThreadProc (void *threadArg)
BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount)
{
- size_t cpuCount, i;
+ size_t cpuCount = 0, i = 0, processors = 0, totalProcessors = 0;
+ int threadProcessorGroups[128];
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined (WIN64)
+ for (i = 0; i < GetActiveProcessorGroupCount(); ++i)
+ {
+ processors = GetActiveProcessorCount(i);
+ totalProcessors += processors;
+}
+#endif
if (ThreadPoolRunning)
return TRUE;
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
+ SYSTEM_INFO sysInfo;
+ GetSystemInfo(&sysInfo);
+ cpuCount = (IsWindows7OrGreater) ? totalProcessors : sysInfo.dwNumberOfProcessors;
+#endif
+
+/*
#ifdef DEVICE_DRIVER
cpuCount = GetCpuCount();
#else
@@ -277,7 +308,7 @@ BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount)
cpuCount = sysInfo.dwNumberOfProcessors;
}
#endif
-
+*/
if (cpuCount > encryptionFreeCpuCount)
cpuCount -= encryptionFreeCpuCount;
@@ -337,11 +368,34 @@ BOOL EncryptionThreadPoolStart (size_t encryptionFreeCpuCount)
for (ThreadCount = 0; ThreadCount < cpuCount; ++ThreadCount)
{
+
+#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
+ // Determine which processor group to bind the thread to.
+ totalProcessors = 0U;
+ for (i = 0U; i < GetActiveProcessorGroupCount(); ++i)
+ {
+ totalProcessors += GetActiveProcessorCount(i);
+ if (totalProcessors >= ThreadCount)
+ {
+ threadProcessorGroups[ThreadCount] = i;
+ break;
+ }
+ }
+#endif
+
+#ifdef DEVICE_DRIVER
+ if (!NT_SUCCESS(TCStartThread(EncryptionThreadProc, (void*)(&threadProcessorGroups[ThreadCount]), &ThreadHandles[ThreadCount])))
+#else
+ if (!(ThreadHandles[ThreadCount] = (HANDLE)_beginthreadex(NULL, 0, EncryptionThreadProc, (void*)(&threadProcessorGroups[ThreadCount]), 0, NULL)))
+#endif
+
+/*
#ifdef DEVICE_DRIVER
if (!NT_SUCCESS (TCStartThread (EncryptionThreadProc, NULL, &ThreadHandles[ThreadCount])))
#else
if (!(ThreadHandles[ThreadCount] = (HANDLE) _beginthreadex (NULL, 0, EncryptionThreadProc, NULL, 0, NULL)))
#endif
+*/
{
EncryptionThreadPoolStop();
return FALSE;