进程管理模块重构完成 (#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

@ -2,8 +2,6 @@
#include <DragonOS/stdint.h>
#include <common/glib.h>
#include <common/mutex.h>
#include <common/semaphore.h>
#define BLK_TYPE_AHCI 0
@ -83,5 +81,4 @@ struct blk_gendisk
struct block_device *partition; // 磁盘分区数组
const struct block_device_operation *fops; // 磁盘操作
void *private_data;
mutex_t open_mutex; // open()/close()操作的互斥锁
};

View File

@ -1,47 +0,0 @@
#include <common/spinlock.h>
#include <common/wait_queue.h>
#include <process/process.h>
#include <time/sleep.h>
#include <time/timer.h>
// 永久地设置该completion已经被完成,不会再有进程等待
#define COMPLETE_ALL UINT32_MAX
struct completion
{
unsigned int done;
wait_queue_head_t wait_queue;
};
#define DECLARE_COMPLETION_ON_STACK(name) \
struct completion name = {0}; \
completion_init(&name);
/**
* 对外函数声明
*/
void completion_init(struct completion *x);
void complete(struct completion *x);
void complete_all(struct completion *x);
void wait_for_completion(struct completion *x);
long wait_for_completion_timeout(struct completion *x, long timeout);
void wait_for_completion_interruptible(struct completion *x);
long wait_for_completion_interruptible_timeout(struct completion *x, long timeout);
void wait_for_multicompletion(struct completion x[], int n);
bool try_wait_for_completion(struct completion *x);
bool completion_done(struct completion *x);
struct completion *completion_alloc();
/**
* 测试函数声明 (测试代码辅助函数)
*/
struct __test_data
{
int id;
struct completion *one_to_one;
struct completion *one_to_many;
struct completion *many_to_one;
};
int __test_completion_waiter(void *data); // 等待者
int __test_completion_worker(void *data); // 执行者
void __test_completion();

View File

@ -56,7 +56,6 @@ struct cpu_core_info_t
{
uint64_t stack_start; // 栈基地址
uint64_t ist_stack_start; // IST栈基地址
uint64_t tss_vaddr; // tss地址
};
extern struct cpu_core_info_t cpu_core_info[MAX_CPU_NUM];

View File

@ -358,10 +358,3 @@ Values in this inclusive range are reserved for OS-specific semantics.
// --> end ========== program header =========
/**
* @brief 校验是否为ELF文件
*
* @param ehdr
*/
bool elf_check(void * ehdr);

View File

