课程中以时间片轮转多道程序为例,来分析进程的启动和切换机制
程序执行步骤:
1、 由my_start_kernel内核入口函数进行初始化task
2、 通过以下汇编代码启动第一个my_process
asm volatile(
"movl %1,%%esp\n\t" /* set task[pid].thread.sp to esp */
"pushl %1\n\t" /* push ebp */
"pushl %0\n\t" /* push task[pid].thread.ip */
"ret\n\t" /* pop task[pid].thread.ip to eip */
"popl %%ebp\n\t"
:
: "c" (task[pid].thread.ip),"d" (task[pid].thread.sp) /* input c or d mean %ecx/%edx*/
);
3、 发生中断时my_timer_handler函数, 并到达时间片需要切换, 设my_need_sched=1
4、 my_process函数内判断my_need_sched==1时调用my_schedule
5、 my_schedule切换or新启动下一个进程
源代码文件:
mypcb.h
myinterrupt.c
mymain.c
测试步骤:
cd LinuxKernel/linux-3.9.4
make
qemu -kernel arch/x86/boot/bzImage
运行截图:
© 岳光勇
原创作品转载请注明出处
《Linux内核分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000
本文以时间片轮转多道程序为例,介绍进程启动与切换机制。详细讲解了my_start_kernel内核入口函数初始化task的过程及通过汇编代码启动my_process的方法。当时间片结束时,触发中断调用my_timer_handler函数,并通过my_schedule实现进程切换。
313

被折叠的 条评论
为什么被折叠?



