Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3564004rwb; Fri, 30 Sep 2022 05:29:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6beUHdRoeBFbdfL82WN1agjlOJRaT74goaAoN5UBuHFJe5xrmbfwCszTYFm+i1fWp2dOpT X-Received: by 2002:a17:907:96ab:b0:782:2f88:cf29 with SMTP id hd43-20020a17090796ab00b007822f88cf29mr6397767ejc.72.1664540981742; Fri, 30 Sep 2022 05:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664540981; cv=none; d=google.com; s=arc-20160816; b=RXlanwOhoXFU4Kdm2mPJP9jPoReg/DxngQHsbiTpr2P4gjcSoPBHWIZRXBdCpZ3Wlc x1ttYJGsh0S+AXNLbbLLFPB0h9957IXVJjkZ9fk30SgpFqes2ZUtnpvTbhfUpbmwiePc byeEV2k+36nrTaNGfKmjsr7zKC1ewPHwipUu2QOndAzP1O2uOpZfGjqsssJawVmiL6Oy 0E4sSORTbQ3jmLR8/yWzJTVt+V1d4tJf7V2VySEy1lJFh2+64W6aQPd3MFW/QwShc3OS RWFdKt+jw5IvN/Qn7J5BrecKQl52RunecKrv90QW3QFbJHXhZbGtpImm+Z5cW2QFLFGX 8zcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ozTbXXJfUdSBobVpszDipEgg2ApMkeDnWVcRePHgGWU=; b=p5+YdQmjR/5qhfLe7jaV/zMohRW7prVG5MPcxfHslur20bsZZwCqVFnKl/VshgLg4F TtA5CKbO7CLe4p/dyt3eyR3cnk5tztDeWVAXb+bp4Wnf2KLYNwLHG8jXfHaAI9bVikcu btMs6Elpv5syWidvWn/5pSln+VUja4aAdIEeFPg+H3g28rtIae/Aah0+J3hI/N8Af8rF YaANXL5reiP5Z2M1RjxjK96N+QhBtkx3kmlk/2KYUE4LL6S2ODEis6M99WfgUSk5fSju /MQs/wJ4iegd5lPBMy0G9IdJtZthNdQtnnncK6Wkfk6G8Tu2nl2fyPIUTTD1mnZxzKCL ONoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q+AWobz7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a056402518a00b004548ba1dc5dsi2131114edd.446.2022.09.30.05.29.15; Fri, 30 Sep 2022 05:29:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q+AWobz7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231592AbiI3MQm (ORCPT + 99 others); Fri, 30 Sep 2022 08:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbiI3MQk (ORCPT ); Fri, 30 Sep 2022 08:16:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 342E917B52E for ; Fri, 30 Sep 2022 05:16:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7114062316 for ; Fri, 30 Sep 2022 12:16:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78FD5C433D6; Fri, 30 Sep 2022 12:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664540197; bh=h+KMnKvy2rH8iR2ELT9m5DYIjnlRASkttN82L1ercCY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=q+AWobz7JZkClM3mLMtKSs4fmjbCsoM6tKTnAT4RxTESpG59P2r6lVyAXeAHyBMuw 6T9eb1moSl819JgNRxlGmpIvGjh6UIFUYv9vc6DLWPf3IwnmwQngB9Nc5KiWRTFwbQ BJBKq6jJsOu1hsuy4Qw0MxSga4/mTmOKmP7vN+qaQqDhPZ+SXj2i0G4gepJRntNRTk WHumIX5YOfteNPxz0v+yt7/IKbtRSKVul8Z6xGafeB+hf/Z/5RTkrEA6LjYwcqQogY qYUafqt9oPeO+0FsDQ4CeG06n4MANtqoLq/6bQ7oXdRieB1o3NNVsf00PYlxz22Glv EM3ywO4OvXPqA== Date: Fri, 30 Sep 2022 14:16:34 +0200 From: Frederic Weisbecker To: zhengzucheng Cc: Peter Zijlstra , 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, hucool.lihua@huawei.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next] sched/cputime: Fix the time backward issue about /proc/stat Message-ID: <20220930121634.GA266766@lothringen> References: <20220928033402.181530-1-zhengzucheng@huawei.com> <20220928121134.GA233658@lothringen> <5126b2dc-8624-babc-2e1e-58ac27927c31@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5126b2dc-8624-babc-2e1e-58ac27927c31@huawei.com> X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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)); > > .