-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
runtime: steal tasks from the LIFO slot #7431
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
Open
hawkw
wants to merge
17
commits into
master
Choose a base branch
from
eliza/lifo-steal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1220253
runtime: Make multithreaded rt LIFO slot atomic
hawkw 75d8116
runtime: start moving LIFO into the run queue
hawkw 730a581
runtime: actually steal LIFO task (stupid version)
hawkw a5a656d
Merge branch 'master' into eliza/lifo-steal
hawkw 4c680ae
runtime: docs fixes
hawkw 9ad2404
runtime: add loom tests with lifo slot
hawkw fe53128
runtime: add test for #4941
hawkw 86b16c4
runtime: fix remote queue depth for metrics
hawkw 9651b82
Merge branch 'master' into eliza/lifo-steal
hawkw 0497b31
runtime: fix lifo loom tests not popping from their own lifo slots
hawkw cb27dda
runtime: fix wrong accounting for LIFO slot in new queue len
hawkw 3022aae
runtime: fix racy `worker_local_queue_depth` test
hawkw eba7e1d
Update queue.rs
hawkw f5d5766
unbreak return types after applying @mkeeter's suggestion
hawkw adf146f
match on LIFO push result
hawkw 0889f08
more comments explaining the `lifo_stealable` test
hawkw aff05a9
get rid of `should_notify`
hawkw 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
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::loom::sync::atomic::AtomicPtr; | ||
use crate::runtime::task::{Header, Notified, RawTask}; | ||
|
||
use std::marker::PhantomData; | ||
use std::ptr; | ||
use std::ptr::NonNull; | ||
use std::sync::atomic::Ordering::{AcqRel, Acquire}; | ||
|
||
/// An atomic cell which can contain a pointer to a [`Notified`] task. | ||
/// | ||
/// This is similar to the `crate::util::AtomicCell` type, but specialized to | ||
/// hold a task pointer --- this type "remembers" the task's scheduler generic | ||
/// when a task is stored in the cell, so that the pointer can be turned back | ||
/// into a [`Notified`] task with the correct generic type when it is retrieved. | ||
pub(crate) struct AtomicNotified<S: 'static> { | ||
task: AtomicPtr<Header>, | ||
_scheduler: PhantomData<S>, | ||
} | ||
|
||
impl<S: 'static> AtomicNotified<S> { | ||
pub(crate) fn empty() -> Self { | ||
Self { | ||
task: AtomicPtr::new(ptr::null_mut()), | ||
_scheduler: PhantomData, | ||
} | ||
} | ||
|
||
pub(crate) fn swap(&self, task: Option<Notified<S>>) -> Option<Notified<S>> { | ||
let new = task | ||
.map(|t| t.into_raw().header_ptr().as_ptr()) | ||
.unwrap_or_else(ptr::null_mut); | ||
let old = self.task.swap(new, AcqRel); | ||
NonNull::new(old).map(|ptr| unsafe { | ||
// Safety: since we only allow tasks with the same scheduler type to | ||
// be placed in this cell, we know that the pointed task's scheduler | ||
// type matches the type parameter S. | ||
Notified::from_raw(RawTask::from_raw(ptr)) | ||
}) | ||
} | ||
|
||
pub(crate) fn take(&self) -> Option<Notified<S>> { | ||
self.swap(None) | ||
} | ||
|
||
pub(crate) fn is_some(&self) -> bool { | ||
!self.task.load(Acquire).is_null() | ||
} | ||
} | ||
|
||
unsafe impl<S: Send> Send for AtomicNotified<S> {} | ||
unsafe impl<S: Send> Sync for AtomicNotified<S> {} | ||
|
||
impl<S> Drop for AtomicNotified<S> { | ||
fn drop(&mut self) { | ||
// Ensure the task reference is dropped if this cell is dropped. | ||
let _ = self.take(); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
For reviewers: Rust has defined the casting from
bool
tou16
.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's also possible to use
u16::from(bool)
, if you care aboutcast_lossless
cleanliness.