-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Patch refactor process management exit #340
Patch refactor process management exit #340
Conversation
…process-management-exit
kernel/src/process/mod.rs
Outdated
/// 退出进程,回收资源 | ||
/// | ||
/// 功能参考 https://opengrok.ringotek.cn/xref/DragonOS/kernel/src/process/process.c?r=40fe15e0953f989ccfeb74826d61621d43dea6bb&mo=7649&fi=246#246 | ||
pub fn exit(exit_code: usize) -> ! { | ||
todo!() | ||
cli(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不能直接使用cli和sti,具体用法请使用CurrentIrqArch::save_and_disable_irq
kernel/src/process/mod.rs
Outdated
@@ -160,16 +160,38 @@ impl ProcessManager { | |||
pub fn sleep() -> Result<(), SystemError> { | |||
todo!() | |||
} | |||
|
|||
/// 当子进程退出后向父进程发送通知 | |||
pub fn exit_notify() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数不用pub
let weak_ref = Arc::downgrade(&pcb); | ||
if weak_ref.strong_count() <= 1 { | ||
drop(pcb); | ||
ALL_PROCESS.lock().as_mut().unwrap().remove(&pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里如果不为1就panic
let weak_ref = Arc::downgrade(&pcb); | ||
if weak_ref.strong_count() <= 1 { | ||
drop(pcb); | ||
ALL_PROCESS.lock().as_mut().unwrap().remove(&pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里如果不为1就panic
kernel/src/process/mod.rs
Outdated
} | ||
|
||
/// 回收线程结构体 | ||
pub fn exit_thread(&self) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不需要哈哈,删了即可
kernel/src/process/mod.rs
Outdated
@@ -409,6 +431,13 @@ impl ProcessControlBlock { | |||
return self.basic.read().fd_table().unwrap(); | |||
} | |||
|
|||
/// 释放文件描述符数组 | |||
pub fn exit_files(&self) { | |||
self.basic.write().exit_files(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我感觉drop就已经能够很好的去释放了。因为如何释放某个文件,其实还跟文件的标志位有关,因此不如直接交给FileDescriptorVec的drop函数去处理。这样更符合“信息专家”的理论
kernel/src/process/mod.rs
Outdated
@@ -74,7 +74,7 @@ impl SwitchResult { | |||
|
|||
#[derive(Debug)] | |||
pub struct ProcessManager; | |||
|
|||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里暂时不加这个哈哈,重构过程有warning比较方便看
kernel/src/lib.rs
Outdated
loop {} | ||
println!( | ||
"Current PCB:\n\t{:?}", | ||
*(ProcessManager::current_pcb().basic()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我在想,为啥不直接打印整个Pcb
kernel/src/arch/x86_64/mm/mod.rs
Outdated
@@ -391,7 +391,7 @@ unsafe fn allocator_init() { | |||
|
|||
// 初始化buddy_allocator | |||
let buddy_allocator = unsafe { BuddyAllocator::<X86_64MMArch>::new(bump_allocator).unwrap() }; | |||
|
|||
kinfo!("set_inner_allocator"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个需要删掉哈哈
…process-management-exit
…h-refactor-process-management-exit
269a9b8
into
DragonOS-Community:patch-refactor-process-management
* 添加新版pcb的数据结构 (#273) * 将pcb中的内容分类,分别加锁 (#305) * 进程管理重构:完成fork的主体逻辑 (#309) 1.完成fork的主体逻辑 2.将文件系统接到新的pcb上 3.经过思考,暂时弃用signal机制,待进程管理重构完成后,重写signal机制.原因是原本的signal机制太烂了 * chdir getcwd pid pgid ppid (#310) --------- Co-authored-by: longjin <[email protected]> * 删除旧的fork以及signal的代码,并调整fork/vfork/execve系统调用 (#325) 1.删除旧的fork 2.删除signal相关代码,等进程管理重构结束之后,再重新写. 3.调整了fork/vfork/execve系统调用 * 实现切换进程的代码 (#331) * 实现切换进程的代码 * Patch modify preempt (#332) * 修改设置preempt的代码 * 删除rust的list和refcount * 为每个核心初始化idle进程 (#333) * 为每个核心初始化idle进程 * 完成了新的内核线程机制 (#335) * 调度器的pcb替换为新的Arc<ProcessControlBlock>,把调度器队列锁从 RwSpinLock 替换为了 SpinLock (#336) * 把调度器的pcb替换为新的Arc<ProcessControlBlock> * 把调度器队列锁从 RwSpinLock 替换为了 SpinLock ,修改了签名以通过编译 * 修正一些双重加锁、细节问题 --------- Co-authored-by: longjin <[email protected]> * github workflow自动检查代码是否格式化 * cache toolchain yml * 调整rust版本的waitqueue中的pcb为新版的pcb (#343) * 解决设置rust workspace带来的“工具链不一致”的问题 (#344) * 解决设置rust workspace带来的“工具链不一致”的问题 更改workflow * 调整pcb的sched_info和rwlock,以避免调度器死锁问题 (#341) * 调整pcb的sched_info和rwlock,以避免调度器死锁问题 * 修改为在 WriterGuard 中维护 Irq_guard * 修正了 write_irqsave方法 * 优化了代码 * 把 set state 操作从 wakup 移动到 sched_enqueue 中 * 修正为在 wakeup 中设置 running ,以保留 set_state 的私有性 * 移除了 process_wakeup * 实现进程退出的逻辑 (#340) 实现进程退出的逻辑 * 标志进程sleep * 修复wakeup的问题 --------- Co-authored-by: longjin <[email protected]> * rust 重构 completion (#350) * 完成了completion的基本结构,待完善上级调用 * 用SpinLock保护结构体并发安全 * 修改原子变量为u32,修复符号错误 * irq guard * 修改为具有内部可变性的结构体 * temp fix * 修复了由于进程持有自旋锁导致的不被调度的问题 * 对 complete 系列方法上锁,保护 done 数据并发安全 * 移除了未使用的依赖 * 重写显示刷新驱动 (#363) * 重构显示刷新驱动 * Patch refactor process management (#366) * 维护进程树 * 维护进程树 * 更改代码结构 * 新建进程时,设置cwd * 调整adopt childern函数,降低开销 --------- Co-authored-by: longjin <[email protected]> * waitqueue兼容C部分 (#351) * PATH * safe init * waitqueue兼容C部分 * waitqueue兼容C部分 * 删除semaphore.c,在ps2_keyboard中使用waitqueue * 删除semaphore.c,在ps2_keyboard中使用waitqueue * current_pcb的C兼容 * current_pcb的C兼容 * current_pcb的C兼容 * fmt * current_pcb的兼容 * 针对修改 * 调整代码 * fmt * 删除pcb的set flags * 更改函数名 --------- Co-authored-by: longjin <[email protected]> * merge master * Patch debug process management refactor (#372) * 能够调通,执行完textui_init * 能跑到initial kernel thread * fmt * 能够正常初始化所有服务(尚未能切换到用户程序) * 删除部分无用的extern * 存在问题:ap处理器启动后,bsp的smp_init函数return之后就出错了,怀疑是栈损坏 * 解决smp启动由于未换栈导致的内存访问错误 * debug * 1 * 1 * lock no preempt * 调通 * 优化代码,删除一些调试日志 * fix * 使用rust重写wait4 (#377) * 维护进程树 * 维护进程树 * 更改代码结构 * 新建进程时,设置cwd * 调整adopt childern函数,降低开销 * wait4 * 删除c_sys_wait4 * 使用userbuffer保护裸指针 --------- Co-authored-by: longjin <[email protected]> * 消除warning * 1. 修正未设置cpu executing的问题 * 修正kthread机制可能存在的内存泄露问题 * 删除pcb文档 * 删除C的tss struct --------- Co-authored-by: Bullet <[email protected]> Co-authored-by: Chiichen <[email protected]> Co-authored-by: hanjiezhou <[email protected]> Co-authored-by: GnoCiYeH <[email protected]> Co-authored-by: houmkh <[email protected]>
No description provided.