linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Question] Reading /proc/stat has a time backward issue
@ 2022-07-27  4:02 Lihua (lihua, ran)
  2022-08-04  7:44 ` Lihua (lihua, ran)
  0 siblings, 1 reply; 5+ messages in thread
From: Lihua (lihua, ran) @ 2022-07-27  4:02 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, open list:SCHEDULER

Hi all,

I found a problem that the statistical time goes backward, the value read first is 319, and the value read again is 318. As follows:
first:
cat /proc/stat |  grep cpu1
cpu1    319    0    496    41665    0    0    0    0    0    0
then:
cat /proc/stat |  grep cpu1
cpu1    318    0    497    41674    0    0    0    0    0    0

Time goes back, which is counterintuitive.

After debug this, I found that the problem is caused by the implementation of kcpustat_cpu_fetch_vtime. As follows:

                               CPU0                                                                          CPU1
First:
show_stat():
     ->kcpustat_cpu_fetch()
         ->kcpustat_cpu_fetch_vtime()
             ->cpustat[CPUTIME_USER] = kcpustat_cpu(cpu) + vtime->utime + delta;              rq->curr is in user mod
              ---> When CPU1 rq->curr running on userspace, need add utime and delta
                                                                                              --->  rq->curr->vtime->utime is less than 1 tick
Then:
show_stat():
     ->kcpustat_cpu_fetch()
         ->kcpustat_cpu_fetch_vtime()
             ->cpustat[CPUTIME_USER] = kcpustat_cpu(cpu);                                     rq->curr is in kernel mod
             ---> When CPU1 rq->curr running on kernel space, just got kcpustat

Because the values ​​of utime、 stime and delta are temporarily written to cpustat. Therefore, there are two problems  read from /proc/stat:
1. There may be a regression phenomenon;
2. When there are many tasks, the statistics are not accurate enough when utime and stime do not exceed one TICK.
The time goes back is counterintuitive, and I want to discuss whether there is a good solution without compromising performance.

Thanks a lot.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-13  5:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27  4:02 [Question] Reading /proc/stat has a time backward issue Lihua (lihua, ran)
2022-08-04  7:44 ` Lihua (lihua, ran)
2022-08-08 12:23   ` Lihua (lihua, ran)
2022-08-11 12:49     ` Frederic Weisbecker
2022-08-13 18:58       ` Li Hua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).