diff options
author | Araq <rumpf_a@web.de> | 2015-08-24 17:59:29 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-08-24 18:01:41 +0200 |
commit | 646af76c873f46875e91390f50dc3a2efb5e6d4d (patch) | |
tree | 76bf709559583a6231df7974f2f5905d1dce4017 | |
parent | e703afdb3bcdf251be8d2f930a2bb3450f192809 (diff) | |
download | Nim-646af76c873f46875e91390f50dc3a2efb5e6d4d.tar.gz |
implemented nimPinToCpu threadpool feature
-rw-r--r-- | lib/pure/concurrency/threadpool.nim | 10 | ||||
-rw-r--r-- | web/news.txt | 6 |
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim index 7c9d8adfd..0079cf302 100644 --- a/lib/pure/concurrency/threadpool.nim +++ b/lib/pure/concurrency/threadpool.nim @@ -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) diff --git a/web/news.txt b/web/news.txt index 46867ac4c..040442695 100644 --- a/web/news.txt +++ b/web/news.txt @@ -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 |