mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-18 17:08:32 +00:00
implemented nimPinToCpu threadpool feature
This commit is contained in:
@@ -322,6 +322,9 @@ var
|
||||
distinguished: array[MaxDistinguishedThread, TThread[ptr Worker]]
|
||||
distinguishedData: array[MaxDistinguishedThread, Worker]
|
||||
|
||||
when defined(nimPinToCpu):
|
||||
var gCpus: Natural
|
||||
|
||||
proc setMinPoolSize*(size: range[1..MaxThreadPoolSize]) =
|
||||
## sets the minimal thread pool size. The default value of this is 4.
|
||||
minPoolSize = size
|
||||
@@ -342,6 +345,8 @@ proc activateWorkerThread(i: int) {.noinline.} =
|
||||
workersData[i].q.empty = createSemaphore()
|
||||
initLock(workersData[i].q.lock)
|
||||
createThread(workers[i], slave, addr(workersData[i]))
|
||||
when defined(nimPinToCpu):
|
||||
if gCpus > 0: pinToCpu(workers[i], i mod gCpus)
|
||||
|
||||
proc activateDistinguishedThread(i: int) {.noinline.} =
|
||||
distinguishedData[i].taskArrived = createSemaphore()
|
||||
@@ -353,7 +358,10 @@ proc activateDistinguishedThread(i: int) {.noinline.} =
|
||||
createThread(distinguished[i], distinguishedSlave, addr(distinguishedData[i]))
|
||||
|
||||
proc setup() =
|
||||
currentPoolSize = min(countProcessors(), MaxThreadPoolSize)
|
||||
let p = countProcessors()
|
||||
when defined(nimPinToCpu):
|
||||
gCpus = p
|
||||
currentPoolSize = min(p, MaxThreadPoolSize)
|
||||
readyWorker = addr(workersData[0])
|
||||
for i in 0.. <currentPoolSize: activateWorkerThread(i)
|
||||
|
||||
|
||||
@@ -56,10 +56,12 @@ News
|
||||
Library additions
|
||||
-----------------
|
||||
|
||||
- The nre module has been added, providing a better interface to PCRE than
|
||||
re.
|
||||
- The nre module has been added, providing a better interface to PCRE than re.
|
||||
- The ``expandSymlink`` proc has been added to the ``os`` module.
|
||||
- The ``tailDir`` proc has been added to the ``os`` module.
|
||||
- Define ``nimPinToCpu`` to make the ``threadpool`` use explicit thread
|
||||
affinities. This can speed up or slow down the thread pool; it's up to you
|
||||
to benchmark it.
|
||||
|
||||
|
||||
Language Additions
|
||||
|
||||
Reference in New Issue
Block a user