feat(pi_lock): feat pi_lock and fix lock#1926
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19d239331a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // 正在远端 CPU 运行 → 发 IPI 让其尽快进 __schedule(),在那里 deactivate | ||
| if is_current && !update_clock { | ||
| kick_cpu(target_cpu).ok(); |
There was a problem hiding this comment.
在远端 stop 当前任务前先从 rq 摘除或走阻塞调度路径
stop_task() 对“目标任务正运行在远端 CPU”的分支只发送 kick_cpu(),并依赖 __schedule() 中后续 deactivate(见注释“在那里 deactivate”);但中断路径进入的是 __schedule(SM_PREEMPT),而该路径不会执行非可运行任务的 deactivate 逻辑(deactivate 仅在 !SM_MASK_PREEMPT 分支)。结果是被置为 Stopped 的当前任务仍可能留在 runqueue 上并再次被选中运行,导致 stop 语义失效(典型场景:对正在远端运行的线程发送作业控制 stop 信号)。
Useful? React with 👍 / 👎.
1. Introduce
|
|
@codex review |
💡 Codex ReviewDragonOS/kernel/src/process/mod.rs Lines 607 to 614 in b4b51e9 当 SIGSTOP/作业控制停止命中正在其他 CPU 上运行的任务时,这里先把远端 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9694d3eb21
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
补充一个非阻塞的构建配置 review 点:本 PR 把 建议保持默认 |
Signed-off-by: aLinChe <1129332011@qq.com>
Signed-off-by: aLinChe <1129332011@qq.com>
Signed-off-by: aLinChe <1129332011@qq.com>
Signed-off-by: aLinChe <1129332011@qq.com>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: aLinChe <1129332011@qq.com>
1. 引入
pi_lock替代inner_lock,对齐 Linuxtask_rq_lock()锁序原实现使用
RwLock<InnerSchedInfo>保护进程状态、优先级、调度策略,锁粒度过大且与 Linux 语义不符。InnerSchedInfo(含state+sleep),新增state_atomic: AtomicU32,使用与 Linux 一致的位编码(TASK_RUNNING=0x0000,TASK_INTERRUPTIBLE=0x0001,TASK_UNINTERRUPTIBLE=0x0002,TASK_STOPPED=0x0004,TASK_DEAD_MARKER=0x0080,退出码存高 20 位)。pi_lock: SpinLock<PiProtected>:保护cpus_allowed和nr_cpus_allowed,集中管理受 pi_lock 保护的字段。sched_policy: RwLock<SchedPolicy>→AtomicU8;prio_data: RwLock<PrioData>→ 拆分为prio: AtomicI32、static_prio: AtomicI32、normal_prio: AtomicI32。pi_lock → rq_lock(对齐 Linuxtask_rq_lock()),释放时先rq_lock后pi_lock。2. 修复
rwlock抢占/中断顺序原
read_irqsave/write_irqsave/upgradeable_read_irqsave在自旋循环内部每次迭代都重新关中断,中断状态不一致。save_and_disable_irq()+preempt_disable(),循环内仅尝试获取锁。downgrade_to_read):使用mem::forget(self)跳过原 Guard 的preempt_enable,由新 Guard 接管。Drop顺序:所有 Guard 先恢复中断(irq_guard.take()),再启用抢占(preempt_enable())。3. 修复
spinlock解锁顺序,对齐 Linuxspin_unlock_irqrestore/spin_unlock_bhSpinLock::unlock()中的preempt_enable(),移至SpinLockGuard::drop()中,确保顺序为:先解锁 → 恢复中断 → 启用抢占。SpinLockBhGuard字段顺序为guard在前、bh在后,确保 Rust Drop 顺序为:先解锁 → 恢复 BH(对齐spin_unlock_bh)。4. 重构
__schedule()对齐 Linux 信号检查语义is_mark_sleep判断(原InnerSchedInfo.sleep标志)。smp_mb__after_spinlock()语义:获取rq_lock后插入fence(Ordering::SeqCst)。nr_uninterruptible++在deactivate_task之前;nr_iowait++在deactivate_task之后。activate_task/deactivate_task:移除其中的nr_iowait/nr_uninterruptible/IDLE_CPUS维护,移至调用方。5. 修复
sched_fork()子进程策略/优先级继承normal_prio、static_prio、policy6. 修复
copy_flags()子进程标志位继承子进程不再继承父进程运行时状态标志(
NEED_SCHEDULE、EXITING、WAKEKILL、SIGNALED、NEED_MIGRATE等),仅继承RANDOMIZE(ASLR 配置)。KTHREAD标志由创建参数显式设置。7. 函数重命名(修复拼写)
check_preempt_currnet→check_preempt_currentwakeup_new_task→wake_up_new_task8. Nix 构建系统:新增 GDB 调试支持
QEMU_GDB_WAIT=1暂停等待连接。gdb-${target}app/package,使用rust-gdb(x86_64)或gdb-multiarch(其他架构)。dunitest测试框架集成。