Linux上下文切换性能测试的一种新方法
2018-07-28孙菲艳李彦峰王娜汪辰
孙菲艳 李彦峰 王娜 汪辰
摘要:上下文切换是Linux操作系统内核优化的一个关键参数指标,如何精确方便地测量上下文切换开销显得至关重要。本文说明了使用nanosleep()函数测试方法的不合理性,提出了一种在用户态编写应用程序并且调用schedu_yield()系统调用主动放弃处理器实现任务切换的测试方法,并且基于ARM Linux-3.2.0实验平台,与传统的使用管道读写切换、在内核态测试context_switch()函数的开销等方法进行了对比分析,结果表明,使用该方法测试上下文切换的准确性和便捷性均有所提高。
关键词:Linux;上下文切换;系统调用;用户态;内核态
中图分类号:TP316 文献标志码:A 文章编号:1009-3044(2018)15-0047-04
A New Method for Testing the Performance of Linux Context Switch
SUN Fei-yan, LI Yan-feng, WANG Na, WANG Chen
(Nanjing Software Institute, Jinling Institute of Technology, Nanjing 211100, China)
Abstract: Context switch is a key parameter of the kernel optimization of Linux operating system. It is very important to measure the cost of context switch accurately and conveniently. This paper illustrates the irrationality of the test method using the nanosleep () function and presents a method, which is to write an user mode application program and use schedu_yield () system call to take the initiative to give up processor, and also compared with other methods like using traditional read / write with pipes to switch, using nanosleep() and testing the context_switch() function cost in the kernel mode directly based on the experimental platform of arm Linux - 3.2.0. And results show that this new method can improve the accuracy and convenience of the context switch testing.
Key words: Linux-3.2.0; context switch; system call; user mode; kernel mode
隨着信息技术、嵌入式技术的快速发展,Linux作为一种可裁剪、广泛支持、易开发的通用操作系统,也得到了越来越广泛的应用[1][2]。上下文切换延时作为linux操作系统内核的任务调度子系统的主要性能指标,测试上下文切换延时已是一项重要的工作。上下文切换是保存上一个任务的执行环境,准备下一个将要运行的任务的环境的必要操作。研究表明,上下文切换操作在操作系统中,每秒会发生几十至几百次,其带来的时间开销不可忽略[3]。有的测试程序采用nanosleep等睡眠函数来测试上下文切换[4][5],但是由于内核中进入睡眠状态的实时任务是在软中断中被唤醒,在软中断没有到来前实际上并不能保证两个实时任务交替切换;也有很多测试程序采用创建管道读写的方式来测试上下文切换[6][7],该方法程序编写相对复杂,所得到的测试结果是上下文切换延时和管道读写延时的总和,而管道读写延时的开销相对较大,会使得测试结果不够精确。……
