Skip to content

Commit 23de87e

Browse files
committed
Simplify scheduling, do cleanup
1 parent 35fbeec commit 23de87e

File tree

4 files changed

+17
-59
lines changed

4 files changed

+17
-59
lines changed

src/concurrency/genmc/dummy.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ impl GenmcCtx {
226226
unreachable!()
227227
}
228228

229+
/**** Scheduling functionality ****/
230+
231+
pub fn schedule_thread<'tcx>(
232+
&self,
233+
_ecx: &InterpCx<'tcx, MiriMachine<'tcx>>,
234+
) -> InterpResult<'tcx, ThreadId> {
235+
unreachable!()
236+
}
237+
229238
/**** Blocking instructions ****/
230239

231240
#[allow(unused)]

src/concurrency/genmc/mod.rs

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ use self::helper::{
1818
use self::mapping::{min_max_to_genmc_rmw_op, to_genmc_rmw_op};
1919
use self::thread_info_manager::ThreadInfoManager;
2020
use crate::concurrency::genmc::helper::{is_terminator_atomic, split_access};
21-
use crate::concurrency::thread::{EvalContextExt as _, ThreadState};
2221
use crate::{
23-
AtomicFenceOrd, AtomicReadOrd, AtomicRwOrd, AtomicWriteOrd, BlockReason, MemoryKind,
24-
MiriConfig, MiriMachine, MiriMemoryKind, Scalar, TerminationInfo, ThreadId, ThreadManager,
25-
VisitProvenance, VisitWith,
22+
AtomicFenceOrd, AtomicReadOrd, AtomicRwOrd, AtomicWriteOrd, MemoryKind, MiriConfig,
23+
MiriMachine, MiriMemoryKind, Scalar, TerminationInfo, ThreadId, ThreadManager, VisitProvenance,
24+
VisitWith,
2625
};
2726

2827
mod config;
@@ -843,7 +842,7 @@ impl GenmcCtx {
843842

844843
/**** Scheduling functionality ****/
845844

846-
fn schedule_thread<'tcx>(
845+
pub fn schedule_thread<'tcx>(
847846
&self,
848847
ecx: &InterpCx<'tcx, MiriMachine<'tcx>>,
849848
) -> InterpResult<'tcx, ThreadId> {
@@ -910,49 +909,6 @@ impl GenmcCtx {
910909
}
911910
}
912911

913-
/// Other functionality not directly related to event handling
914-
impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
915-
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
916-
/**** Scheduling functionality ****/
917-
918-
/// Ask for a scheduling decision. This should be called before every MIR instruction.
919-
///
920-
/// GenMC may realize that the execution is blocked, then this function will return a `InterpErrorKind::MachineStop` with error kind `TerminationInfo::GenmcBlockedExecution`).
921-
///
922-
/// This is **not** an error by iself! Treat this as if the program ended normally: `handle_execution_end` should be called next, which will determine if were are any actual errors.
923-
fn genmc_schedule_thread(&mut self) -> InterpResult<'tcx, ThreadId> {
924-
let this = self.eval_context_mut();
925-
loop {
926-
let genmc_ctx = this.machine.data_race.as_genmc_ref().unwrap();
927-
let next_thread_id = genmc_ctx.schedule_thread(this)?;
928-
929-
match this.machine.threads.threads_ref()[next_thread_id].get_state() {
930-
ThreadState::Blocked {
931-
reason: block_reason @ (BlockReason::Mutex | BlockReason::GenmcAssume),
932-
..
933-
} => {
934-
info!(
935-
"GenMC: schedule returned thread {next_thread_id:?}, which is blocked, so we unblock it now."
936-
);
937-
this.unblock_thread(next_thread_id, *block_reason)?;
938-
939-
// In some cases, like waiting on a Mutex::lock, the thread might still be blocked here:
940-
if this.machine.threads.threads_ref()[next_thread_id]
941-
.get_state()
942-
.is_blocked_on(crate::BlockReason::Mutex)
943-
{
944-
info!("GenMC: Unblocked thread is blocked on a Mutex again!");
945-
continue;
946-
}
947-
}
948-
_ => {}
949-
}
950-
951-
return interp_ok(next_thread_id);
952-
}
953-
}
954-
}
955-
956912
impl VisitProvenance for GenmcCtx {
957913
fn visit_provenance(&self, _visit: &mut VisitWith<'_>) {
958914
// We don't have any tags.

src/concurrency/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ pub mod weak_memory;
2222
mod genmc;
2323

2424
pub use self::data_race_handler::{AllocDataRaceHandler, GlobalDataRaceHandler};
25-
pub use self::genmc::{EvalContextExt as GenmcEvalContextExt, GenmcConfig, GenmcCtx, miri_genmc};
25+
pub use self::genmc::{GenmcConfig, GenmcCtx, miri_genmc};
2626
pub use self::vector_clock::VClock;

src/concurrency/thread.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::mir::Mutability;
1616
use rustc_middle::ty::layout::TyAndLayout;
1717
use rustc_span::Span;
1818

19-
use crate::concurrency::{GenmcEvalContextExt as _, GlobalDataRaceHandler};
19+
use crate::concurrency::GlobalDataRaceHandler;
2020
use crate::shims::tls;
2121
use crate::*;
2222

@@ -110,8 +110,6 @@ pub enum BlockReason {
110110
Eventfd,
111111
/// Blocked on unnamed_socket.
112112
UnnamedSocket,
113-
/// Blocked on a GenMC `assume` statement (GenMC mode only).
114-
GenmcAssume,
115113
}
116114

117115
/// The state of a thread.
@@ -535,11 +533,6 @@ impl<'tcx> ThreadManager<'tcx> {
535533
self.active_thread
536534
}
537535

538-
pub fn threads_ref(&self) -> &IndexVec<ThreadId, Thread<'tcx>> {
539-
// TODO GENMC: should this implementation detail be exposed?
540-
&self.threads
541-
}
542-
543536
/// Get the total number of threads that were ever spawn by this program.
544537
pub fn get_total_thread_count(&self) -> usize {
545538
self.threads.len()
@@ -725,8 +718,8 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
725718
let this = self.eval_context_mut();
726719

727720
// In GenMC mode, we let GenMC do the scheduling.
728-
if this.machine.data_race.as_genmc_ref().is_some() {
729-
let next_thread_id = this.genmc_schedule_thread()?;
721+
if let Some(genmc_ctx) = this.machine.data_race.as_genmc_ref() {
722+
let next_thread_id = genmc_ctx.schedule_thread(this)?;
730723

731724
let thread_manager = &mut this.machine.threads;
732725
thread_manager.active_thread = next_thread_id;

0 commit comments

Comments
 (0)