Linux 6.6 Enables Tracking Per-CPU Cgroup CPU Usage Stats
With the new cgroup code in Linux 6.6, the per-CPU CPU usage stats are now being tracked.
As noted in last week's cgroup merge to Linux 6.6 Git, the per-CPU CPU usage stats are being tracked now and can be exposed such as via eBPF but not currently exposed via the cgroupfs interface. In a future kernel release the per-CPU usage stats will hopefully be exposed via cgroupfs once an adequate interface has been agreed upon.
The patch during the summer provided more insight into this per-CPU CPU usage stats tracking:
"Now the member variable bstat of the structure cgroup_rstat_cpu records the per-cpu time of the cgroup itself, but does not include the per-cpu time of its descendants. The per-cpu time including descendants is very useful for calculating the per-cpu usage of cgroups.
Although we can indirectly obtain the total per-cpu time of the cgroup and its descendants by accumulating the per-cpu bstat of each descendant of the cgroup. But after a child cgroup is removed, we will lose its bstat information. This will cause the cumulative value to be non-monotonic, thus affecting the accuracy of cgroup per-cpu usage.
So we add the cumul_bstat variable to record the total per-cpu time of this cgroup and its descendants, which is similar to "cpuacct.usage*" in cgroup v1. And this is also helpful for the migration from cgroup v1 to cgroup v2. After adding this variable, we can obtain the per-cpu time of cgroup and its descendants in user mode through eBPF, etc."
This cgroup contribution to the upstream kernel was carried out by Bytedance engineers.