Troubleshooting Tip: How high CPU usage should be investigated
| Description | This article describes how to analyze high CPU usage on a FortiGate. |
| Scope | FortiGate, FortiOS. |
| Solution | It is important to understand how CPU usage is measured:
3 distinct spaces can mainly use the CPU:
Better options to start investigating are 'get sys performance status' and 'diagnose sys mpstat <refresh seconds>'.
get sys performance status
Once the main type of usage has been identified, the focus can be moved to the specific use space.
At this point, 'diagnose system top' can be used to identify the application that is consuming all the CPU time and debug it with the specific application debug commands.
Additional information about a process (like the last CPU it ran, status, syscalls, memory usage, etc) can be gathered in the following underlying directories:
fnsysctl cat /proc/<pid>/status
Refer to the Linux man page to understand these files.
System: If high CPU usage is seen in system space, a CPU profiling can show what the most frequently called functions in the source code are, whether they are Linux kernel functions or Fortinet-specific system functions. This will give an idea of what is going on at the system level during a specific amount of time. After identifying which CPU is experiencing high system usage, run the following commands:
fnsysctl date diagnose sys profile start
Wait approximately 10 to 30 seconds.
diagnose sys profile stop diagnose sys profile show detail
The show order will print something like this:
0xffffffff8025fb50: 454 vprintk_emit+0x190/0x4f0
Note that poll_idle is the kernel function executed when no other function is being executed to measure the actual CPU usage, as stated at the beginning.
Interrupts (hardware or software interrupts) are special functions triggered when certain events occur. They order the CPU to interrupt the current operation to execute the actual raised interrupt handler. This means the CPU is not waiting for the event to occur, but the interrupt sends the signal to the CPU upon being triggered and executes an interrupt of related code (a real-life analogy would be ringing a doorbell, so when the doorbell rings, the people inside stop what they are doing to check who is at the door).
On a firewall or network devices in general, the main source of interrupts is network packets received on interfaces.
High IRQ could mean an L2 issue, such as L2 broadcast storms, a high number of non-offloaded sessions, or just a high session setup rate. To investigate high softirq or irq, obtain useful information about session setup rate, and offloaded vs non-offloaded sessions with 'get sys performance status'.
get sys performance status
Additionally, use the command 'diagnose sys session stat':
diagnose sys session stat
EG --> 0xffffffffa0164feb: 1 np6_clean_rx+0xcb/0xe30
To have an idea of how interrupts are distributed among CPUs, run the following:
diagnose hardware sysinfo interrupts
Or:
fnsysctl cat /proc/interrupts
fnsysctl cat /proc/interrupts ...
Each line of the above output represents an interrupt with its unique ID, a counter for each CPU, so that the user can see on which CPU the interrupt is executed. Every interrupt is configured with an affinity to a CPU or a set of CPUs; this affinity can be reviewed with the commands below:
fnsysctl cat /proc/irq/<IRQ ID>/smp_affinity_list --> decimal fnsysctl cat /proc/irq/<IRQ ID>/smp_affinity --> HEX mask
So, as per the previous output, it is possible to see that the configured affinity for interrupt NP6_0_tx-rx3 (ID:145, this interrupt is raised when NP6 0 is sending non-offloaded traffic to the kernel or when non-offloaded traffic processed by the kernel needs to be sent out through an interface) has an affinity with CPU 3 and it has been executed on CPU 3 3319842 times.
fnsysctl cat /proc/irq/145/smp_affinity
fnsysctl cat /proc/irq/145/smp_affinity_list
session info: proto=6 proto_state=01 duration=302 expire=3597 timeout=3600 refresh_dir=both flags=00000000 socktype=0 sockport=0 av_idx=0 use=3 ...
Additional info: Note that the provided outputs refer to a FortiGate equipped with an NP6.
FortiGate physical appliances can be equipped with different Content Processors and Network Processor co-processors to accelerate traffic offloading it from the processor. For more info regarding hardware acceleration, see the Hardware Acceleration guide.
There are 2 methods to find out which CP and NP co-processors a FortiGate is equipped with:
FortiGate-VM: NP/CP acceleration features do not exist for them, so the entire computational load is managed by the CPU of the Virtual Machine.
To reduce the load of the CPU, if the Virtual Machine uses Intel processors, the FortiGate uses dedicated drivers.
The drivers available for IPSec encryption/decryption are not the same in different FortiOS minor release patches.
A bug with driver availability, bug ID #1049015, affects the v7.2 and v7.4 patches. It has been resolved in FortiOS v7.6.3 and all newer releases, as indicated in the Resolved issues.
To resolve this in older versions, execute the command diagnose vpn ipsec driver (this command does not exist anymore starting from FortiOS 7.6.3).
The output indicates that there are drivers available using aes-cbc, aes-gcm and chacha20poly1305 in phases 1 and 2 of IPsec tunnels.
This is the expected output when running it in a FortiGate-VM running a 7.4 patch, while even fewer should be seen when running it on a FortiGate-VM 7.2.
This bug causes a performance reduction regarding the IPSec traffic after the FortiOS upgrade from v7.0 or older to a v7.2 or v7.4 patch.
The problem can also affects physical appliances if NPU offload is disabled under phase1 of an IPsec tunnel.
Related articles:
If CPU Spikes are temporary, such as for 30 seconds or a couple of minutes, and if they occur after a configuration change, see Troubleshooting Tip: CPU Spikes after a configuration change.
To improve performances of FortiGate-VMs in KVM environments, it is possible to activate DPDK: Enhancing FortiGate-VM performance with DPDK and vNP offloading.
A scenario with FortiGate-VM using only 1vCPU after a license renewal is covered here: Technical Tip: FortiGate VM Decreases Active CPUs to 1 After License Change.
Other related articles: |
