From patchwork Sat Nov 18 17:12:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: cruzzhao X-Patchwork-Id: 166586 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1281877vqn; Sat, 18 Nov 2023 09:12:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnYjDO2NZxxF9chB/0ENVwrxVd7q8phAg+bsVh94q0js6bNZIjLFl4W51imEi6Uhw9tAGW X-Received: by 2002:a05:6a20:3d0c:b0:187:27f6:45d4 with SMTP id y12-20020a056a203d0c00b0018727f645d4mr3712364pzi.5.1700327567921; Sat, 18 Nov 2023 09:12:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700327567; cv=none; d=google.com; s=arc-20160816; b=qI90dNEsmyZEjwZkw9UHnxKIxAsl4EGVp0f1Q/Eojt+Fm7yW5q5UbY8PswqsXXau57 3Wpk4kLjSUoMZxgSvHxrfBXnTuxIWRQdaPEcENByo/lhW+dS3GIDAY3XMtiO/4Jjenfy RCapfdIRv2t146RBRqnLDvEtBj/Ed7cwrGhhqBZmjNKyVFrnwYOsaVJlKoglvIY2turv a8mZdrrQ8XPvEuFxYQV+82A+vObxURLa5+9viJQnAlSR8MoFfpuzw7dlmnTEfMh1f4bs ZCrY6kRrhr9JhuXe+zBc/ebXSlkmTbUi5Sle8mGShQmBvYwncxXGZEq8qMOp8FiPibzo BTgA== 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=Ceaa0Q6xBphCYoktW2ej1b7bPEiMlwZ0nFWBWmRwL2E=; fh=QlmRtWuTYJDhaxF0GCu0nvK7RUqeTMNKD6hMg0kv7eo=; b=rOGZoWsY9TBdCMCPGw9sBtKbRFdpUQ/JAZTm2mDVlYkUjur8SqFfemJxZhhAoWMFGA G+9UJb6xRZ2r+uhQX/y9byKxflbTEjmQkJOEiw32r9CDY2w9dNWfmAj5eYHTu8JVm2oD dzCHBLvJrZcXuRLmBnJsdhG9d5q4RqGPsFldYvgHG2nCw3kTCTp7DHvP3t/0g3NZL0Wd r4PPNVkTQrCk5T90pqQM/v82I8VljR2wC7/FQyV32J4qa0sWWHjlhVI2i3RtP0i0H2ww xzYEcr9VLuUxcrEwJExcns9h0u3c+DxQ2pDyssLMKmZWTAtZuG3WZ+ncZBF0dBqCDQJz Wknw== 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 g9-20020a632009000000b005b3d703ca05si4683025pgg.780.2023.11.18.09.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 09:12:47 -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 15231804920F; Sat, 18 Nov 2023 09:12:47 -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 S229896AbjKRRMr (ORCPT + 29 others); Sat, 18 Nov 2023 12:12:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjKRRMp (ORCPT ); Sat, 18 Nov 2023 12:12:45 -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 0FBA0B8 for ; Sat, 18 Nov 2023 09:12:40 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VwclsC7_1700327550; Received: from localhost.localdomain(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VwclsC7_1700327550) by smtp.aliyun-inc.com; Sun, 19 Nov 2023 01:12:38 +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 v3] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update Date: Sun, 19 Nov 2023 01:12:30 +0800 Message-Id: <20231118171230.4999-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_BLOCKED,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]); Sat, 18 Nov 2023 09:12:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782922679811871062 X-GMAIL-MSGID: 1782922679811871062 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..8e6d9bf351c2 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, delta); } #endif