CPU context switching and understanding of related Zabbix monitoring indicators (transfer)

Preface

I have never understood the word context switching. After reading it countless times, I have forgotten it countless times. After reading the book "Introduction to Operating Systems", I finally have a slight understanding. This also proves that my direction is correct. I always think that I still have to understand the underlying knowledge to do operation and maintenance. I don’t understand many things but porters. For example, I have done monitoring countless times, but do I understand the specific monitoring indicators? This monitoring How the indicator measures the performance of the system.

 

Official understanding

1) What the operating system has to do is to save the value of some registers for the currently executing process, and restore the value of some registers for the process to be executed, so that the operating system can ensure that the last execution of the return instruction from the trap is not Return to the previously running process but continue to execute another process.

2) Now Linux is based on preemptive mode. The CPU gives each task a certain amount of service time. When the time slice rotates, it needs to save the current state and load the next task at the same time. This process is called context switching. The way of time slice rotation makes it possible for multiple tasks to be executed with one CPU, but saving the scene and loading the scene also brings performance consumption.

 

related information

1) Virtualization

     In order to virtualize the CPU, the operating system needs to allow many tasks to share the physical CPU in some way so that they appear to be running at the same time. The basic idea: Run one process for a period of time, and then run another process, in such a rotation, by sharing the CPU time-sharing in this way, virtualization is realized.

 

2) Clock interrupt

     The purpose of the clock interrupt is to allow the CPU to regain control of the CPU, then stop the current process and run another process.

 

Therefore, when stopping the current process to run another process, you need to keep the relevant information of the current process and read the relevant information of the process to be run next, so that the system knows which process needs to be run, this saves the current process information, and Reading information about the next process is called context switching.

 

Understand by yourself

 

1) Easy-to-understand teaching: the number of process switching times per second

2) Unit: ksps (thousand times per second)

3) Index type: performance index

4) Monitoring items on zabbix: system.cpu.switches process switching times per second

     Related monitoring items: system.cpu.intr The number of clock interrupts per second

 

 

 

 

The purpose of time interruption is to switch processes, so these two monitoring lines are generally put together. The clock interruption is for process switching, but each clock interruption does not necessarily switch processes.

 

Context of the test system

 1) Tool lmbench

 wget http://www.bitmover.com/lmbench/lmbench3.tar.gz
 tar -zxvf lmbench3.tar.gz 
 cd src/
 make results

 

2) An error may be reported:

gmake[1]: Entering directory `/lmbeanch/lmbench3/src'
gmake[1]: *** No rule to make target `../SCCS/s.ChangeSet', needed by `bk.ver'.  Stop.
gmake[1]: Leaving directory `/lmbeanch/lmbench3/src'
make: *** [lmbench] Error 2

 

3) Solution:

把src/Makefile文件的第231行的$O/lmbench : ../scripts/lmbench  bk.ver  的 bk.ver 去掉为$O/lmbench : ../scripts/lmbench

 

4) Use

The next blog post specifically summarizes.

Guess you like

Origin blog.csdn.net/ccpit2b2c/article/details/109326979