Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2241443rwb; Mon, 15 Aug 2022 01:20:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6HnfWOe3DSja9Qd++qSpMLOcSCMs+yAVnRVSs2Y55syPSuZxwwq6oslllXQJ9SUQl6Iavt X-Received: by 2002:a17:906:5a71:b0:730:aaa1:a9ec with SMTP id my49-20020a1709065a7100b00730aaa1a9ecmr9704949ejc.440.1660551652077; Mon, 15 Aug 2022 01:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660551652; cv=none; d=google.com; s=arc-20160816; b=fcaOSoOoOV5gnnbynTjIlhpgvLBg/CxDZfHXs6/SuM7gSX83TuUpud0M8TuSgofZ+C Sn6FA6bZ0W8c9ABmC4X2Wk9eWqKf57D7OItmwY7iJn2aeLQGjuJS642NEAVmfKfQHW9l spNnBcMPLUF2sTijmSykvdtzP2kIFvUDihSIwmMoLko/dmhEoiOCFdQXCm3nqXQxT3BC AyN9pn4aTifOHCplyYNweF+NwaLFgarzifM1aYnM279iiKTuMVf1uD4mFZV8LB0SljXh 7BAXNAezn6TAwJ3Ofbliyo08+fSNPqZHojERv6y6FDDxSkSfm7F6MCJrCZVhZOUDZXIE 3q9A== 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=8Ewz/NjlMw51NrevL6mP6tY09Paxwi5mAgndnXxIDBg=; b=uqLIjl4piH4GnFXmPed0z3Bamk0VfC674q0oO7JLD6zNvpQ8prKhzgH3rrAs73oRRX FPAvIP/FBIXwDY827wWD++LiIsI720tMMGktBsy3DWkkIBCQno+LoZHGP1r/4D9CAB6n sh5wjU8wO1p3AzTYMiXKB3d5R8ct5JCbjrZ63h4IhWB+boSnyYtrOJULNWngI7Tw92IL 88D+nrvTOyQpDi4gLHT0YySBnz5ditGzv9jGnPZCBrzUAN3gsniA/hHs7UxufKNXU5xL XzopIdSnvrIt0bfWFIt+LsbPs6n0buyx4UtkAagS/33hgMwToPRt1nTeILBbYsa2DyZy tGVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=l0fFEmCL; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp21-20020a170906c15500b0073860fab971si839129ejc.215.2022.08.15.01.20.26; Mon, 15 Aug 2022 01:20:52 -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=@infradead.org header.s=desiato.20200630 header.b=l0fFEmCL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241744AbiHOIQB (ORCPT + 99 others); Mon, 15 Aug 2022 04:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbiHOIPh (ORCPT ); Mon, 15 Aug 2022 04:15:37 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10DBF639E; Mon, 15 Aug 2022 01:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=8Ewz/NjlMw51NrevL6mP6tY09Paxwi5mAgndnXxIDBg=; b=l0fFEmCLMSXx9W2xsG+a7cIUXK Wa/U1dxWGmmtRQ5aP1D0E55ZzWtF6se5QPpXFADHuyFZtEG3qBMDdpkI+44S5+lVHDWZcKopE57Se zrPO8UKMLMRtUEbhd9j7+c7i23fyo6IFAtuVZbStiVxy6d23p2e5UKD/JzJYxta7Pp82UN1ql/a7W TIzHyUpthpkFuErAFlCh6t/LcHzj95hJgoxf+JHTb5I/REVOqnFVxVzE8xzp1FqjnKw9WEdIJCrvI +gH1SqrnnhhXpNMYwRAXxJU2pwyEgnZ+CaKBZR53RQsf6NvwKPp/+wbSG3EttTq+F6dPmJRHPH8Mr RGFVfGfA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNVFk-002cVb-B6; Mon, 15 Aug 2022 08:15:16 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 3D37B980153; Mon, 15 Aug 2022 10:15:15 +0200 (CEST) Date: Mon, 15 Aug 2022 10:15:15 +0200 From: Peter Zijlstra To: Li Hua 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 Message-ID: References: <20220813000102.42051-1-hucool.lihua@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220813000102.42051-1-hucool.lihua@huawei.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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?!?