根据任务的不同 CPU上下文切换可以分为进程上下文切换 线程上下文切换和中断上下文切换
# man pidstat
-w Report task switching activity (kernels 2.6.23 and later only). The following
values may be displayed:
CPU 上下文切换又分为:
# yum install sysbench
https://www.jianshu.com/p/7a80898c6866
系统在空闲状态下信息
# vmstat 1 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 2213652 218252 1250912 0 0 1 10 23 42 1 1 98 0 0
上下文切换和中断分别为23 10
r(running) 0 b(block) 0
模拟多线程切换
#sysbench --threads=10 --max-time=300 threads run
#watch cat /proc/interrupts
RTR: 0 0 APIC ICR read retries
RES: 3604171 3787902 Rescheduling interrupts
CAL: 279 363 Function call interrupts
APIC表示高级可编程中断控制器(Advanced Programmable Interrupt Controlle),APIC是SMP体系的核心,通过APIC可将中断分发到不同的CPU处理
# pidstat -wt 1
10:17:40 AM 0 - 7815 45551.00 233127.00 |__sysbench
10:17:40 AM 0 - 7816 46589.00 212956.00 |__sysbench
10:17:40 AM 0 - 7817 44445.00 209561.00 |__sysbench
10:17:40 AM 0 - 7818 56768.00 198699.00 |__sysbench
10:17:40 AM 0 - 7819 43265.00 207024.00 |__sysbench
10:17:40 AM 0 - 7820 46311.00 226274.00 |__sysbench
# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
8 0 0 2203604 218300 1251784 0 0 1 10 24 3 1 1 98 0 0
8 0 0 2203644 218300 1251784 0 0 0 68 3196 2522357 8 92 0 0 0
6 0 0 2202120 218300 1251844 0 0 0 16 3265 2463744 8 92 0 0 0
7 0 0 2202812 218300 1251912 0 0 0 56 3103 2515468 7 92 1 0 0
10 0 0 2202900 218300 1251832 0 0 0 0 2894 2488509 8 92 0 0 0
6 0 0 2202036 218300 1251832 0 0 0 0 3337 2510344 8 91 0 0 0
7 0 0 2201488 218300 1251840 0 0 0 0 2976 2520970 8 92 1 0 0
8 0 0 2203256 218300 1251792 0 0 0 92 4409 2508097 8 92 0 0 0
7 0 0 2203216 218300 1251796 0 0 0 92 2440 2521490 8 92 0 0 0
5 0 0 2203256 218300 1251804 0 0 0 0 3213 2526508 7 92 0 0 0
可以看到CPU中断次数在不断增加
参考链接http://itoperationswiki.blogspot.com/2013/12/protection-rings-and-types-of.html
https://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。