mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-24 21:33:27 +00:00
进程管理模块重构完成 (#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:
@ -1,13 +1,13 @@
|
||||
use super::kick_cpu;
|
||||
use super::{core::smp_get_processor_id, kick_cpu};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rs_kick_cpu(cpu_id: usize) -> usize {
|
||||
pub extern "C" fn rs_kick_cpu(cpu_id: u32) -> usize {
|
||||
return kick_cpu(cpu_id)
|
||||
.map(|_| 0usize)
|
||||
.unwrap_or_else(|e| e.to_posix_errno() as usize);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn rs_smp_init_idle() {
|
||||
crate::smp::init_smp_idle_process();
|
||||
pub extern "C" fn rs_current_cpu_id() -> i32 {
|
||||
return smp_get_processor_id() as i32;
|
||||
}
|
||||
|
@ -3,8 +3,3 @@
|
||||
pub fn smp_get_processor_id() -> u32 {
|
||||
return crate::arch::cpu::current_cpu_id();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn smp_send_reschedule(_cpu: u32) {
|
||||
// todo:
|
||||
}
|
||||
|
@ -1,21 +1,15 @@
|
||||
use crate::{
|
||||
arch::{asm::current::current_pcb, interrupt::ipi::send_ipi},
|
||||
arch::interrupt::ipi::send_ipi,
|
||||
exception::ipi::{IpiKind, IpiTarget},
|
||||
mm::INITIAL_PROCESS_ADDRESS_SPACE,
|
||||
syscall::SystemError,
|
||||
};
|
||||
|
||||
pub mod c_adapter;
|
||||
pub mod core;
|
||||
|
||||
pub fn kick_cpu(cpu_id: usize) -> Result<(), SystemError> {
|
||||
pub fn kick_cpu(cpu_id: u32) -> Result<(), SystemError> {
|
||||
// todo: 增加对cpu_id的有效性检查
|
||||
|
||||
send_ipi(IpiKind::KickCpu, IpiTarget::Specified(cpu_id));
|
||||
send_ipi(IpiKind::KickCpu, IpiTarget::Specified(cpu_id as usize));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
/// 初始化AP核的idle进程
|
||||
pub unsafe fn init_smp_idle_process() {
|
||||
current_pcb().set_address_space(INITIAL_PROCESS_ADDRESS_SPACE());
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <process/preempt.h>
|
||||
#include <sched/sched.h>
|
||||
#include <driver/acpi/acpi.h>
|
||||
#include <driver/interrupt/apic/apic.h>
|
||||
#include "ipi.h"
|
||||
|
||||
static void __smp_kick_cpu_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs);
|
||||
@ -22,8 +21,10 @@ static struct acpi_Processor_Local_APIC_Structure_t *proc_local_apic_structs[MAX
|
||||
static uint32_t total_processor_num = 0;
|
||||
static int current_starting_cpu = 0;
|
||||
|
||||
static int num_cpu_started = 1;
|
||||
extern void rs_smp_init_idle();
|
||||
int num_cpu_started = 1;
|
||||
|
||||
extern void smp_ap_start();
|
||||
extern uint64_t rs_get_idle_stack_top(uint32_t cpu_id);
|
||||
|
||||
// 在head.S中定义的,APU启动时,要加载的页表
|
||||
// 由于内存管理模块初始化的时候,重置了页表,因此我们要把当前的页表传给APU
|
||||
@ -94,37 +95,13 @@ void smp_init()
|
||||
// continue;
|
||||
io_mfence();
|
||||
spin_lock(&multi_core_starting_lock);
|
||||
preempt_enable(); // 由于ap处理器的pcb与bsp的不同,因此ap处理器放锁时,bsp的自旋锁持有计数不会发生改变,需要手动恢复preempt
|
||||
// count
|
||||
rs_preempt_enable(); // 由于ap处理器的pcb与bsp的不同,因此ap处理器放锁时,bsp的自旋锁持有计数不会发生改变,需要手动恢复preempt
|
||||
// count
|
||||
current_starting_cpu = proc_local_apic_structs[i]->ACPI_Processor_UID;
|
||||
io_mfence();
|
||||
// 为每个AP处理器分配栈空间
|
||||
cpu_core_info[current_starting_cpu].stack_start = (uint64_t)kmalloc(STACK_SIZE, 0) + STACK_SIZE;
|
||||
cpu_core_info[current_starting_cpu].ist_stack_start = (uint64_t)(kmalloc(STACK_SIZE, 0)) + STACK_SIZE;
|
||||
io_mfence();
|
||||
memset((void *)cpu_core_info[current_starting_cpu].stack_start - STACK_SIZE, 0, STACK_SIZE);
|
||||
memset((void *)cpu_core_info[current_starting_cpu].ist_stack_start - STACK_SIZE, 0, STACK_SIZE);
|
||||
io_mfence();
|
||||
cpu_core_info[current_starting_cpu].stack_start = (uint64_t)rs_get_idle_stack_top(current_starting_cpu);
|
||||
|
||||
// 设置ap处理器的中断栈及内核栈中的cpu_id
|
||||
((struct process_control_block *)(cpu_core_info[current_starting_cpu].stack_start - STACK_SIZE))->cpu_id =
|
||||
proc_local_apic_structs[i]->local_apic_id;
|
||||
((struct process_control_block *)(cpu_core_info[current_starting_cpu].ist_stack_start - STACK_SIZE))->cpu_id =
|
||||
proc_local_apic_structs[i]->local_apic_id;
|
||||
|
||||
cpu_core_info[current_starting_cpu].tss_vaddr = (uint64_t)&initial_tss[current_starting_cpu];
|
||||
|
||||
memset(&initial_tss[current_starting_cpu], 0, sizeof(struct tss_struct));
|
||||
// kdebug("core %d, set tss", current_starting_cpu);
|
||||
set_tss_descriptor(10 + (current_starting_cpu * 2), (void *)(cpu_core_info[current_starting_cpu].tss_vaddr));
|
||||
io_mfence();
|
||||
set_tss64(
|
||||
(uint *)cpu_core_info[current_starting_cpu].tss_vaddr, cpu_core_info[current_starting_cpu].stack_start,
|
||||
cpu_core_info[current_starting_cpu].stack_start, cpu_core_info[current_starting_cpu].stack_start,
|
||||
cpu_core_info[current_starting_cpu].ist_stack_start, cpu_core_info[current_starting_cpu].ist_stack_start,
|
||||
cpu_core_info[current_starting_cpu].ist_stack_start, cpu_core_info[current_starting_cpu].ist_stack_start,
|
||||
cpu_core_info[current_starting_cpu].ist_stack_start, cpu_core_info[current_starting_cpu].ist_stack_start,
|
||||
cpu_core_info[current_starting_cpu].ist_stack_start);
|
||||
io_mfence();
|
||||
|
||||
// kdebug("core %d, to send start up", current_starting_cpu);
|
||||
@ -144,65 +121,33 @@ void smp_init()
|
||||
|
||||
// 由于ap处理器初始化过程需要用到0x00处的地址,因此初始化完毕后才取消内存地址的重映射
|
||||
rs_unmap_at_low_addr();
|
||||
kdebug("init proc's preempt_count=%ld", current_pcb->preempt_count);
|
||||
kinfo("Successfully cleaned page table remapping!\n");
|
||||
io_mfence();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AP处理器启动后执行的第一个函数
|
||||
*
|
||||
*/
|
||||
void smp_ap_start()
|
||||
void smp_ap_start_stage2()
|
||||
{
|
||||
|
||||
// 切换栈基地址
|
||||
// uint64_t stack_start = (uint64_t)kmalloc(STACK_SIZE, 0) + STACK_SIZE;
|
||||
__asm__ __volatile__("movq %0, %%rbp \n\t" ::"m"(cpu_core_info[current_starting_cpu].stack_start)
|
||||
: "memory");
|
||||
__asm__ __volatile__("movq %0, %%rsp \n\t" ::"m"(cpu_core_info[current_starting_cpu].stack_start)
|
||||
: "memory");
|
||||
|
||||
ksuccess("AP core %d successfully started!", current_starting_cpu);
|
||||
io_mfence();
|
||||
++num_cpu_started;
|
||||
io_mfence();
|
||||
|
||||
apic_init_ap_core_local_apic();
|
||||
|
||||
// ============ 为ap处理器初始化IDLE进程 =============
|
||||
memset(current_pcb, 0, sizeof(struct process_control_block));
|
||||
|
||||
barrier();
|
||||
current_pcb->state = PROC_RUNNING;
|
||||
current_pcb->flags = PF_KTHREAD;
|
||||
current_pcb->address_space = NULL;
|
||||
rs_smp_init_idle();
|
||||
|
||||
list_init(¤t_pcb->list);
|
||||
current_pcb->addr_limit = KERNEL_BASE_LINEAR_ADDR;
|
||||
current_pcb->priority = 2;
|
||||
current_pcb->virtual_runtime = 0;
|
||||
|
||||
current_pcb->thread = (struct thread_struct *)(current_pcb + 1); // 将线程结构体放置在pcb后方
|
||||
current_pcb->thread->rbp = cpu_core_info[current_starting_cpu].stack_start;
|
||||
current_pcb->thread->rsp = cpu_core_info[current_starting_cpu].stack_start;
|
||||
current_pcb->thread->fs = KERNEL_DS;
|
||||
current_pcb->thread->gs = KERNEL_DS;
|
||||
current_pcb->cpu_id = current_starting_cpu;
|
||||
|
||||
initial_proc[proc_current_cpu_id] = current_pcb;
|
||||
barrier();
|
||||
load_TR(10 + current_starting_cpu * 2);
|
||||
current_pcb->preempt_count = 0;
|
||||
|
||||
sched_set_cpu_idle(current_starting_cpu, current_pcb);
|
||||
|
||||
io_mfence();
|
||||
spin_unlock(&multi_core_starting_lock);
|
||||
preempt_disable(); // 由于ap处理器的pcb与bsp的不同,因此ap处理器放锁时,需要手动恢复preempt count
|
||||
io_mfence();
|
||||
current_pcb->flags |= PF_NEED_SCHED;
|
||||
spin_unlock_no_preempt(&multi_core_starting_lock);
|
||||
|
||||
apic_timer_ap_core_init();
|
||||
|
||||
sti();
|
||||
sched();
|
||||
|
||||
@ -214,7 +159,7 @@ void smp_ap_start()
|
||||
|
||||
while (1)
|
||||
{
|
||||
printk_color(BLACK, WHITE, "CPU:%d IDLE process.\n", proc_current_cpu_id);
|
||||
printk_color(BLACK, WHITE, "CPU:%d IDLE process.\n", rs_current_cpu_id());
|
||||
}
|
||||
while (1) // 这里要循环hlt,原因是当收到中断后,核心会被唤醒,处理完中断之后不会自动hlt
|
||||
hlt();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <common/glib.h>
|
||||
|
||||
#include <common/stddef.h>
|
||||
#include <common/asm.h>
|
||||
|
||||
#define MAX_SUPPORTED_PROCESSOR_NUM 1024
|
||||
@ -17,4 +17,7 @@ void smp_init();
|
||||
|
||||
extern int64_t rs_kick_cpu(uint32_t cpu_id);
|
||||
|
||||
uint32_t smp_get_total_cpu();
|
||||
uint32_t smp_get_total_cpu();
|
||||
|
||||
extern void set_current_core_tss(uint64_t stack_start, uint64_t ist0);
|
||||
extern void rs_load_current_core_tss();
|
Reference in New Issue
Block a user