现代作业系统核心

上传人:tian****1990 文档编号:82031189 上传时间:2019-02-23 格式:PPT 页数:125 大小:598KB
返回 下载 相关 举报
现代作业系统核心_第1页
第1页 / 共125页
现代作业系统核心_第2页
第2页 / 共125页
现代作业系统核心_第3页
第3页 / 共125页
现代作业系统核心_第4页
第4页 / 共125页
现代作业系统核心_第5页
第5页 / 共125页
点击查看更多>>
资源描述

《现代作业系统核心》由会员分享,可在线阅读,更多相关《现代作业系统核心(125页珍藏版)》请在金锄头文库上搜索。

1、1,CE6130 現代作業系統核心 Modern Operating System Kernels 許 富 皓,2,C Preprocessor: Stringification,When a macro parameter is used with a leading #, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant. Unlike normal parameter replacement, the argument is n

2、ot macro-expanded first. This is called stringification. #define WARN_IF(EXP) do if (EXP) fprintf (stderr, “Warning: “ #EXP “n“); while (0) = WARN_IF (x = 0); = do if (x = 0) fprintf (stderr, “Warning: “ “x = 0“ “n“); while (0);,3,Multiple Kernel Mode Stacks,If the size of the thread_union structure

3、 is 8KB, the kernel mode stack of the current process is used for every type of kernel control path: exceptions, interrupts, and deferrable functions. If the size of the thread_union structure is 4KB, the kernel makes use of three types of kernel mode stacks.,4,Exception Stack,The exception stack is

4、 used when handling exceptions (including system calls). This is the stack contained in the per-process thread_union data structure, thus the kernel makes use of a different exception stack for each process in the system.,5,Hard IRQ Stack,The hard IRQ stack is used when handling interrupts. There is

5、 one hard IRQ stack for each CPU in the system, and each stack is contained in a single page frame. In a multiprocessor system, all hard IRQ stacks are contained in the hardirq_stack array.,6,Structure of Hard IRQ Stack,static char hardirq_stackNR_CPUS * THREAD_SIZE _attribute_(_aligned_(THREAD_SIZE

6、);,element 5 (THREAD_SIZE bytes) element 4 (THREAD_SIZE bytes) element 3 (THREAD_SIZE bytes) element 2 (THREAD_SIZE bytes) element 1 (THREAD_SIZE bytes),Each hardirq_stack array element is a union of type irq_ctx that span a single page.,union irq_ctx struct thread_info tinfo; u32 stackTHREAD_SIZE/s

7、izeof(u32); ;,hardirq_stack,7,Soft IRQ Stack,The soft IRQ stack is used when handling deferrable functions (softirqs or tasklets). There is one soft IRQ stack for each CPU in the system, and each stack is contained in a single page frame. All soft IRQ stacks are contained in the softirq_stack array.

8、,8,Structure of Soft IRQ Stack,static char softirq_stackNR_CPUS * THREAD_SIZE _attribute_(_aligned_(THREAD_SIZE);,Each softirq_stack array element is a union of type irq_ctx that span a single page.,union irq_ctx struct thread_info tinfo; u32 stackTHREAD_SIZE/sizeof(u32); ;,softirq_stack,element 5 (

9、THREAD_SIZE bytes) element 4 (THREAD_SIZE bytes) element 3 (THREAD_SIZE bytes) element 2 (THREAD_SIZE bytes) element 1 (THREAD_SIZE bytes),9,Layout of a irq_ctx Structure,At the bottom of a irq_ctx page is stored a thread_info structure, while the spare memory locations are used for the stack rememb

10、er that each stack grows towards lower addresses.,10,Differences between Hard IRQ Stacks, Soft IRQ Stacks and Exception Stacks,Hard IRQ stacks and soft IRQ stacks are very similar to the exception stacks, the only difference is that in the former the thread_info structure coupled with each stack is

11、associated with a CPU rather than a process.,11,hardirq_ctx and softirq_ctx,The hardirq_ctx and softirq_ctx arrays allow the kernel to quickly determine the hard IRQ stack and soft IRQ stack of a given CPU, respectively: they contain pointers to the corresponding irq_ctx elements. static union irq_c

12、tx *hardirq_ctxNR_CPUS; static union irq_ctx *softirq_ctxNR_CPUS;,12,From hardirq_ctx to hardirq_stack,hardirq_stack,.,hardirq_ctx,Stack thread_info,CPU 1,Initialized by irq_ctx_init,element 5 (THREAD_SIZE bytes) element 4 (THREAD_SIZE bytes) element 3 (THREAD_SIZE bytes) element 2 (THREAD_SIZE byte

13、s) element 1 (THREAD_SIZE bytes),13,do_IRQ(),14,Invoke do_IRQ,The do_IRQ( ) function is invoked to execute all interrupt service routines associated with an interrupt. It is declared as follows: _attribute_(regparm(3) unsigned int do_IRQ(struct pt_regs *regs) The regparm keyword instructs the functi

14、on to go to the eax register to find the value of the regs argument; as seen above, eax points to the stack location containing the last register value pushed on by SAVE_ALL.,15,do_IRQ () Increase a Counter,Executes the irq_enter( ) macro, which increases a counter representing the number of nested

15、interrupt handlers. The counter is stored in the preempt_count field of the thread_info structure of the current process (see Table 4-10 later in this chapter). #define irq_enter() do account_system_vtime(current); add_preempt_count(HARDIRQ_OFFSET); while (0),P.S.: the depth field of an element of i

16、rq_desc array only records information for the corresponding interrupt.,16,do_IRQ () Prepare Hard IRQ Stack If the Size of thread_union Is 4KB,If the size of the thread_union structure is 4 KB, it switches to the hard IRQ stack. In particular, the function performs some extra substeps before proceeding to the next step.,17,4KB thread_un

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号