Skip to content

Commit

Permalink
Stashing: Sadly, we might never know the perf of this channel, back t…
Browse files Browse the repository at this point in the history
…o the drawing board - nim-lang/Nim#12695
  • Loading branch information
mratsim committed Nov 21, 2019
1 parent 1743c3b commit 6520097
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion weave/datatypes/context_global.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import
../channels/channels_mpsc_bounded_lock,
../channels/channels_mpsc_unbounded,
../channels/channels_spsc_single_ptr,
../memory/persistacks,
../config,
Expand Down Expand Up @@ -35,7 +36,7 @@ type
# would work but then it requires a pointer indirection
# per channel
# and a known max number of workers
thefts*: ptr UncheckedArray[ChannelLegacy[StealRequest]]
thefts*: ptr UncheckedArray[ChannelMPSCunbounded[StealRequest]]
tasks*: ptr UncheckedArray[Persistack[WV_MaxConcurrentStealPerWorker, ChannelSpscSinglePtr[Task]]]

GlobalContext* = object
Expand Down
6 changes: 4 additions & 2 deletions weave/datatypes/sync_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import
../config,
../channels/channels_spsc_single_ptr,
../instrumentation/contracts,
../memory/allocs
../memory/allocs,
std/atomics

# Inter-thread synchronization types
# ----------------------------------------------------------------------------------
Expand Down Expand Up @@ -72,7 +73,8 @@ type
# Padding shouldn't be needed as steal requests are used as value types
# and deep-copied between threads
StealRequest* = ptr object
thiefAddr*: ptr ChannelSpscSinglePtr[Task] # Channel for sending tasks back to the thief
next*: Atomic[StealRequest] # For intrusive lists and queues
thiefAddr*: ptr ChannelSpscSinglePtr[Task] # Channel for sending tasks back to the thief
thiefID*: WorkerID
retry*: int32 # 0 <= retry <= num_workers
victims*: SparseSet # set of potential victims
Expand Down
9 changes: 7 additions & 2 deletions weave/scheduler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import
./primitives/barriers,
./datatypes/[sync_types, prell_deques, context_thread_local, flowvars, sparsesets],
./channels/[channels_mpsc_bounded_lock, channels_spsc_single_ptr, channels_spsc_single_object],
./memory/[persistacks, intrusive_stacks],
./memory/[persistacks, intrusive_stacks, allocs],
./contexts, ./config,
./victims, ./loop_splitting,
./thieves, ./workers,
Expand All @@ -28,10 +28,14 @@ proc init*(ctx: var TLContext) =
## Initialize the thread-local context of a worker (including the lead worker)

myWorker().deque = newPrellDeque(Task)
myThieves().initialize(WV_MaxConcurrentStealPerWorker * workforce())
myTodoBoxes().initialize()
myWorker().initialize(maxID = workforce() - 1)

# The StealRequest MPSC channel requires a dummy node
var dummy: StealRequest
wv_allocPtr(dummy)
myThieves().initialize(dummy)

localCtx.stealCache.initialize()
for i in 0 ..< localCtx.stealCache.len:
localCtx.stealCache.access(i).victims.allocate(capacity = workforce())
Expand Down Expand Up @@ -148,6 +152,7 @@ proc schedulingLoop() =

proc threadLocalCleanup*() =
myWorker().deque.delete()
myThieves().removeDummy().wv_free()
myThieves().delete()

for i in 0 ..< WV_MaxConcurrentStealPerWorker:
Expand Down
2 changes: 1 addition & 1 deletion weave/thieves.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import
./datatypes/[sparsesets, sync_types, context_thread_local],
./contexts, ./targets,
./instrumentation/[contracts, profilers, loggers],
./channels/channels_mpsc_bounded_lock,
./channels/channels_mpsc_unbounded,
./memory/persistacks,
./config, ./signals

Expand Down

0 comments on commit 6520097

Please sign in to comment.