Skip to content

Commit

Permalink
Refactoring and tidy up
Browse files Browse the repository at this point in the history
This is a port of some of the changes from my private local-GC branch
(which is still in darcs, I haven't converted it to git yet).  There
are a couple of small functional differences in the GC stats: first,
per-thread GC timings should now be more accurate, and secondly we now
report average and maximum pause times. e.g. from minimax +RTS -N8 -s:

                                    Tot time (elapsed)  Avg pause  Max pause
  Gen  0      2755 colls,  2754 par   13.16s    0.93s     0.0003s    0.0150s
  Gen  1       769 colls,   769 par    3.71s    0.26s     0.0003s    0.0059s
  • Loading branch information
simonmar committed Apr 11, 2011
1 parent 7bf5bf3 commit 1fb3844
Show file tree
Hide file tree
Showing 19 changed files with 465 additions and 411 deletions.
46 changes: 18 additions & 28 deletions rts/Capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,51 +842,41 @@ freeCapabilities (void)
------------------------------------------------------------------------ */

void
markSomeCapabilities (evac_fn evac, void *user, nat i0, nat delta,
rtsBool no_mark_sparks USED_IF_THREADS)
markCapability (evac_fn evac, void *user, Capability *cap,
rtsBool no_mark_sparks USED_IF_THREADS)
{
nat i;
Capability *cap;
InCall *incall;

// Each GC thread is responsible for following roots from the
// Capability of the same number. There will usually be the same
// or fewer Capabilities as GC threads, but just in case there
// are more, we mark every Capability whose number is the GC
// thread's index plus a multiple of the number of GC threads.
for (i = i0; i < n_capabilities; i += delta) {
cap = &capabilities[i];
evac(user, (StgClosure **)(void *)&cap->run_queue_hd);
evac(user, (StgClosure **)(void *)&cap->run_queue_tl);
evac(user, (StgClosure **)(void *)&cap->run_queue_hd);
evac(user, (StgClosure **)(void *)&cap->run_queue_tl);
#if defined(THREADED_RTS)
evac(user, (StgClosure **)(void *)&cap->inbox);
evac(user, (StgClosure **)(void *)&cap->inbox);
#endif
for (incall = cap->suspended_ccalls; incall != NULL;
incall=incall->next) {
evac(user, (StgClosure **)(void *)&incall->suspended_tso);
}
for (incall = cap->suspended_ccalls; incall != NULL;
incall=incall->next) {
evac(user, (StgClosure **)(void *)&incall->suspended_tso);
}

#if defined(THREADED_RTS)
if (!no_mark_sparks) {
traverseSparkQueue (evac, user, cap);
}
#endif
if (!no_mark_sparks) {
traverseSparkQueue (evac, user, cap);
}
#endif

#if !defined(THREADED_RTS)
evac(user, (StgClosure **)(void *)&blocked_queue_hd);
evac(user, (StgClosure **)(void *)&blocked_queue_tl);
evac(user, (StgClosure **)(void *)&sleeping_queue);
#endif
// Free STM structures for this Capability
stmPreGCHook(cap);
}

void
markCapabilities (evac_fn evac, void *user)
{
markSomeCapabilities(evac, user, 0, 1, rtsFalse);
nat n;
for (n = 0; n < n_capabilities; n++) {
markCapability(evac, user, &capabilities[n], rtsFalse);
}
}

/* -----------------------------------------------------------------------------
Messages
-------------------------------------------------------------------------- */

6 changes: 4 additions & 2 deletions rts/Capability.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ INLINE_HEADER void contextSwitchCapability(Capability *cap);
void freeCapabilities (void);

// For the GC:
void markSomeCapabilities (evac_fn evac, void *user, nat i0, nat delta,
rtsBool no_mark_sparks);
void markCapability (evac_fn evac, void *user, Capability *cap,
rtsBool no_mark_sparks USED_IF_THREADS);

void markCapabilities (evac_fn evac, void *user);

void traverseSparkQueues (evac_fn evac, void *user);

/* -----------------------------------------------------------------------------
Expand Down
13 changes: 4 additions & 9 deletions rts/STM.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,17 +879,12 @@ static StgBool check_read_only(StgTRecHeader *trec STG_UNUSED) {

/************************************************************************/

void stmPreGCHook() {
nat i;

void stmPreGCHook (Capability *cap) {
lock_stm(NO_TREC);
TRACE("stmPreGCHook");
for (i = 0; i < n_capabilities; i ++) {
Capability *cap = &capabilities[i];
cap -> free_tvar_watch_queues = END_STM_WATCH_QUEUE;
cap -> free_trec_chunks = END_STM_CHUNK_LIST;
cap -> free_trec_headers = NO_TREC;
}
cap->free_tvar_watch_queues = END_STM_WATCH_QUEUE;
cap->free_trec_chunks = END_STM_CHUNK_LIST;
cap->free_trec_headers = NO_TREC;
unlock_stm(NO_TREC);
}

Expand Down
2 changes: 1 addition & 1 deletion rts/STM.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
--------------
*/

void stmPreGCHook(void);
void stmPreGCHook(Capability *cap);

/*----------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions rts/Schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,16 @@ freeScheduler( void )
#endif
}

void markScheduler (evac_fn evac USED_IF_NOT_THREADS,
void *user USED_IF_NOT_THREADS)
{
#if !defined(THREADED_RTS)
evac(user, (StgClosure **)(void *)&blocked_queue_hd);
evac(user, (StgClosure **)(void *)&blocked_queue_tl);
evac(user, (StgClosure **)(void *)&sleeping_queue);
#endif
}

/* -----------------------------------------------------------------------------
performGC
Expand Down
1 change: 1 addition & 0 deletions rts/Schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
void initScheduler (void);
void exitScheduler (rtsBool wait_foreign);
void freeScheduler (void);
void markScheduler (evac_fn evac, void *user);

// Place a new thread on the run queue of the current Capability
void scheduleThread (Capability *cap, StgTSO *tso);
Expand Down
Loading

0 comments on commit 1fb3844

Please sign in to comment.