forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 656
Simplify {session_,}result_with_timings types #1126
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,8 +484,8 @@ struct ThreadManager<S: SpawnableScheduler<TH>, TH: TaskHandler> { | |
pool: Arc<SchedulerPool<S, TH>>, | ||
new_task_sender: Sender<NewTaskPayload>, | ||
new_task_receiver: Receiver<NewTaskPayload>, | ||
session_result_sender: Sender<Option<ResultWithTimings>>, | ||
session_result_receiver: Receiver<Option<ResultWithTimings>>, | ||
session_result_sender: Sender<ResultWithTimings>, | ||
session_result_receiver: Receiver<ResultWithTimings>, | ||
session_result_with_timings: Option<ResultWithTimings>, | ||
scheduler_thread: Option<JoinHandle<()>>, | ||
handler_threads: Vec<JoinHandle<()>>, | ||
|
@@ -542,6 +542,7 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
(result, timings): &mut ResultWithTimings, | ||
executed_task: Box<ExecutedTask>, | ||
) { | ||
timings.accumulate(&executed_task.result_with_timings.1); | ||
match executed_task.result_with_timings.0 { | ||
Ok(()) => {} | ||
Err(error) => { | ||
|
@@ -553,7 +554,6 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
*result = Err(error); | ||
} | ||
} | ||
timings.accumulate(&executed_task.result_with_timings.1); | ||
} | ||
|
||
fn take_session_result_with_timings(&mut self) -> ResultWithTimings { | ||
|
@@ -660,7 +660,7 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
let (finished_idle_task_sender, finished_idle_task_receiver) = | ||
crossbeam_channel::unbounded::<Box<ExecutedTask>>(); | ||
|
||
let mut result_with_timings = self.session_result_with_timings.take(); | ||
assert_matches!(self.session_result_with_timings, None); | ||
|
||
// High-level flow of new tasks: | ||
// 1. the replay stage thread send a new task. | ||
|
@@ -727,19 +727,19 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
let mut state_machine = unsafe { | ||
SchedulingStateMachine::exclusively_initialize_current_thread_for_scheduling() | ||
}; | ||
let mut result_with_timings = initialized_result_with_timings(); | ||
|
||
loop { | ||
if let Ok(NewTaskPayload::OpenSubchannel(context)) = new_task_receiver.recv() { | ||
// signal about new SchedulingContext to handler threads | ||
runnable_task_sender | ||
.send_chained_channel(context, handler_count) | ||
.unwrap(); | ||
assert_matches!( | ||
result_with_timings.replace(initialized_result_with_timings()), | ||
None | ||
); | ||
} else { | ||
unreachable!(); | ||
match new_task_receiver.recv() { | ||
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. changed to match for later pr.. |
||
Ok(NewTaskPayload::OpenSubchannel(context)) => { | ||
// signal about new SchedulingContext to handler threads | ||
runnable_task_sender | ||
.send_chained_channel(context, handler_count) | ||
.unwrap(); | ||
} | ||
_ => { | ||
unreachable!(); | ||
} | ||
} | ||
|
||
let mut is_finished = false; | ||
|
@@ -769,8 +769,7 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
let executed_task = executed_task.unwrap(); | ||
|
||
state_machine.deschedule_task(&executed_task.task); | ||
let result_with_timings = result_with_timings.as_mut().unwrap(); | ||
Self::accumulate_result_with_timings(result_with_timings, executed_task); | ||
Self::accumulate_result_with_timings(&mut result_with_timings, executed_task); | ||
}, | ||
recv(dummy_unblocked_task_receiver) -> dummy => { | ||
assert_matches!(dummy, Err(RecvError)); | ||
|
@@ -801,8 +800,7 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
let executed_task = executed_task.unwrap(); | ||
|
||
state_machine.deschedule_task(&executed_task.task); | ||
let result_with_timings = result_with_timings.as_mut().unwrap(); | ||
Self::accumulate_result_with_timings(result_with_timings, executed_task); | ||
Self::accumulate_result_with_timings(&mut result_with_timings, executed_task); | ||
}, | ||
}; | ||
|
||
|
@@ -812,10 +810,9 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
if session_ending { | ||
state_machine.reinitialize(); | ||
session_result_sender | ||
.send(Some( | ||
result_with_timings | ||
.take() | ||
.unwrap_or_else(initialized_result_with_timings), | ||
.send(std::mem::replace( | ||
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. hint: this is the sole sender. |
||
&mut result_with_timings, | ||
initialized_result_with_timings(), | ||
)) | ||
.unwrap(); | ||
session_ending = false; | ||
|
@@ -894,9 +891,8 @@ impl<S: SpawnableScheduler<TH>, TH: TaskHandler> ThreadManager<S, TH> { | |
.send(NewTaskPayload::CloseSubchannel) | ||
.unwrap(); | ||
|
||
if let Some(result_with_timings) = self.session_result_receiver.recv().unwrap() { | ||
self.put_session_result_with_timings(result_with_timings); | ||
} | ||
let result_with_timings = self.session_result_receiver.recv().unwrap(); | ||
self.put_session_result_with_timings(result_with_timings); | ||
} | ||
|
||
fn start_session(&mut self, context: &SchedulingContext) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
okay, I'm now very selective for piggybacking minor cleanups.... xD