Skip to content

Commit 61c06af

Browse files
fix: revert change_state conditional reorder and sigurg_handler Syscall check, reorder WriteSyscallFacade to match impl_facade!
Agent-Logs-Url: https://github.com/acl-dev/open-coroutine/sessions/6b5b9353-541a-4b6b-9636-2fdee16b53fd Co-authored-by: loongs-zhang <38336731+loongs-zhang@users.noreply.github.com>
1 parent b364319 commit 61c06af

File tree

3 files changed

+5
-38
lines changed

3 files changed

+5
-38
lines changed

core/src/coroutine/state.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,11 @@ where
1818
new_state: CoroutineState<Yield, Return>,
1919
) -> CoroutineState<Yield, Return> {
2020
let old_state = self.state.replace(new_state);
21-
//对→Running的转换:先记录日志再通知MonitorListener。
22-
//on_state_changed(Running)会通过MonitorListener设置10ms的NOTIFY_NODE定时器,
23-
//如果先通知再记录日志,在QEMU等慢平台上info!()可能耗时>10ms,
24-
//导致定时器在日志记录期间过期→SIGURG→抢占活锁。
25-
//先记录日志确保NOTIFY_NODE定时器在日志I/O完成后才启动。
26-
// For →Running transitions: log BEFORE notifying MonitorListener.
27-
// on_state_changed(Running) sets a 10ms NOTIFY_NODE timer via MonitorListener.
28-
// If notified first, info!() can take >10ms on slow platforms (QEMU),
29-
// causing the timer to expire during logging → SIGURG → preemption live-lock.
30-
// Logging first ensures the NOTIFY_NODE timer starts after slow I/O completes.
31-
if matches!(new_state, CoroutineState::Running) {
32-
info!("{} {:?}->{:?}", self.name(), old_state, new_state);
33-
self.on_state_changed(self, old_state, new_state);
21+
self.on_state_changed(self, old_state, new_state);
22+
if let CoroutineState::Error(_) = new_state {
23+
error!("{} {:?}->{:?}", self.name(), old_state, new_state);
3424
} else {
35-
self.on_state_changed(self, old_state, new_state);
36-
if let CoroutineState::Error(_) = new_state {
37-
error!("{} {:?}->{:?}", self.name(), old_state, new_state);
38-
} else {
39-
info!("{} {:?}->{:?}", self.name(), old_state, new_state);
40-
}
25+
info!("{} {:?}->{:?}", self.name(), old_state, new_state);
4126
}
4227
old_state
4328
}

core/src/monitor.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,6 @@ impl Monitor {
7878
set.remove(Signal::SIGURG);
7979
set.thread_set_mask()
8080
.expect("Failed to remove SIGURG signal mask!");
81-
//不抢占处于Syscall状态的协程。
82-
//MonitorListener的设计理念是不对Syscall状态的协程发送信号。
83-
//但由于NOTIFY_NODE移除和monitor线程遍历之间存在竞态条件,
84-
//SIGURG可能在协程刚进入Syscall状态时到达。
85-
//如果此时抢占,协程会被放入syscall_map但无人唤醒(因为没有io_uring/epoll注册),
86-
//导致死锁。
87-
// Skip preemption for coroutines in Syscall state.
88-
// MonitorListener's design is to NOT send signals to Syscall-state
89-
// coroutines. However, a race between NOTIFY_NODE removal and the
90-
// monitor's queue iteration can cause SIGURG to arrive just after
91-
// the coroutine entered Syscall state. If preempted here, the
92-
// coroutine lands in the syscall map with no io_uring/epoll/timer
93-
// registration to wake it, causing a deadlock.
94-
if let Some(co) = SchedulableCoroutine::current() {
95-
if matches!(co.state(), CoroutineState::Syscall((), _, _)) {
96-
return;
97-
}
98-
}
9981
if let Some(suspender) = SchedulableSuspender::current() {
10082
suspender.suspend();
10183
}

core/src/syscall/unix/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl<I: WriteSyscall> WriteSyscall for WriteSyscallFacade<I> {
4242
return RawWriteSyscall::default().write(fn_ptr, fd, buf, len);
4343
}
4444
let syscall = crate::common::constants::SyscallName::write;
45-
crate::info!("enter syscall {}", syscall);
4645
if let Some(co) = crate::scheduler::SchedulableCoroutine::current() {
4746
let new_state = crate::common::constants::SyscallState::Executing;
4847
if co.syscall((), syscall, new_state).is_err() {
@@ -51,6 +50,7 @@ impl<I: WriteSyscall> WriteSyscall for WriteSyscallFacade<I> {
5150
);
5251
}
5352
}
53+
crate::info!("enter syscall {}", syscall);
5454
let r = self.inner.write(fn_ptr, fd, buf, len);
5555
if let Some(co) = crate::scheduler::SchedulableCoroutine::current() {
5656
if co.running().is_err() {

0 commit comments

Comments
 (0)