add miss time to CPUTIME_USER when kernel boots with highres=off
PATCH v2 1/1 add miss time to CPUTIME_USER when kernel boots with highres=off
When kernel boots with highres=off and the cpu load isn't full, almost every tick will account towards CPUTIME_IDLE. But in /proc/stat, idle time is obtained from get_idle_time.
So the sum time will lose the time of user tasks.
For example:
# stress-ng --cpu 2 --taskset 66 --timeout 600 --cpu-load 50 & # cat /proc/stat | grep "cpu66";sleep 10; cat /proc/stat | grep "cpu66" cpu66 1038 0 72 50124 75 17 1 0 0 0 cpu66 1038 0 72 50569 75 18 2 0 0 0
the detla of sum time is 447, which should be 1000 actually. It will casue the data in top is imprecise.
v2:
Fix build error when CONFIG_HIGH_RES_TIMERS is not set.
Signed-off-by Liu Chao <[email protected]>
--- fs/proc/stat.c | 5 +++++ include/linux/hrtimer.h | 2 ++ kernel/time/hrtimer.c | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-)
fs/proc/stat.c +5 -0
@@ -141,6 +141,9 @@ static int show_stat(struct seq_file *p, void *v) sum +=kstat_cpu_irqs_sum (i); sum +=arch_irq_stat_cpu (i); +if (hrtimer_is_hres_enabled () ==0 ) + user += cpustat[CPUTIME_IDLE ] -get_idle_time (&kcpustat, i); +for (j =0 ; j <NR_SOFTIRQS ; j++) {unsigned int softirq_stat =kstat_softirqs_cpu (j, i);
@@ -179,6 +182,8 @@ static int show_stat(struct seq_file *p, void *v) steal = cpustat[CPUTIME_STEAL ]; guest = cpustat[CPUTIME_GUEST ]; guest_nice = cpustat[CPUTIME_GUEST_NICE ]; +if (hrtimer_is_hres_enabled () ==0 ) + user += cpustat[CPUTIME_IDLE ] - idle;seq_printf (p,"cpu%d" , i);seq_put_decimal_ull (p," " ,nsec_to_clock_t (user));seq_put_decimal_ull (p," " ,nsec_to_clock_t (nice));
include/linux/hrtimer.h +2 -0
@@ -326,6 +326,8 @@ extern unsigned int hrtimer_resolution;#endif +extern int hrtimer_is_hres_enabled (void ); +static inline ktime_t __hrtimer_expires_remaining_adjusted (const struct hrtimer *timer,ktime_t now) {
kernel/time/hrtimer.c +2 -2
@@ -722,7 +722,7 @@ __setup("highres=", setup_hrtimer_hres);/* * hrtimer_high_res_enabled - query, if the highres mode is enabled */ -static inline int hrtimer_is_hres_enabled (void ) +int hrtimer_is_hres_enabled (void ) {return hrtimer_hres_enabled; }
@@ -751,7 +751,7 @@ static void hrtimer_switch_to_hres(void)#else -static inline int hrtimer_is_hres_enabled (void ) {return 0 ; } +int hrtimer_is_hres_enabled (void ) {return 0 ; }static inline void hrtimer_switch_to_hres (void ) { }#endif /* CONFIG_HIGH_RES_TIMERS */
base-commit: e65c6a46df94c8d76ea1129eb2d4564670c6f214
prerequisite-patch-id: 3099d45f464060b03429daa159ee8d882d113edc
prerequisite-patch-id: db6e0da8d4379352a3bd819eb158f78e66abf01d
Signature · 1 line
2.23.0