Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp177334imm; Sun, 8 Jul 2018 22:55:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpen7+YRkqNGC0uSbmR4gl3usrxUZ8cmyMGZwST4cFjJNAKqHo7JtpTqZcs5nun2MN1Nt5FO X-Received: by 2002:a63:a042:: with SMTP id u2-v6mr17352742pgn.80.1531115727533; Sun, 08 Jul 2018 22:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531115727; cv=none; d=google.com; s=arc-20160816; b=T8diBlAfGScUzRZnNcsTjU8X2E3wdo8uy7hoAGdkEnRiAbV7NnMbcBE5ARYtKjnoQD SjBpnuXJnrsAodJL7lcp8gq+M3TPYsAr8kdYRAr5VhYSjA4S2Fs5yprfLvJWYz0fuYpo ET6+n7H8vG54UNlF7OODDxHTcTMVeItTsTEclIX4abzFZQ10v1qciKhBeKyxT41Ilo+9 YpBSALfXpUvdAlcNJcXsWJB+xjKgRmqnaeA21AJQkh0lNVOg256ceT4AwPDYjGvSCLPk 7cgGVarjjH1izKOvr5+Jds/EUhHsCL4THspnLgcaonNtzUtBz/J4J+oSxzszwb95VDlU 5ZIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:reply-to :arc-authentication-results; bh=DVWxhComzXcl0GOpymQKlfPzR+D7jEJFW+lSn9hF10g=; b=aL64PsHr4FXbjc47HJBBoSg+twnrP7fgVCvF0lnqMi1Oc4ircxYXh3QldrFevpjpI+ M27ZiedI42xAD92r6U645Z3jhS5RIAImrapu2B7U3wtDZ/+gzwI7LFPfMJOgQ/ym1D/K +MgMXgpBpDggqZ9SFq65BBRG+sthD9QYfYmrgz1FXyYePJfu7mv3QJtc7EohLfXChwyr 5UJ0/Suz2Rn/knoCq8J2OL7tDwVKD7lPi72QAvP1EFYN+e24Y6hXjocd7GrnNxXxqOF2 S8l06qRisYUg05uKDCCs6uOR0zEPpi/CQ8QlAg31Lx/6KuNiQoYYqsSGB2obSKiTKKZC VJcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m73-v6si145345pga.398.2018.07.08.22.55.12; Sun, 08 Jul 2018 22:55:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754459AbeGIFws (ORCPT + 99 others); Mon, 9 Jul 2018 01:52:48 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:39212 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750996AbeGIFwr (ORCPT ); Mon, 9 Jul 2018 01:52:47 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0T4G08X3_1531115558; Received: from xunleideMacBook-Pro.local(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0T4G08X3_1531115558) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 Jul 2018 13:52:38 +0800 Reply-To: xlpang@linux.alibaba.com Subject: Re: [PATCH] sched/cputime: Ensure correct utime and stime proportion From: Xunlei Pang To: Peter Zijlstra Cc: Ingo Molnar , Frederic Weisbecker , Tejun Heo , linux-kernel@vger.kernel.org References: <20180622071542.61569-1-xlpang@linux.alibaba.com> <20180626154908.GE2458@hirez.programming.kicks-ass.net> <20180705104632.GE2494@hirez.programming.kicks-ass.net> Message-ID: <5a3354c1-d3fe-33dc-53cf-6eb621177052@linux.alibaba.com> Date: Mon, 9 Jul 2018 13:52:38 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------BE11F3B1CFC23A9FAB906983" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------BE11F3B1CFC23A9FAB906983 Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 7bit Hi Peter, On 7/5/18 9:21 PM, Xunlei Pang wrote: > On 7/5/18 6:46 PM, Peter Zijlstra wrote: >> On Wed, Jun 27, 2018 at 08:22:42PM +0800, Xunlei Pang wrote: >>> tick-based whole utime is utime_0, tick-based whole stime >>> is stime_0, scheduler time is rtime_0. >> >>> For a long time, the process runs mainly in userspace with >>> run-sleep patterns, and because two different clocks, it >>> is possible to have the following condition: >>> rtime_0 < utime_0 (as with little stime_0) >> >> I don't follow... what? >> >> Why are you, and why do you think it makes sense to, compare rtime_0 >> against utime_0 ? >> >> The [us]time_0 are, per your earlier definition, ticks. They're not an >> actual measure of time. Do not compare the two, that makes no bloody >> sense. >> > > [us]time_0 is task_struct:utime{stime}, I cited directly from > cputime_adjust(), both in nanoseconds. I assumed "rtime_0 < utime_0" > here to simple the following proof to help explain the problem we met. > Please see the enclosure for the reproducer cputime_adjust.tgz (process_top.sh, usr_sys.c): gcc usr_sys.c -o usr_sys Firstly, the function consume_sys() in usr_sys.c yields 100% sys which can be verified as follows: $ taskset -c 0 ./usr_sys 1 $ ./process_top.sh $(pidof usr_sys) 0.0 usr, 100.0 sys 0.0 usr, 100.0 sys Tested on my local box on 4.17.0 by executing "taskset -c 0 ./usr_sys", then executing "./process_top.sh $(pidof usr_sys)" to watch. 1) Before this patch 50.0 usr, 0.0 sys 50.0 usr, 1.0 sys 50.0 usr, 0.0 sys 50.0 usr, 0.0 sys 49.0 usr, 4.0 sys //switch to consume 100% sys, ignore this line 12.0 usr, 88.0 sys 11.0 usr, 89.0 sys 10.0 usr, 90.0 sys 10.0 usr, 90.0 sys 9.0 usr, 91.0 sys 8.0 usr, 91.0 sys Obviously there were around 10% sys wrongly goes to usr 2) After this patch 50.0 usr, 0.0 sys 50.0 usr, 0.0 sys 50.0 usr, 0.0 sys 50.0 usr, 0.0 sys 11.0 usr, 76.0 sys //switch to consume 100% sys, ignore this line 1.0 usr, 100.0 sys 0.0 usr, 100.0 sys 1.0 usr, 100.0 sys 0.0 usr, 100.0 sys 0.0 usr, 100.0 sys So it displayed the correct result as we expected after this patch. Thanks, Xunlei --------------BE11F3B1CFC23A9FAB906983 Content-Type: application/x-gzip; name="cputime_adjust.tgz" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="cputime_adjust.tgz" H4sIAPLzQlsAA+1XbW+bSBDuV/gVU4eecOIXFmOnd44rVWlOqprGUZrTfUgrRGGxuWCwWEjT l/z3m9kFJ7hO2kht76oykYDMzs48s/PM7tpfFnm04K4X/FOIvP/ge4hlWbvDIcj3SL0t21Hv UoANBrY13GW7FgOLOcMBewDD74JmTTBrL0Mol/HSS2a326FZGN7hp8xj9f5JxK/Xf5mlPhfC zdNlT8y/UYwv1N8esd1V/Ue7VP9dx3EegPWN4t8pv3j9sdBuWCS+2dY/6lqc+l4MxyfTfffV 6dNT98/nhwfw7OBoevKyGoySnGcX+EFUcXFVcnxkrP6vreta3cukJbnVN1ifjFq6VjmatAy7 BVvoGAT30yTogF9kGU9yYKVG1wFlSzIVBD2loo5g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