lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <d41afbd5-6040-50ec-c0a5-c52ae48f6515@huawei.com>
Date:   Sun, 9 Oct 2022 10:28:43 +0800
From:   zhengzucheng <zhengzucheng@...wei.com>
To:     Frederic Weisbecker <frederic@...nel.org>
CC:     Peter Zijlstra <peterz@...radead.org>, <mingo@...hat.com>,
        <juri.lelli@...hat.com>, <vincent.guittot@...aro.org>,
        <dietmar.eggemann@....com>, <rostedt@...dmis.org>,
        <bsegall@...gle.com>, <mgorman@...e.de>, <bristot@...hat.com>,
        <vschneid@...hat.com>, <hucool.lihua@...wei.com>,
        <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH -next] sched/cputime: Fix the time backward issue about
 /proc/stat


在 2022/9/30 20:16, Frederic Weisbecker 写道:
> On Fri, Sep 30, 2022 at 10:43:58AM +0800, zhengzucheng wrote:
>> 在 2022/9/28 20:11, Frederic Weisbecker 写道:
>>> @@ -1024,20 +1045,20 @@ static int kcpustat_cpu_fetch_vtime(struct kernel_cpustat *dst,
>>>    		 * add pending nohz time to the right place.
>>>    		 */
>>>    		if (state == VTIME_SYS) {
>>> -			cpustat[CPUTIME_SYSTEM] += vtime->stime + delta;
>>> +			cpustat[CPUTIME_SYSTEM] += delta;
>>>    		} else if (state == VTIME_USER) {
>>>    			if (task_nice(tsk) > 0)
>>> -				cpustat[CPUTIME_NICE] += vtime->utime + delta;
>>> +				cpustat[CPUTIME_NICE] += delta;
>>>    			else
>>> -				cpustat[CPUTIME_USER] += vtime->utime + delta;
>>> +				cpustat[CPUTIME_USER] += delta;
>> “delta” has the same problem as vtime->utime, which varies with different
>> tasks. switching between different tasks may cause time statistics to be
>> reversed.
> I'm a bit confused, can you provide an example?
Chinese National Day holiday, sorry for not replying to you in time.

CONFIG_HZ=100
const struct kernel_cpustat *src = &kcpustat_cpu(cpu);
struct vtime *vtime = &tsk->vtime;
cpustat[CPUTIME_USER] += vtime->utime + delta;

first:
cat /proc/stat | grep cpu1
cpu1 319 0 496 41665 0 0 0 0 0 0
Task A is running on CPU 1,so vtime is A->vtime and delta is A's delta.
kcpustat_cpu_fetch_vtime: cpu=1 src->cpustat[CPUTIME_USER]=3189000000 
vtime->utime=900000 delta=100001
cpustat[CPUTIME_USER] = 3189000000 + 900000 + 100001 is 3,190,000,001, 
319 ticks

again:
cat /proc/stat | grep cpu1
cpu1 318 0 497 41674 0 0 0 0 0 0
Task B is running on CPU 1,so vtime is B->vtime and delta is B's delta.
kcpustat_cpu_fetch_vtime: cpu=1 src->cpustat[CPUTIME_USER]=3189000000 
vtime->utime=900000 delta=90000
cpustat[CPUTIME_USER] = 3189000000 + 900000 + 90000 is 3,189,990,000, 
318 ticks

The root cause is that the value of task B's "vtime->utime + delta" may 
be smaller than task A.
>
> Thanks.
>
>>>    		} else {
>>>    			WARN_ON_ONCE(state != VTIME_GUEST);
>>>    			if (task_nice(tsk) > 0) {
>>> -				cpustat[CPUTIME_GUEST_NICE] += vtime->gtime + delta;
>>> -				cpustat[CPUTIME_NICE] += vtime->gtime + delta;
>>> +				cpustat[CPUTIME_GUEST_NICE] += delta;
>>> +				cpustat[CPUTIME_NICE] += delta;
>>>    			} else {
>>> -				cpustat[CPUTIME_GUEST] += vtime->gtime + delta;
>>> -				cpustat[CPUTIME_USER] += vtime->gtime + delta;
>>> +				cpustat[CPUTIME_GUEST] += delta;
>>> +				cpustat[CPUTIME_USER] += delta;
>>>    			}
>>>    		}
>>>    	} while (read_seqcount_retry(&vtime->seqcount, seq));
>>> .
> .

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