-
Notifications
You must be signed in to change notification settings - Fork 384
Added random scheduling #4272
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
base: master
Are you sure you want to change the base?
Added random scheduling #4272
Conversation
@rustbot ready |
self.active_thread = id; | ||
break; | ||
} | ||
.chain(self.threads.iter_enumerated().take(self.active_thread.index() + 1)) |
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.
What's with the +1 here?
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.
this is to include the current thread as well in the vec. So that it can also be randomly scheduled as well.
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.
Doesn't round robin scheduling get stuck on the same thread then possibly if the current thread is also the first thread? Or does yielding mark it as not ready so this was always just an optimization on master?
Either way, just remove the chain and take and thus just iterate all threads always?
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.
Doesn't round robin scheduling get stuck on the same thread then possibly if the current thread is also the first thread?
if the current thread is the first it means that all the other threads are terminated or blocked. So it is fine to schedule it again ig.
Or does yielding mark it as not ready so this was always just an optimization on master?
No I dont think yielding marks it as not ready.
src/bin/miri.rs
Outdated
miri_config.fixed_scheduling = true; | ||
miri_config.preemption_rate = 0.0; |
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.
We should just not auto-preempt when fixed_scheduling
is set, so we don't have to set two fields here.
src/machine.rs
Outdated
let mut threads = ThreadManager::default(); | ||
threads.set_round_robin_scheduling(config.fixed_scheduling); |
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.
Instead of such a setter, please add a ThreadManager::new
method that takes &MiriConfig
as argument.
src/concurrency/thread.rs
Outdated
.filter(|(_id, thread)| thread.state.is_enabled()) | ||
.collect::<Vec<_>>(); | ||
|
||
let mut new_thread = threads.first(); |
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.
Also here, please don't use an initialize-then-mutate pattern. It's almost always better to initialize things with the right value immediately and eschew mutation. So here that would be let new_thread = if self.round_robin_scheduling { ... } else { ... }
.
src/concurrency/thread.rs
Outdated
.filter(|(_id, thread)| thread.state.is_enabled()) | ||
.collect::<Vec<_>>(); | ||
|
||
let mut new_thread = threads.first(); |
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.
Since you are now adding the current thread, this can never be None
.
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.
but the current thread can be in terminated stated or blocked state. So this can be None
.
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.
Oh, right.
} | ||
|
||
if let Some((id, _thread)) = new_thread { |
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.
If the randomized scheduler picks the original thread again, we'll still enter this codepath and print the "thread switched" marker.
Closes #4230.