From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77386207A02 for ; Sat, 25 Jan 2025 05:26:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737782763; cv=none; b=P05IsW1Fyuc65nCuvfoXnTNwr2FcELWZV3pDlk8R1lN3WC1OCjJmnIepLcz5iN8Tdm4wm5vOSqRMfU8vVy/fokpQ9EJXALYJugxEyoRdW2zFTBlY50R0aVJY7kWRwZePrRnD9bvbp+tolNSgvMEvVg+fBcZV08T/ryRdflum5TI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737782763; c=relaxed/simple; bh=LKw6HaeW05jbHUxXDx+rmwHbEdYlclYGnPRLLJQzy60=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QHJkYe105wrTuz/w/b9WLHlYyUDBwS8sa4PWtJIAUN/FV+dZLtptSxKm1iTCcd7eMR0LvLZyAVzFaKHZurfmOueXEVmqw5WYPbXHWihzPtoVLXx3Y+2y58VsyPLErOQCcVg1uM6+dO3WEx9ic2BGxAWm54hOhnTszBxUYdl+oyg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=UiCe0ZHM; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="UiCe0ZHM" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2f440e152fdso634394a91.0 for ; Fri, 24 Jan 2025 21:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737782761; x=1738387561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WiWK8iJRg8z+aUiF8sWc5hRLfRD7QwQ2HIsrRNActc8=; b=UiCe0ZHM79m0DJUIW7mXuZI1NCNFTQeCcmr7a2pF1sHywNWdAm6FAGSqxX63nM5sVk soCWx6nTw18SG0IPgk9zJH0Pf4MCPQZdL1jLVER/Nvoq6AVcBAE7967YC++cNptzSUlP ea2UmkJHyJVXgOuOigyCjubv+kbUsYpxCPzGuFqomXMCFRfvpNtnDaD2HYF/VCIvEXxj PFRXeitqvbuVwOD8oI0ghWHAKs8U7tpqxPBixp4bzORz3q4MQx+qDUQZpQw7JJ4pfm3S UtZed/g0sYObWYwO/jmvR7u4hXzmEgWC/KbwNfhtDHqTli1BKSlaPs8gxQz8P2KHhXkg e4MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737782761; x=1738387561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WiWK8iJRg8z+aUiF8sWc5hRLfRD7QwQ2HIsrRNActc8=; b=TeMtsuet4Pqql4axLmC54+UU5IFYjlAB92PHrpPHd9zXbekZaWamNQevUJ4BzF9D4O FWSXKTzFONW/3xUtnkIZ8gDkT/v9BcLlY8ARisDhh2lnfZXwqT/Q8UCpieFdT9gS4Ob6 NY+0ZsNmxPt/kllsy4qLsJCvYU1XAq3hRU5b2Q4YnG0VlGz8RVrxRKbRORf30ImNPytx A3nZk3aoWBAOii28KQv1cwjq1ts9YUSamGI8fiV0fnaPZyWE7V5grQ2bO/B/q0sDBRC5 AQiy89DClgikPohc/u6WRlPQBUzxk1CU+ha6UPL9hJY52V91fdQ3YhikZbPK5xS79mBx u8Wg== X-Forwarded-Encrypted: i=1; AJvYcCU2qLxpgEeIzD7aymDBimQxMKbaS+nDDOfFOvmSb0tRYfvDiNKbl3bptcGYRwfnBUZHC6bBjtCV6Dcm5Cs=@vger.kernel.org X-Gm-Message-State: AOJu0YxKn6hNsILehdbkO/+82ENZluBlyBsGOJQQGIZ4v+yg4M6QLGUc tQf0hWa+iV8c27viGmhrhOThPP4Bzli5mYVCcIsNh2vr0T8KjJkq0TmeWHls1mE= X-Gm-Gg: ASbGncsZTNuz3kVY2oa3vkZn1dQbec/4XcG5TP0hownU739t8T+kIjiHs6HGr8BoiAL znrlJayR2ZOF196iQYOxUO3gKJvwN8PxIQQxchq2yei7oPEQ8jnDbth3Gw4vtbG44Att9S771nj 43x7zpkCIAjX9eQz61r6r2E0swTH5OHk4CEsUt3VcRBL1MQ9YFtIpw+peEEjGjrOvKGvKq5fUjd bIiSd2uI5jLZ98z7PParZuFLzp5q8jY0B3fuk+R9tGusGjqHb7Y2bOh5Se12GZvWkrA9OfP4pgM c+aIIdE3n/k9iUP78/ioQ/637fTpe39sczwokhiE8iM= X-Google-Smtp-Source: AGHT+IH+E7+zyXLvCWAiXzV6o5l6ebSPI18pr2IFPQuGjkRm7m10xzWPBeH3vqaVimkyMkQaYvC5FA== X-Received: by 2002:a17:902:e750:b0:215:2bfb:3cd7 with SMTP id d9443c01a7336-21c3562959bmr192927435ad.10.1737782760661; Fri, 24 Jan 2025 21:26:00 -0800 (PST) Received: from C02DV8HUMD6R.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ac496bbdc9esm2563856a12.63.2025.01.24.21.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 21:26:00 -0800 (PST) From: Abel Wu To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Yury Norov , Bitao Hu , Abel Wu , Andrew Morton , Thomas Gleixner , Chen Ridong Cc: cgroups@vger.kernel.org (open list:CONTROL GROUP (CGROUP)), linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/3] cgroup/rstat: Fix forceidle time in cpu.stat Date: Sat, 25 Jan 2025 13:25:10 +0800 Message-Id: <20250125052521.19487-2-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20250125052521.19487-1-wuyun.abel@bytedance.com> References: <20250125052521.19487-1-wuyun.abel@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- kernel/cgroup/rstat.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 5877974ece92..c2784c317cdd 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -613,36 +613,33 @@ static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat 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() */ -- 2.37.3