Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

geetanshjuneja
Copy link
Contributor

@geetanshjuneja geetanshjuneja commented Apr 13, 2025

Closes #4230.

@geetanshjuneja
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Apr 13, 2025
self.active_thread = id;
break;
}
.chain(self.threads.iter_enumerated().take(self.active_thread.index() + 1))
Copy link
Contributor

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?

Copy link
Contributor Author

@geetanshjuneja geetanshjuneja Apr 13, 2025

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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
Comment on lines 577 to 578
miri_config.fixed_scheduling = true;
miri_config.preemption_rate = 0.0;
Copy link
Member

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
Comment on lines 672 to 673
let mut threads = ThreadManager::default();
threads.set_round_robin_scheduling(config.fixed_scheduling);
Copy link
Member

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.

.filter(|(_id, thread)| thread.state.is_enabled())
.collect::<Vec<_>>();

let mut new_thread = threads.first();
Copy link
Member

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 { ... }.

.filter(|(_id, thread)| thread.state.is_enabled())
.collect::<Vec<_>>();

let mut new_thread = threads.first();
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 {
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support non-round-robin scheduling
4 participants