implemented nimPinToCpu threadpool feature
This commit is contained in:
parent
e703afdb3b
commit
646af76c87
2 changed files with 13 additions and 3 deletions
|
|
@ -322,6 +322,9 @@ var
|
||||||
distinguished: array[MaxDistinguishedThread, TThread[ptr Worker]]
|
distinguished: array[MaxDistinguishedThread, TThread[ptr Worker]]
|
||||||
distinguishedData: array[MaxDistinguishedThread, Worker]
|
distinguishedData: array[MaxDistinguishedThread, Worker]
|
||||||
|
|
||||||
|
when defined(nimPinToCpu):
|
||||||
|
var gCpus: Natural
|
||||||
|
|
||||||
proc setMinPoolSize*(size: range[1..MaxThreadPoolSize]) =
|
proc setMinPoolSize*(size: range[1..MaxThreadPoolSize]) =
|
||||||
## sets the minimal thread pool size. The default value of this is 4.
|
## sets the minimal thread pool size. The default value of this is 4.
|
||||||
minPoolSize = size
|
minPoolSize = size
|
||||||
|
|
@ -342,6 +345,8 @@ proc activateWorkerThread(i: int) {.noinline.} =
|
||||||
workersData[i].q.empty = createSemaphore()
|
workersData[i].q.empty = createSemaphore()
|
||||||
initLock(workersData[i].q.lock)
|
initLock(workersData[i].q.lock)
|
||||||
createThread(workers[i], slave, addr(workersData[i]))
|
createThread(workers[i], slave, addr(workersData[i]))
|
||||||
|
when defined(nimPinToCpu):
|
||||||
|
if gCpus > 0: pinToCpu(workers[i], i mod gCpus)
|
||||||
|
|
||||||
proc activateDistinguishedThread(i: int) {.noinline.} =
|
proc activateDistinguishedThread(i: int) {.noinline.} =
|
||||||
distinguishedData[i].taskArrived = createSemaphore()
|
distinguishedData[i].taskArrived = createSemaphore()
|
||||||
|
|
@ -353,7 +358,10 @@ proc activateDistinguishedThread(i: int) {.noinline.} =
|
||||||
createThread(distinguished[i], distinguishedSlave, addr(distinguishedData[i]))
|
createThread(distinguished[i], distinguishedSlave, addr(distinguishedData[i]))
|
||||||
|
|
||||||
proc setup() =
|
proc setup() =
|
||||||
currentPoolSize = min(countProcessors(), MaxThreadPoolSize)
|
let p = countProcessors()
|
||||||
|
when defined(nimPinToCpu):
|
||||||
|
gCpus = p
|
||||||
|
currentPoolSize = min(p, MaxThreadPoolSize)
|
||||||
readyWorker = addr(workersData[0])
|
readyWorker = addr(workersData[0])
|
||||||
for i in 0.. <currentPoolSize: activateWorkerThread(i)
|
for i in 0.. <currentPoolSize: activateWorkerThread(i)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,12 @@ News
|
||||||
Library additions
|
Library additions
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
- The nre module has been added, providing a better interface to PCRE than
|
- The nre module has been added, providing a better interface to PCRE than re.
|
||||||
re.
|
|
||||||
- The ``expandSymlink`` proc has been added to the ``os`` module.
|
- The ``expandSymlink`` proc has been added to the ``os`` module.
|
||||||
- The ``tailDir`` 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
|
Language Additions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue