The current way of calculating the CPU utilization rate is not accurate. The accounting system only works In the interval of two ticks. However, a process can give up the CPU before the tick ending.
This can be fixed by counting the idel time via the scheduler. We can use the sum_exe_runtime of the idle process of each CPU to calculate the the CPU utilization rate. The idle time of each CPU is given in the /proc/stat2 file. An example of using this file is also attached.
Hongyu Li (2): eulerfs: add the /proc/stat2 file tools: add a tool to calculate the CPU utilization rate
fs/proc/Kconfig | 7 +++ fs/proc/Makefile | 1 + fs/proc/stat2.c | 91 ++++++++++++++++++++++++++++ kernel/sched/cputime.c | 34 +++++++++++ kernel/sched/idle.c | 38 ++++++++++++ tools/accounting/Makefile | 2 +- tools/accounting/cpu_rate_cal.c | 91 ++++++++++++++++++++++++++++ tools/accounting/cpu_rate_cal_readme | 15 +++++ 8 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 fs/proc/stat2.c create mode 100644 tools/accounting/cpu_rate_cal.c create mode 100644 tools/accounting/cpu_rate_cal_readme