implemented nimPinToCpu threadpool feature

This commit is contained in:
Araq
2015-08-24 17:59:29 +02:00
parent e703afdb3b
commit 646af76c87
2 changed files with 13 additions and 3 deletions

View File

@@ -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)

View File

@@ -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