mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-03 15:53:56 +00:00
fix(scheduler)!: 中断栈语义(嵌套抢占 LIFO),并修掉抢占空转
用户指正:存在**中断被中断**的场景,所以被打断的现场要进**中断栈**。 我此前把 suspendPool 明确写成“不是栈、按优先级取”,是错的。 改动: - suspendPool 改名 suspendStack,恢复纪律改为**严格 LIFO(只比栈顶)**; 栈内不做优先级重排——嵌套抢占天然使栈自底向上基础级递增, 且“后被打断的先恢复”才是栈语义。取出即弹栈。 - 修掉一个由此暴露的真 bug(抢占空转):一次抢占生效后,被挂起的原任务 会因饥饿防护提升有效级,与抢占者同级;此时若按“先到先服务”,原任务 (入队更早)会被立刻选回,抢占者永远排不到 —— 抢占等于没发生。 现在**同级时 pendingInterrupts 优先于其它两类**,保证抢占必然生效。 - 状态 DTO:SuspendPool/suspend_pool → SuspendStack/suspend_stack - 设计稿:§2 用语更正(它**就是**中断栈)、§4.1 选择函数(候选只含栈顶 + pending 同级优先,并说明为何必需)、§6.2/§6.3/§9/§11 用例同步 测试新增 scheduler_stack_test.go 3 项: - 嵌套 L1→L2→L3,恢复严格 LIFO(B 先于 A) - 只比栈顶:人为构造“栈底 L3、栈顶 L2”,必须取栈顶(区分两种实现) - 嵌套下的深度上限 验收:agent 全量 + -race;全仓 build/vet 通过
This commit is contained in:
@ -67,8 +67,8 @@ func TestPreempt_DeferredDuringToolExec(t *testing.T) {
|
||||
if a.DumpScheduler().Running == nil {
|
||||
t.Fatal("工具执行中不得挂起(StepToolExec 是临界区)")
|
||||
}
|
||||
if len(a.DumpScheduler().SuspendPool) != 0 {
|
||||
t.Fatal("工具执行中 suspendPool 应为空")
|
||||
if len(a.DumpScheduler().SuspendStack) != 0 {
|
||||
t.Fatal("工具执行中 suspendStack 应为空")
|
||||
}
|
||||
|
||||
// 放行工具 → 工具返回后的安全点才挂起。
|
||||
@ -80,11 +80,11 @@ func TestPreempt_DeferredDuringToolExec(t *testing.T) {
|
||||
}
|
||||
|
||||
snap := a.DumpScheduler()
|
||||
if len(snap.SuspendPool) != 1 {
|
||||
t.Fatalf("工具返回后 suspendPool=%d,期望 1", len(snap.SuspendPool))
|
||||
if len(snap.SuspendStack) != 1 {
|
||||
t.Fatalf("工具返回后 suspendStack=%d,期望 1", len(snap.SuspendStack))
|
||||
}
|
||||
if snap.SuspendPool[0].Frame.Step != StepToolAfter {
|
||||
t.Fatalf("应在工具执行后的安全点挂起(StepToolAfter),实际 %v", snap.SuspendPool[0].Frame.Step)
|
||||
if snap.SuspendStack[0].Frame.Step != StepToolAfter {
|
||||
t.Fatalf("应在工具执行后的安全点挂起(StepToolAfter),实际 %v", snap.SuspendStack[0].Frame.Step)
|
||||
}
|
||||
if len(snap.PendingInterrupts) != 1 {
|
||||
t.Fatalf("中断请求不得丢失,pendingInterrupts=%d", len(snap.PendingInterrupts))
|
||||
@ -142,7 +142,7 @@ func TestBatch_NotAbandonedWithoutPreemption(t *testing.T) {
|
||||
t.Fatalf("同批工具应全部按序执行,实际 %v", ran)
|
||||
}
|
||||
snap := a.DumpScheduler()
|
||||
if len(snap.SuspendPool) != 0 || len(snap.PendingInterrupts) != 0 {
|
||||
if len(snap.SuspendStack) != 0 || len(snap.PendingInterrupts) != 0 {
|
||||
t.Fatalf("无抢占时不应有挂起或待处理中断:%+v", snap)
|
||||
}
|
||||
if snap.Stats.Executed != 1 {
|
||||
|
||||
Reference in New Issue
Block a user