Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp26893imn; Tue, 26 Jul 2022 21:06:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sapkzUb1LchuSySCqTsSyHWuP83OLeErCJ4cqXJKBNcO+Z1jESQ4PaZJt4O/HdW06g/fLr X-Received: by 2002:aa7:de91:0:b0:43a:d5b0:e0bb with SMTP id j17-20020aa7de91000000b0043ad5b0e0bbmr20849521edv.165.1658894777607; Tue, 26 Jul 2022 21:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658894777; cv=none; d=google.com; s=arc-20160816; b=h/DfN/S4KQE9jRasO0hGbtAqvzmxYoNuu1/2aOARgLcQiQ3UNO7hnT+/9vaArIF9I0 KmuISIdauLrupfQW+Szd7Q93T6IkFcz/2+oromyfV98F/n+lEpj3O0XYq71baArilfxv nD5oiLEQ3IehSDh1vXx9jdJzElpwoPS3qJEH5btM1IW6Bchx1PVxNTpgJyZYmlntvfVQ 0gaz9FCGONpxSCJUZSpl/iM6Le/piGMmv/+FBHTG6OCsQpMmChxIBivjLKx1vd3njEoL hDuuaM3rk+M6/r/rYE1TyJMhxNhim+4UyE7OexI5pXWzLu7pkcUSMcVDQNkzCiB4aiGO fVcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:to :user-agent:mime-version:date:message-id; bh=lM2dpCIM03BuAruWfG1TQHoGhFqsB2tHvFrvSW+Yess=; b=F7l+jXVLjWC0tqaRWvH+hewmbTUmhuBnkuqGGh2XfYCDGiDNdipkX4Sbr1P+v2AwjW gwFJ5AowgDWgy3ljQZFflHoocbF5Oq43qYTQXafoGyA8LBDx9buaYabLOUgQqmbZhHvc UstQv0zrOvojzer27iLdelmCNp8LyL27qCf6AKImRJTJraGFMnQ2B7FEjMy3E+wi1TXC yrBJ/BDaCdulkKNt4aVAZZHL+AWbnz29Va+PRPZwVRc9Vfmg8rl9n5V2M1PrTBb2BtYb HLcKdRSrVAzLcmToXbO7CwGK8OLzS/yK/of5BUgOqXFMSZN8D7bxt5D4NUNjm3Xmnh2f Tknw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ej27-20020a056402369b00b0043bcafe41c9si15539505edb.2.2022.07.26.21.05.52; Tue, 26 Jul 2022 21:06:17 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233554AbiG0ECz (ORCPT + 99 others); Wed, 27 Jul 2022 00:02:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231448AbiG0ECy (ORCPT ); Wed, 27 Jul 2022 00:02:54 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D1C315820 for ; Tue, 26 Jul 2022 21:02:53 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Lt0RL2rhFzjXMK; Wed, 27 Jul 2022 11:59:58 +0800 (CST) Received: from [10.67.109.51] (10.67.109.51) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 27 Jul 2022 12:02:51 +0800 Message-ID: <85d5087b-450c-351f-270d-c61303cf3187@huawei.com> Date: Wed, 27 Jul 2022 12:02:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , "open list:SCHEDULER" From: "Lihua (lihua, ran)" Subject: [Question] Reading /proc/stat has a time backward issue Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.109.51] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 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.