进程管理模块重构完成 (#380)

* 添加新版pcb的数据结构 (#273)

* 将pcb中的内容分类,分别加锁 (#305)

* 进程管理重构:完成fork的主体逻辑 (#309)

1.完成fork的主体逻辑
2.将文件系统接到新的pcb上
3.经过思考,暂时弃用signal机制,待进程管理重构完成后,重写signal机制.原因是原本的signal机制太烂了

* chdir getcwd pid pgid ppid (#310)


---------

Co-authored-by: longjin <longjin@RinGoTek.cn>

* 删除旧的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 <longjin@RinGoTek.cn>

* 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 <longjin@RinGoTek.cn>

* 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 <longjin@RinGoTek.cn>

* 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 <longjin@RinGoTek.cn>

* 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 <longjin@RinGoTek.cn>

* 消除warning

* 1. 修正未设置cpu executing的问题

* 修正kthread机制可能存在的内存泄露问题

* 删除pcb文档

* 删除C的tss struct

---------

Co-authored-by: Bullet <93781792+GP-Bullet@users.noreply.github.com>
Co-authored-by: Chiichen <39649411+Chiichen@users.noreply.github.com>
Co-authored-by: hanjiezhou <zhouhanjie@dragonos.org>
Co-authored-by: GnoCiYeH <118462160+GnoCiYeH@users.noreply.github.com>
Co-authored-by: houmkh <1119644616@qq.com>
This commit is contained in:
LoGin
2023-09-15 14:58:19 +08:00
committed by GitHub
parent b087521e07
commit 1496ba7b24
153 changed files with 4895 additions and 8190 deletions

View File

@ -126,7 +126,7 @@ pub fn poll_ifaces() {
for (_, iface) in guard.iter() {
iface.poll(&mut sockets).ok();
}
SOCKET_WAITQUEUE.wakeup_all((-1i64) as u64);
SOCKET_WAITQUEUE.wakeup_all(None);
}
/// 对ifaces进行轮询最多对SOCKET_SET尝试times次加锁。
@ -154,7 +154,7 @@ pub fn poll_ifaces_try_lock(times: u16) -> Result<(), SystemError> {
for (_, iface) in guard.iter() {
iface.poll(&mut sockets).ok();
}
SOCKET_WAITQUEUE.wakeup_all((-1i64) as u64);
SOCKET_WAITQUEUE.wakeup_all(None);
return Ok(());
}

View File

@ -5,7 +5,6 @@ use num_traits::{FromPrimitive, ToPrimitive};
use smoltcp::wire;
use crate::{
arch::asm::current::current_pcb,
filesystem::vfs::{
file::{File, FileMode},
syscall::{IoVec, IoVecs},
@ -13,6 +12,7 @@ use crate::{
include::bindings::bindings::verify_area,
libs::spinlock::SpinLockGuard,
net::socket::{AddressFamily, SOL_SOCKET},
process::ProcessManager,
syscall::{Syscall, SystemError},
};
@ -59,7 +59,11 @@ impl Syscall {
let f = File::new(socketinode, FileMode::O_RDWR)?;
// kdebug!("do_socket: f: {f:?}");
// 把socket添加到当前进程的文件描述符表中
let fd = current_pcb().alloc_fd(f, None).map(|x| x as usize);
let binding = ProcessManager::current_pcb().fd_table();
let mut fd_table_guard = binding.write();
let fd = fd_table_guard.alloc_fd(f, None).map(|x| x as usize);
drop(fd_table_guard);
// kdebug!("do_socket: fd: {fd:?}");
return fd;
}
@ -77,7 +81,7 @@ impl Syscall {
optname: usize,
optval: &[u8],
) -> Result<usize, SystemError> {
let socket_inode: Arc<SocketInode> = current_pcb()
let socket_inode: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
// 获取内层的socket真正的数据
@ -103,7 +107,7 @@ impl Syscall {
) -> Result<usize, SystemError> {
// 获取socket
let optval = optval as *mut u32;
let binding: Arc<SocketInode> = current_pcb()
let binding: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let socket = binding.inner();
@ -166,7 +170,7 @@ impl Syscall {
/// @return 成功返回0失败返回错误码
pub fn connect(fd: usize, addr: *const SockAddr, addrlen: usize) -> Result<usize, SystemError> {
let endpoint: Endpoint = SockAddr::to_endpoint(addr, addrlen)?;
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let mut socket = socket.inner();
@ -184,7 +188,7 @@ impl Syscall {
/// @return 成功返回0失败返回错误码
pub fn bind(fd: usize, addr: *const SockAddr, addrlen: usize) -> Result<usize, SystemError> {
let endpoint: Endpoint = SockAddr::to_endpoint(addr, addrlen)?;
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let mut socket = socket.inner();
@ -214,7 +218,7 @@ impl Syscall {
Some(SockAddr::to_endpoint(addr, addrlen)?)
};
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let socket = socket.inner();
@ -237,7 +241,7 @@ impl Syscall {
addr: *mut SockAddr,
addrlen: *mut u32,
) -> Result<usize, SystemError> {
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let socket = socket.inner();
@ -268,7 +272,7 @@ impl Syscall {
// 检查每个缓冲区地址是否合法生成iovecs
let mut iovs = unsafe { IoVecs::from_user(msg.msg_iov, msg.msg_iovlen, true)? };
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let socket = socket.inner();
@ -297,7 +301,7 @@ impl Syscall {
///
/// @return 成功返回0失败返回错误码
pub fn listen(fd: usize, backlog: usize) -> Result<usize, SystemError> {
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let mut socket = socket.inner();
@ -312,7 +316,7 @@ impl Syscall {
///
/// @return 成功返回0失败返回错误码
pub fn shutdown(fd: usize, how: usize) -> Result<usize, SystemError> {
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let socket = socket.inner();
@ -328,7 +332,7 @@ impl Syscall {
///
/// @return 成功返回新的文件描述符,失败返回错误码
pub fn accept(fd: usize, addr: *mut SockAddr, addrlen: *mut u32) -> Result<usize, SystemError> {
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
// kdebug!("accept: socket={:?}", socket);
@ -340,7 +344,10 @@ impl Syscall {
// kdebug!("accept: new_socket={:?}", new_socket);
// Insert the new socket into the file descriptor vector
let new_socket: Arc<SocketInode> = SocketInode::new(new_socket);
let new_fd = current_pcb().alloc_fd(File::new(new_socket, FileMode::O_RDWR)?, None)?;
let new_fd = ProcessManager::current_pcb()
.fd_table()
.write()
.alloc_fd(File::new(new_socket, FileMode::O_RDWR)?, None)?;
// kdebug!("accept: new_fd={}", new_fd);
if !addr.is_null() {
// kdebug!("accept: write remote_endpoint to user");
@ -371,7 +378,7 @@ impl Syscall {
if addr.is_null() {
return Err(SystemError::EINVAL);
}
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let socket = socket.inner();
@ -401,7 +408,7 @@ impl Syscall {
return Err(SystemError::EINVAL);
}
let socket: Arc<SocketInode> = current_pcb()
let socket: Arc<SocketInode> = ProcessManager::current_pcb()
.get_socket(fd as i32)
.ok_or(SystemError::EBADF)?;
let socket = socket.inner();