public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: zhengzucheng <zhengzucheng@huawei.com>
To: Peter Zijlstra <peterz@infradead.org>, Li Hua <hucool.lihua@huawei.com>
Cc: <mingo@redhat.com>, <juri.lelli@redhat.com>,
	<vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>,
	<rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>,
	<bristot@redhat.com>, <vschneid@redhat.com>,
	<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH -next] sched/cputime: Fix the bug of reading time backward from /proc/stat
Date: Mon, 5 Sep 2022 11:47:41 +0800	[thread overview]
Message-ID: <0b2f6919-7ed4-b30d-e92b-355c09bbfd25@huawei.com> (raw)
In-Reply-To: <YvoAk1pnU4gZcFJ1@worktop.programming.kicks-ass.net>


Assume that a CPU time“ A” is read from /proc/stat, and after a while,  
a CPU time “B” is read. If T = B – A < 0, T is identified as a large 
number as an unsigned integer. As a result, the CPU usage calculated by 
this way will be abnormally high. It seems to be a problem to be fixed.

original link:
https://lore.kernel.org/lkml/20220813000102.42051-1-hucool.lihua@huawei.com/

在 2022/8/15 16:15, Peter Zijlstra 写道:
> On Sat, Aug 13, 2022 at 08:01:02AM +0800, Li Hua wrote:
>> The 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, 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
> This is unreadable, what?!?
> .

      parent reply	other threads:[~2022-09-05  3:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-13  0:01 [PATCH -next] sched/cputime: Fix the bug of reading time backward from /proc/stat Li Hua
2022-08-15  8:15 ` Peter Zijlstra
2022-08-17  0:44   ` Li Hua
2022-08-29 15:57     ` Li Hua
2022-08-29  5:27       ` Greg KH
2022-09-05  3:47   ` zhengzucheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0b2f6919-7ed4-b30d-e92b-355c09bbfd25@huawei.com \
    --to=zhengzucheng@huawei.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=hucool.lihua@huawei.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox