-
Notifications
You must be signed in to change notification settings - Fork 354
Description
Hi,
I noticed that in perftest, the CPU usage is calculated using values from the first line of /proc/stat, but only the user and idle fields are used. Specifically, the calculation looks like this:
ustat_diff = user[1] - user[0]; // only user time
idle_diff = idle[1] - idle[0]; // idle time
cpu_usage = (ustat_diff / (ustat_diff + idle_diff)) * 100;However, this approach seems incomplete because it ignores other CPU usage fields such as system, nice, irq, etc. A more accurate calculation should include all CPU time components. Typically, it should be:
total_diff = Δuser + Δnice + Δsystem + Δidle + Δiowait + Δirq + Δsoftirq + Δsteal + ...
idle_diff = Δidle + Δiowait
cpu_usage = (total_diff - idle_diff) / total_diff * 100In short:
cpu_usage = (Δtotal - Δidle) / ΔtotalBy only considering user time, the current calculation underestimates total CPU usage, especially under workloads that heavily use system or irq time.
This becomes particularly problematic in two-sided RDMA mode (e.g., RDMA Send/Recv), where the application might use event-driven programming (e.g., using poll/select/epoll). In such cases, user time remains low while system time or interrupt time may be high. As a result, the current method can misleadingly show near-zero CPU usage, even when the system is busy handling RDMA events.
Is this an oversight or intentional simplification? If it's not intentional, I believe this might be a bug worth correcting.
Thanks!