An Overview of CPU Statistics In Linux

Posted By : Nitin Sharma | 31-May-2022

linux

Loading...

Let's take a step back for a moment. There are three general states in which your CPU can be:

  1. It's idle, which means it's not doing anything.
  2. A user space programme, such as a command shell, an email server, or a compiler, is being run.
  3. Managing resources, handling interrupts, and running the kernel.

These three meta states can be subdivided further. User space programmes, for example, can be divided into two groups: those that run with a low priority and those that run with a high priority. Niceness is a method of lowering a process's priority level so that it runs less frequently. The niceness scale runs from -20 (the most beneficial scheduling) to 19 (the least pleasant scheduling) (least favorable). On Linux, processes are started with a niceness of 0 by default.

The following are seven CPU outcomes and analysis that have been explained

The various CPU statistics may be viewed in a variety of ways. Using the top command is perhaps the most popular.

To use the top command, simply type top at the command prompt:

The output from the top is split into two halves. The first few lines provide an overview of the system's resources, including a breakdown of the number of processes, CPU statistics, and memory consumption. A live list of the currently operating processes is displayed beneath these statistics. This list may be sorted by PID, CPU, RAM, and other factors.

This is what the CPU line will look like:

%Cpu(s): 29.9 us, 0.7 sy, 0.1 ni, 75.8 id, 0.2 wa, 0.3 hi, 0.1 si, 0.8 st

29.9 us - The processor spends 29.9 percent of its time operating user space programmes, according to this. Any process that isn't part of the kernel is referred to as a user space application. Shells, compilers, databases, web servers, and desktop apps are all examples of user space processes. If the processor isn't idle, it's usual for user space processes to take up the majority of CPU time.

0.7 sy - This is the amount of time the kernel took to run on the CPU. The Linux kernel is in charge of all processes and system resources. The kernel is executing when a user space process demands anything from the system, such as memory allocation, I/O, or the creation of a child process. In fact, the kernel includes the scheduler, which controls which process runs next. The time spent in the kernel should be kept to a bare minimum. In this situation, the kernel received only 0.7 percent of the total time allotted to the various processes. This figure can skyrocket, especially if there's a lot of I/O going on.

0.1 ni - The priority level of a user space process can be modified by modifying its niceness, as previously described. The ni statistic reveals how much time the CPU spent running niced user space processes. The number will be 0 on a system where no processes have been niced.

75.8 id - The id statistic tells us that the processor remained idle slightly over 75.8% of the time during the last sampling period, skipping over a few other statistics for a moment. The sum of the user space percentage, the niced percentage, and the idle percentage, id, should be close to 100%. This is the situation in this instance. If the CPU spends more time in the other states, something is likely wrong.

0.2 wa - When compared to the speed of a CPU, input and output processes such as reading and writing to a disc are slow. Even while these actions are quick in comparison to typical human tasks, they are still slow when compared to a CPU's speed. There are occasions when the processor has started a read or write operation and now has nothing else to do but wait for the result. In other words, it is idle while awaiting the completion of an I/O activity. The wa statistic shows how much time the CPU spends in this state.

0.3 hi and 0.1 si- These two figures represent the amount of time the CPU has spent dealing with interrupts. Hardware interrupts are represented by hi, while software interrupts are represented by si. Physical interruptions from peripherals like as drives and network interfaces are communicated to the CPU as hardware interrupts. Processes operating on the system cause software interrupts. A hardware interrupt causes the CPU to pause what it's doing and respond to the interruption. A software interrupt occurs at the kernel level rather than at the CPU level.

0.8 st - The st statistic displays how long the virtual CPU has been waiting for the hypervisor to serve another virtual CPU operating on a different virtual machine when Linux is running as a virtual machine on a hypervisor. Because these virtual processors share the same physical processor(s) in the real world, there will be moments when the virtual machine wants to run but the hypervisor has another virtual machine scheduled instead.

At Oodles, we specialize in building custom enterprise applications for the diverse industries-specific needs of our clients. Our seasoned developers use open-source software platforms like Odoo, OFBiz, ERPNext, and Opentaps For custom ERP development from the ground up. To learn more about our custom ERP development services, contact us at [email protected].