Deep Understanding of Linux CPU

Preface

When analyzing the load characteristics running on linux machines, it is often necessary to analyze many metrics. CPU is one of the key factors affecting the efficiency of load operation. Here, the metrics of CPU extracted from promethues are analyzed in detail. It is also an in-depth understanding of linux CPU.

1. Understanding CPU utilization

In linux system, cpu execution is divided into user state, system state and idle state. Represents the cpu execution time in user mode, system mode execution time and idle system process execution time, respectively. cpu utilization is the time of non-idle processes / total execution time of cpu processes
It can also be expressed as:
1-cpu idle runtime/cpu total runtime

2. How to calculate CPU utilization

cpu utilization can be calculated in the / proc/stat file. This file contains information about all cpu activities, and all values are from the start of the system to the current moment.

root@ccrfox111:/home/wychen# cat /proc/stat 
cpu  19482732 658887 17810123 4863711023 2257224 0 2502875 0 0 0
cpu0 1080572 36868 1022322 150931201 24236 0 320696 0 0 0
cpu1 970443 39283 896713 151127028 76293 0 139106 0 0 0
cpu2 885327 38633 924001 151120244 194046 0 95816 0 0 0
cpu3 809150 35663 824706 151368080 95386 0 85577 0 0 0
cpu4 888204 18108 853836 151196320 213321 0 88810 0 0 0
cpu5 813351 17197 760230 151469481 80663 0 83352 0 0 0
cpu6 903539 15295 839289 151242659 158490 0 87598 0 0 0
cpu7 810276 15995 752474 151496058 67115 0 81945 0 0 0
cpu8 881509 15523 827310 151344019 108021 0 86076 0 0 0
cpu9 801434 15916 745196 151520620 62655 0 80216 0 0 0
cpu10 900545 15076 811303 151365504 89333 0 83428 0 0 0
cpu11 801766 15720 741800 151525518 63670 0 79729 0 0 0
cpu12 870335 15164 801125 151402061 98221 0 80436 0 0 0
cpu13 799814 18229 741643 151529017 61832 0 78541 0 0 0
cpu14 883848 15634 796733 151428426 60969 0 81238 0 0 0
cpu15 783835 16051 737709 151551629 61513 0 78285 0 0 0
cpu16 367533 15365 284016 152582422 88945 0 54388 0 0 0
cpu17 324896 23586 309820 152657977 20958 0 60294 0 0 0
cpu18 416391 15450 280204 152504237 123288 0 50465 0 0 0
cpu19 320234 22779 300225 152682350 15508 0 60266 0 0 0
cpu20 406168 15375 285095 152503376 135212 0 45795 0 0 0
cpu21 323230 23777 313614 152663375 18832 0 58529 0 0 0
cpu22 385040 15693 291949 152546759 108834 0 46004 0 0 0
cpu23 327446 23554 322367 152650941 17094 0 59102 0 0 0
cpu24 364650 16359 278396 152637007 50923 0 45874 0 0 0
cpu25 316525 24195 307784 152673564 17915 0 60456 0 0 0
cpu26 362492 15379 273206 152670445 25924 0 45247 0 0 0
cpu27 323518 23521 307272 152671054 14859 0 61765 0 0 0
cpu28 351997 15438 277955 152659331 40648 0 50222 0 0 0
cpu29 322048 24629 312710 152665213 16160 0 61441 0 0 0
cpu30 366290 15614 279102 152653788 30606 0 51069 0 0 0
cpu31 320314 23805 310003 152671306 15738 0 61098 0 0 0
intr 3489535069 43 0 0 0 0 0 0 0 1 3 246 0 0 0 0 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 110547 320210 1365104 362686 1432413 352945 1118622 294995 682894 274136 648019 296554 580118 284050 372673 268098 792928 41528 1089936 44986 1060673 51181 1079085 39617 657784 62386 257702 39265 457135 80618 0 189382 36987 0 0 0 1498493 0 0 0 11027489 3486077 6199271 3816255 2364228 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 10149973761
btime 1534667648
processes 8987149
procs_running 1
procs_blocked 0
softirq 4946136337 6 583266925 313944 3037525697 15491661 0 3221168 531837767 0 774479169

The parameters are explained as follows:
Meaning of each column parameter value
User accumulates cpu time from system start-up to current time in user mode
Nice accumulates the cpu time taken by processes with negative nice values from the start of the system to the current time
System accumulates from system startup to current time, core time
idle accumulates from the start of the system to the current time, waiting time other than hard disk IO waiting time
iowait accumulates from system boot to current time, hard disk IO waiting time
irq accumulates from system startup to current time, hard interrupt time
softirq accumulates from system startup to current time, soft interrupt time
Note: The last three columns of 000 do not know what it means to be studied.
CPU time = user+system+nice+idle+iowait+irq+softirq

The "intr" line gives information about interrupts. The first is the number of interrupts that have occurred since the system was started; then each number corresponds to the number of times a particular interrupt has occurred since the system started.
"ctxt" gives the number of contextual exchanges that have taken place in the CPU since the system was started.
"btime" gives the time from system start up to now, in seconds.
The number of tasks created by processes (total_forks) since the system started.
"procs_running": Number of tasks currently running the queue.
"procs_blocked": Number of tasks currently blocked.

Then CPU utilization can use the following two methods. Firstly, two sampling points are selected, and then the difference is calculated.
cpu usage=(idle2-idle1)/(total_2 - total_1)*100
cpu usage=[(user_2 +sys_2+nice_2) - (user_1 + sys_1+nice_1)]/(total_2 - total_1)*100

3. Measurement of each CPU core

The server allocated by the subject group I locked in had 32 CPU cores, so the statistics of 32 CPUs were displayed when monitoring.

Reference resources

https://blog.csdn.net/Alisa_xf/article/details/71430406
https://blog.csdn.net/baidu_35692628/article/details/71773886

Keywords: Linux

Added by snipe7kills on Wed, 15 May 2019 06:02:42 +0300