Skip to content

Commit 1efabc6

Browse files
committed
.
1 parent 659c3c1 commit 1efabc6

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

runtime/debug.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ CHEETAH_INTERNAL extern const char *const __cilkrts_assertion_failed;
9999
: cilkrts_bug("%s: %d: cilk_assertion failed: %s (%p) == %s (%p)", \
100100
__FILE__, __LINE__, #P1, _t1, #P2, _t2);})
101101

102+
#define CILK_ASSERT_INTEGER_EQUAL(I1, I2) \
103+
({ long _t1 = (I1), _t2 = (I2); __builtin_expect(_t1 == _t2, 1) \
104+
? (void)0 \
105+
: cilkrts_bug("%s: %d: cilk_assertion failed: %s (%ld) == %s (%ld)", \
106+
__FILE__, __LINE__, #I1, _t1, #I2, _t2);})
107+
102108
#define CILK_ASSERT_INDEX_ZERO(LEFT, I, RIGHT, FMT) \
103109
(__builtin_expect(!(LEFT[I] RIGHT), 1) \
104110
? (void)0 \

runtime/global.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ struct global_state {
6363

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

66-
jmpbuf boss_ctx __attribute__((aligned(CILK_CACHE_LINE)));
67-
void *orig_rsp;
66+
void *orig_rsp __attribute__((aligned(CILK_CACHE_LINE)));
6867
bool workers_started;
6968

7069
// These fields are shared between the boss thread and a couple workers.

runtime/init.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -564,17 +564,9 @@ void __cilkrts_internal_invoke_cilkified_root(__cilkrts_stack_frame *sf) {
564564
__cilkrts_start_workers(g);
565565
}
566566

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

580572
// Finish the execution of a Cilkified region. Executed by the boss worker.

runtime/scheduler.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ static void setup_for_sync(__cilkrts_worker *w, worker_id self, Closure *t) {
212212
}
213213

214214
static void resume_boss(__cilkrts_worker *w, worker_id self, Closure *t) {
215-
CILK_ASSERT(t->status == CLOSURE_SUSPENDED);
216-
CILK_ASSERT(!Closure_has_children(t));
217215
// TODO: This should not be on any worker's deque
218216
Closure_lock(self, t);
217+
CILK_ASSERT_INTEGER_EQUAL(t->status, CLOSURE_SUSPENDED);
218+
CILK_ASSERT(!Closure_has_children(t));
219219
setup_for_sync(w, self, t);
220220
Closure_set_status(t, CLOSURE_RUNNING);
221221
Closure_unlock(self, t);
@@ -1431,6 +1431,7 @@ void do_what_it_says_boss(__cilkrts_worker *w, Closure *t) {
14311431
CILK_STOP_TIMING(w, INTERVAL_SCHED);
14321432
worker_change_state(w, WORKER_IDLE);
14331433
worker_scheduler(w);
1434+
cilkrts_bug("boss worker exited scheduling loop");
14341435
}
14351436

14361437
void worker_scheduler(__cilkrts_worker *w) {
@@ -1483,10 +1484,16 @@ void worker_scheduler(__cilkrts_worker *w) {
14831484
CILK_START_TIMING(w, INTERVAL_SCHED);
14841485
CILK_START_TIMING(w, INTERVAL_IDLE);
14851486

1486-
if (rts->activate_boss) {
1487+
if (is_boss && rts->activate_boss) {
14871488
t = rts->root_closure;
14881489
resume_boss(w, self, t);
14891490
rts->activate_boss = false;
1491+
/* bookkeeping */
1492+
fails = maybe_reengage_workers
1493+
(rts, self, nworkers, w, fails,
1494+
&sample_threshold, &inefficient_history, &efficient_history,
1495+
sentinel_count_history, &sentinel_count_history_tail,
1496+
&recent_sentinel_count);
14901497
break;
14911498
}
14921499

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

16631670
CILK_STOP_TIMING(w, INTERVAL_SCHED);
16641671
worker_change_state(w, WORKER_IDLE);
1665-
if (is_boss) {
1666-
__builtin_longjmp(rts->boss_ctx, 1);
1667-
}
16681672
}
16691673

16701674
void *scheduler_thread_proc(void *arg) {

runtime/worker_sleep.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,12 @@ handle_failed_steal_attempts(global_state *const rts, worker_id self,
467467

468468
#endif
469469
if (is_boss) {
470-
if (fails % NAP_THRESHOLD == 0 && !rts->activate_boss) {
471-
// The boss thread should never disengage or
472-
// sleep for a long time.
470+
if (fails % NAP_THRESHOLD == 0) {
471+
// The boss thread should never disengage. Sleep instead.
473472
const struct timespec sleeptime = {
474473
.tv_sec = 0,
475-
.tv_nsec = 1000
476-
};
474+
.tv_nsec =
475+
(fails > SLEEP_THRESHOLD) ? SLEEP_NSEC : NAP_NSEC};
477476
nanosleep(&sleeptime, NULL);
478477
}
479478
} else {

0 commit comments

Comments
 (0)