فهرست منبع

Limit the amount of worker threads to half the available CPU cores.

Lasse Öörni 14 سال پیش
والد
کامیت
1fbbf5f2cd
2فایلهای تغییر یافته به همراه4 افزوده شده و 4 حذف شده
  1. 1 1
      Docs/Reference.dox
  2. 3 3
      Engine/Engine/Engine.cpp

+ 1 - 1
Docs/Reference.dox

@@ -1081,7 +1081,7 @@ Like with ordinary events, in script event types are strings instead of name has
 
 
 Urho3D uses a task-based multithreading model. The WorkQueue subsystem can be supplied with tasks described by the WorkItem structure, by calling \ref WorkQueue::AddWorkItem "AddWorkItem()". These will be executed in background worker threads. The function \ref WorkQueue::Complete "Complete()" will complete all currently pending tasks, and execute them also in the main thread to make them finish faster.
 Urho3D uses a task-based multithreading model. The WorkQueue subsystem can be supplied with tasks described by the WorkItem structure, by calling \ref WorkQueue::AddWorkItem "AddWorkItem()". These will be executed in background worker threads. The function \ref WorkQueue::Complete "Complete()" will complete all currently pending tasks, and execute them also in the main thread to make them finish faster.
 
 
-On single-core systems no worker threads will be created. In the presence of more cores, worker threads will be created up to a maximum of four. Two cores will be preferably left free to allow one for the main thread, and another for the GPU driver and audio processing.
+On single-core systems no worker threads will be created. In the presence of more cores, worker threads will be created up to half of the number of CPU cores minus one that is reserved for the main thread.
 
 
 The work items include a function pointer to call, with the signature "void WorkFunction(const WorkItem* item, unsigned threadIndex)." The thread index ranges from 0 to n, where 0 represents the main thread and n is the number of worker threads created. Its function is to aid in splitting work into per-thread data structures that need no locking. The work item also contains three void pointers: start, end and aux, which can be used to describe a range of sub-work items, and an auxiliary data structure, which may for example be the object that originally queued the work.
 The work items include a function pointer to call, with the signature "void WorkFunction(const WorkItem* item, unsigned threadIndex)." The thread index ranges from 0 to n, where 0 represents the main thread and n is the number of worker threads created. Its function is to aid in splitting work into per-thread data structures that need no locking. The work item also contains three void pointers: start, end and aux, which can be used to describe a range of sub-work items, and an auxiliary data structure, which may for example be the object that originally queued the work.
 
 

+ 3 - 3
Engine/Engine/Engine.cpp

@@ -175,12 +175,12 @@ bool Engine::Initialize(const String& windowTitle, const String& logName, const
     Log* log = GetSubsystem<Log>();
     Log* log = GetSubsystem<Log>();
     log->Open(logName);
     log->Open(logName);
     
     
-    // Set amount of worker threads according to the free CPU cores. Leave one for the main thread and another for
-    // GPU & audio drivers, and clamp to a maximum of three for now
+    // Set amount of worker threads according to the free CPU cores. For the case hyperthreading is in use,
+    // limit to half of the available cores, and reserve one core for the main thread
     int numCores = GetNumCPUCores();
     int numCores = GetNumCPUCores();
     if (threads && numCores > 1)
     if (threads && numCores > 1)
     {
     {
-        int numThreads = Clamp(numCores - 2, 1, 3);
+        int numThreads = Max(numCores / 2 - 1, 1);
         GetSubsystem<WorkQueue>()->CreateThreads(numThreads);
         GetSubsystem<WorkQueue>()->CreateThreads(numThreads);
         
         
         String workerThreadString = "Created " + String(numThreads) + " worker thread";
         String workerThreadString = "Created " + String(numThreads) + " worker thread";