@ -1,125 +0,0 @@
#pragma once
#include <common/err.h>
#include <common/numa.h>
#include <process/proc-types.h>
#include <process/process.h>
/**
* @brief kthread信息
* 该结构体将会绑定到pcb的worker_private中
*/
struct kthread_info_t
{
uint64_t flags;
uint32_t cpu;
int result;
int (*thread_fn)(void *);
void *data;
// todo: 将这里改为completion机制
bool exited; // 是否已退出
char *full_name; // 内核线程的名称
};
struct process_control_block *kthread_create_on_node(int (*thread_fn)(void *data), void *data, int node,
const char name_fmt[], ...);
/**
* @brief 在当前结点上创建一个内核线程
*
* @param thread_fn 该内核线程要执行的函数
* @param data 传递给 thread_fn 的参数数据
* @param name_fmt printf-style format string for the thread name
* @param arg name_fmt的参数
*
* 请注意,该宏会创建一个内核线程,并将其设置为停止状态
*/
#define kthread_create(thread_fn, data, name_fmt, arg...) \
kthread_create_on_node(thread_fn, data, NUMA_NO_NODE, name_fmt, ##arg)
/**
* @brief 创建内核线程,并将其唤醒
*
* @param thread_fn 该内核线程要执行的函数
* @param data 传递给 thread_fn 的参数数据
* @param name_fmt printf-style format string for the thread name
* @param arg name_fmt的参数
*/
#define kthread_run(thread_fn, data, name_fmt, ...) \
({ \
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
if (!IS_ERR(__kt)) \
process_wakeup(__kt); \
__kt; \
})
/**
* @brief 创建内核实时线程,并将其唤醒
*
* @param thread_fn 该内核线程要执行的函数
* @param data 传递给 thread_fn 的参数数据
* @param name_fmt printf-style format string for the thread name
* @param arg name_fmt的参数
*/
#define kthread_run_rt(thread_fn, data, name_fmt, ...) \
({ \
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
__kt = process_init_rt_pcb(__kt); \
if (!IS_ERR(__kt)) \
{ \
process_wakeup(__kt); \
} \
__kt; \
})
/**
* @brief 向kthread发送停止信号请求其结束
*
* @param pcb 内核线程的pcb
* @return int 错误码
*/
int kthread_stop(struct process_control_block *pcb);
/**
* @brief 内核线程调用该函数,检查自身的标志位,判断自己是否应该执行完任务后退出
*
* @return true 内核线程应该退出
* @return false 无需退出
*/
bool kthread_should_stop(void);
/**
* @brief 让当前内核线程退出并返回result参数给kthread_stop()函数
*
* @param result 返回值
*/
void kthread_exit(long result);
/**
* @brief 初始化kthread机制(只应被process_init调用)
*
* @return int 错误码
*/
int kthread_mechanism_init();
/**
* @brief 设置pcb中的worker_private字段只应被设置一次
*
* @param pcb pcb
* @return bool 成功或失败
*/
bool kthread_set_worker_private(struct process_control_block *pcb);
/**
* @brief 获取pcb中的kthread结构体
*
* @param pcb pcb
* @return struct kthread* kthread信息结构体
*/
struct kthread_info_t *to_kthread(struct process_control_block *pcb);
/**
* @brief 释放pcb指向的worker private
*
* @param pcb 要释放的pcb
*/
void free_kthread_struct(struct process_control_block *pcb);

View File

@ -1,69 +0,0 @@
#pragma once
#include <common/atomic.h>
#include <common/spinlock.h>
#include <common/glib.h>
#include <process/proc-types.h>
/**
* @brief Mutex - 互斥锁
*
* - 同一时间只有1个任务可以持有mutex
* - 不允许递归地加锁、解锁
* - 只允许通过mutex的api来操作mutex
* - 在硬中断、软中断中不能使用mutex
*/
typedef struct
{
atomic_t count; // 锁计数。1->已解锁。 0->已上锁,且有可能存在等待者
spinlock_t wait_lock; // mutex操作锁用于对mutex的list的操作进行加锁
struct List wait_list; // Mutex的等待队列
} mutex_t;
/**
* @brief 在mutex上的等待者的结构体
*
*/
struct mutex_waiter_t
{
struct List list;
struct process_control_block *pcb;
};
/**
* @brief 初始化互斥量
*
* @param lock mutex结构体
*/
void mutex_init(mutex_t *lock);
/**
* @brief 对互斥量加锁
*
* @param lock mutex结构体
*/
void mutex_lock(mutex_t *lock);
/**
* @brief 对互斥量解锁
*
* @param lock mutex结构体
*/
void mutex_unlock(mutex_t *lock);
/**
* @brief 尝试对互斥量加锁
*
* @param lock mutex结构体
*
* @return 成功加锁->1, 加锁失败->0
*/
int mutex_trylock(mutex_t *lock);
/**
* @brief 判断mutex是否已被加锁
*
* @return 已加锁->1, 未加锁->0
*/
#define mutex_is_locked(lock) ((atomic_read(&(lock)->count) == 1) ? 0 : 1)

View File

@ -1,47 +0,0 @@
/**
* @file semaphore.h
* @author fslngjin (lonjin@RinGoTek.cn)
* @brief 信号量
* @version 0.1
* @date 2022-04-12
*
* @copyright Copyright (c) 2022
*
*/
#pragma once
#include <common/atomic.h>
#include <common/wait_queue.h>
/**
* @brief 信号量的结构体
*
*/
typedef struct
{
atomic_t counter;
wait_queue_node_t wait_queue;
} semaphore_t;
/**
* @brief 初始化信号量
*
* @param sema 信号量对象
* @param count 信号量的初始值
*/
static __always_inline void semaphore_init(semaphore_t *sema, ul count)
{
atomic_set(&sema->counter, count);
wait_queue_init(&sema->wait_queue, NULL);
}
/**
* @brief 信号量down
*
* @param sema
*/
void semaphore_down(semaphore_t *sema);
void semaphore_up(semaphore_t *sema);

View File

@ -2,7 +2,7 @@
#include "./sys/types.h"
#define NULL 0
#define NULL (void*)0
typedef __PTRDIFF_TYPE__ ptrdiff_t; // Signed integer type of the result of subtracting two pointers.

View File

@ -1,7 +0,0 @@
#pragma once
// todo: 引入用户命名空间
struct user_namespace
{
};

View File

@ -1,118 +0,0 @@
#pragma once
#include <common/glib.h>
#include <common/spinlock.h>
struct process_control_block;
// todo: 按照linux里面的样子修正等待队列。也就是修正好wait_queue_node和wait_queue_head的意思。
/**
* @brief 信号量的等待队列
*
*/
typedef struct
{
struct List wait_list;
struct process_control_block *pcb;
} wait_queue_node_t;
/**
* @brief 初始化等待队列
*
* @param wait_queue 等待队列
* @param pcb pcb
*/
void wait_queue_init(wait_queue_node_t *wait_queue, struct process_control_block *pcb);
/**
* @brief 在等待队列上进行等待
*
* @param wait_queue_head 队列头指针
*/
void wait_queue_sleep_on(wait_queue_node_t *wait_queue_head);
/**
* @brief 在等待队列上进行等待,同时释放自旋锁
*
* @param wait_queue_head 队列头指针
*/
void wait_queue_sleep_on_unlock(wait_queue_node_t *wait_queue_head, void *lock);
/**
* @brief 在等待队列上进行等待(允许中断)
*
* @param wait_queue_head 队列头指针
*/
void wait_queue_sleep_on_interriptible(wait_queue_node_t *wait_queue_head);
/**
* @brief 唤醒在等待队列的头部的进程
*
* @param wait_queue_head 队列头
* @param state 要唤醒的进程的状态
*/
void wait_queue_wakeup(wait_queue_node_t *wait_queue_head, int64_t state);
typedef struct
{
struct List wait_list;
spinlock_t lock; // 队列需要有一个自旋锁,虽然目前内部并没有使用,但是以后可能会用.[在completion内部使用]
} wait_queue_head_t;
#define DECLARE_WAIT_ON_STACK(name, pcb) \
wait_queue_node_t name = {0}; \
wait_queue_init(&(name), pcb);
#define DECLARE_WAIT_ON_STACK_SELF(name) \
wait_queue_node_t name = {0}; \
wait_queue_init(&(name), current_pcb);
#define DECLARE_WAIT_ALLOC(name, pcb) \
wait_queue_node_t *wait = (wait_queue_node_t *)kzalloc(sizeof(wait_queue_node_t), 0); \
wait_queue_init(&(name), pcb);
#define DECLARE_WAIT_ALLOC_SELF(name) \
wait_queue_node_t *wait = (wait_queue_node_t *)kzalloc(sizeof(wait_queue_node_t), 0); \
wait_queue_init(&(name), current_pcb);
#define DECLARE_WAIT_QUEUE_HEAD(name) \
struct wait_queue_head_t name = {0}; \
wait_queue_head_init(&name);
/**
* @brief 初始化wait_queue队列头
*
* @param wait_queue
*/
void wait_queue_head_init(wait_queue_head_t *wait_queue);
/**
* @brief 在等待队列上进行等待, 但是你需要确保wait已经被init, 同时wakeup只能使用wake_up_on_stack函数。
*
* @param q 队列头指针
* @param wait wait节点
*/
void wait_queue_sleep_with_node(wait_queue_head_t *q, wait_queue_node_t *wait);
/**
* @brief 在等待队列上进行等待,同时释放自旋锁, 但是你需要确保wait已经被init, 同时wakeup只能使用wake_up_on_stack函数。
*
* @param q 队列头指针
* @param wait wait节点
* @param lock
*/
void wait_queue_sleep_with_node_unlock(wait_queue_head_t *q, wait_queue_node_t *wait, void *lock);
/**
* @brief 在等待队列上进行等待(允许中断), 但是你需要确保wait已经被init, 同时wakeup只能使用wake_up_on_stack函数。
*
* @param wait_queue_head 队列头指针
* @param wait wait节点
*/
void wait_queue_sleep_with_node_interriptible(wait_queue_head_t *q, wait_queue_node_t *wait);
/**
* @brief 唤醒在等待队列的头部的进程, 但是不会free掉这个节点的空间(默认这个节点在栈上创建)
*
* @param wait_queue_head_t q: 队列头
* @param state 要唤醒的进程的状态
*/
void wait_queue_wakeup_on_stack(wait_queue_head_t *q, int64_t state);