Linux系统的实时性研究
详细信息    本馆镜像全文|  推荐本文 |  |   获取CNKI官网全文
摘要
凭借着源代码公开、适用范围广泛、可移植性强、软件资源丰富等优势,Linux系统被越来越多的人所认知与认同。但是,在某些应用环境下,特别是某些嵌入式的环境下,Linux的实时性能并不令人满意。
     本文便是为了提高Linux操作系统的实时性能而进行的研究。
     首先学习Linux的相关理论知识,然后针对Linux实时性不强的原因进行了分析并制定了改进的方案。
     针对Linux系统调度算法的不足,用动态优先级的调度方法对其进行改进,并且利用反馈和设定阙值的方法解决了由于采用最小裕度优先算法而导致的进程频繁切换的问题。
     针对系统定时器粒度过大的问题,采用单次触发模式对系统的时钟中断发生时机进行了改进,实现了定时器粒度的细化。
     最后,通过改写中断服务程序完成了与中断延迟相关的实验,并利用管道完成了系统任务切换时间的测试实验,通过这两个实验验证了通过改进,系统的实时性能得到了提高。
Nowadays, with the fast development of embedded system product, the claim toembedded system is more and more rigorous. However, there is not a mature orcomprehensively applied product in China. As the mature software, Linux bring the firstlight of morning for our country with its open source, high stability, low cost and someother characteristics. In the beginning, Linux is designed on the basis of fundamentals thatthe average response time is as possible as short and the throughput is as possible as high,which is for a operation system. Some characteristics like coarse time granularity,frequently interrupt disable for protecting data’s safety and consistency and the use ofvirtual memory,which lead to real time deficiency when Linux is used in some real timeclaim environment .So improving on real-time support of Linux system is becoming a hottopicoftheresearch.
     With more and more company. research communityand amateur participating in Linuxreal time performance research, a lot of achievements come out .Although goals are same,improving real time performance, the solutions are different and worth reference, whichhave different starting point, like decreasing use of interrupt or closing interrupt, realizingpreempted kernel, using double kernel, refine time granularity, threaded interrupts and soon. These solutions are successful for improving system real time ability in some aspects,someofwhicharepracticallyappliedanddeveloprelativeproducts.
     This paper is based upon studying relative theory of Linux. The solutions of improvingreal time ability of Linux system are analyzed by modifying process schedule and timegranularityofkernel.
     The fit task Process will be selected by scheduling algorithm to handle among manyprocesses and fix on process runtime, which directly influence system real-timeperformance. Although Linux adopt advanced O(1) algorithm, it doesn’t take into accountsystem dynamic operation, which will lead to low system real-time ability by adoptingstatic priority algorithm to schedule system process. This paper adopt lowest slackpriorityalgorithm to improve former algorithm, which consider the factor with relationshiptotime.Basedonthenewalgorithm,systemscheduleisnotonlyrelatedtoprocesspriority,but also related to process pressing degree—the slack。When the system schedule system process, it determines a certain process to run, which is most compatible to least slack firstalgorithm and to process priority.
     Because of considering the slack, the system may frequently switch some processeswhich have the same priority and similar slack. It will bring on extra burden and influencesystem performance. To solve this problem, this paper adopt feedback and threshold valueto decrease probability of problem occurring, which will improve system performance.
     Time interrupt play an important role in the system. When time interrupts occur,system will inspect process running state, providing an opportunity to schedule, which isimportant for improving system real time performance.
     This hope of the paper firstly is to improve on system performance by increasing timeclock frequency, but it failed. Later based upon KURT advanced theory , This paper adoptenhancing time granularity to improve system real time ability by means of one-shottriggering。
     The core of one-shot triggering time interrupt is that: the system need not have torespond to any change every time, but only make response when having to respond.Optimization scheme is carried out with PIT8254, time stamp counter-TSC and soft timer.At first, using TSC to time accurately, and using 8254 to bring out time interrupt. Whentime interrupt occur, system examine whether there are mature timers or not at the next timecycle. If there are mature timers, system calculate parameters which are based on maturetime. The parameters are used to modify 8254 control registers,which will bring out aninterrupt and make relative operation when system is at specific time. By this way, it isequivalent to enhancing system time frequency and refine time granularity. But it doesn’tincrease the system burden like only enhancing system time frequency.
     To estimate whether Linux performance is enhanced by the two modificationsmentioned above, the paper performs a relative test. First of all, the modified source code togenerate a new kernel file, by modifying the startup files, the system is running successfully.In order to test the system interrupt latency, I modify the clock interrupt service routine,firstly, through the TSC interrupt service routine to read the start-up time, and then removezero channel count of the PIT8254 and to carry out the two units conversion, and finally getout in microseconds as the unit of interrupt latency.
     In order to prove the higher performance of the context switch time, we create a fatherprocess and a son process, and two half- duplex pipes to pass message between the fatherand the son process. Because of the message ,the processes will be blocked. When theprocess switches, we record the right time with rdtsc() and calculate the value between the times. Through the two experiments, we can see that the performance of de systembecomes better in some degree.
     With the increasing popularity of Linux, it is used in more and more fields. But it isrestricted in many areas because of the deficiency of real time performance. I modify thekernel by modifying scheduling algorithm and refining time granularity. It is proved thatsystem real time performance is improved at a certain extent.
