mpstat

The mpstat command in a Linux or Unix system gives the processor related statistics. mpstat is a part of the sysstat package for performance monitoring under Linux. The mpstat command gives the CPU utilization report and the hardware and software interrupts per second for each processor. By default, the CPU utilization report is printed. For example,

$ mpstat Linux 3.0.0-14-generic (hostname) Wednesday 20 June 2012 _i686_ (2 CPU) 02:33:15 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 02:33:15 IST all 18.71 0.19 2.12 0.46 0.00 0.08 0.00 0.00 78.43

mpstat prints the kernel name and release, host nodename, date, machine hardware name and the number of CPUs in the system. Then there is a column header and the report output lines. The first two words give the timestamp (02:33:15 IST, here). The timestamp in the header is the time at which the command is given. The timestamp in the beginning of each report line tells the time at which that report line was generated. In this case, we have a single report giving the global statistics for all processors since the system startup time. The CPUs have been working at the user level 18.71% time, 0.19% working at user level with nice priority, working 2.12% time at the system (kernel) level, 0.46% time waiting for I/O, 0.00 % time servicing hardware interrupts, 0.08% time servicing software interrupts, 0.00% time was spent waiting while the hypervisor was servicing another virtual processor, 0.00% time was spent to run a virtual processor and, lastly, 78.43% time the processors were idle.

The above report is for the time since the system startup. We can append a time interval in seconds to the mpstat command to print the corresponding report repeatedly every time the given time interval elapsed. And, if we put a count after the time interval the report is printed that many times. For example, to print the CPU utilization every 5 seconds four times, the command is,

$ mpstat 5 4 Linux 2.6.38-8-virtual (hostname) 06/20/2012 _i686_ (1 CPU) 01:23:30 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 01:23:35 PM all 0.10 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.90 01:23:40 PM all 4.56 0.00 0.56 0.00 0.00 0.00 7.12 0.00 87.76 01:23:45 PM all 0.00 0.00 0.00 0.10 0.00 0.00 0.00 0.00 99.90 01:23:50 PM all 5.32 0.00 0.23 0.00 0.00 0.00 8.49 0.00 85.96 Average: all 2.35 0.00 0.19 0.03 0.00 0.00 3.68 0.00 93.76

The -u specifically asks for the CPU utilization report. It is possible to select a processor using the -P option. The processor numbers start with 0 and using the -P n option, prints the report for the nth processor. And using the -P ALL option, prints the report for all processors. For example,

$ mpstat -u -P ALL 2 3 Linux 3.0.0-14-generic (hostname) Wednesday 20 June 2012 _i686_ (2 CPU) 07:13:20 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 07:13:22 IST all 3.51 0.00 1.50 1.00 0.00 0.00 0.00 0.00 93.98 07:13:22 IST 0 5.03 0.00 1.01 2.01 0.00 0.00 0.00 0.00 91.96 07:13:22 IST 1 2.00 0.00 1.50 0.00 0.00 0.00 0.00 0.00 96.50 07:13:22 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 07:13:24 IST all 4.50 0.00 2.25 0.00 0.00 0.25 0.00 0.00 93.00 07:13:24 IST 0 4.00 0.00 2.00 0.00 0.00 0.50 0.00 0.00 93.50 07:13:24 IST 1 4.52 0.00 2.51 0.00 0.00 0.00 0.00 0.00 92.96 07:13:24 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 07:13:26 IST all 4.75 0.00 1.50 0.00 0.00 0.00 0.00 0.00 93.75 07:13:26 IST 0 4.98 0.00 1.99 0.00 0.00 0.00 0.00 0.00 93.03 07:13:26 IST 1 4.98 0.00 1.49 0.00 0.00 0.00 0.00 0.00 93.53 Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle Average: all 4.25 0.00 1.75 0.33 0.00 0.08 0.00 0.00 93.58 Average: 0 4.67 0.00 1.67 0.67 0.00 0.17 0.00 0.00 92.83 Average: 1 3.83 0.00 1.83 0.00 0.00 0.00 0.00 0.00 94.33

Interrupt Statistics

The -I option followed by one of the keywords, SUM, CPU, SCPU or ALL gives interrupt per second statistics for the CPUs. If the CPU keyword is used, the number of each interrupt received by the CPU(s) is displayed. If the SCPU keyword is used, the number of each software interrupt received by the CPU(s) is displayed. If the SUM keyword is used, a total number of interrupts per second for all processors is reported. And, the use of ALL keyword has the effect of using the SUM, CPU and SCPU keywords together. For example, to find all interrupts for all processors, we can give the command,

$ mpstat -I ALL -u -P ALL Linux 3.0.0-14-generic (hostname) Thursday 21 June 2012 _i686_ (2 CPU) 03:09:44 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 03:09:44 IST all 15.28 0.18 1.98 0.45 0.00 0.07 0.00 0.00 82.04 03:09:44 IST 0 15.29 0.24 2.05 0.64 0.00 0.13 0.00 0.00 81.66 03:09:44 IST 1 15.26 0.13 1.92 0.26 0.00 0.01 0.00 0.00 82.42 03:09:44 IST CPU intr/s 03:09:44 IST all 894.87 03:09:44 IST 0 0.00 03:09:44 IST 1 0.00 03:09:44 IST CPU 0/s 1/s 5/s 7/s 8/s 9/s 12/s 14/s 15/s 18/s 19/s 20/s 21/s 22/s 23/s NMI/s LOC/s SPU/s PMI/s IWI/s RES/s CAL/s TLB/s TRM/s THR/s MCE/s MCP/s ERR/s MIS/s 03:09:44 IST 0 8.96 0.00 0.02 0.00 0.00 0.01 45.31 0.03 0.00 34.29 28.82 0.00 0.00 0.00 10.54 0.00 222.97 0.00 0.00 0.00 86.59 1.17 1.96 0.00 0.00 0.00 0.00 0.00 0.00 03:09:44 IST 1 305.39 0.20 0.00 0.00 0.00 0.00 0.00 2.97 0.00 0.00 0.00 0.00 0.00 0.00 0.07 0.00 54.01 0.00 0.00 0.00 88.74 1.10 1.71 0.00 0.00 0.00 0.00 0.00 0.00 03:09:44 IST CPU HI/s TIMER/s NET_TX/s NET_RX/s BLOCK/s BLOCK_IOPOLL/s TASKLET/s SCHED/s HRTIMER/s RCU/s 03:09:44 IST 0 0.00 459.54 0.00 1.53 3.71 0.00 47.53 10.26 0.07 14.93 03:09:44 IST 1 0.00 59.71 0.00 0.00 1.01 0.00 0.16 5.82 0.07 12.87

We could have given the command, mpstat -A instead as -A option is a shorthand for -I ALL -u -P ALL. The data for the reports is taken from files in the /proc filesystem. The CPU utilization and the interrupt summary comes from /proc/stat. The interrupts per second for each CPU is based on /proc/interrupts. The first column in /proc/interrupts gives the IRQ number. The same is reported as column heading in the interrupts per second report. Similarly, the report on software interrupts is based on /proc/softirqs.

Software: