Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxSciurorum committed Sep 19, 2024
1 parent 659c3c1 commit 1efabc6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
6 changes: 6 additions & 0 deletions runtime/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ CHEETAH_INTERNAL extern const char *const __cilkrts_assertion_failed;
: cilkrts_bug("%s: %d: cilk_assertion failed: %s (%p) == %s (%p)", \
__FILE__, __LINE__, #P1, _t1, #P2, _t2);})

#define CILK_ASSERT_INTEGER_EQUAL(I1, I2) \
({ long _t1 = (I1), _t2 = (I2); __builtin_expect(_t1 == _t2, 1) \
? (void)0 \
: cilkrts_bug("%s: %d: cilk_assertion failed: %s (%ld) == %s (%ld)", \
__FILE__, __LINE__, #I1, _t1, #I2, _t2);})

#define CILK_ASSERT_INDEX_ZERO(LEFT, I, RIGHT, FMT) \
(__builtin_expect(!(LEFT[I] RIGHT), 1) \
? (void)0 \
Expand Down
3 changes: 1 addition & 2 deletions runtime/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ struct global_state {

// These fields are accessed exclusively by the boss thread.

jmpbuf boss_ctx __attribute__((aligned(CILK_CACHE_LINE)));
void *orig_rsp;
void *orig_rsp __attribute__((aligned(CILK_CACHE_LINE)));
bool workers_started;

// These fields are shared between the boss thread and a couple workers.
Expand Down
14 changes: 3 additions & 11 deletions runtime/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,17 +564,9 @@ void __cilkrts_internal_invoke_cilkified_root(__cilkrts_stack_frame *sf) {
__cilkrts_start_workers(g);
}

if (__builtin_setjmp(g->boss_ctx) == 0) {
CILK_SWITCH_TIMING(w, INTERVAL_CILKIFY_ENTER, INTERVAL_SCHED);
do_what_it_says_boss(w, root_closure);
} else {
// The stack on which
// __cilkrts_internal_invoke_cilkified_root() was called may
// be corrupted at this point, so we call this helper method,
// marked noinline, to ensure the compiler does not try to use
// any data from the stack.
boss_wait_helper();
}
// XXX Temporary
CILK_SWITCH_TIMING(w, INTERVAL_CILKIFY_ENTER, INTERVAL_SCHED);
do_what_it_says_boss(w, root_closure);
}

// Finish the execution of a Cilkified region. Executed by the boss worker.
Expand Down
16 changes: 10 additions & 6 deletions runtime/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ static void setup_for_sync(__cilkrts_worker *w, worker_id self, Closure *t) {
}

static void resume_boss(__cilkrts_worker *w, worker_id self, Closure *t) {
CILK_ASSERT(t->status == CLOSURE_SUSPENDED);
CILK_ASSERT(!Closure_has_children(t));
// TODO: This should not be on any worker's deque
Closure_lock(self, t);
CILK_ASSERT_INTEGER_EQUAL(t->status, CLOSURE_SUSPENDED);
CILK_ASSERT(!Closure_has_children(t));
setup_for_sync(w, self, t);
Closure_set_status(t, CLOSURE_RUNNING);
Closure_unlock(self, t);
Expand Down Expand Up @@ -1431,6 +1431,7 @@ void do_what_it_says_boss(__cilkrts_worker *w, Closure *t) {
CILK_STOP_TIMING(w, INTERVAL_SCHED);
worker_change_state(w, WORKER_IDLE);
worker_scheduler(w);
cilkrts_bug("boss worker exited scheduling loop");
}

void worker_scheduler(__cilkrts_worker *w) {
Expand Down Expand Up @@ -1483,10 +1484,16 @@ void worker_scheduler(__cilkrts_worker *w) {
CILK_START_TIMING(w, INTERVAL_SCHED);
CILK_START_TIMING(w, INTERVAL_IDLE);

if (rts->activate_boss) {
if (is_boss && rts->activate_boss) {
t = rts->root_closure;
resume_boss(w, self, t);
rts->activate_boss = false;
/* bookkeeping */
fails = maybe_reengage_workers
(rts, self, nworkers, w, fails,
&sample_threshold, &inefficient_history, &efficient_history,
sentinel_count_history, &sentinel_count_history_tail,
&recent_sentinel_count);
break;
}

Expand Down Expand Up @@ -1662,9 +1669,6 @@ void worker_scheduler(__cilkrts_worker *w) {

CILK_STOP_TIMING(w, INTERVAL_SCHED);
worker_change_state(w, WORKER_IDLE);
if (is_boss) {
__builtin_longjmp(rts->boss_ctx, 1);
}
}

void *scheduler_thread_proc(void *arg) {
Expand Down
9 changes: 4 additions & 5 deletions runtime/worker_sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,12 @@ handle_failed_steal_attempts(global_state *const rts, worker_id self,

#endif
if (is_boss) {
if (fails % NAP_THRESHOLD == 0 && !rts->activate_boss) {
// The boss thread should never disengage or
// sleep for a long time.
if (fails % NAP_THRESHOLD == 0) {
// The boss thread should never disengage. Sleep instead.
const struct timespec sleeptime = {
.tv_sec = 0,
.tv_nsec = 1000
};
.tv_nsec =
(fails > SLEEP_THRESHOLD) ? SLEEP_NSEC : NAP_NSEC};
nanosleep(&sleeptime, NULL);
}
} else {
Expand Down

0 comments on commit 1efabc6

Please sign in to comment.