Skip to content

Commit

Permalink
Revert "rt: reduce no-op wakeups in the multi-threaded scheduler (tok…
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi- committed Mar 6, 2023
1 parent ff2f286 commit 54d068c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 6 additions & 7 deletions tokio/src/runtime/scheduler/multi_thread/idle.rs
Expand Up @@ -64,7 +64,7 @@ impl Idle {

// A worker should be woken up, atomically increment the number of
// searching workers as well as the number of unparked workers.
State::unpark_one(&self.state, 1);
State::unpark_one(&self.state);

// Get the worker to unpark
let ret = sleepers.pop();
Expand Down Expand Up @@ -113,21 +113,20 @@ impl Idle {
/// within the worker's park routine.
///
/// Returns `true` if the worker was parked before calling the method.
pub(super) fn unpark_worker_by_id(&self, worker_id: usize) -> bool {
pub(super) fn unpark_worker_by_id(&self, worker_id: usize) {
let mut sleepers = self.sleepers.lock();

for index in 0..sleepers.len() {
if sleepers[index] == worker_id {
sleepers.swap_remove(index);

// Update the state accordingly while the lock is held.
State::unpark_one(&self.state, 0);
State::unpark_one(&self.state);

return true;
return;
}
}

false
}

/// Returns `true` if `worker_id` is contained in the sleep set.
Expand Down Expand Up @@ -155,8 +154,8 @@ impl State {
State(cell.load(ordering))
}

fn unpark_one(cell: &AtomicUsize, num_searching: usize) {
cell.fetch_add(num_searching | (1 << UNPARK_SHIFT), SeqCst);
fn unpark_one(cell: &AtomicUsize) {
cell.fetch_add(1 | (1 << UNPARK_SHIFT), SeqCst);
}

fn inc_num_searching(cell: &AtomicUsize, ordering: Ordering) {
Expand Down
5 changes: 3 additions & 2 deletions tokio/src/runtime/scheduler/multi_thread/worker.rs
Expand Up @@ -570,7 +570,7 @@ impl Context {

// If there are tasks available to steal, but this worker is not
// looking for tasks to steal, notify another worker.
if !core.is_searching && core.run_queue.is_stealable() {
if core.run_queue.is_stealable() {
self.worker.handle.notify_parked();
}

Expand Down Expand Up @@ -687,7 +687,8 @@ impl Core {
// state when the wake originates from another worker *or* a new task
// is pushed. We do *not* want the worker to transition to "searching"
// when it wakes when the I/O driver receives new events.
self.is_searching = !worker.handle.shared.idle.unpark_worker_by_id(worker.index);
worker.shared.idle.unpark_worker_by_id(worker.index);
self.is_searching = true;
return true;
}

Expand Down

0 comments on commit 54d068c

Please sign in to comment.