Skip to content

Commit

Permalink
fixup! threads: further optimize scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Sep 10, 2019
1 parent 63d6bc6 commit f2039a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/partr.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ JL_DLLEXPORT int jl_enqueue_task(jl_task_t *task)
// sleep_check_after_threshold() -- if sleep_threshold ns have passed, return 1
static int sleep_check_after_threshold(uint64_t *start_cycles)
{
return 1;
JULIA_DEBUG_SLEEPWAKE( return 1 ); // hammer on the sleep/wake logic much harder
if (!(*start_cycles)) {
*start_cycles = jl_hrtime();
Expand All @@ -338,7 +339,7 @@ static int sleep_check_after_threshold(uint64_t *start_cycles)
static void wake_thread(int16_t tid)
{
jl_ptls_t other = jl_all_tls_states[tid];
if (jl_atomic_load(&other->sleep_check_state) != not_sleeping) {
if (1 /*jl_atomic_load(&other->sleep_check_state) != not_sleeping*/) {
int16_t state = jl_atomic_exchange(&other->sleep_check_state, not_sleeping); // prohibit it from sleeping
if (state == sleeping) { // see if it was possibly sleeping before now
uv_mutex_lock(&other->sleep_lock);
Expand Down Expand Up @@ -375,8 +376,8 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid)
// something added to the sticky-queue: notify that thread
wake_thread(tid);
// check if we need to notify uv_run too
/*unsigned long system_tid = jl_all_tls_states[tid]->system_id;*/
if (uvlock != system_self /*TODO: && jl_atomic_load(&jl_uv_mutex.owner) == system_tid*/)
unsigned long system_tid = jl_all_tls_states[tid]->system_id;
if (uvlock != system_self && jl_atomic_load(&jl_uv_mutex.owner) == system_tid)
wake_libuv();
}
// check if the other threads might be sleeping
Expand All @@ -391,7 +392,7 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid)
if (tid != self)
wake_thread(tid);
// check if we need to notify uv_run too
if (uvlock != system_self /*TODO: && jl_atomic_load(&jl_uv_mutex.owner) != 0*/)
if (uvlock != system_self && jl_atomic_load(&jl_uv_mutex.owner) != 0)
wake_libuv();
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,11 @@ JL_DLLEXPORT void jl_threading_run(jl_value_t *func)
args2[0] = schd_func;
args2[1] = (jl_value_t*)t;
jl_apply(args2, 2);
if (i == 1 && nthreads > 1) {
if (i == 1 && nthreads > 2) {
// hint to threads that work is coming soon
jl_wakeup_thread(-1);
}
}
if (nthreads > 1) {
// let threads know work is ready (guaranteed)
jl_wakeup_thread(-1);
}
// join with all tasks
JL_TRY {
for (int i = 0; i < nthreads; i++) {
Expand Down

0 comments on commit f2039a3

Please sign in to comment.