LINUX内核分析及实时性改造

上传人:jiups****uk12 文档编号:40000466 上传时间:2018-05-22 格式:DOC 页数:75 大小:1.50MB
返回 下载 相关 举报
LINUX内核分析及实时性改造_第1页
第1页 / 共75页
LINUX内核分析及实时性改造_第2页
第2页 / 共75页
LINUX内核分析及实时性改造_第3页
第3页 / 共75页
LINUX内核分析及实时性改造_第4页
第4页 / 共75页
LINUX内核分析及实时性改造_第5页
第5页 / 共75页
点击查看更多>>
资源描述

《LINUX内核分析及实时性改造》由会员分享,可在线阅读,更多相关《LINUX内核分析及实时性改造(75页珍藏版)》请在金锄头文库上搜索。

1、电子科技大学 硕士学位论文 Linux内核分析及实时性改造 姓名:赖娟 申请学位级别:硕士 专业:软件工程 指导教师:廖建明;刘强 20070607摘要 摘要实时操作系统是近年来研究的一个热点,与常见的通用操作系统相比,实时 操作系统的特点在于系统的正确性不仅依赖于逻辑的正确性,还取决于输出结果 的及时性。目前的实时操作系统广泛应用于国防、工业自动控制、通信等领域。Linux2.6 内核在 2003 年底发布以来,已经被大量测试和实际应用证明其是一 个高效稳定的内核。相比 2.4 内核,2.6 采用了一些新技术使得实时性有了很大提 髙,如可抢占式内核、新的 0(1)调度算法等。这些以及其他相关

2、的背景工作使得 将 Linux 转变为实时操作系统(RTOS)成为可能。尽管实时操作系统的开发者可以 从这些改变中受益,但是 Linux2.6 仍然不是一个实时内核。因此需荽对 Linux2.6 内核进行实时化改造,进一步提高实时性。本文在对 Linux2.6 内核源代码进行研究的基础上,对 Linux 2.6 内核的进程调 度机制、时钟机制等进行了深入的分析和总结。作为改进方案,针对 Limix2.6 内 核时钟机制中时钟粒度过粗的问题,借鉴了 Kurt-Limix 有关时钟机制的改造思想, 将 One-Shot Mode(单次触发模式)引入了 Linux2.6 定时器,巧妙地实现了新的时钟

3、 机制。使得系统在达到了微秒级时钟精度的同时,保持了原有的负载能力;针对 Linux 2.6 内核进程调度机制中缺乏实时调度策略的问题,借鉴了优秀的动态实时 调度算法 LSF(最小裕度优先算法)的“裕度”思想,将其与崭新的 Linux2.6 进程调 度结构相结合,在保持了原有系统 0(1)调度特性的同时,有效地增强了实时调度 能力通过测试,本文所采用的以实时进程的“裕度”值为连接纽带,实时动态调 度机制与单次触发细粒度时钟机制相结合的改进 Linux 系统,在实时性能上较 Linux2.6 内核有了进一步的提高,更加适用于嵌入式实时性应用的开发。关键词:Linux,内核,实时,时钟粒度,调度A

4、bstractAbstractStudy of Real-time Operating System (RTOS) is now a hot topic. Compared with common OS, RTOS has the characteristic that its validity does not only depend on the logistic correctness, but also depends on outputting result in time, RTOS are wildly used in fields, such as defense, indus

5、trial automation control and communicatioiLAfter being released in early 2004,Linux 2.6 kernel has been proved to be stable and high efficient Compared with 2,4 version kernel, 2.6 has been improved in real-time performance by adopting some new technologies, such as preemptive kernel, new O(l) sched

6、ule algorithm etc. Although the developer of RTOS can benefit from these changes, Linux 2,6 is still not a real-time kernel All these changes make it possible to convert Linux to a RTOS. So the reforming of Linux kernel is needed which improve real-time performance.On the basis of reading and resear

7、ch of Linux 2.6 kernel resource codes, the paper gives the deep analyses and summaries of Linux 2.6 kerners task scheduler mechanism, timer mechanism. As the improvement solution, As to the problem of Linux 2.6 kernels too large timer granularity in timer mechanism, One-shot Mode is introduced in Li

8、nux timers from the principle of timer mechanism improvement in Kurt-Linux.the new timer mechanism is implemented skillfully. The new timer mechanism makes the system reached the microsecond level timer precision and maintains its original Load capability, as to the problem of Linux 2.6 kernel lacki

