From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F1C9250BE7; Thu, 3 Apr 2025 15:25:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743693958; cv=none; b=O37IjwCWdr0IHzs4KtY2q5VuW93YZBD1zlXv5gk8eTwe8XKytL/poiaG2b0dgj06hq162zFqQ7mYkYliwTDkscsQw91zQ6KHPDGd/EBCcHwEAtNzsXo2qLLzE736RGQ/riM324NLdfGAkxws4YUfeTagSM5HATlcHPUw489SDFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743693958; c=relaxed/simple; bh=lofMlRktAYU/G/TAA8vFn1P2Kahj/1eU4EXBlgb1f1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tD918PxFc419aIwUj9Nsl17M5d35/AaHCy5AjduOvSkWTXdhI4Go5z50FIcnnZBEncr1CLZp3RJBoBK/hJzNbcikD1dOLCMmObqI0TPBaunK7VKrG3wb6WiOf3HLA3fhUmfAIctdVTDODl8ljVs7vTYPmrvgMXI5ZywoSR/JLZU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=EyvHgiDX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="EyvHgiDX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC169C4CEE3; Thu, 3 Apr 2025 15:25:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1743693958; bh=lofMlRktAYU/G/TAA8vFn1P2Kahj/1eU4EXBlgb1f1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EyvHgiDXwcxNkV8+IY1FmCkgGWOa8VbvwHGHY+uYqzeRnITTRGb+Nb+x4zJ4iu1KJ l5HASpaYRw8ejxgcxiC32jkIQUkeKxlFgJHiBiPPJdH2AwcJtC8yB5zKEMTliTeP6b ayP4G9Nb18MGPFRPK2u8whGwKm6dXsn36ZAN+was= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Abel Wu , Tejun Heo Subject: [PATCH 6.13 05/23] cgroup/rstat: Fix forceidle time in cpu.stat Date: Thu, 3 Apr 2025 16:20:22 +0100 Message-ID: <20250403151622.431025548@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250403151622.273788569@linuxfoundation.org> References: <20250403151622.273788569@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Abel Wu commit c4af66a95aa3bc1d4f607ebd4eea524fb58946e3 upstream. The commit b824766504e4 ("cgroup/rstat: add force idle show helper") retrieves forceidle_time outside cgroup_rstat_lock for non-root cgroups which can be potentially inconsistent with other stats. Rather than reverting that commit, fix it in a way that retains the effort of cleaning up the ifdef-messes. Fixes: b824766504e4 ("cgroup/rstat: add force idle show helper") Signed-off-by: Abel Wu Signed-off-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- kernel/cgroup/rstat.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -612,36 +612,33 @@ static void cgroup_force_idle_show(struc void cgroup_base_stat_cputime_show(struct seq_file *seq) { struct cgroup *cgrp = seq_css(seq)->cgroup; - u64 usage, utime, stime, ntime; + struct cgroup_base_stat bstat; if (cgroup_parent(cgrp)) { cgroup_rstat_flush_hold(cgrp); - usage = cgrp->bstat.cputime.sum_exec_runtime; + bstat = cgrp->bstat; cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime, - &utime, &stime); - ntime = cgrp->bstat.ntime; + &bstat.cputime.utime, &bstat.cputime.stime); cgroup_rstat_flush_release(cgrp); } else { - /* cgrp->bstat of root is not actually used, reuse it */ - root_cgroup_cputime(&cgrp->bstat); - usage = cgrp->bstat.cputime.sum_exec_runtime; - utime = cgrp->bstat.cputime.utime; - stime = cgrp->bstat.cputime.stime; - ntime = cgrp->bstat.ntime; + root_cgroup_cputime(&bstat); } - do_div(usage, NSEC_PER_USEC); - do_div(utime, NSEC_PER_USEC); - do_div(stime, NSEC_PER_USEC); - do_div(ntime, NSEC_PER_USEC); + do_div(bstat.cputime.sum_exec_runtime, NSEC_PER_USEC); + do_div(bstat.cputime.utime, NSEC_PER_USEC); + do_div(bstat.cputime.stime, NSEC_PER_USEC); + do_div(bstat.ntime, NSEC_PER_USEC); seq_printf(seq, "usage_usec %llu\n" "user_usec %llu\n" "system_usec %llu\n" "nice_usec %llu\n", - usage, utime, stime, ntime); + bstat.cputime.sum_exec_runtime, + bstat.cputime.utime, + bstat.cputime.stime, + bstat.ntime); - cgroup_force_idle_show(seq, &cgrp->bstat); + cgroup_force_idle_show(seq, &bstat); } /* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */