From patchwork Sat Nov 18 04:38:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: cruzzhao X-Patchwork-Id: 166447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp986456vqn; Fri, 17 Nov 2023 20:39:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEf24o4J7mBBf3Ipu/WgaX5O/fKLWBNf464+CQghKibd8+D2wuXWz4D21yjP9JazdhFGZ9X X-Received: by 2002:a05:6808:13cc:b0:3b6:c3af:b684 with SMTP id d12-20020a05680813cc00b003b6c3afb684mr2275716oiw.23.1700282368901; Fri, 17 Nov 2023 20:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700282368; cv=none; d=google.com; s=arc-20160816; b=eQlYBiBO41UkF6pqnOTzdR2bGtwWGHuAeVyg4gyFiPFuWS4OYz2Nf40bFTxrve8jQs Xk4HZo7Dc5zCVBAPgwGbOg+ePqBv6AqcmcjRAdvQJrQVyRUSP6t6l2FZar8+gj1+3n4z 4Tz7mlxDBXsqI52FYPwjSFYqXdnsCxZ6JaH89Tdb4LFlEQ15Zdsnr9pcs5UOYgA8913C JJ3Ow73Jt/KaiJu1pYBbLb5Gp57jGxpWHG01BUY8ILob0vvJRJQRQ1cRHdo9kw/2tFE7 dM/70cv4xYwGTn0Fn+mbUfoCYovL5UVEbqV+2MRLJgnY3nxQ2Ts/nyj308sDcEWjbby5 r4bQ== 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=tu5bl6HnKOQw3yRdP8jige6JLBvHNVeS0YlHUSL3LCo=; fh=QlmRtWuTYJDhaxF0GCu0nvK7RUqeTMNKD6hMg0kv7eo=; b=DR6L0oMF0DEaPbOzpG83VOwNIZvhoQer65rLGTOzl4SWtM63LaZjidEMHUIHoWW1gg GB78q1GNRqYWSQKY5C8d1P3oy+dzoeCjeAUAYH9HH8A4cIQM1XLQcK89+aafzh/4jcM6 DQU2yVjoET7PjulcWmGo8r4Nb50HCJsLHZaKMc9C45oN/Y+PXtk/gYd++XddD8AWbdMr 7tmo3V0t/P25etdbVvUoqokY7IihT/XPL9h8oIq5RdPWyiPeW2s8ay3m0IAg9X3P3fcy o1Wc2Z0y7L4zszDtLtI9WjIC6bC77HA/rez0wVWetlvVYlF+gPk47NNOUIM15+NhGG9B JyeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e10-20020a056a0000ca00b006c99b02c2ecsi3372860pfj.317.2023.11.17.20.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 20:39:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id CA57F82E4833; Fri, 17 Nov 2023 20:39:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231504AbjKREi5 (ORCPT + 29 others); Fri, 17 Nov 2023 23:38:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbjKREiz (ORCPT ); Fri, 17 Nov 2023 23:38:55 -0500 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1DD6D6D for ; Fri, 17 Nov 2023 20:38:51 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VwbPiW6_1700282322; Received: from localhost.localdomain(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VwbPiW6_1700282322) by smtp.aliyun-inc.com; Sat, 18 Nov 2023 12:38:49 +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 v2] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update Date: Sat, 18 Nov 2023 12:38:42 +0800 Message-Id: <20231118043842.45047-1-CruzZhao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Fri, 17 Nov 2023 20:39:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782875285220076904 X-GMAIL-MSGID: 1782875285220076904 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..843d6cabae59 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, CPUTIME_FORCEIDLE, tmp); } #endif