From patchwork Fri Nov 17 12:56:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: cruzzhao X-Patchwork-Id: 166156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp504810vqn; Fri, 17 Nov 2023 04:57:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdqrJE+q288IAqzjiSkoCVf82eDnyEU1aPHA8lgY2AkV1neVFA3KWwiAnFSS1ZtNRxO3sK X-Received: by 2002:a05:6e02:16ce:b0:359:d1c4:b454 with SMTP id 14-20020a056e0216ce00b00359d1c4b454mr28690967ilx.20.1700225857929; Fri, 17 Nov 2023 04:57:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700225857; cv=none; d=google.com; s=arc-20160816; b=rtQZPa5D1YaVfB66uhuf+zt5oN9oQ8J9IgjFmhPqX42CAyAAY6SRj75xD91j482GEI /X8BKkpd0MenlS7i7n3ScE/Q5MJxlucSR708B6f3NBzbyBRDQZVzmjccvFBl+ceAPch4 IYB8K8E908asZFM/AYc+wB53E7pSJNX72d13tD8NcVlOYIQL+03eCEeHllURSQJ1zrq7 TwfRx7JPiUbVgZmRAkvB6eZMkGE1VHOT2HQBwHe7FP2dQKjZhycg1pzsVZafo5KO7YDz JKSRovJhOvdzkU0RoKhSI1ZkYKN0SvRx5eWa85F9Bv8pv2Fpwhqj3c4474DZxeGdH2Wc o0Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=s61n8AXGJhTyOEl5PeOYQoFt+Cwgw3MnrzmdvgoqEhw=; fh=QlmRtWuTYJDhaxF0GCu0nvK7RUqeTMNKD6hMg0kv7eo=; b=nKVAdryB/4HSKasjsBsOCskpizHPaGoX8M3hmV3ckAMmzo/cyFvf03mPK87sgpOFNd AAb/jLLxSeUeXmZa5zby9Uo4gCbRltwvxLXbK5n/eb9VBTmwM/nMKhhe/jvstudQSRjw uMENVg42zskFn37MDiySshhTWa6Tb4F4vdxXsJuII8L/iR/j0UYkh87wiBfkL+z26LJR LhHVTSFojlYbh0hD9+DsZYcBH5nlnop78qhpqOYE2f9Vs9Bl0oEer5UvnqRgArhum/zn h0ZcOEzREwRFDHQBRdWl5ykaS+17nb6QgeJMoWBk9ROhlBtK70CxrJnXdeN1Ubkptxhx oT7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id d15-20020a63fd0f000000b005be232472easi1845746pgh.78.2023.11.17.04.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 04:57:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A9A7780615D0; Fri, 17 Nov 2023 04:56:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346008AbjKQM4k (ORCPT + 30 others); Fri, 17 Nov 2023 07:56:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbjKQM4i (ORCPT ); Fri, 17 Nov 2023 07:56:38 -0500 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D87CD5F for ; Fri, 17 Nov 2023 04:56:34 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R781e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VwZsbOP_1700225784; Received: from localhost.localdomain(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VwZsbOP_1700225784) by smtp.aliyun-inc.com; Fri, 17 Nov 2023 20:56:32 +0800 From: Cruz Zhao To: mingo@redhat.com, peterz@infradead.org, 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, joel@joelfernandes.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update Date: Fri, 17 Nov 2023 20:56:24 +0800 Message-Id: <20231117125624.16745-1-CruzZhao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 04:56:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782816029172258535 X-GMAIL-MSGID: 1782816029172258535 In function __account_forceidle_time(), task_group_account_field() is called to update kernel_cpustat.cpustat[CPUTIME_FORCEIDLE]. However, p may be not running on current cpu, so update cpustat with this_cpu_add() is incorrect. To fix this problem, we get the cpu of p first, and then add delta to kcpustat_cpu(cpu).cpustat[CPUTIME_FORCEIDLE]. Fixes: 1fcf54deb767 ("sched/core: add forced idle accounting for cgroups") Signed-off-by: Cruz Zhao --- kernel/sched/cputime.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index af7952f12e6c..6f18fdc4a0dc 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -239,9 +239,12 @@ void account_idle_time(u64 cputime) */ void __account_forceidle_time(struct task_struct *p, u64 delta) { + unsigned int cpu = task_cpu(p); + __schedstat_add(p->stats.core_forceidle_sum, delta); - task_group_account_field(p, CPUTIME_FORCEIDLE, delta); + kcpustat_cpu(cpu).cpustat[CPUTIME_FORCEIDLE] += delta; + cgroup_account_cputime_field(p, index, tmp); } #endif