From nobody Tue Jun 23 17:23:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25839C433EF for ; Tue, 1 Mar 2022 15:25:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235720AbiCAPZo (ORCPT ); Tue, 1 Mar 2022 10:25:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235657AbiCAPZ0 (ORCPT ); Tue, 1 Mar 2022 10:25:26 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 314678BE0C; Tue, 1 Mar 2022 07:24:45 -0800 (PST) Date: Tue, 01 Mar 2022 15:24:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646148283; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FgqIQu/w7rPa846Zp4oSmI/zW0SECYHzIYadGlqu5zk=; b=d5IXsbOZoVt/BSJTQWDM38vvY91ni2GoMV8zbx+QgWkuIniAKffab0aVZ7048vSekwn+9C 07lEoObHXL0R9Cla5n+4xRnbcDAPIrCka/tFDKqWxgEmJaQK/y5rWZnJKpfsrS+hfuEjKu rhInbOISCoxbu3zB1/qFcr6VSM+bejbgBw4RHTf7bcwk8102Im/J6hNhQgsHasMXlGj3u/ LQS+iLh/UofzC9fyqeCmxE8kbkYMSuGXxsgCRGlBNidt6V9zRtEXj3fRu+4zt93xgaKMcG KQk4IB2f2VRApPR/q91wtU7OMUag7/0tll8hdo4+9JA3qY33fZ2bsLNSGN/s7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646148283; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FgqIQu/w7rPa846Zp4oSmI/zW0SECYHzIYadGlqu5zk=; b=kBGbKwr13l37fO2RCTUeTCVImqECI71rmuR/CRXRRa9KQpP6+16lAx/Glb4gVEOOAzd0R/ MLeMgOAN8xJI1jAA== From: "tip-bot2 for Chengming Zhou" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/cpuacct: Fix charge percpu cpuusage Cc: Minye Zhu , Chengming Zhou , "Peter Zijlstra (Intel)" , Tejun Heo , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220220051426.5274-1-zhouchengming@bytedance.com> References: <20220220051426.5274-1-zhouchengming@bytedance.com> MIME-Version: 1.0 Message-ID: <164614828279.16921.6828134750682486610.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 248cc9993d1cc12b8e9ed716cc3fc09f6c3517dd Gitweb: https://git.kernel.org/tip/248cc9993d1cc12b8e9ed716cc3fc09f6= c3517dd Author: Chengming Zhou AuthorDate: Sun, 20 Feb 2022 13:14:24 +08:00 Committer: Peter Zijlstra CommitterDate: Tue, 01 Mar 2022 16:18:37 +01:00 sched/cpuacct: Fix charge percpu cpuusage The cpuacct_account_field() is always called by the current task itself, so it's ok to use __this_cpu_add() to charge the tick time. But cpuacct_charge() maybe called by update_curr() in load_balance() on a random CPU, different from the CPU on which the task is running. So __this_cpu_add() will charge that cputime to a random incorrect CPU. Fixes: 73e6aafd9ea8 ("sched/cpuacct: Simplify the cpuacct code") Reported-by: Minye Zhu Signed-off-by: Chengming Zhou Signed-off-by: Peter Zijlstra (Intel) Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20220220051426.5274-1-zhouchengming@bytedan= ce.com --- kernel/sched/cpuacct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index 3d06c5e..3078005 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c @@ -334,12 +334,13 @@ static struct cftype files[] =3D { */ void cpuacct_charge(struct task_struct *tsk, u64 cputime) { + unsigned int cpu =3D task_cpu(tsk); struct cpuacct *ca; =20 rcu_read_lock(); =20 for (ca =3D task_ca(tsk); ca; ca =3D parent_ca(ca)) - __this_cpu_add(*ca->cpuusage, cputime); + *per_cpu_ptr(ca->cpuusage, cpu) +=3D cputime; =20 rcu_read_unlock(); }