Refactor scheduler and worker creation #539
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is part 2 of refactoring the scheduler: #532
But don't merge it yet, because there is a known problem: it breaks options from command line. See below.For now we temporarily disable setting the number of GC threads from the command line.We now construct the
GCWorkScheduler
in one step, so that we no longer need to make every fieldOption<T>
and set the value duringinitialize
.To make it possible, we eliminated cyclic references by considering
MMTK
,GCWorkScheduler
andGCWorkerShared
as nested data, like this:So inner structures do not refer to outer structures. We eliminated the
GCWorkScheduler::mmtk
field.On the other hand, actors (threads) have references to all shared data they need. Both
GCWorker
andGCController
contain a reference to theMMTK
instance, so they no longer need to navigate from the scheduler to MMTK. And, obviously, private data of the actors (threads, includingGCWorker
andGCController
) never refer to one another.Known problem
We create
GCWorkScheduler
whenMMTK
is created. This is too early for now, because theMMTK
instance is usually created statically by the VM. When it is created, we still don't know how many threads we have. The number of threads is determined by themmtk.options.threads
option, which can be set by either environment variable or command-line options. This is too late for the creation ofGCWorkScheduler
. The current PR will simply disregard any changes to the value ofmmtk.options.threads
afterGCWorkScheduler
is created.To solve this problem, we need to make one (or both) of the following changes before applying this PR.
MMTKBuilder
, and build theMMTK
instance after options are parsed.GCWorkScheduler
is created.MMTK::scheduler
toOption<Arc<GCWorkScheduler>>
.We will need to do (1) anyway, because currently options are also held by an
UnsafeOptionsWrapper
, which is unsafe.Method (2) needs to make the worker group synchronised (probably using a
RwLock
). Adding aRwLock
directly may add performance overhead because the work packet system frequently queries if all workers are parked. To do it efficiently, we should redesign the synchronisation algorithm and make the lock more coarse-grained. Issue #537 covers some of the details.Method (2) will also enable the potential of dynamically adjusting the number of workers during execution, but let's not attempt that for now.
Method (3) simply pushes the
Option<T>
from the fields ofGCWorkScheduler
to the field ofMMTK
. It simply moves the problem to a different place.