-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply misc small cleanups to unified scheduler #4080
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,7 +551,7 @@ mod chained_channel { | |
|
||
pub(super) fn send_chained_channel( | ||
&mut self, | ||
context: C, | ||
context: &C, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. taking ref here will soon be desired in upcoming pr... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. difference here is only that |
||
count: usize, | ||
) -> std::result::Result<(), SendError<ChainedChannel<P, C>>> { | ||
let (chained_sender, chained_receiver) = crossbeam_channel::unbounded(); | ||
|
@@ -771,7 +771,6 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
fn new(pool: Arc<SchedulerPool<S, TH>>) -> Self { | ||
let (new_task_sender, new_task_receiver) = crossbeam_channel::unbounded(); | ||
let (session_result_sender, session_result_receiver) = crossbeam_channel::unbounded(); | ||
let handler_count = pool.handler_count; | ||
|
||
Self { | ||
scheduler_id: pool.new_scheduler_id(), | ||
|
@@ -782,7 +781,7 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
session_result_receiver, | ||
session_result_with_timings: None, | ||
scheduler_thread: None, | ||
handler_threads: Vec::with_capacity(handler_count), | ||
handler_threads: vec![], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
|
@@ -1101,7 +1100,7 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
// enter into the preceding `while(!is_finished) {...}` loop again. | ||
// Before that, propagate new SchedulingContext to handler threads | ||
runnable_task_sender | ||
.send_chained_channel(new_context, handler_count) | ||
.send_chained_channel(&new_context, handler_count) | ||
.unwrap(); | ||
result_with_timings = new_result_with_timings; | ||
} | ||
|
@@ -1152,54 +1151,56 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
// 2. Subsequent contexts are propagated explicitly inside `.after_select()` as part of | ||
// `select_biased!`, which are sent from `.send_chained_channel()` in the scheduler | ||
// thread for all-but-initial sessions. | ||
move || loop { | ||
let (task, sender) = select_biased! { | ||
recv(runnable_task_receiver.for_select()) -> message => { | ||
let Ok(message) = message else { | ||
break; | ||
}; | ||
if let Some(task) = runnable_task_receiver.after_select(message) { | ||
(task, &finished_blocked_task_sender) | ||
} else { | ||
continue; | ||
move || { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just indent stuff |
||
loop { | ||
let (task, sender) = select_biased! { | ||
recv(runnable_task_receiver.for_select()) -> message => { | ||
let Ok(message) = message else { | ||
break; | ||
}; | ||
if let Some(task) = runnable_task_receiver.after_select(message) { | ||
(task, &finished_blocked_task_sender) | ||
} else { | ||
continue; | ||
} | ||
}, | ||
recv(runnable_task_receiver.aux_for_select()) -> task => { | ||
if let Ok(task) = task { | ||
(task, &finished_idle_task_sender) | ||
} else { | ||
runnable_task_receiver.never_receive_from_aux(); | ||
continue; | ||
} | ||
}, | ||
}; | ||
defer! { | ||
if !thread::panicking() { | ||
return; | ||
} | ||
}, | ||
recv(runnable_task_receiver.aux_for_select()) -> task => { | ||
if let Ok(task) = task { | ||
(task, &finished_idle_task_sender) | ||
|
||
// The scheduler thread can't detect panics in handler threads with | ||
// disconnected channel errors, unless all of them has died. So, send an | ||
// explicit Err promptly. | ||
let current_thread = thread::current(); | ||
error!("handler thread is panicking: {:?}", current_thread); | ||
if sender.send(Err(HandlerPanicked)).is_ok() { | ||
info!("notified a panic from {:?}", current_thread); | ||
} else { | ||
runnable_task_receiver.never_receive_from_aux(); | ||
continue; | ||
// It seems that the scheduler thread has been aborted already... | ||
warn!("failed to notify a panic from {:?}", current_thread); | ||
} | ||
}, | ||
}; | ||
defer! { | ||
if !thread::panicking() { | ||
return; | ||
} | ||
|
||
// The scheduler thread can't detect panics in handler threads with | ||
// disconnected channel errors, unless all of them has died. So, send an | ||
// explicit Err promptly. | ||
let current_thread = thread::current(); | ||
error!("handler thread is panicking: {:?}", current_thread); | ||
if sender.send(Err(HandlerPanicked)).is_ok() { | ||
info!("notified a panic from {:?}", current_thread); | ||
} else { | ||
// It seems that the scheduler thread has been aborted already... | ||
warn!("failed to notify a panic from {:?}", current_thread); | ||
let mut task = ExecutedTask::new_boxed(task); | ||
Self::execute_task_with_handler( | ||
runnable_task_receiver.context(), | ||
&mut task, | ||
&pool.handler_context, | ||
); | ||
if sender.send(Ok(task)).is_err() { | ||
warn!("handler_thread: scheduler thread aborted..."); | ||
break; | ||
} | ||
} | ||
let mut task = ExecutedTask::new_boxed(task); | ||
Self::execute_task_with_handler( | ||
runnable_task_receiver.context(), | ||
&mut task, | ||
&pool.handler_context, | ||
); | ||
if sender.send(Ok(task)).is_err() { | ||
warn!("handler_thread: scheduler thread aborted..."); | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
|
@@ -1441,7 +1442,7 @@ impl<TH: TaskHandler> InstalledScheduler for PooledScheduler<TH> { | |
|
||
impl<S, TH> UninstalledScheduler for PooledSchedulerInner<S, TH> | ||
where | ||
S: SpawnableScheduler<TH, Inner = PooledSchedulerInner<S, TH>>, | ||
S: SpawnableScheduler<TH, Inner = Self>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see 2 line above... ;) |
||
TH: TaskHandler, | ||
{ | ||
fn return_to_pool(self: Box<Self>) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it turned out returning all call sites ended up calling .clone_with_scheduler() immediately after this. so, just do it inside here.
also, this makes it consistent the cousin (
BankForks::working_bank
), which isn't returning refs as well.