操作系统学习笔记(35)--创建新进程并调度
2010-06-03 22:29
309 查看
新进程创建:
1 初始化内存,分配内存页面
2 初始化内核进程
3 添加到进程列表
然后通过进程调度器调度运行
进程调度进行进程运行的切换
进程切换过程如下:
0 仿中断调用
1 保存当前进程的寄存器等信息进入当前堆栈
2 清当前进程的计时器为0
3 恢复切换进程为当前进程(切换进程需要传递信息 结合数据定义获取下面恢复设置)
4 恢复切换进程的堆栈设置
5 根据堆栈信息回复寄存器
6 中断退出
7 运行新切换的进程
1 初始化内存,分配内存页面
2 初始化内核进程
3 添加到进程列表
然后通过进程调度器调度运行
/* * Schedule a thread that is waiting to run. * Must be called with interrupts off! * The current thread should already have been placed * on whatever queue is appropriate (i.e., either the * run queue if it is still runnable, or a wait queue * if it is waiting for an event to occur). */ void Schedule(void) { struct Kernel_Thread* runnable; /* Make sure interrupts really are disabled */ KASSERT(!Interrupts_Enabled()); /* Preemption should not be disabled. */ KASSERT(!g_preemptionDisabled); /* Get next thread to run from the run queue */ runnable = Get_Next_Runnable(); /* * Activate the new thread, saving the context of the current thread. * Eventually, this thread will get re-activated and Switch_To_Thread() * will "return", and then Schedule() will return to wherever * it was called from. */ Switch_To_Thread(runnable); }
进程调度进行进程运行的切换
Switch_To_Thread: ; Modify the stack to allow a later return via an iret instruction. ; We start with a stack that looks like this: ; ; thread_ptr ; esp --> return addr ; ; We change it to look like this: ; ; thread_ptr ; eflags ; cs ; esp --> return addr push eax ; save eax mov eax, [esp+4] ; get return address mov [esp-4], eax ; move return addr down 8 bytes from orig loc add esp, 8 ; move stack ptr up pushfd ; put eflags where return address was mov eax, [esp-4] ; restore saved value of eax push dword KERNEL_CS ; push cs selector sub esp, 4 ; point stack ptr at return address ; Push fake error code and interrupt number push dword 0 push dword 0 ; Save general purpose registers. Save_Registers ; Save stack pointer in the thread context struct (at offset 0). mov eax, [g_currentThread] mov [eax+0], esp ; Clear numTicks field in thread context, since this ; thread is being suspended. mov [eax+4], dword 0 ; Load the pointer to the new thread context into eax. ; We skip over the Interrupt_State struct on the stack to ; get the parameter. mov eax, [esp+INTERRUPT_STATE_SIZE] ; Make the new thread current, and switch to its stack. mov [g_currentThread], eax mov esp, [eax+0] ; Restore general purpose and segment registers, and clear interrupt ; number and error code. Restore_Registers ; We'll return to the place where the thread was ; executing last. iret
进程切换过程如下:
0 仿中断调用
1 保存当前进程的寄存器等信息进入当前堆栈
2 清当前进程的计时器为0
3 恢复切换进程为当前进程(切换进程需要传递信息 结合数据定义获取下面恢复设置)
4 恢复切换进程的堆栈设置
5 根据堆栈信息回复寄存器
6 中断退出
7 运行新切换的进程
相关文章推荐
- 操作系统学习笔记(4)——进程的控制与调度
- 操作系统学习笔记(28)--初始化进程调度
- 【操作系统】学习笔记(三)基于时间片轮转的进程调度算法
- 操作系统学习笔记(三)--进程
- 操作系统学习笔记:进程同步
- JAVA学习笔记49——线程概念+进程、线程区别+创建进程三种方法
- 操作系统学习笔记--进程的三种基本状态
- 操作系统学习笔记--进程生命周期
- 操作系统学习笔记三 进程
- 操作系统学习笔记:CPU调度
- 操作系统--内存学习笔记(1)进程内存管理--内存的分布
- 学习笔记——操作系统_Linux的进程通信
- 操作系统学习笔记--程序、进程
- nginx 源码学习笔记(十六)—— ngx_start_worker_processes子进程创建
- [操作系统学习笔记(4)] 进程同步,信号量
- 《Linux内核设计与实现》第四章学习笔记——进程调度
- 现代操作系统学习笔记——进程
- Linux内核学习笔记之进程创建(十)
- 操作系统学习笔记之进程管理(三)
- 操作系统学习笔记:进程同步