9、ng in real-time scheduling algorithms and policies in the scheduler mechanism, the “laxity“ notion is introduced from the good dynamic real-time schedule algorithm LSF(laxity small first). Combination of the laxity and the new task scheduler data structure in Linux2,6 enhances the systems real-time

10、scheduler capability as well as maintains the original O (1) scheduling characteristic;From the testing results, we can see that the Linux 2.6 kernel has the stronger real-time capability .It Is more fit for the real-time application in embedded fields.Keywords: Linux,Kernel, Real-time, time granula

11、rity, schedulen独创性声明本人声明所呈交的学位论文是本人在导师指导下进行的研究工 作及取得的研究成果。据我所知,除了文中特别加以标注和致谢的地 方外,论文中不包含其他人已经发表或撰写过的研究成果,也不包含 为获得电子科技大学或其它教育机构的学位或证书而使用过的材料。 与我一同工作的同志对本研究所做的任何贡献均已在论文中作了明 确的说明并表示谢意。签名:曰期:年 do_timer_interrupt() 一 do_timer_interrupt_hook() do_timer() 不过 do_timer()函数的实现有所不同: void do_timer(struct pt_reg

12、s *regs) jifFies_64+; update_processJimes(user_xiiode(regs); update_timesO ; 两者所调用的函数基本相同,但是 2.4 内核和 2.6 内核中,对于 update_process_times()函数的实现不同,2.6 中 update_process_times()调用 run_local_timers()引起 TIMER_SOFTIRQ 定时器软中断,处理器在随后的合适的 时机运行软中断处理函数 nm_timer_softirq,这个函数是在 init_timers()函数中注 册的。事实上软中断处理函数 nmJime

13、r_softirq()并没有做什么工作,主要的任务 还是通过调用_mn_timerS( 函数完成的,这个函数相当于 2.4 内核当中的 run_timerjist()函数的功能,该函数在时间列表数据结构当中査找是否存在需要进 行超时处理的定时器,如果有定时器已经超时,则调用该个定时器的处理函数, 并将其从列表中删除。从上面的描述可知道,标准内核中定时器处理函数是在软中断中运行的,然 而,由于软中断执行时间的不确定性,因此无法保证定时能精确按预先设置好的 时间执行,而且定时中断间隔为 1 毫秒,这种粗粒度定时器本身就无法满足大部 分嵌入式应用对时间的要求,因此需要对其进行改进。4.3 细粒度定时

14、器的实现所有的 x86 微处理器都包含一条 CLK 输入线,他接收外部振荡器的时钟信 号,从 Pentium 开始,很多 x86 微处理器都包含一个有 64 位的时间戳计数器 (TSC)的寄存器,可以通过汇编语言指令 rdtsc 读这个寄存器。该寄存器是一个 计 数器,它在每个时钟信号到来时加 1,例如,如果时钟节拍的频率是 400MHZ, 那 么,时间戳计数器每 2.5 纳秒增加一次与可编程间隔定时器(8254)传递来 的时 间测量相比,利用这个寄存器可获得更精确的时间测量,本节所描述的方法 正是 利用该寄存器,同时利用定时芯片 8254 的模式 4,为系统提供一个微秒级精 确度的 定时器系

15、统,该精确度已经可以满足一般的嵌入式实时应用。此方法的基本原理:在系统中增加一个新的定时器链表,该链表中每一项的 超时处理函数都在中断环境中执行,同时该链表的定时可以精确到微秒级,这是 通过 x86 处理器的时间戳寄存器将系统时钟周期 1 毫秒进一步细分来实现的。 下面讲述具体实现 定时器链表类型: struct HRT_timer_list struct 第4章Linux时钟系统改进37HRT_timer_Iist *next; unsigned long expires Jiffies; unsigned long expires_tsc; void (*function)(unsigae

16、d long); unsigned long data; *HRT_timers;expiresjiffies 为还剩下多少个定时器周期该定时器到期,expiresjsc 为当 expiresjiffies 为 0 时,该定时还有多少时间到期,单位为 tsc 数,即 cpu 时钟 周期数,此项为实现微秒级定时器的关键所在。HRT_timers 为定时器链表头。从上一节可知,当时钟中断发生时,系统将调用 timerJnterruptO 函数,我们 对 timerJntemiptO 函数修改如下: timerinterrupt Oi%it_mod = PERIOD_MOD) HRTjperiod_tsc = read_tscO; if(should_set_period_mod =1) HRT_set_pit_mod(PERIOD_MOD, PERIODCOUNTER); should_set_period_mod = 0; if(HRT_timers- expiresjiffies = 0) comter=HRT_tsc_t

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

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