Skip to content

Commit

Permalink
commented out some spin master stuff for now
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Feb 9, 2023
1 parent aaec774 commit abe4675
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/partr.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ int64_t gc_spin_master_count_work(jl_ptls_t ptls)

void gc_spin_master_recruit_workers(jl_ptls_t ptls, size_t nworkers)
{
// Only try to recruit threads 1..jl_n_gcthreads (that's it the gc threads)
// Only try to recruit threads 1..jl_n_gcthreads (that's it, the gc threads)
for (int i = 1; i <= jl_n_gcthreads && nworkers > 0; i++) {
if (i != ptls->tid) {
jl_ptls_t ptls2 = gc_all_tls_states[i];
if (jl_atomic_load(&ptls2->gc_state) == JL_GC_STATE_WAITING) {
uv_mutex_lock(&ptls2->sleep_lock);
jl_atomic_store(&ptls2->gc_state, 0);
// jl_atomic_store(&ptls2->gc_state, 0);
uv_cond_signal(&ptls2->wake_signal);
uv_mutex_unlock(&ptls2->sleep_lock);
nworkers--;
Expand All @@ -159,15 +159,15 @@ void gc_spin_master_notify_all(void)

void gc_try_to_become_spin_master(jl_ptls_t ptls)
{
if (jl_atomic_load(&gc_n_threads_marking) == 0) {
if (!jl_atomic_load(&jl_gc_marking)) {
return;
}
if (jl_mutex_trylock_nogc(&gc_spin_master_lock)) {
spin : {
if (jl_atomic_load(&gc_n_threads_marking) != 0) {
if (jl_atomic_load(&jl_gc_marking)) {
int64_t work = gc_spin_master_count_work(ptls);
if (work > 1) {
jl_atomic_store(&ptls->gc_state, 0);
// jl_atomic_store(&ptls->gc_state, 0);
gc_spin_master_recruit_workers(ptls, work - 1);
jl_mutex_unlock_nogc(&gc_spin_master_lock);
gc_mark_loop_worker(ptls);
Expand All @@ -176,12 +176,12 @@ void gc_try_to_become_spin_master(jl_ptls_t ptls)
goto spin;
}
}
gc_spin_master_notify_all();
// gc_spin_master_notify_all();
jl_mutex_unlock_nogc(&gc_spin_master_lock);
}
}

const size_t timeout_ns = 10000;
const size_t timeout_ns = 1000;

// gc thread function
void jl_gc_threadfun(void *arg)
Expand All @@ -204,16 +204,18 @@ void jl_gc_threadfun(void *arg)
uv_mutex_unlock(&gc_threads_lock);
while (jl_atomic_load(&jl_gc_marking)) {
gc_try_to_become_spin_master(ptls);
uv_mutex_lock(&ptls->sleep_lock);
while (jl_atomic_load(&ptls->gc_state) == JL_GC_STATE_WAITING) {
uv_cond_timedwait(&ptls->wake_signal, &ptls->sleep_lock, timeout_ns);
}
uv_mutex_unlock(&ptls->sleep_lock);
// Wait until get recruited by spin master
// The wait is timed to ensure a new spin master is
// "elected" after some time
// uv_mutex_lock(&ptls->sleep_lock);
// while (jl_atomic_load(&ptls->gc_state) == JL_GC_STATE_WAITING) {
// uv_cond_timedwait(&ptls->wake_signal, &ptls->sleep_lock, timeout_ns);
// }
// uv_mutex_unlock(&ptls->sleep_lock);
// Thread was recruited for parallel marking
if (jl_atomic_load(&ptls->gc_state) == 0) {
gc_mark_loop_worker(ptls);
jl_atomic_store(&ptls->gc_state, JL_GC_STATE_WAITING);
}
// if (jl_atomic_load(&ptls->gc_state) == 0) {
// gc_mark_loop_worker(ptls);
// }
}
}
}
Expand Down

0 comments on commit abe4675

Please sign in to comment.