引文
[1] Gloria D,Alessandro. Microprocessor design for embedded system. Journal of SystemsArchitecture[J].1999,45(6),1139-1149.
    [2] Wayne Wolf. Computers as Components Principles of Embedded Computing SystemDesign[M].Beijing:PublishingHouseofMachineryIndustry.2002:11-14.
    [3] MSPU RI,GBUTTAZ ZO. Schedule Tasks in Dynamic Priority of Real Time Syste-ms[J].JourmalofReal-TimeSystems,2006,10(2):9-10.
    [4]刘洋.基于Linux的嵌入式操作系统实时性研究[C].沈阳工业大学,2003.3:1-3.
    [5]桑金歌.嵌入式Linux实时性研究[C].河北工业大学,2007:2.
    [6]陈莉君.深入理解LINUX内核[M].北京:中国电力出版社,2007.9:5-8.
    [7]毛德操,胡希明. LINUX内核源代码情景分析[M].杭州:浙江大学出版社.2001.9:5.
    [8] M.Kaashoek. Interrupt and task scheduling of RT-Linux. Embedded Systems Program-ming[J],2003,Vol.20(8):1456-1471.
    [9] Darrick Addison. Embedded Linux applications: An overview-From wrist watches tocluster-basedsupercomputers[J].IBMdeveloperWorks.August2001.
    [10]C.M.Krishna,KangG,Shin.Real-timeSystem[J].McGraw-hill.2001.
    [11]Michael B. A Linux-based Real-time Operating System[D]. Socorro, New Mexico:NewMexicoInstituteofMiningandTechnology,l997.
    [12]Steve B. Shielded CPUs:real-time performance in standard Linux[J]. Linux JournalOnline,2004(121).
    [13]左万历,周长林.计算机操作系统教程[M].北京:高等教育出版社,1994.1:4-8.
    [14]舒志文.嵌入式Linux操作系统实时性的研究与实现[C].华中科技大学,2007.1:8-9.
    [15]陈莉君.深入理解LINUX内核[M].北京:中国电力出版社,2007.9:8-12.
    [16]范磊.Linux内核源代码[M].北京:人民邮电出版社,2002.
    [17]DANIEL P.BOVET, MARCO CESATI. UNDERSTANDING THE LINUX KERNEL(ThirdEdition)[M],O’REILYPress,2006.
    [18]左万历,周长林.计算机操作系统教程[M].北京:高等教育出版社,1994.1:18-23.
    [19]Wang Y, Saksena M. Scheduling fixed-priority tasks with preemption threshold. In:Gakkai JS,ed. Proc.of the 6th Int’l Conf. on Real-Time Computing Systems andApplication. Los Alamitos: IEEE Computer Society, 1999. 328-335.
    [20]倪继利.Linux内核分析及编程[M].北京:电子工业出版社,2005.9:15-19.
    [21]陈莉君.深入理解LINUX内核[M].中国电力出版社,2007.9:263.
    [22]Robert L. Linux Kernel Development[M].2nd.US:Novel Press, 2005.
    [23]赵国相,于秀峰,微型计算机原理与接口技术[M].北京:科学出版社,2004: 65-69.
    [24]赵炯.Linux内核完全剖析.北京:机械工业出版社,2006.1:108-113.
    [25]于晓锋.嵌入式实时Linux系统的构建[J].电子科技大学,2008.7:19-24.
    [26]Daniel P. Bovet, Marco Cesati. Understanding the Linux Kernel, 3rd Edition[M],O'Reilly, 2005.11.
    [27]Broko Furht, Dan Grostick. Real-time UNIX system: design and application guide [M],Kluwer Academic Publishers Group, Norwell, MA,USA,1991.
    [28]Shui Oikawa, Rag Rajkmar. Linux/RK: A Portable Resource Kernel in Linux[J]. IEEEReal-Time Systems SymposiumWork-In-Progress,1998:43-47.
    [29]赖娟. Linux内核分析及实时性改造.西安:电子科技大学, 2007.6:28-33.
    [30]Zou Yong, Wang Qing, Li Ming-shu. Research and implementing of real-time supportof linux kernel[J]. Journal of Computer Research and Development, 2002, 39(4):466-472.
    [31]陈莉君. Linux操作系统内核分析[M].北京:人民邮电出版社, 2000:243-297.
    [32]Srinivasan B. A firm shelf hardware and free real-time system implementation usingcommercial off-the-software: (master thesis). American: University of Kansas, 1998.
    [33]C.L.Liu and J.W.Layland. Scheduling algorithms for multiprogramming in a hardreal-time environment [J]. Journal of the ACM, January 1973 vol.20(1):44-61.
    [34]Liu C L, Layland J W. Scheduling algorithms for multi programming in a hardreal-time environment[J]. The Association for Computing Machinery, 1973,20(1):46-61.
    [35]Hildebrandt J,Golatowski F,Timmermann D. Scheduling Coprocessor for EnhancedLeast-Laxity-First Scheduling in Hard Real-Time Systems L Proc. of the 1lthEuromicro Conf. 011Real-Time Systems. os Alamitos: IEEE Computer SocietyPress,2002:208-215.
    [36]Liu J WS. Real-Time System [M]. Upper Saddle River Hall, 2000.
    [37]Liu C L, Layland JW. Scheduling algorithms for multi programming in a hard real-timeenvironment[ J]. ACM, 1973, 20(1): 40-61.
    [38]Obenza R. Rate monotonic analysis for real-time systems[J]. IEEE Computer, 1993,26(3): 73-74.
    [39]Gafford J. Rate monotonic scheduling [ J]. IEEE Micro 1991 11(3): 34-39.
    [40]]WangYuchung, LinKwei Jay. Implementing a general real times schedulingframework in the RED Linux real time kernel [A]. Proceedings RealTime SystemsSymposium [C], 1999: 246.
    [41]Terrasa A, Garcia-FornesA,Botti VJ. Flexible realtime linux:A flexible hard real-timeenvironment Real-Time Systems, 2004,22(2): 151-173.
    [42]Jonathan Corbet, Greg Kroah Hartman, Alessanddo Rubini.Linux Device Drivers, 3rdedition . O’Reilly Publishing 2005: 345-347.
    [43]Linux内核的时钟中断机制.14-15, http://www.docin.com/ p-1624090. html#docTitle.
    [44]Aron Leucht, Lineo.Hard Real-Time Capability under Linux. Electronic EngineeringDesign, 2002(2): 50-54.
    [45]河秦,王洪涛. Linux2.6内核标准教程.人民邮电出版社[M], 2008.10: 323-324.
    [46]朱响斌,涂洪亮. Linux的实时性能测试[J].微电子科学与技术, 2004, 21(11): 86-90.