Skip to content

falk-werner/spoil-cpu-usage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spoil CPU Usage

This repository contains a tool used to spoil CPU usage computation on linux system with RT_PREEMPT patch enabled.

CPU usage

Build

cmake -B build
cmake --build build

Problem

There is a good description of the problem available at https://docs.kernel.org/admin-guide/cpu-load.html. Following this, all tools that measure CPU usage using /proc/stat such as htop may display incorrect values.

Other Ideas

cgroup v1

cgroups

Note

cpuacct was removed in cgroup v2

Notes on /proc/schedstat

In order to enable /proc/schedstat the kernel option CONFIG_SCHEDSTATS=y must active.

Some docs suggest to also enable scheduler statistics at runtime using the following command:

sudo sysctl -w kernel.sched_schedstats=1

But, as observation shows, this is not necessary to gather basic CPU usage information. The required field #7 of /proc/schedstat is updated even if kernel.sched_schedstats=0 is set (not sure if this is true for all linux system / kernel versions).

Security Considerations

Note

There is some criticism about /proc/schedstat when it is used in security-aware environments.

The source of this criticism are papers about side channel attacs. Some of them are linked below for reference. Note that those papers use various information exposed by /proc filesystem. In fact, /proc/schedstat is only mentioned in very few of them directrly and only as side note.

If security is a need, there is more required than disabling /proc/schedstat, e.g. use the mount option hidepid=2 when mounting the /proc filesystem.

In order to prevent other users than root to see the contents of /proc/schedstat a start script can change the visibility of the file on bootup.

chmod 0400 /proc/schedstat

Runtime Overhead

There are voices (not confirmed yet, since there is no clear reference found yet) that /proc/schedstat comes with a runtime overhead of 1-2% CPU usage.

This overhead occurs when kernel.sched_schedstats is set to 1, which may not be necessary as stated above.

References

/proc/schedstat related

About

Tool to display errors when computing CPU usage on devices with RT_PREEMPT enabled kernels

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors